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

(usagi-users 02069) Re: recvfrom ipv6



RTFM / STFW
 - usage of recvfrom() is incorrect.
 - head of the buffer will be top of the icmp6 header.
 - use getnameinfo().

In article <20030107084318.F57925-100000@xxxxxxxxxxxxxxxxxxxx> (at Tue, 7 Jan 2003 08:52:28 -0600 (CST)), Abdul Basit <basit@xxxxxxxx> says:

>   struct ip6_hdr *ip6;
>   struct icmp6_hdr *icmp6;
>   struct sockaddr_storage *s6;
                            s6;
>   struct sockaddr_in6 *in6;
>   static char src6host[128];
>   socklen_t len6;
>   struct icmp6_filter fil;
:

>     {
        len6 = sizeof(s6);
>       n6 =
>         recvfrom (sock6fd, buf6,
>                   sizeof (struct ip6_hdr) + sizeof (struct icmp6_hdr), 0,
>                   (struct sockaddr *) s6, &len6);
                                        &s6,
>    if (n6 > 0)
>         {
>           ip6 = (struct ip6_hdr *) buf6;
>           ip6_len = sizeof (struct ip6_hdr);
>           icmp6 = (struct icmp6_hdr *) (buf6 + ip6_len);
>           in6 = (struct sockaddr_in6 *) s6;

            icmp6 = (struct icmp6_hdr *) buf6;
            //buf6 points head of icmp6 header.
> 
>         // a tricky way, inet_ntoa doesn't support struct sockaddr_in6 ..
>           inet_ntop (AF_INET6, &in6->sin6_addr, src6host, sizeof (src6host));

            if (getnameinfo((struct sockaddr *)&s6, len6,
                            src6host, sizeof(src6host), NULL, 0,
			    NI_NUMERICHOST)) 
	         strcpy(src6host, "???");
> 
>      if (icmp6->icmp6_type == 0)
:

-- 
Hideaki YOSHIFUJI @ USAGI Project <yoshfuji@xxxxxxxxxxxxxx>
GPG FP: 9022 65EB 1ECF 3AD1 0BDF  80D8 4807 F894 E062 0EEA