added Andy's new ISC changes

This commit is contained in:
Todd C. Miller
1995-04-30 00:15:10 +00:00
parent c93d5f8064
commit 431c0a7e5e

54
sudo.c
View File

@@ -91,6 +91,9 @@ static char rcsid[] = "$Id$";
#include <sys/sioctl.h> #include <sys/sioctl.h>
#include <sys/stropts.h> #include <sys/stropts.h>
#include <net/errno.h> #include <net/errno.h>
#define STRSET(cmd, param, len) {strioctl.ic_cmd=(cmd);\
strioctl.ic_dp=(param);\
strioctl.ic_len=(len);}
#endif /* _ISC */ #endif /* _ISC */
#ifdef _MIPS #ifdef _MIPS
#include <net/soioctl.h> #include <net/soioctl.h>
@@ -595,18 +598,15 @@ static void load_interfaces()
char buf[BUFSIZ]; char buf[BUFSIZ];
int sock, i, j; int sock, i, j;
#ifdef _ISC #ifdef _ISC
struct ifreq *ifrp; struct ifreq *ifr;
struct ifconf *ifc;
struct strioctl strioctl; struct strioctl strioctl;
#endif /* _ISC */ #endif /* _ISC */
/* so we can skip localhost and its ilk */ /* so we can skip localhost and its ilk */
localhost_mask = inet_addr("127.0.0.0"); localhost_mask = inet_addr("127.0.0.0");
#ifdef _ISC sock = socket(AF_INET, SOCK_DGRAM, 0);
sock = socket(AF_INET, SOCK_STREAM, 0);
#else
sock = socket(AF_INET, SOCK_DGRAM, 0);
#endif /* _ISC */
if (sock < 0) { if (sock < 0) {
perror("socket"); perror("socket");
exit(1); exit(1);
@@ -618,32 +618,27 @@ static void load_interfaces()
ifconf.ifc_len = sizeof(buf); ifconf.ifc_len = sizeof(buf);
ifconf.ifc_buf = buf; ifconf.ifc_buf = buf;
#ifdef _ISC #ifdef _ISC
strioctl.ic_cmd = SIOCGIFCONF; ifc = (struct ifconf *)buf;
strioctl.ic_dp = (char *)&ifconf; ifc->ifc_len = sizeof (buf) - sizeof(struct ifconf);
strioctl.ic_len = sizeof(ifconf); STRSET(SIOCGIFCONF, (caddr_t)ifc, sizeof(buf));
if (ioctl(sock, I_STR, &strioctl) < 0) { if (ioctl(sock, I_STR, &strioctl) < 0) {
/* networking probably not installed in kernel */ /* networking probably not installed in kernel */
return; return;
} }
ifconf = *ifc;
/*
* Still can't get any more than the loopback interface out
* of the INTERACTIVE ioctl :-(
*/
num_interfaces = 1;
#else #else
if (ioctl(sock, SIOCGIFCONF, (char *)(&ifconf)) < 0) { if (ioctl(sock, SIOCGIFCONF, (char *)(&ifconf)) < 0) {
/* networking probably not installed in kernel */ /* networking probably not installed in kernel */
return; return;
} }
#endif /* _ISC */
/* /*
* find out how many interfaces exist * find out how many interfaces exist
*/ */
num_interfaces = ifconf.ifc_len / sizeof(struct ifreq); num_interfaces = ifconf.ifc_len / sizeof(struct ifreq);
#endif /* _ISC */
/* /*
* malloc() space for interfaces array * malloc() space for interfaces array
*/ */
@@ -658,19 +653,31 @@ static void load_interfaces()
/* /*
* for each interface, get the ip address and netmask * for each interface, get the ip address and netmask
*/ */
#ifdef _ISC
ifr = (struct ifreq *)(ifc->ifc_req);
for (i = 0, j = 0; i < num_interfaces; i++, ifr++) {
(void) strncpy(ifreq.ifr_name, ifr->ifr_name,
sizeof(ifr->ifr_name));
/* get the ip address */
STRSET(SIOCGIFADDR, (caddr_t)ifr, sizeof(ifreq));
if (ioctl(sock, I_STR, &strioctl) < 0) {
/* non-fatal error if interface is down or not supported */
if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT)
continue;
(void) fprintf(stderr, "%s: Error, ioctl: SIOCGIFADDR ", Argv[0]);
perror("");
exit(1);
}
sin = (struct sockaddr_in *)&ifr->ifr_addr;
#else
for (i = 0, j = 0; i < num_interfaces; i++) { for (i = 0, j = 0; i < num_interfaces; i++) {
(void) strncpy(ifreq.ifr_name, ifconf.ifc_req[i].ifr_name, (void) strncpy(ifreq.ifr_name, ifconf.ifc_req[i].ifr_name,
sizeof(ifreq.ifr_name)); sizeof(ifreq.ifr_name));
/* get the ip address */ /* get the ip address */
#ifdef _ISC
strioctl.ic_cmd = SIOCGIFADDR;
strioctl.ic_dp = (char *)&ifreq;
strioctl.ic_len = sizeof(ifreq);
if (ioctl(sock, I_STR, &strioctl) < 0) {
#else
if (ioctl(sock, SIOCGIFADDR, (caddr_t)(&ifreq))) { if (ioctl(sock, SIOCGIFADDR, (caddr_t)(&ifreq))) {
#endif /* _ISC */
/* non-fatal error if interface is down or not supported */ /* non-fatal error if interface is down or not supported */
if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT)
continue; continue;
@@ -680,6 +687,7 @@ static void load_interfaces()
exit(1); exit(1);
} }
sin = (struct sockaddr_in *)&ifreq.ifr_addr; sin = (struct sockaddr_in *)&ifreq.ifr_addr;
#endif /* _ISC */
/* make sure we don't have a dupe (usually consecutive) */ /* make sure we don't have a dupe (usually consecutive) */
if (j > 0 && memcmp(&interfaces[j-1].addr, &(sin->sin_addr), if (j > 0 && memcmp(&interfaces[j-1].addr, &(sin->sin_addr),