X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=interfaces.c;h=eed07530150ea66bac0814cbedeb014a1e409d5b;hb=refs%2Ftags%2Fdebian%2F1.7.2p6-1;hp=b3dc14e91454a9475c1a5fa70e335b092dc31cb9;hpb=a922b9e5432b28b092428393180b1a2c2569f708;p=debian%2Fsudo diff --git a/interfaces.c b/interfaces.c index b3dc14e..eed0753 100644 --- a/interfaces.c +++ b/interfaces.c @@ -1,5 +1,6 @@ /* - * Copyright (c) 1996, 1998-2005 Todd C. Miller + * Copyright (c) 1996, 1998-2005, 2007-2009 + * Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -19,7 +20,7 @@ */ /* - * Supress a warning w/ gcc on Digital UN*X. + * Suppress a warning w/ gcc on Digital UN*X. * The system headers should really do this.... */ #if defined(__osf__) && !defined(__cplusplus) @@ -59,11 +60,6 @@ struct rtentry; #ifdef HAVE_UNISTD_H # include #endif /* HAVE_UNISTD_H */ -#ifdef HAVE_ERR_H -# include -#else -# include "emul/err.h" -#endif /* HAVE_ERR_H */ #include #include #ifdef _ISC @@ -88,10 +84,10 @@ struct rtentry; #include "sudo.h" #include "interfaces.h" -#ifndef lint -__unused static const char rcsid[] = "$Sudo: interfaces.c,v 1.72.2.6 2007/08/14 15:19:25 millert Exp $"; -#endif /* lint */ - +/* Minix apparently lacks IFF_LOOPBACK */ +#ifndef IFF_LOOPBACK +# define IFF_LOOPBACK 0 +#endif #ifdef HAVE_GETIFADDRS @@ -104,7 +100,7 @@ load_interfaces() { struct ifaddrs *ifa, *ifaddrs; struct sockaddr_in *sin; -#ifdef AF_INET6 +#ifdef HAVE_IN6_ADDR struct sockaddr_in6 *sin6; #endif int i; @@ -121,7 +117,7 @@ load_interfaces() switch(ifa->ifa_addr->sa_family) { case AF_INET: -#ifdef AF_INET6 +#ifdef HAVE_IN6_ADDR case AF_INET6: #endif num_interfaces++; @@ -143,26 +139,34 @@ load_interfaces() switch(ifa->ifa_addr->sa_family) { case AF_INET: sin = (struct sockaddr_in *)ifa->ifa_addr; + if (sin == NULL) + continue; memcpy(&interfaces[i].addr, &sin->sin_addr, sizeof(struct in_addr)); sin = (struct sockaddr_in *)ifa->ifa_netmask; + if (sin == NULL) + continue; memcpy(&interfaces[i].netmask, &sin->sin_addr, sizeof(struct in_addr)); interfaces[i].family = AF_INET; i++; break; -#ifdef AF_INET6 +#ifdef HAVE_IN6_ADDR case AF_INET6: sin6 = (struct sockaddr_in6 *)ifa->ifa_addr; + if (sin6 == NULL) + continue; memcpy(&interfaces[i].addr, &sin6->sin6_addr, sizeof(struct in6_addr)); sin6 = (struct sockaddr_in6 *)ifa->ifa_netmask; + if (sin6 == NULL) + continue; memcpy(&interfaces[i].netmask, &sin6->sin6_addr, sizeof(struct in6_addr)); interfaces[i].family = AF_INET6; i++; break; -#endif /* AF_INET6 */ +#endif /* HAVE_IN6_ADDR */ } } #ifdef HAVE_FREEIFADDRS @@ -193,7 +197,7 @@ load_interfaces() sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) - err(1, "cannot open socket"); + error(1, "cannot open socket"); /* * Get interface configuration or return (leaving num_interfaces == 0) @@ -249,7 +253,7 @@ load_interfaces() continue; #ifdef SIOCGIFFLAGS - memset(&ifr_tmp, 0, sizeof(ifr_tmp)); + zero_bytes(&ifr_tmp, sizeof(ifr_tmp)); strncpy(ifr_tmp.ifr_name, ifr->ifr_name, sizeof(ifr_tmp.ifr_name) - 1); if (ioctl(sock, SIOCGIFFLAGS, (caddr_t) &ifr_tmp) < 0) #endif @@ -267,7 +271,7 @@ load_interfaces() previfname = ifr->ifr_name; /* Get the netmask. */ - (void) memset(&ifr_tmp, 0, sizeof(ifr_tmp)); + zero_bytes(&ifr_tmp, sizeof(ifr_tmp)); strncpy(ifr_tmp.ifr_name, ifr->ifr_name, sizeof(ifr_tmp.ifr_name) - 1); #ifdef SIOCGIFNETMASK #ifdef _ISC @@ -325,7 +329,7 @@ void dump_interfaces() { int i; -#ifdef AF_INET6 +#ifdef HAVE_IN6_ADDR char addrbuf[INET6_ADDRSTRLEN], maskbuf[INET6_ADDRSTRLEN]; #endif @@ -336,7 +340,7 @@ dump_interfaces() printf("\t%s / ", inet_ntoa(interfaces[i].addr.ip4)); puts(inet_ntoa(interfaces[i].netmask.ip4)); break; -#ifdef AF_INET6 +#ifdef HAVE_IN6_ADDR case AF_INET6: inet_ntop(AF_INET6, &interfaces[i].addr.ip6, addrbuf, sizeof(addrbuf)); @@ -344,7 +348,7 @@ dump_interfaces() maskbuf, sizeof(maskbuf)); printf("\t%s / %s\n", addrbuf, maskbuf); break; -#endif /* AF_INET6 */ +#endif /* HAVE_IN6_ADDR */ } } }