From 76afc31e9ba2f37e64c70adc006ade9e37e9ef73 Mon Sep 17 00:00:00 2001 From: Anton Lundin Date: Thu, 20 Aug 2009 07:49:26 -0700 Subject: [PATCH] Try both v4 and v6 socket types The libroken-getifaddrs fails to retrive the ipv6-address in solaris-zones but it might connect over ipv6 anyway, and then the kdc refuses to give a ticket with the cryptic message: kinit: krb5_get_init_creds: No ENC-TS found A saner message ends up in the kdc's logfile. because of a ENXIO when looking for a ipv6-address on the ipv4-interface, the whole getlifaddrs2 fails and getifaddrs2 is run instead and it just discovers the ipv4-address. Signed-off-by: Love Hornquist Astrand --- lib/roken/getifaddrs.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/roken/getifaddrs.c b/lib/roken/getifaddrs.c index 281460add..6acbc1676 100644 --- a/lib/roken/getifaddrs.c +++ b/lib/roken/getifaddrs.c @@ -1010,11 +1010,12 @@ getifaddrs2(struct ifaddrs **ifap, #if defined(HAVE_IPV6) && defined(SIOCGLIFCONF) && defined(SIOCGLIFFLAGS) static int getlifaddrs2(struct ifaddrs **ifap, - int af, int siocgifconf, int siocgifflags, + int siocgifconf, int siocgifflags, size_t ifreq_sz) { int ret; - int fd; + int fd_inet6; + int fd_inet; size_t buf_size; char *buf; struct lifconf ifconf; @@ -1027,10 +1028,16 @@ getlifaddrs2(struct ifaddrs **ifap, buf = NULL; memset (&sa_zero, 0, sizeof(sa_zero)); - fd = socket(af, SOCK_DGRAM, 0); - if (fd < 0) + fd_inet6 = socket(AF_INET6, SOCK_DGRAM, 0); + if (fd_inet6 < 0) return -1; + fd_inet = socket(AF_INET, SOCK_DGRAM, 0); + if (fd_inet < 0) { + close(fd_inet6); + return -1; + } + buf_size = 8192; for (;;) { buf = calloc(1, buf_size); @@ -1048,7 +1055,7 @@ getlifaddrs2(struct ifaddrs **ifap, /* * Solaris returns EINVAL when the buffer is too small. */ - if (ioctl (fd, siocgifconf, &ifconf) < 0 && errno != EINVAL) { + if (ioctl (fd_inet, siocgifconf, &ifconf) < 0 && errno != EINVAL) { ret = errno; goto error_out; } @@ -1086,9 +1093,11 @@ getlifaddrs2(struct ifaddrs **ifap, memset (&ifreq, 0, sizeof(ifreq)); memcpy (ifreq.lifr_name, ifr->lifr_name, sizeof(ifr->lifr_name)); - if (ioctl(fd, siocgifflags, &ifreq) < 0) { - ret = errno; - goto error_out; + if (ioctl(fd_inet6, siocgifflags, &ifreq) < 0) { + if (ioctl(fd_inet, siocgifflags, &ifreq) < 0) { + ret = errno; + goto error_out; + } } *end = malloc(sizeof(**end)); @@ -1142,12 +1151,14 @@ getlifaddrs2(struct ifaddrs **ifap, } *ifap = start; - close(fd); + close(fd_inet6); + close(fd_inet); free(buf); return 0; error_out: rk_freeifaddrs(start); - close(fd); + close(fd_inet6); + close(fd_inet); free(buf); errno = ret; return -1; @@ -1166,7 +1177,7 @@ rk_getifaddrs(struct ifaddrs **ifap) #endif #if defined(HAVE_IPV6) && defined(SIOCGLIFCONF) && defined(SIOCGLIFFLAGS) if (ret) - ret = getlifaddrs2 (ifap, AF_INET6, SIOCGLIFCONF, SIOCGLIFFLAGS, + ret = getlifaddrs2 (ifap, SIOCGLIFCONF, SIOCGLIFFLAGS, sizeof(struct lifreq)); #endif #if defined(HAVE_IPV6) && defined(SIOCGIFCONF)