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 <lha@h5l.org>
This commit is contained in:
Anton Lundin
2009-08-20 07:49:26 -07:00
committed by Love Hornquist Astrand
parent 86d22e328f
commit 76afc31e9b

View File

@@ -1010,11 +1010,12 @@ getifaddrs2(struct ifaddrs **ifap,
#if defined(HAVE_IPV6) && defined(SIOCGLIFCONF) && defined(SIOCGLIFFLAGS) #if defined(HAVE_IPV6) && defined(SIOCGLIFCONF) && defined(SIOCGLIFFLAGS)
static int static int
getlifaddrs2(struct ifaddrs **ifap, getlifaddrs2(struct ifaddrs **ifap,
int af, int siocgifconf, int siocgifflags, int siocgifconf, int siocgifflags,
size_t ifreq_sz) size_t ifreq_sz)
{ {
int ret; int ret;
int fd; int fd_inet6;
int fd_inet;
size_t buf_size; size_t buf_size;
char *buf; char *buf;
struct lifconf ifconf; struct lifconf ifconf;
@@ -1027,10 +1028,16 @@ getlifaddrs2(struct ifaddrs **ifap,
buf = NULL; buf = NULL;
memset (&sa_zero, 0, sizeof(sa_zero)); memset (&sa_zero, 0, sizeof(sa_zero));
fd = socket(af, SOCK_DGRAM, 0); fd_inet6 = socket(AF_INET6, SOCK_DGRAM, 0);
if (fd < 0) if (fd_inet6 < 0)
return -1; return -1;
fd_inet = socket(AF_INET, SOCK_DGRAM, 0);
if (fd_inet < 0) {
close(fd_inet6);
return -1;
}
buf_size = 8192; buf_size = 8192;
for (;;) { for (;;) {
buf = calloc(1, buf_size); buf = calloc(1, buf_size);
@@ -1048,7 +1055,7 @@ getlifaddrs2(struct ifaddrs **ifap,
/* /*
* Solaris returns EINVAL when the buffer is too small. * 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; ret = errno;
goto error_out; goto error_out;
} }
@@ -1086,9 +1093,11 @@ getlifaddrs2(struct ifaddrs **ifap,
memset (&ifreq, 0, sizeof(ifreq)); memset (&ifreq, 0, sizeof(ifreq));
memcpy (ifreq.lifr_name, ifr->lifr_name, sizeof(ifr->lifr_name)); memcpy (ifreq.lifr_name, ifr->lifr_name, sizeof(ifr->lifr_name));
if (ioctl(fd, siocgifflags, &ifreq) < 0) { if (ioctl(fd_inet6, siocgifflags, &ifreq) < 0) {
ret = errno; if (ioctl(fd_inet, siocgifflags, &ifreq) < 0) {
goto error_out; ret = errno;
goto error_out;
}
} }
*end = malloc(sizeof(**end)); *end = malloc(sizeof(**end));
@@ -1142,12 +1151,14 @@ getlifaddrs2(struct ifaddrs **ifap,
} }
*ifap = start; *ifap = start;
close(fd); close(fd_inet6);
close(fd_inet);
free(buf); free(buf);
return 0; return 0;
error_out: error_out:
rk_freeifaddrs(start); rk_freeifaddrs(start);
close(fd); close(fd_inet6);
close(fd_inet);
free(buf); free(buf);
errno = ret; errno = ret;
return -1; return -1;
@@ -1166,7 +1177,7 @@ rk_getifaddrs(struct ifaddrs **ifap)
#endif #endif
#if defined(HAVE_IPV6) && defined(SIOCGLIFCONF) && defined(SIOCGLIFFLAGS) #if defined(HAVE_IPV6) && defined(SIOCGLIFCONF) && defined(SIOCGLIFFLAGS)
if (ret) if (ret)
ret = getlifaddrs2 (ifap, AF_INET6, SIOCGLIFCONF, SIOCGLIFFLAGS, ret = getlifaddrs2 (ifap, SIOCGLIFCONF, SIOCGLIFFLAGS,
sizeof(struct lifreq)); sizeof(struct lifreq));
#endif #endif
#if defined(HAVE_IPV6) && defined(SIOCGIFCONF) #if defined(HAVE_IPV6) && defined(SIOCGIFCONF)