Revert "Try both v4 and v6 socket types"
It broke detection of IPv4 addresses on HP-UX machines with an IPv6
loopback address. Successful resolution of at least one IPv6 address
would then skip doing a separate IPv4 lookup as required by HP-UX.
This reverts commit 76afc31e9b
.
Signed-off-by: Love Hornquist Astrand <lha@h5l.org>
This commit is contained in:

committed by
Love Hornquist Astrand

parent
7fc0f55b89
commit
54817ef6f3
@@ -1010,12 +1010,11 @@ 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 siocgifconf, int siocgifflags,
|
int af, int siocgifconf, int siocgifflags,
|
||||||
size_t ifreq_sz)
|
size_t ifreq_sz)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int fd_inet6;
|
int fd;
|
||||||
int fd_inet;
|
|
||||||
size_t buf_size;
|
size_t buf_size;
|
||||||
char *buf;
|
char *buf;
|
||||||
struct lifconf ifconf;
|
struct lifconf ifconf;
|
||||||
@@ -1028,16 +1027,10 @@ getlifaddrs2(struct ifaddrs **ifap,
|
|||||||
buf = NULL;
|
buf = NULL;
|
||||||
|
|
||||||
memset (&sa_zero, 0, sizeof(sa_zero));
|
memset (&sa_zero, 0, sizeof(sa_zero));
|
||||||
fd_inet6 = socket(AF_INET6, SOCK_DGRAM, 0);
|
fd = socket(af, SOCK_DGRAM, 0);
|
||||||
if (fd_inet6 < 0)
|
if (fd < 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);
|
||||||
@@ -1055,7 +1048,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_inet, siocgifconf, &ifconf) < 0 && errno != EINVAL) {
|
if (ioctl (fd, siocgifconf, &ifconf) < 0 && errno != EINVAL) {
|
||||||
ret = errno;
|
ret = errno;
|
||||||
goto error_out;
|
goto error_out;
|
||||||
}
|
}
|
||||||
@@ -1093,12 +1086,10 @@ 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_inet6, siocgifflags, &ifreq) < 0) {
|
if (ioctl(fd, siocgifflags, &ifreq) < 0) {
|
||||||
if (ioctl(fd_inet, siocgifflags, &ifreq) < 0) {
|
|
||||||
ret = errno;
|
ret = errno;
|
||||||
goto error_out;
|
goto error_out;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
*end = malloc(sizeof(**end));
|
*end = malloc(sizeof(**end));
|
||||||
if (*end == NULL) {
|
if (*end == NULL) {
|
||||||
@@ -1151,14 +1142,12 @@ getlifaddrs2(struct ifaddrs **ifap,
|
|||||||
|
|
||||||
}
|
}
|
||||||
*ifap = start;
|
*ifap = start;
|
||||||
close(fd_inet6);
|
close(fd);
|
||||||
close(fd_inet);
|
|
||||||
free(buf);
|
free(buf);
|
||||||
return 0;
|
return 0;
|
||||||
error_out:
|
error_out:
|
||||||
rk_freeifaddrs(start);
|
rk_freeifaddrs(start);
|
||||||
close(fd_inet6);
|
close(fd);
|
||||||
close(fd_inet);
|
|
||||||
free(buf);
|
free(buf);
|
||||||
errno = ret;
|
errno = ret;
|
||||||
return -1;
|
return -1;
|
||||||
@@ -1177,7 +1166,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, SIOCGLIFCONF, SIOCGLIFFLAGS,
|
ret = getlifaddrs2 (ifap, AF_INET6, SIOCGLIFCONF, SIOCGLIFFLAGS,
|
||||||
sizeof(struct lifreq));
|
sizeof(struct lifreq));
|
||||||
#endif
|
#endif
|
||||||
#if defined(HAVE_IPV6) && defined(SIOCGIFCONF)
|
#if defined(HAVE_IPV6) && defined(SIOCGIFCONF)
|
||||||
|
Reference in New Issue
Block a user