+
+void
+load_if_names()
+{
+#ifdef SIOCGIFCONF
+ int s;
+ int i;
+ struct ifconf ifc;
+ char interfacebuf[1024];
+
+ s = socket(AF_INET, SOCK_DGRAM, 0);
+ if (s == -1)
+ return;
+
+ /* get the list of known IP address from the kernel */
+ 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));
+ close(s);
+ return;
+ }
+ close(s);
+
+ /* scan the list of IP address */
+ if (tTd(0, 40))
+ printf("scanning for interface specific names, ifc_len=%d\n",
+ ifc.ifc_len);
+
+ 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 hostent *hp;
+ 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))
+ printf("%s\n", anynet_ntoa((SOCKADDR *) sa));
+
+ if (ifr->ifr_addr.sa_family != AF_INET)
+ continue;
+
+ /* extract IP address from the list*/
+ ia = (((struct sockaddr_in *) sa)->sin_addr);
+
+ /* save IP address in text from */
+ (void) sprintf(ip_addr, "[%s]",
+ inet_ntoa(((struct sockaddr_in *) sa)->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
+}