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:55:15PM +0100, Roy Marples wrote:
> David Young wrote:
>> 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.
>
> So something like this?
>
> 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:51:33 -0000
> @@ -1061,7 +1061,8 @@ sysctl_iflist(int af, struct rt_walkarg
>                         }
>                 }
>                 IFADDR_FOREACH(ifa, ifp) {
> -                       if (af && af != ifa->ifa_addr->sa_family)
> +                       if (ifa == ifp->if_dl ||
> +                           (af && af != ifa->ifa_addr->sa_family))
>                                 continue;
>                         info.rti_info[RTAX_IFA] = ifa->ifa_addr;
>                         info.rti_info[RTAX_NETMASK] = ifa->ifa_netmask;

The kernel copies out the interface information in an RTM_IFINFO
message, then each of the addresses in an RTM_NEWADDR message.  There
is overlap between the _IFINFO and _NEWADDR information, but it's not
a *total* overlap, so you really do have to copy out one _NEWADDR per
ifaddr.

Have another look at the doco and source for getifaddrs(3).  I think
that if there is a bug, you will find it there.

Dave

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


Home | Main Index | Thread Index | Old Index