Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin assume presense of getifaddrs(3).



details:   https://anonhg.NetBSD.org/src/rev/a7c55d50697a
branches:  trunk
changeset: 547236:a7c55d50697a
user:      itojun <itojun%NetBSD.org@localhost>
date:      Thu May 15 14:50:02 2003 +0000

description:
assume presense of getifaddrs(3).

diffstat:

 usr.sbin/rarpd/rarpd.c   |  98 +-----------------------------------------------
 usr.sbin/rbootd/Makefile |   4 +-
 usr.sbin/rbootd/bpf.c    |  80 +--------------------------------------
 3 files changed, 5 insertions(+), 177 deletions(-)

diffs (281 lines):

diff -r 73bd7c60cfa1 -r a7c55d50697a usr.sbin/rarpd/rarpd.c
--- a/usr.sbin/rarpd/rarpd.c    Thu May 15 14:47:49 2003 +0000
+++ b/usr.sbin/rarpd/rarpd.c    Thu May 15 14:50:02 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rarpd.c,v 1.47 2002/10/21 01:33:02 lukem Exp $ */
+/*     $NetBSD: rarpd.c,v 1.48 2003/05/15 14:50:02 itojun Exp $        */
 
 /*
  * Copyright (c) 1990 The Regents of the University of California.
@@ -28,7 +28,7 @@
 #endif /* not lint */
 
 #ifndef lint
-__RCSID("$NetBSD: rarpd.c,v 1.47 2002/10/21 01:33:02 lukem Exp $");
+__RCSID("$NetBSD: rarpd.c,v 1.48 2003/05/15 14:50:02 itojun Exp $");
 #endif
 
 
@@ -70,9 +70,7 @@
 #include <syslog.h>
 #include <unistd.h>
 #include <util.h>
-#ifdef HAVE_IFADDRS_H
 #include <ifaddrs.h>
-#endif
 
 #define FATAL          1       /* fatal error occurred */
 #define NONFATAL       0       /* non fatal error occurred */
@@ -243,7 +241,6 @@
 void
 init_all(void)
 {
-#ifdef HAVE_IFADDRS_H
        struct ifaddrs *ifap, *ifa, *p;
 
        if (getifaddrs(&ifap) != 0) {
@@ -267,52 +264,6 @@
 #undef SIN
        }
        freeifaddrs(ifap);
-#else
-       char inbuf[8192*2];
-       struct ifconf ifc;
-       struct ifreq ifreq, ifrd, *ifr, *ifrp;
-       int fd;
-       int i, len;
-
-       if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
-               rarperr(FATAL, "socket: %s", strerror(errno));
-               /* NOTREACHED */
-       }
-
-       ifc.ifc_len = sizeof(inbuf);
-       ifc.ifc_buf = inbuf;
-       if (ioctl(fd, SIOCGIFCONF, (caddr_t)&ifc) < 0 ||
-           ifc.ifc_len < sizeof(struct ifreq)) {
-               rarperr(FATAL, "init_all: SIOCGIFCONF: %s", strerror(errno));
-               /* NOTREACHED */
-       }
-       ifr = &ifrd;
-       ifrp = ifc.ifc_req;
-       ifreq.ifr_name[0] = '\0';
-       for (i = 0; i < ifc.ifc_len;
-            i += len, ifrp = (struct ifreq *)((caddr_t)ifrp + len)) {
-#define SIN(s) ((struct sockaddr_in *) (s))
-               memcpy(&ifrd, ifrp, sizeof (ifrd));
-               len = sizeof(ifr->ifr_name) + ifr->ifr_addr.sa_len;
-               if (ifr->ifr_addr.sa_family != AF_INET)
-                       continue;
-               if (!strncmp(ifreq.ifr_name, ifr->ifr_name, sizeof(ifr->ifr_name))
-                   && SIN(&ifreq.ifr_addr)->sin_addr.s_addr == SIN(&ifr->ifr_addr)->sin_addr.s_addr)
-                       continue;
-               ifreq = *ifr;
-               if (ioctl(fd, SIOCGIFFLAGS, (caddr_t)ifr) < 0) {
-                       rarperr(FATAL, "init_all: SIOCGIFFLAGS: %s",
-                           strerror(errno));
-                       /* NOTREACHED */
-               }
-               if ((ifr->ifr_flags &
-                   (IFF_UP | IFF_LOOPBACK | IFF_POINTOPOINT)) != IFF_UP)
-                       continue;
-               init_one(ifr->ifr_name, SIN(&ifreq.ifr_addr)->sin_addr.s_addr);
-#undef SIN
-       }
-       (void)close(fd);
-#endif
 }
 
 void
