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



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

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;

OK to commit?

Thanks

Roy


Home | Main Index | Thread Index | Old Index