[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(usagi-users 02110) Re: multiproto bind() ?



I tried to use getnameinfo

----
     host is char buf[NI_MAXHOST];

     for(;;) {

         slen  = res->ai_addrlen;
         ptr1  = malloc(sizeof(int));
         *ptr1 = accept(listenfd, caddr,  &slen);

        if((k=getnameinfo(res->ai_addr,res->ai_addrlen,buf,sizeof(buf),NULL,0,NI_NAMEREQD)) <0) {
            printf("%s\n",gai_strerror(k));
        }
     }

it prints:

buf = |

? any help
I saw
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/ipv6_enabled_server_code_2.asp

they are using multiple listenfds to handle this ?

-- basit

On Sun, 19 Jan 2003, YOSHIFUJI Hideaki / [iso-2022-jp] 吉藤英明 wrote:

> In article <20030119015348.W43691-100000@xxxxxxxxxxxxxxxxxxxx> (at Sun, 19 Jan 2003 01:59:46 -0600 (CST)), Abdul Basit <basit@xxxxxxxx> says:
>
> >          slen  = res->ai_addrlen;
> >          ptr  = malloc(sizeof(int));
> >          *ptr = accept(listenfd, caddr, &slen);
> >
> >        // using res->ai_family 'd give same result.
> >          printf("%uc\n",caddr->sa_family);
>                      ~garbage?
> >        }
> >
> > i want to distinguish between clients coming to ipv4 or ipv6
> > and print client address ? if i would get sa_family correct
> > i can switch(family) { and case for AF_INET and AF_INET6 and
> > use inet_ntop to print address ? but i am getting same family
> > always (28c/bsd and 10c/linux --> AF_INET6)
>
> please use getnameinfo().
>
> --yoshfuji
>
>
>