From 412c954afacf0e5f62ff66ae870df18444b4a799 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sun, 26 Sep 2004 11:11:28 +0000 Subject: [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]. --- sunrpc/clnt_udp.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'sunrpc/clnt_udp.c') 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 #include #include +#include #ifdef USE_IN_LIBIO # include #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 -- cgit v1.2.3