Source-Changes-HG archive

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

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



details:   https://anonhg.NetBSD.org/src/rev/8ecb925d5071
branches:  trunk
changeset: 517907:8ecb925d5071
user:      itojun <itojun%NetBSD.org@localhost>
date:      Wed Nov 21 06:53:13 2001 +0000

description:
assume the presense of getifaddrs(3).  sync with kame

diffstat:

 usr.sbin/faithd/faithd.c |  114 +----------------------------------------------
 1 files changed, 1 insertions(+), 113 deletions(-)

diffs (160 lines):

diff -r 4f657030dd63 -r 8ecb925d5071 usr.sbin/faithd/faithd.c
--- a/usr.sbin/faithd/faithd.c  Wed Nov 21 06:52:35 2001 +0000
+++ b/usr.sbin/faithd/faithd.c  Wed Nov 21 06:53:13 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: faithd.c,v 1.21 2001/11/21 06:52:35 itojun Exp $       */
+/*     $NetBSD: faithd.c,v 1.22 2001/11/21 06:53:13 itojun Exp $       */
 /*     $KAME: faithd.c,v 1.40 2001/07/02 14:36:48 itojun Exp $ */
 
 /*
@@ -36,7 +36,6 @@
  * Usage: faithd [<port> <progpath> <arg1(progname)> <arg2> ...]
  *   e.g. faithd telnet /usr/local/v6/sbin/telnetd telnetd
  */
-#define HAVE_GETIFADDRS
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -72,9 +71,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>
-#ifdef HAVE_GETIFADDRS
 #include <ifaddrs.h>
-#endif
 
 #ifdef FAITH4
 #include <resolv.h>
@@ -121,9 +118,6 @@
 static void start_daemon __P((void));
 static void exit_stderr __P((const char *, ...))
        __attribute__((__format__(__printf__, 1, 2)));
-#ifndef HAVE_GETIFADDRS
-static unsigned int if_maxindex __P((void));
-#endif
 static void grab_myaddrs __P((void));
 static void free_myaddrs __P((void));
 static void update_myaddrs __P((void));
@@ -856,27 +850,9 @@
 }
 
 #ifdef USE_ROUTE
-#ifndef HAVE_GETIFADDRS
-static unsigned int
-if_maxindex()
-{
-       struct if_nameindex *p, *p0;
-       unsigned int max = 0;
-
-       p0 = if_nameindex();
-       for (p = p0; p && p->if_index && p->if_name; p++) {
-               if (max < p->if_index)
-                       max = p->if_index;
-       }
-       if_freenameindex(p0);
-       return max;
-}
-#endif
-
 static void
 grab_myaddrs()
 {
-#ifdef HAVE_GETIFADDRS
        struct ifaddrs *ifap, *ifa;
        struct myaddrs *p;
        struct sockaddr_in6 *sin6;
@@ -928,94 +904,6 @@
        }
 
        freeifaddrs(ifap);
-#else
-       int s;
-       unsigned int maxif;
-       struct ifreq *iflist;
-       struct ifconf ifconf;
-       struct ifreq *ifr, *ifrp, *ifr_end;
-       struct myaddrs *p;
-       struct sockaddr_in6 *sin6;
-       size_t siz;
-       char ifrbuf[sizeof(struct ifreq) + 1024];
-
-       maxif = if_maxindex() + 1;
-       iflist = (struct ifreq *)malloc(maxif * BUFSIZ);        /* XXX */
-       if (!iflist) {
-               exit_failure("not enough core");
-               /*NOTREACHED*/
-       }
-
-       if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
-               exit_failure("socket(SOCK_DGRAM)");
-               /*NOTREACHED*/
-       }
-       memset(&ifconf, 0, sizeof(ifconf));
-       ifconf.ifc_req = iflist;
-       ifconf.ifc_len = maxif * BUFSIZ;        /* XXX */
-       if (ioctl(s, SIOCGIFCONF, &ifconf) < 0) {
-               exit_failure("ioctl(SIOCGIFCONF)");
-               /*NOTREACHED*/
-       }
-       close(s);
-
-       /* Look for this interface in the list */
-       ifr_end = (struct ifreq *) (ifconf.ifc_buf + ifconf.ifc_len);
-       for (ifrp = ifconf.ifc_req;
-            ifrp < ifr_end;
-            ifrp = (struct ifreq *)((char *)ifrp + siz)) {
-               memcpy(ifrbuf, ifrp, sizeof(*ifrp));
-               ifr = (struct ifreq *)ifrbuf;
-               siz = ifr->ifr_addr.sa_len;
-               if (siz < sizeof(ifr->ifr_addr))
-                       siz = sizeof(ifr->ifr_addr);
-               siz += (sizeof(*ifrp) - sizeof(ifr->ifr_addr));
-               if (siz > sizeof(ifrbuf)) {
-                       /* ifr too big */
-                       break;
-               }
-               memcpy(ifrbuf, ifrp, siz);
-
-               switch (ifr->ifr_addr.sa_family) {
-               case AF_INET:
-               case AF_INET6:
-                       p = (struct myaddrs *)malloc(sizeof(struct myaddrs)
-                               + ifr->ifr_addr.sa_len);
-                       if (!p) {
-                               exit_failure("not enough core");
-                               /*NOTREACHED*/
-                       }
-                       memcpy(p + 1, &ifr->ifr_addr, ifr->ifr_addr.sa_len);
-                       p->next = myaddrs;
-                       p->addr = (struct sockaddr *)(p + 1);
-#ifdef __KAME__
-                       if (ifr->ifr_addr.sa_family == AF_INET6) {
-                               sin6 = (struct sockaddr_in6 *)p->addr;
-                               if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)
-                                || IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) {
-                                       sin6->sin6_scope_id =
-                                               ntohs(*(u_int16_t *)&sin6->sin6_addr.s6_addr[2]);
-                                       sin6->sin6_addr.s6_addr[2] = 0;
-                                       sin6->sin6_addr.s6_addr[3] = 0;
-                               }
-                       }
-#endif
-                       myaddrs = p;
-                       if (dflag) {
-                               char hbuf[NI_MAXHOST];
-                               getnameinfo(p->addr, p->addr->sa_len,
-                                       hbuf, sizeof(hbuf), NULL, 0,
-                                       NI_NUMERICHOST);
-                               syslog(LOG_INFO, "my interface: %s %s", hbuf, ifr->ifr_name);
-                       }
-                       break;
-               default:
-                       break;
-               }
-       }
-
-       free(iflist);
-#endif
 }
 
 static void



Home | Main Index | Thread Index | Old Index