@@ -678,7 +629,6 @@
 void
 lookup_eaddr(char *ifname, u_char *eaddr)
 {
-#ifdef HAVE_IFADDRS_H
        struct ifaddrs *ifap, *ifa;
        struct sockaddr_dl *sdl;
 
@@ -703,50 +653,6 @@
        }
        rarperr(FATAL, "lookup_eaddr: Never saw interface `%s'!", ifname);
        freeifaddrs(ifap);
-#else
-       char inbuf[8192*2];
-       struct ifconf ifc;
-       struct ifreq *ifr;
-       struct sockaddr_dl *sdl;
-       int fd;
-       int i, len;
-
-       /* We cannot use SIOCGIFADDR on the BPF descriptor.
-          We must instead get all the interfaces with SIOCGIFCONF
-          and find the right one.  */
-
-       /* Use datagram socket to get Ethernet address. */
-       if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
-               rarperr(FATAL, "socket: %s", strerror(errno));
-               /* NOTREACHED */
-       }
-
-       ifc.ifc_len = sizeof(inbuf);
-       ifc.ifc_buf = inbuf;
-       if (ioctl(fd, SIOCGIFCONF, (caddr_t)&ifc) < 0 ||
-           ifc.ifc_len < sizeof(struct ifreq)) {
-               rarperr(FATAL, "lookup_eaddr: SIOGIFCONF: %s", strerror(errno));
-               /* NOTREACHED */
-       }
-       ifr = ifc.ifc_req;
-       for (i = 0; i < ifc.ifc_len;
-            i += len, ifr = (struct ifreq *)((caddr_t)ifr + len)) {
-               len = sizeof(ifr->ifr_name) + ifr->ifr_addr.sa_len;
-               sdl = (struct sockaddr_dl *)&ifr->ifr_addr;
-               if (sdl->sdl_family != AF_LINK || sdl->sdl_type != IFT_ETHER ||
-                   sdl->sdl_alen != 6)
-                       continue;
-               if (!strncmp(ifr->ifr_name, ifname, sizeof(ifr->ifr_name))) {
-                       memmove((caddr_t)eaddr, (caddr_t)LLADDR(sdl), 6);
-                       debug("%s: %x:%x:%x:%x:%x:%x",
-                           ifr->ifr_name, eaddr[0], eaddr[1],
-                           eaddr[2], eaddr[3], eaddr[4], eaddr[5]);
-                       return;
-               }
-       }
-
-       rarperr(FATAL, "lookup_eaddr: Never saw interface `%s'!", ifname);
-#endif
 }
 /*
  * Lookup the IP address and network mask of the interface named 'ifname'.
diff -r 73bd7c60cfa1 -r a7c55d50697a usr.sbin/rbootd/Makefile
--- a/usr.sbin/rbootd/Makefile  Thu May 15 14:47:49 2003 +0000
+++ b/usr.sbin/rbootd/Makefile  Thu May 15 14:50:02 2003 +0000
@@ -1,12 +1,10 @@
 #      from: @(#)Makefile      8.1 (Berkeley) 6/4/93
-#      $NetBSD: Makefile,v 1.8 2000/04/13 08:52:44 itojun Exp $
+#      $NetBSD: Makefile,v 1.9 2003/05/15 14:50:50 itojun Exp $
 
 PROG=  rbootd
 SRCS=  bpf.c conf.c parseconf.c rbootd.c rmpproto.c utils.c
 MAN=   rbootd.8
 
-CPPFLAGS+=-DHAVE_IFADDRS_H
-
 LDADD+=        -lutil
 DPADD+=        ${LIBUTIL}
 
diff -r 73bd7c60cfa1 -r a7c55d50697a usr.sbin/rbootd/bpf.c
--- a/usr.sbin/rbootd/bpf.c     Thu May 15 14:47:49 2003 +0000
+++ b/usr.sbin/rbootd/bpf.c     Thu May 15 14:50:02 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bpf.c,v 1.11 2001/02/05 02:37:34 lukem Exp $   */
+/*     $NetBSD: bpf.c,v 1.12 2003/05/15 14:50:50 itojun Exp $  */
 
 /*
  * Copyright (c) 1988, 1992 The University of Utah and the Center
@@ -51,7 +51,7 @@
 #if 0
 static char sccsid[] = "@(#)bpf.c      8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: bpf.c,v 1.11 2001/02/05 02:37:34 lukem Exp $");
+__RCSID("$NetBSD: bpf.c,v 1.12 2003/05/15 14:50:50 itojun Exp $");
 #endif
 #endif /* not lint */
 
