handle AF_LINK addresses on 4.4BSD networking
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Wed, 17 May 1995 22:20:50 +0000 (14:20 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Wed, 17 May 1995 22:20:50 +0000 (14:20 -0800)
SCCS-vsn: usr.sbin/sendmail/src/conf.h 8.161
SCCS-vsn: usr.sbin/sendmail/src/daemon.c 8.89
SCCS-vsn: usr.sbin/sendmail/src/conf.c 8.168

usr/src/usr.sbin/sendmail/src/conf.c
usr/src/usr.sbin/sendmail/src/conf.h
usr/src/usr.sbin/sendmail/src/daemon.c

index 5ff431a..5b998c2 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)conf.c     8.167 (Berkeley) %G%";
+static char sccsid[] = "@(#)conf.c     8.168 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -2984,52 +2984,61 @@ void
 load_if_names()
 {
 #ifdef SIOCGIFCONF
 load_if_names()
 {
 #ifdef SIOCGIFCONF
-       struct hostent *hp;
        int s;
        int s;
+       int i;
         struct ifconf ifc;
         struct ifconf ifc;
-        struct ifreq *ifr;
        char interfacebuf[1024];
        char interfacebuf[1024];
-       int n;
-       extern char *inet_ntoa();
-       extern struct hostent *gethostbyaddr();
 
        s = socket(AF_INET, SOCK_DGRAM, 0);
        if (s == -1)
                return;
 
        /* get the list of known IP address from the kernel */
 
        s = socket(AF_INET, SOCK_DGRAM, 0);
        if (s == -1)
                return;
 
        /* get the list of known IP address from the kernel */
-        ifc.ifc_len = sizeof(interfacebuf);
         ifc.ifc_buf = interfacebuf;
         ifc.ifc_buf = interfacebuf;
+        ifc.ifc_len = sizeof interfacebuf;
        if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0)
        {
                if (tTd(0, 4))
                        printf("SIOGIFCONF failed: %s\n", errstring(errno));
        if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0)
        {
                if (tTd(0, 4))
                        printf("SIOGIFCONF failed: %s\n", errstring(errno));
+               close(s);
                return;
        }
                return;
        }
+       close(s);
 
        /* scan the list of IP address */
        if (tTd(0, 4))
                printf("scanning for interface specific names, ifc_len=%d\n",
                        ifc.ifc_len);
 
 
        /* scan the list of IP address */
        if (tTd(0, 4))
                printf("scanning for interface specific names, ifc_len=%d\n",
                        ifc.ifc_len);
 
