+ syslog(LOG_ERR, "/dev/kmem: %m");
+ exit(1);
+ }
+ (void) lseek(kmemf, (long)nl[NL_BOOTTIME].n_value, L_SET);
+ (void) read(kmemf, (char *)&mywd.wd_boottime,
+ sizeof (mywd.wd_boottime));
+ mywd.wd_boottime = htonl(mywd.wd_boottime);
+}
+
+/*
+ * Figure out device configuration and select
+ * networks which deserve status information.
+ */
+configure(s)
+ int s;
+{
+ char buf[BUFSIZ];
+ struct ifconf ifc;
+ struct ifreq ifreq, *ifr;
+ struct sockaddr_in *sin;
+ register struct neighbor *np;
+ int n;
+
+ ifc.ifc_len = sizeof (buf);
+ ifc.ifc_buf = buf;
+ if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) {
+ syslog(LOG_ERR, "ioctl (get interface configuration)");
+ return (0);
+ }
+ ifr = ifc.ifc_req;
+ for (n = ifc.ifc_len / sizeof (struct ifreq); n > 0; n--, ifr++) {
+ for (np = neighbors; np != NULL; np = np->n_next)
+ if (np->n_name &&
+ strcmp(ifr->ifr_name, np->n_name) == 0)
+ break;
+ if (np != NULL)
+ continue;
+ ifreq = *ifr;
+ np = (struct neighbor *)malloc(sizeof (*np));
+ if (np == NULL)
+ continue;
+ np->n_name = malloc(strlen(ifr->ifr_name) + 1);
+ if (np->n_name == NULL) {
+ free((char *)np);
+ continue;
+ }
+ strcpy(np->n_name, ifr->ifr_name);
+ np->n_addrlen = sizeof (ifr->ifr_addr);
+ np->n_addr = malloc(np->n_addrlen);
+ if (np->n_addr == NULL) {
+ free(np->n_name);
+ free((char *)np);
+ continue;
+ }
+ bcopy((char *)&ifr->ifr_addr, np->n_addr, np->n_addrlen);
+ if (ioctl(s, SIOCGIFFLAGS, (char *)&ifreq) < 0) {
+ syslog(LOG_ERR, "ioctl (get interface flags)");
+ free((char *)np);
+ continue;
+ }
+ if ((ifreq.ifr_flags & IFF_UP) == 0 ||
+ (ifreq.ifr_flags & (IFF_BROADCAST|IFF_POINTOPOINT)) == 0) {
+ free((char *)np);
+ continue;
+ }
+ np->n_flags = ifreq.ifr_flags;
+ if (np->n_flags & IFF_POINTOPOINT) {
+ if (ioctl(s, SIOCGIFDSTADDR, (char *)&ifreq) < 0) {
+ syslog(LOG_ERR, "ioctl (get dstaddr)");
+ free((char *)np);
+ continue;
+ }
+ /* we assume addresses are all the same size */
+ bcopy((char *)&ifreq.ifr_dstaddr,
+ np->n_addr, np->n_addrlen);
+ }
+ if (np->n_flags & IFF_BROADCAST) {
+ if (ioctl(s, SIOCGIFBRDADDR, (char *)&ifreq) < 0) {
+ syslog(LOG_ERR, "ioctl (get broadaddr)");
+ free((char *)np);
+ continue;
+ }
+ /* we assume addresses are all the same size */
+ bcopy((char *)&ifreq.ifr_broadaddr,
+ np->n_addr, np->n_addrlen);
+ }
+ /* gag, wish we could get rid of Internet dependencies */
+ sin = (struct sockaddr_in *)np->n_addr;
+ sin->sin_port = sp->s_port;
+ np->n_next = neighbors;
+ neighbors = np;