summary refs log tree commit diff
path: root/sunrpc/clnt_udp.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2004-09-26 11:11:28 +0000
committerUlrich Drepper <drepper@redhat.com>2004-09-26 11:11:28 +0000
commit412c954afacf0e5f62ff66ae870df18444b4a799 (patch)
tree8ddcfdae9cc216d068b171a1bda2b4e83a6bd04c /sunrpc/clnt_udp.c
parent6497a1d081505a2d0b50e06fcdca71d5f0a11192 (diff)
downloadglibc-412c954afacf0e5f62ff66ae870df18444b4a799.tar.gz
glibc-412c954afacf0e5f62ff66ae870df18444b4a799.tar.xz
glibc-412c954afacf0e5f62ff66ae870df18444b4a799.zip
[BZ #381]
Update.
	* sunrpc/clnt_udp.c (is_network_up): Use getifaddrs instead of ioctl.
	* sunrpc/get_myaddr.c (get_myaddress): Likewise.
	* sunrpc/pmap_clnt.c (__get_myaddress): Likewise.
	* sunrpc/pmap_rmt.c (getbroadcastnets): Likewise.  Change interface
	to avoid buffer overrun and remove now useless parameters.
	(clnt_broadcast): Adjust caller.  [BZ #381].
Diffstat (limited to 'sunrpc/clnt_udp.c')
-rw-r--r--sunrpc/clnt_udp.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/sunrpc/clnt_udp.c b/sunrpc/clnt_udp.c
index f906173363..1836ff3433 100644
--- a/sunrpc/clnt_udp.c
+++ b/sunrpc/clnt_udp.c
@@ -50,6 +50,7 @@ static char sccsid[] = "@(#)clnt_udp.c 1.39 87/08/11 Copyr 1984 Sun Micro";
 #include <errno.h>
 #include <rpc/pmap_clnt.h>
 #include <net/if.h>
+#include <ifaddrs.h>
 #ifdef USE_IN_LIBIO
 # include <wchar.h>
 #endif
@@ -234,28 +235,24 @@ INTDEF (clntudp_create)
 static int
 is_network_up (int sock)
 {
-  struct ifconf ifc;
-  char buf[UDPMSGSIZE];
-  struct ifreq ifreq, *ifr;
-  int n;
-
-  ifc.ifc_len = sizeof (buf);
-  ifc.ifc_buf = buf;
-  if (__ioctl(sock, SIOCGIFCONF, (char *) &ifc) == 0)
+  struct ifaddrs *ifa;
+
+  if (getifaddrs (&ifa) != 0)
+    return 0;
+
+  struct ifaddrs *run = ifa;
+  while (run != NULL)
     {
-      ifr = ifc.ifc_req;
-      for (n = ifc.ifc_len / sizeof (struct ifreq); n > 0; n--, ifr++)
-	{
-	  ifreq = *ifr;
-	  if (__ioctl (sock, SIOCGIFFLAGS, (char *) &ifreq) < 0)
-	    break;
+      if ((run->ifa_flags & IFF_UP) != 0
+	  && run->ifa_addr->sa_family == AF_INET)
+	break;
 
-	  if ((ifreq.ifr_flags & IFF_UP)
-	      && ifr->ifr_addr.sa_family == AF_INET)
-	    return 1;
-	}
+      run = run->ifa_next;
     }
-  return 0;
+
+  freeifaddrs (ifa);
+
+  return run != NULL;
 }
 
 static enum clnt_stat