michael@715: Index: arpd.c michael@714: --- arpd.c.dist 2003-07-02 16:49:31.000000000 +0200 michael@714: +++ arpd.c 2003-07-02 16:53:25.000000000 +0200 michael@715: @@ -33,7 +33,7 @@ michael@715: #define ARPD_MAX_ACTIVE 600 michael@715: #define ARPD_MAX_INACTIVE 300 michael@715: michael@715: -#define PIDFILE "/var/run/arpd.pid" michael@715: +#define PIDFILE "/opsw/var/arpd/arpd.pid" michael@715: michael@715: struct arp_req { michael@715: struct addr pa; michael@714: @@ -111,9 +111,11 @@ michael@714: struct in_addr in; michael@714: ip_addr_t istart, iend; michael@714: michael@714: - second = p; michael@714: + first = p; michael@714: + second = strchr(p, '-'); michael@714: + if (second != NULL) michael@714: + *second++ = '\0'; michael@714: michael@714: - first = strsep(&second, "-"); michael@714: if (second == NULL) michael@714: errx(1, "%s: Invalid network range: %s", michael@714: __func__, p); michael@715: @@ -185,7 +187,7 @@ michael@715: arpd_init(char *dev, int naddresses, char **addresses) michael@715: { michael@715: struct bpf_program fcode; michael@715: - char filter[1024], ebuf[PCAP_ERRBUF_SIZE], *dst; michael@715: + char filter[1024], ebuf[PCAP_ERRBUF_SIZE], *dst, *iface; michael@715: intf_t *intf; michael@715: michael@715: dst = arpd_expandips(naddresses, addresses); michael@715: @@ -203,7 +205,16 @@ michael@715: errx(1, "pcap_lookupdev: %s", ebuf); michael@715: } michael@715: arpd_ifent.intf_len = sizeof(arpd_ifent); michael@715: - strncpy(arpd_ifent.intf_name, dev, sizeof(arpd_ifent.intf_name) - 1); michael@715: + michael@715: + /* mitigate slash paths in OS that provide */ michael@715: + /* network devices in subdirectories of /dev */ michael@715: + iface = strrchr(dev, '/'); michael@715: + if (iface) michael@715: + iface += sizeof(char); michael@715: + else michael@715: + iface = dev; michael@715: + michael@715: + strncpy(arpd_ifent.intf_name, iface, sizeof(arpd_ifent.intf_name) - 1); michael@715: arpd_ifent.intf_name[sizeof(arpd_ifent.intf_name) - 1] = '\0'; michael@715: michael@715: if (intf_get(intf, &arpd_ifent) < 0) michael@715: @@ -218,7 +229,7 @@ michael@715: dst ? "and (" : "", dst ? dst : "", dst ? ")" : "", michael@715: addr_ntoa(&arpd_ifent.intf_link_addr)); michael@715: michael@715: - if ((arpd_pcap = pcap_open_live(dev, 128, 0, 500, ebuf)) == NULL) michael@715: + if ((arpd_pcap = pcap_open_live(iface, 128, 0, 500, ebuf)) == NULL) michael@715: errx(1, "pcap_open_live: %s", ebuf); michael@715: michael@715: if (pcap_compile(arpd_pcap, &fcode, filter, 1, 0) < 0 || michael@715: @@ -265,7 +276,7 @@ michael@714: spa->addr_ip, tha->addr_eth, tpa->addr_ip); michael@714: michael@714: if (op == ARP_OP_REQUEST) { michael@714: - syslog(LOG_DEBUG, __FUNCTION__ ": who-has %s tell %s", michael@714: + syslog(LOG_DEBUG, "%s: who-has %s tell %s", __FUNCTION__, michael@714: addr_ntoa(tpa), addr_ntoa(spa)); michael@714: } else if (op == ARP_OP_REPLY) { michael@714: syslog(LOG_INFO, "arp reply %s is-at %s", michael@715: @@ -282,7 +293,7 @@ michael@714: int error; michael@714: michael@714: if (addr_cmp(addr, &arpd_ifent.intf_addr) == 0) { michael@714: - syslog(LOG_DEBUG, __FUNCTION__ ": %s at %s", michael@714: + syslog(LOG_DEBUG, "%s: %s at %s", __FUNCTION__, michael@714: addr_ntoa(addr), addr_ntoa(&arpd_ifent.intf_link_addr)); michael@714: return (0); michael@714: } michael@715: @@ -291,10 +302,10 @@ michael@714: error = arp_get(arpd_arp, &arpent); michael@714: michael@714: if (error == -1) { michael@714: - syslog(LOG_DEBUG, __FUNCTION__ ": no entry for %s", michael@714: + syslog(LOG_DEBUG, "%s: no entry for %s", __FUNCTION__, michael@714: addr_ntoa(addr)); michael@714: } else { michael@714: - syslog(LOG_DEBUG, __FUNCTION__ ": %s at %s", michael@714: + syslog(LOG_DEBUG, "%s: %s at %s", __FUNCTION__, michael@714: addr_ntoa(addr), addr_ntoa(&arpent.arp_ha)); michael@714: } michael@714: return (error); michael@715: @@ -423,7 +434,7 @@ michael@714: if ((req = SPLAY_FIND(tree, &arpd_reqs, &tmp)) != NULL) { michael@714: addr_pack(&src.arp_ha, ADDR_TYPE_ETH, ETH_ADDR_BITS, michael@714: ethip->ar_sha, ETH_ADDR_LEN); michael@714: - syslog(LOG_DEBUG, __FUNCTION__ ": %s at %s", michael@714: + syslog(LOG_DEBUG, "%s: %s at %s", __FUNCTION__, michael@714: addr_ntoa(&req->pa), addr_ntoa(&src.arp_ha)); michael@714: michael@714: /* This address is claimed */ michael@715: @@ -445,9 +456,6 @@ michael@715: void michael@715: terminate_handler(int sig) michael@715: { michael@715: - extern int event_gotsig; michael@715: - michael@715: - event_gotsig = 1; michael@715: arpd_sig = sig; michael@715: } michael@715: michael@715: @@ -464,7 +472,6 @@ michael@715: main(int argc, char *argv[]) michael@715: { michael@715: struct event recv_ev; michael@715: - extern int (*event_sigcb)(void); michael@715: char *dev; michael@715: int c, debug; michael@715: FILE *fp; michael@715: @@ -524,7 +531,6 @@ michael@715: perror("signal"); michael@715: return (-1); michael@715: } michael@715: - event_sigcb = arpd_signal; michael@715: michael@715: event_dispatch(); michael@715: