+** 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 <netdb.h>
+# include <arpa/inet.h>
+# include <net/if.h>
+#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
+}
+\f/*