From b46947c2ef8c801000189e52366cd8a0e237eb26 Mon Sep 17 00:00:00 2001 From: Eric Allman Date: Mon, 15 May 1995 14:31:01 -0800 Subject: [PATCH] probe interface configuration for other possible names SCCS-vsn: usr.sbin/sendmail/src/main.c 8.106 SCCS-vsn: usr.sbin/sendmail/src/conf.c 8.162 --- usr/src/usr.sbin/sendmail/src/conf.c | 123 +++++++++++++++++++++++++-- usr/src/usr.sbin/sendmail/src/main.c | 5 +- 2 files changed, 121 insertions(+), 7 deletions(-) diff --git a/usr/src/usr.sbin/sendmail/src/conf.c b/usr/src/usr.sbin/sendmail/src/conf.c index 6fcbf2c1e1..97c83a07d9 100644 --- a/usr/src/usr.sbin/sendmail/src/conf.c +++ b/usr/src/usr.sbin/sendmail/src/conf.c @@ -7,7 +7,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)conf.c 8.161 (Berkeley) %G%"; +static char sccsid[] = "@(#)conf.c 8.162 (Berkeley) %G%"; #endif /* not lint */ # include "sendmail.h" @@ -1368,7 +1368,7 @@ getla() FILE *fp; fp = fopen(_PATH_LOADAVG, "r"); - if (fp == NULL) + if (fp == NULL) { if (tTd(3, 1)) printf("getla: fopen(%s): %s\n", @@ -1832,7 +1832,7 @@ uname(name) return (0); } #endif - + return (-1); } #endif /* HASUNAME */ @@ -2457,7 +2457,7 @@ lockfile(fd, filename, ext, type) if (ext == NULL) ext = ""; - + bzero(&lfd, sizeof lfd); if (bitset(LOCK_UN, type)) lfd.l_type = F_UNLCK; @@ -2931,6 +2931,117 @@ sm_getpwuid(uid) return getpwuid(uid); } /* +** LOAD_IF_NAMES -- load interface-specific names into $=w +** +** Parameters: +** none. +** +** Returns: +** none. +** +** Side Effects: +** Loads $=w with the names of all the interfaces. +*/ + +#ifdef SIOCGIFCONF +# include +# include +# include +#endif + +void +load_if_names() +{ +#ifdef SIOCGIFCONF + struct hostent *hp; + int s; + struct ifconf ifc; + struct ifreq *ifr; + 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 */ + ifc.ifc_len = sizeof(interfacebuf); + ifc.ifc_buf = interfacebuf; + if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) + { + if (tTd(0, 4)) + printf("SIOGIFCONF failed: %s\n", errstring(errno)); + return; + } + + /* 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++) + { + struct in_addr ia; + char ip_addr[256]; + + if (tTd(0, 20)) + printf("%s\n", anynet_ntoa((SOCKADDR *) &ifr->ifr_addr)); + + if (ifr->ifr_addr.sa_family != AF_INET) + continue; + + /* extract IP address from the list*/ + ia = (((struct sockaddr_in *) (&ifr->ifr_addr))->sin_addr); + + /* save IP address in text from */ + (void) sprintf(ip_addr, "[%s]", + inet_ntoa(((struct sockaddr_in *)(&ifr->ifr_addr))->sin_addr)); + if (!wordinclass(ip_addr, 'w')) + { + setclass('w', ip_addr); + if (tTd(0, 4)) + printf("\ta.k.a.: %s\n", ip_addr); + } + + /* skip "loopback" interface "lo" */ + if (strcmp("lo0", ifr->ifr_name) == 0) + continue; + + /* lookup name with IP address */ + hp = sm_gethostbyaddr((char *) &ia, sizeof(ia), AF_INET); + if (hp == NULL) + { + syslog(LOG_CRIT, "gethostbyaddr() failed for %s\n", + inet_ntoa(ia)); + continue; + } + + /* save its cname */ + if (!wordinclass(hp->h_name, 'w')) + { + setclass('w', hp->h_name); + if (tTd(0, 4)) + printf("\ta.k.a.: %s\n", hp->h_name); + } + + /* save all it aliases name */ + while (*hp->h_aliases) + { + if (!wordinclass(*hp->h_aliases, 'w')) + { + setclass('w', *hp->h_aliases); + if (tTd(0, 4)) + printf("\ta.k.a.: %s\n", *hp->h_aliases); + } + hp->h_aliases++; + } + } +#endif +} + /* ** NI_PROPVAL -- netinfo property value lookup routine ** ** Parameters: @@ -3069,7 +3180,7 @@ ni_propval(keydir, keyprop, keyval, valprop, sepchar) continue; } - /* + /* ** Calculate number of bytes needed and build result */ @@ -3082,7 +3193,7 @@ ni_propval(keydir, keyprop, keyval, valprop, sepchar) strcpy(p, ninl.ni_namelist_val[j]); p += strlen(p); *p++ = sepchar; - } + } *--p = '\0'; ni_namelist_free(&ninl); diff --git a/usr/src/usr.sbin/sendmail/src/main.c b/usr/src/usr.sbin/sendmail/src/main.c index f2417bc012..bf370ae4e3 100644 --- a/usr/src/usr.sbin/sendmail/src/main.c +++ b/usr/src/usr.sbin/sendmail/src/main.c @@ -13,7 +13,7 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)main.c 8.105 (Berkeley) %G%"; +static char sccsid[] = "@(#)main.c 8.106 (Berkeley) %G%"; #endif /* not lint */ #define _DEFINE @@ -412,6 +412,9 @@ main(argc, argv, envp) } } + /* probe interfaces and locate any additional names */ + load_if_names(); + /* current time */ define('b', arpadate((char *) NULL), CurEnv); -- 2.20.1