On 04/10/13(Fri) 11:46, Stuart Henderson wrote:
> It seems that for some interface types (I noticed vlan and lo), a netmask
> with af==0 is returned by getifaddrs().
> 
> Not sure if this was always broken or introduced more recently; happens
> on at least 5.3 and -current so it's not anything particularly recent.
> 
> Demonstration code (yes I know it's crappy but it does show the problem -
> other code also hits it, I noticed this when investigating problems
> reported with 'samenet' in postgresql).

I can reproduce this problem here for IPv4 and IPv6 addresses, but it
doesn't happen when the address is obtained with dhclient(8). 

This small ifconfig diff fixes it, not sure if it's the way to go,
but we might want to fix that in the kernel too.

Index: ifconfig.c
===================================================================
RCS file: /home/ncvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.270
diff -u -p -r1.270 ifconfig.c
--- ifconfig.c  13 Sep 2013 14:32:53 -0000      1.270
+++ ifconfig.c  4 Oct 2013 11:22:32 -0000
@@ -4437,8 +4437,7 @@ in_getaddr(const char *s, int which)
 
        bzero(&tsin, sizeof(tsin));
        sin->sin_len = sizeof(*sin);
-       if (which != MASK)
-               sin->sin_family = AF_INET;
+       sin->sin_family = AF_INET;
 
        if (which == ADDR && strrchr(s, '/') != NULL &&
            (bits = inet_net_pton(AF_INET, s, &tsin.sin_addr,
@@ -4472,8 +4471,7 @@ in_getprefix(const char *plen, int which
                errx(1, "prefix %s: %s", plen, errmsg);
 
        sin->sin_len = sizeof(*sin);
-       if (which != MASK)
-               sin->sin_family = AF_INET;
+       sin->sin_family = AF_INET;
        if ((len == 0) || (len == 32)) {
                memset(&sin->sin_addr, 0xff, sizeof(struct in_addr));
                return;
@@ -4601,8 +4599,7 @@ in6_getprefix(const char *plen, int whic
                errx(1, "prefix %s: %s", plen, errmsg);
 
        sin6->sin6_len = sizeof(*sin6);
-       if (which != MASK)
-               sin6->sin6_family = AF_INET6;
+       sin6->sin6_family = AF_INET6;
        if ((len == 0) || (len == 128)) {
                memset(&sin6->sin6_addr, 0xff, sizeof(struct in6_addr));
                return;

Reply via email to