tech-net archive

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

Re: getifaddrs(3) returns 2 AF_LINK instances for the same interface



On Fri, Apr 17, 2009 at 08:04:46PM +0100, Roy Marples wrote:
> Roy Marples wrote:
>> Martin Husemann wrote:
>>> I'd suspect the libc code...
>>
>> The libc code for getifaddrs.c hasn't changed much since 4.0, and not  
>> for causing this error.
>>
>> I'm guessing it's something in the kernel as it gets info from sysctl...
>
> Yes, a simple off by one error, caused by r1.96 by dyoung

I think that the kernel is doing the right thing.

In your patch, maybe you have equated IFADDR_FIRST(ifp) with ifp->if_dl?
That hasn't been true for a long time.

> Index: sys/net/rtsock.c
> ===================================================================
> RCS file: /cvsroot/src/sys/net/rtsock.c,v
> retrieving revision 1.125
> diff -u -p -r1.125 rtsock.c
> --- sys/net/rtsock.c    2 Apr 2009 21:02:06 -0000       1.125
> +++ sys/net/rtsock.c    17 Apr 2009 19:00:02 -0000
> @@ -1060,7 +1060,12 @@ sysctl_iflist(int af, struct rt_walkarg
>                                 panic("sysctl_iflist(2)");
>                         }
>                 }
> -               IFADDR_FOREACH(ifa, ifp) {
> +               /* We can't use IFADDR_FOREACH because the first address
> +                  is reported above */
> +               for (ifa = IFADDR_NEXT(IFADDR_FIRST(ifp));
> +                   ifa != NULL;
> +                   ifa = IFADDR_NEXT(ifa))
> +               {
>                         if (af && af != ifa->ifa_addr->sa_family)
>                                 continue;
>                         info.rti_info[RTAX_IFA] = ifa->ifa_addr;

Dave

-- 
David Young             OJC Technologies
dyoung%ojctech.com@localhost      Urbana, IL * (217) 278-3933


Home | Main Index | Thread Index | Old Index