@@ -70,9 +70,7 @@
 #include <string.h>
 #include <syslog.h>
 #include <unistd.h>
-#ifdef HAVE_IFADDRS_H
 #include <ifaddrs.h>
-#endif
 #include "defs.h"
 #include "pathnames.h"
 
@@ -226,7 +224,6 @@
 BpfGetIntfName(errmsg)
        char **errmsg;
 {
-#ifdef HAVE_IFADDRS_H
        struct ifaddrs *ifap, *ifa, *p;
        int minunit, n;
        char *cp;
@@ -274,79 +271,6 @@
        device[sizeof(device) - 1] = '\0';
        freeifaddrs(ifap);
        return(device);
-#else
-       struct ifreq ibuf[8], *ifrp, *ifend, *mp;
-       struct ifconf ifc;
-       int fd;
-       int minunit, n;
-       char *cp;
-       static char device[sizeof(ifrp->ifr_name)];
-       static char errbuf[128] = "No Error!";
-
-       if (errmsg != NULL)
-               *errmsg = errbuf;
-
-       if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
-               (void) strcpy(errbuf, "bpf: socket: %m");
-               return(NULL);
-       }
-       ifc.ifc_len = sizeof ibuf;
-       ifc.ifc_buf = (caddr_t)ibuf;
-
-#ifdef OSIOCGIFCONF
-       if (ioctl(fd, OSIOCGIFCONF, (char *)&ifc) < 0 ||
-           ifc.ifc_len < sizeof(struct ifreq)) {
-               (void) strcpy(errbuf, "bpf: ioctl(OSIOCGIFCONF): %m");
-               return(NULL);
-       }
-#else
-       if (ioctl(fd, SIOCGIFCONF, (char *)&ifc) < 0 ||
-           ifc.ifc_len < sizeof(struct ifreq)) {
-               (void) strcpy(errbuf, "bpf: ioctl(SIOCGIFCONF): %m");
-               return(NULL);
-       }
-#endif
-       ifrp = ibuf;
-       ifend = (struct ifreq *)((char *)ibuf + ifc.ifc_len);
-       
-       mp = 0;
-       minunit = 666;
-       for (; ifrp < ifend; ++ifrp) {
-               if (ioctl(fd, SIOCGIFFLAGS, (char *)ifrp) < 0) {
-                       (void) strcpy(errbuf, "bpf: ioctl(SIOCGIFFLAGS): %m");
-                       return(NULL);
-               }
-
-               /*
-                *  If interface is down or this is the loopback interface,
-                *  ignore it.
-                */
-               if ((ifrp->ifr_flags & IFF_UP) == 0 ||
-#ifdef IFF_LOOPBACK
-                   (ifrp->ifr_flags & IFF_LOOPBACK))
-#else
-                   (strcmp(ifrp->ifr_name, "lo0") == 0))
-#endif
-                       continue;
-
-               for (cp = ifrp->ifr_name; !isdigit(*cp); ++cp)
-                       ;
-               n = atoi(cp);
-               if (n < minunit) {
-                       minunit = n;
-                       mp = ifrp;
-               }
-       }
-
-       (void) close(fd);
-       if (mp == 0) {
-               (void) strcpy(errbuf, "bpf: no interfaces found");
-               return(NULL);
-       }
-
-       (void) strcpy(device, mp->ifr_name);
-       return(device);
-#endif
 }
 
 /*



Home | Main Index | Thread Index | Old Index