-        ifr = ifc.ifc_req;
-        for (n = ifc.ifc_len / sizeof(struct ifreq); n > 0; n--, ifr++)
-        {
+       for (i = 0; i < ifc.ifc_len; )
+       {
+               struct ifreq *ifr = (struct ifreq *) &ifc.ifc_buf[i];
+               struct sockaddr *sa = &ifr->ifr_addr;
                struct in_addr ia;
                struct in_addr ia;
+               struct hostent *hp;
                char ip_addr[256];
                char ip_addr[256];
+               extern char *inet_ntoa();
+               extern struct hostent *gethostbyaddr();
+
+#ifdef BSD4_4_SOCKADDR
+               if (sa->sa_len > sizeof ifr->ifr_addr)
+                       i += sizeof ifr->ifr_name + sa->sa_len;
+               else
+#endif
+                       i += sizeof *ifr;
 
                if (tTd(0, 20))
 
                if (tTd(0, 20))
-                       printf("%s\n", anynet_ntoa((SOCKADDR *) &ifr->ifr_addr));
+                       printf("%s\n", anynet_ntoa((SOCKADDR *) sa));
 
                if (ifr->ifr_addr.sa_family != AF_INET)
                        continue;
 
                /* extract IP address from the list*/
 
                if (ifr->ifr_addr.sa_family != AF_INET)
                        continue;
 
                /* extract IP address from the list*/
-               ia = (((struct sockaddr_in *) (&ifr->ifr_addr))->sin_addr);
+               ia = (((struct sockaddr_in *) sa)->sin_addr);
 
                /* save IP address in text from */
                (void) sprintf(ip_addr, "[%s]",
 
                /* save IP address in text from */
                (void) sprintf(ip_addr, "[%s]",
-                       inet_ntoa(((struct sockaddr_in *)(&ifr->ifr_addr))->sin_addr));
+                       inet_ntoa(((struct sockaddr_in *) sa)->sin_addr));
                if (!wordinclass(ip_addr, 'w'))
                {
                        setclass('w', ip_addr);
                if (!wordinclass(ip_addr, 'w'))
                {
                        setclass('w', ip_addr);
index 3d6395f..c10a252 100644 (file)
@@ -5,7 +5,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)conf.h      8.160 (Berkeley) %G%
+ *     @(#)conf.h      8.161 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -444,6 +444,7 @@ typedef int         pid_t;
 # define HASUNSETENV   1       /* has unsetenv(3) call */
 # include <sys/cdefs.h>
 # define ERRLIST_PREDEFINED    /* don't declare sys_errlist */
 # define HASUNSETENV   1       /* has unsetenv(3) call */
 # include <sys/cdefs.h>
 # define ERRLIST_PREDEFINED    /* don't declare sys_errlist */
+# define BSD4_4_SOCKADDR       /* has sa_len */
 # ifndef LA_TYPE
 #  define LA_TYPE      LA_SUBR
 # endif
 # ifndef LA_TYPE
 #  define LA_TYPE      LA_SUBR
 # endif
@@ -462,6 +463,7 @@ typedef int         pid_t;
 # define HASSETSID     1       /* has the setsid(2) POSIX syscall */
 # include <sys/cdefs.h>
 # define ERRLIST_PREDEFINED    /* don't declare sys_errlist */
 # define HASSETSID     1       /* has the setsid(2) POSIX syscall */
 # include <sys/cdefs.h>
 # define ERRLIST_PREDEFINED    /* don't declare sys_errlist */
+# define BSD4_4_SOCKADDR       /* has sa_len */
 # define SFS_TYPE      SFS_MOUNT       /* use <sys/mount.h> statfs() impl */
 # ifndef LA_TYPE
 #  define LA_TYPE      LA_SUBR
 # define SFS_TYPE      SFS_MOUNT       /* use <sys/mount.h> statfs() impl */
 # ifndef LA_TYPE
 #  define LA_TYPE      LA_SUBR
@@ -498,6 +500,7 @@ typedef int         pid_t;
 # endif
 # include <sys/cdefs.h>
 # define ERRLIST_PREDEFINED    /* don't declare sys_errlist */
 # endif
 # include <sys/cdefs.h>
 # define ERRLIST_PREDEFINED    /* don't declare sys_errlist */
+# define BSD4_4_SOCKADDR       /* has sa_len */
 # ifndef LA_TYPE
 #  define LA_TYPE      LA_SUBR
 # endif
 # ifndef LA_TYPE
 #  define LA_TYPE      LA_SUBR
 # endif
index 06ca89a..b7b6339 100644 (file)
@@ -12,9 +12,9 @@
 
 #ifndef lint
 #ifdef DAEMON
 
 #ifndef lint
 #ifdef DAEMON
-static char sccsid[] = "@(#)daemon.c   8.88 (Berkeley) %G% (with daemon mode)";
+static char sccsid[] = "@(#)daemon.c   8.89 (Berkeley) %G% (with daemon mode)";
 #else
 #else
-static char sccsid[] = "@(#)daemon.c   8.88 (Berkeley) %G% (without daemon mode)";
+static char sccsid[] = "@(#)daemon.c   8.89 (Berkeley) %G% (without daemon mode)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -937,6 +937,10 @@ host_map_lookup(map, name, av, statp)
 **             A printable version of that sockaddr.
 */
 
 **             A printable version of that sockaddr.
 */
 
+#ifdef AF_LINK
+# include <net/if_dl.h>
+#endif
+
 char *
 anynet_ntoa(sap)
        register SOCKADDR *sap;
 char *
 anynet_ntoa(sap)
        register SOCKADDR *sap;
@@ -968,9 +972,16 @@ anynet_ntoa(sap)
                return inet_ntoa(sap->sin.sin_addr);
 #endif
 
                return inet_ntoa(sap->sin.sin_addr);
 #endif
 
+#ifdef AF_LINK
+         case AF_LINK:
+               sprintf(buf, "[LINK: %s]",
+                       link_ntoa((struct sockaddr_dl *) &sap->sa));
+               return buf;
+#endif
          default:
          default:
-               /* this case is only to ensure syntactic correctness */
-               break;
+               /* this case is needed when nothing is #defined */
+               /* in order to keep the switch syntactically correct */
+               break;
        }
 
        /* unknown family -- just dump bytes */
        }
 
        /* unknown family -- just dump bytes */