aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/gnu
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2002-09-20 20:34:06 +0000
committerRoland McGrath <roland@gnu.org>2002-09-20 20:34:06 +0000
commit9db6ee8d2fa48ade4451c0de80980b7f242c0f17 (patch)
tree2054d18cc95669fa2d6686cb9565a07407d26a84 /sysdeps/gnu
parentdab9837091a70e6ed6ea0d6474e0508ea6fccde5 (diff)
downloadglibc-9db6ee8d2fa48ade4451c0de80980b7f242c0f17.tar
glibc-9db6ee8d2fa48ade4451c0de80980b7f242c0f17.tar.gz
glibc-9db6ee8d2fa48ade4451c0de80980b7f242c0f17.tar.bz2
glibc-9db6ee8d2fa48ade4451c0de80980b7f242c0f17.zip
* sysdeps/generic/ifreq.h (__if_nextreq): New function.
* sysdeps/unix/sysv/linux/ifreq.h (__if_nextreq): New function. * sysdeps/mach/hurd/ifreq.h (__if_nextreq): New function. * sysdeps/gnu/ifaddrs.c (getifaddrs): Use __if_nextreq for iterating through the list of interfaces. * resolv/res_hconf.c (_res_hconf_reorder_addrs): Likewise. * sysdeps/unix/grantpt.c (pts_name): Set errno when __ptsname_r fails. Reported by Bruno Haible <bruno@clisp.org>.
Diffstat (limited to 'sysdeps/gnu')
-rw-r--r--sysdeps/gnu/ifaddrs.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/sysdeps/gnu/ifaddrs.c b/sysdeps/gnu/ifaddrs.c
index e0a5b424f0..0c1ae5bf05 100644
--- a/sysdeps/gnu/ifaddrs.c
+++ b/sysdeps/gnu/ifaddrs.c
@@ -40,7 +40,7 @@ getifaddrs (struct ifaddrs **ifap)
Some different mechanism entirely must be used for IPv6. */
int fd = __socket (AF_INET, SOCK_DGRAM, 0);
struct ifreq *ifreqs;
- int nifs, i;
+ int nifs;
if (fd < 0)
return -1;
@@ -64,6 +64,8 @@ getifaddrs (struct ifaddrs **ifap)
struct sockaddr addr, netmask, broadaddr;
char name[IF_NAMESIZE];
} *storage;
+ struct ifreq *ifr;
+ int i;
storage = malloc (nifs * sizeof storage[0]);
if (storage == NULL)
@@ -74,10 +76,9 @@ getifaddrs (struct ifaddrs **ifap)
}
i = 0;
+ ifr = ifreqs;
do
{
- struct ifreq *const ifr = &ifreqs[i];
-
/* Fill in all pointers to the storage we've already allocated. */
storage[i].ia.ifa_next = &storage[i + 1].ia;
storage[i].ia.ifa_addr = &storage[i].addr;
@@ -97,6 +98,7 @@ getifaddrs (struct ifaddrs **ifap)
storage[i].ia.ifa_flags = ifr->ifr_flags;
ifr->ifr_addr = storage[i].addr;
+
if (__ioctl (fd, SIOCGIFNETMASK, ifr) < 0)
break;
storage[i].netmask = ifr->ifr_netmask;
@@ -121,6 +123,7 @@ getifaddrs (struct ifaddrs **ifap)
storage[i].ia.ifa_data = NULL; /* Nothing here for now. */
+ ifr = __if_nextreq (ifr);
} while (++i < nifs);
if (i < nifs) /* Broke out early on error. */
{
@@ -129,6 +132,7 @@ getifaddrs (struct ifaddrs **ifap)
__if_freereq (ifreqs, nifs);
return -1;
}
+
storage[i - 1].ia.ifa_next = NULL;
*ifap = &storage[0].ia;