diff options
author | Ulrich Drepper <drepper@redhat.com> | 2004-09-26 11:11:28 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2004-09-26 11:11:28 +0000 |
commit | 412c954afacf0e5f62ff66ae870df18444b4a799 (patch) | |
tree | 8ddcfdae9cc216d068b171a1bda2b4e83a6bd04c | |
parent | 6497a1d081505a2d0b50e06fcdca71d5f0a11192 (diff) | |
download | glibc-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].
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | sunrpc/clnt_udp.c | 35 | ||||
-rw-r--r-- | sunrpc/get_myaddr.c | 53 | ||||
-rw-r--r-- | sunrpc/pmap_clnt.c | 56 | ||||
-rw-r--r-- | sunrpc/pmap_rmt.c | 65 |
5 files changed, 90 insertions, 126 deletions
diff --git a/ChangeLog b/ChangeLog index 91a59dab05..0f80b6c97a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2004-09-26 Ulrich Drepper <drepper@redhat.com> + * 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]. + * sysdeps/generic/s_fdim.c: Handle +inf/+inf * sysdeps/generic/s_fdimf.c: Likewise. * sysdeps/generic/s_fdiml.c: Likewise. 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 diff --git a/sunrpc/get_myaddr.c b/sunrpc/get_myaddr.c index 7a4bb8cb6f..ee822970f9 100644 --- a/sunrpc/get_myaddr.c +++ b/sunrpc/get_myaddr.c @@ -46,6 +46,7 @@ static char sccsid[] = "@(#)get_myaddress.c 1.4 87/08/11 Copyr 1984 Sun Micro"; #include <unistd.h> #include <libintl.h> #include <net/if.h> +#include <ifaddrs.h> #include <sys/ioctl.h> /* Order of following two #includes reversed by roland@gnu */ #include <netinet/in.h> @@ -60,50 +61,42 @@ static char sccsid[] = "@(#)get_myaddress.c 1.4 87/08/11 Copyr 1984 Sun Micro"; void get_myaddress (struct sockaddr_in *addr) { - int s; - char buf[BUFSIZ]; - struct ifconf ifc; - struct ifreq ifreq, *ifr; - int len, loopback = 0; + struct ifaddrs *ifa; - if ((s = __socket (AF_INET, SOCK_DGRAM, 0)) < 0) + if (getifaddrs (&ifa) == 0) { - perror ("get_myaddress: socket"); - exit (1); - } - ifc.ifc_len = sizeof (buf); - ifc.ifc_buf = buf; - if (__ioctl (s, SIOCGIFCONF, (char *) &ifc) < 0) - { - perror (_("get_myaddress: ioctl (get interface configuration)")); + perror ("get_myaddress: getifaddrs"); exit (1); } + int loopback = 0; + struct ifaddrs *run; + again: - ifr = ifc.ifc_req; - for (len = ifc.ifc_len; len; len -= sizeof ifreq) + run = ifa; + while (run != NULL) { - ifreq = *ifr; - if (__ioctl (s, SIOCGIFFLAGS, (char *) &ifreq) < 0) + if ((run->ifa_flags & IFF_UP) && run->ifa_addr->sa_family == AF_INET + && (!(run->ifa_flags & IFF_LOOPBACK) + || (loopback == 1 && (run->ifa_flags & IFF_LOOPBACK)))) { - perror ("get_myaddress: ioctl"); - exit (1); - } - if ((ifreq.ifr_flags & IFF_UP) && (ifr->ifr_addr.sa_family == AF_INET) - && (!(ifreq.ifr_flags & IFF_LOOPBACK) || - (loopback == 1 && (ifreq.ifr_flags & IFF_LOOPBACK)))) - { - *addr = *((struct sockaddr_in *) &ifr->ifr_addr); + *addr = *((struct sockaddr_in *) run->ifa_addr); addr->sin_port = htons (PMAPPORT); - __close (s); - return; + goto out; } - ifr++; + + run = run->ifa_next; } + if (loopback == 0) { loopback = 1; goto again; } - __close (s); + out: + freeifaddrs (ifa); + + /* The function is horribly specified. It does not return any error + if no interface is up. Probably this won't happen (at least + loopback is there) but still... */ } diff --git a/sunrpc/pmap_clnt.c b/sunrpc/pmap_clnt.c index d88487d8f4..c968511e96 100644 --- a/sunrpc/pmap_clnt.c +++ b/sunrpc/pmap_clnt.c @@ -38,6 +38,7 @@ #include <unistd.h> #include <libintl.h> #include <net/if.h> +#include <ifaddrs.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <netinet/in.h> @@ -54,52 +55,41 @@ static bool_t __get_myaddress (struct sockaddr_in *addr) { - int s; - char buf[BUFSIZ]; - struct ifconf ifc; - struct ifreq ifreq, *ifr; - int len, loopback = 1; + struct ifaddrs *ifa; - if ((s = __socket (AF_INET, SOCK_DGRAM, 0)) < 0) + if (getifaddrs (&ifa) == 0) { - perror ("__get_myaddress: socket"); - exit (1); - } - ifc.ifc_len = sizeof (buf); - ifc.ifc_buf = buf; - if (__ioctl (s, SIOCGIFCONF, (char *) &ifc) < 0) - { - perror (_("__get_myaddress: ioctl (get interface configuration)")); + perror ("get_myaddress: getifaddrs"); exit (1); } + int loopback = 1; + struct ifaddrs *run; + again: - ifr = ifc.ifc_req; - for (len = ifc.ifc_len; len; len -= sizeof ifreq) + run = ifa; + while (run != NULL) { - ifreq = *ifr; - if (__ioctl (s, SIOCGIFFLAGS, (char *) &ifreq) < 0) - { - perror ("__get_myaddress: ioctl"); - exit (1); - } - if ((ifreq.ifr_flags & IFF_UP) && (ifr->ifr_addr.sa_family == AF_INET) - && ((ifreq.ifr_flags & IFF_LOOPBACK) || (loopback == 0))) - { - *addr = *((struct sockaddr_in *) &ifr->ifr_addr); - addr->sin_port = htons (PMAPPORT); - __close (s); - return TRUE; - } - ifr++; + if ((run->ifa_flags & IFF_UP) && run->ifa_addr->sa_family == AF_INET + && ((run->ifa_flags & IFF_LOOPBACK) || loopback == 0)) + { + *addr = *((struct sockaddr_in *) run->ifa_addr); + addr->sin_port = htons (PMAPPORT); + goto out; + } + + run = run->ifa_next; } + if (loopback == 1) { loopback = 0; goto again; } - __close (s); - return FALSE; + out: + freeifaddrs (ifa); + + return run == NULL ? FALSE : TRUE; } diff --git a/sunrpc/pmap_rmt.c b/sunrpc/pmap_rmt.c index c02f546b36..e446f5e608 100644 --- a/sunrpc/pmap_rmt.c +++ b/sunrpc/pmap_rmt.c @@ -53,6 +53,7 @@ static char sccsid[] = "@(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro"; #undef _POSIX_SOURCE /* Ultrix <sys/param.h> needs --roland@gnu */ #include <sys/param.h> /* Ultrix needs before net/if --roland@gnu */ #include <net/if.h> +#include <ifaddrs.h> #include <sys/ioctl.h> #include <arpa/inet.h> #define MAX_BROADCAST_SIZE 1400 @@ -174,55 +175,31 @@ INTDEF(xdr_rmtcallres) static int internal_function -getbroadcastnets (struct in_addr *addrs, int sock, char *buf) - /* int sock: any valid socket will do */ - /* char *buf: why allocate more when we can use existing... */ +getbroadcastnets (struct in_addr *addrs, int naddrs) { - struct ifconf ifc; - struct ifreq ifreq, *ifr; - struct sockaddr_in *sin; - int n, i; + struct ifaddrs *ifa; - ifc.ifc_len = UDPMSGSIZE; - ifc.ifc_buf = buf; - if (__ioctl (sock, SIOCGIFCONF, (char *) &ifc) < 0) + if (getifaddrs (&ifa) == 0) { - perror (_("broadcast: ioctl (get interface configuration)")); - return (0); + perror ("broadcast: getifaddrs"); + return 0; } - ifr = ifc.ifc_req; - for (i = 0, n = ifc.ifc_len / sizeof (struct ifreq); n > 0; n--, ifr++) + + int i = 0; + struct ifaddrs *run = ifa; + while (run != NULL && i < naddrs) { - ifreq = *ifr; - if (__ioctl (sock, SIOCGIFFLAGS, (char *) &ifreq) < 0) - { - perror (_("broadcast: ioctl (get interface flags)")); - continue; - } - if ((ifreq.ifr_flags & IFF_BROADCAST) && - (ifreq.ifr_flags & IFF_UP) && - ifr->ifr_addr.sa_family == AF_INET) - { - sin = (struct sockaddr_in *) &ifr->ifr_addr; -#ifdef SIOCGIFBRDADDR /* 4.3BSD */ - if (__ioctl (sock, SIOCGIFBRDADDR, (char *) &ifreq) < 0) - { - addrs[i++] = inet_makeaddr (inet_netof - /* Changed to pass struct instead of s_addr member - by roland@gnu. */ - (sin->sin_addr), INADDR_ANY); - } - else - { - addrs[i++] = ((struct sockaddr_in *) - &ifreq.ifr_addr)->sin_addr; - } -#else /* 4.2 BSD */ - addrs[i++] = inet_makeaddr (inet_netof - (sin->sin_addr.s_addr), INADDR_ANY); -#endif - } + if ((run->ifa_flags & IFF_BROADCAST) != 0 + && (run->ifa_flags & IFF_UP) != 0 + && run->ifa_addr->sa_family == AF_INET) + /* Copy the broadcast address. */ + addrs[i++] = ((struct sockaddr_in *) run->ifa_broadaddr)->sin_addr; + + run = run->ifa_next; } + + freeifaddrs (ifa); + return i; } @@ -280,7 +257,7 @@ clnt_broadcast (prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult) #endif /* def SO_BROADCAST */ fd.fd = sock; fd.events = POLLIN; - nets = getbroadcastnets (addrs, sock, inbuf); + nets = getbroadcastnets (addrs, sizeof (addrs) / sizeof (addrs[0])); __bzero ((char *) &baddr, sizeof (baddr)); baddr.sin_family = AF_INET; baddr.sin_port = htons (PMAPPORT); |