12 |
22 |
13 - first = strsep(&second, "-"); |
23 - first = strsep(&second, "-"); |
14 if (second == NULL) |
24 if (second == NULL) |
15 errx(1, "%s: Invalid network range: %s", |
25 errx(1, "%s: Invalid network range: %s", |
16 __func__, p); |
26 __func__, p); |
17 @@ -267,7 +267,7 @@ |
27 @@ -185,7 +187,7 @@ |
|
28 arpd_init(char *dev, int naddresses, char **addresses) |
|
29 { |
|
30 struct bpf_program fcode; |
|
31 - char filter[1024], ebuf[PCAP_ERRBUF_SIZE], *dst; |
|
32 + char filter[1024], ebuf[PCAP_ERRBUF_SIZE], *dst, *iface; |
|
33 intf_t *intf; |
|
34 |
|
35 dst = arpd_expandips(naddresses, addresses); |
|
36 @@ -203,7 +205,16 @@ |
|
37 errx(1, "pcap_lookupdev: %s", ebuf); |
|
38 } |
|
39 arpd_ifent.intf_len = sizeof(arpd_ifent); |
|
40 - strncpy(arpd_ifent.intf_name, dev, sizeof(arpd_ifent.intf_name) - 1); |
|
41 + |
|
42 + /* mitigate slash paths in OS that provide */ |
|
43 + /* network devices in subdirectories of /dev */ |
|
44 + iface = strrchr(dev, '/'); |
|
45 + if (iface) |
|
46 + iface += sizeof(char); |
|
47 + else |
|
48 + iface = dev; |
|
49 + |
|
50 + strncpy(arpd_ifent.intf_name, iface, sizeof(arpd_ifent.intf_name) - 1); |
|
51 arpd_ifent.intf_name[sizeof(arpd_ifent.intf_name) - 1] = '\0'; |
|
52 |
|
53 if (intf_get(intf, &arpd_ifent) < 0) |
|
54 @@ -218,7 +229,7 @@ |
|
55 dst ? "and (" : "", dst ? dst : "", dst ? ")" : "", |
|
56 addr_ntoa(&arpd_ifent.intf_link_addr)); |
|
57 |
|
58 - if ((arpd_pcap = pcap_open_live(dev, 128, 0, 500, ebuf)) == NULL) |
|
59 + if ((arpd_pcap = pcap_open_live(iface, 128, 0, 500, ebuf)) == NULL) |
|
60 errx(1, "pcap_open_live: %s", ebuf); |
|
61 |
|
62 if (pcap_compile(arpd_pcap, &fcode, filter, 1, 0) < 0 || |
|
63 @@ -265,7 +276,7 @@ |
18 spa->addr_ip, tha->addr_eth, tpa->addr_ip); |
64 spa->addr_ip, tha->addr_eth, tpa->addr_ip); |
19 |
65 |
20 if (op == ARP_OP_REQUEST) { |
66 if (op == ARP_OP_REQUEST) { |
21 - syslog(LOG_DEBUG, __FUNCTION__ ": who-has %s tell %s", |
67 - syslog(LOG_DEBUG, __FUNCTION__ ": who-has %s tell %s", |
22 + syslog(LOG_DEBUG, "%s: who-has %s tell %s", __FUNCTION__, |
68 + syslog(LOG_DEBUG, "%s: who-has %s tell %s", __FUNCTION__, |
23 addr_ntoa(tpa), addr_ntoa(spa)); |
69 addr_ntoa(tpa), addr_ntoa(spa)); |
24 } else if (op == ARP_OP_REPLY) { |
70 } else if (op == ARP_OP_REPLY) { |
25 syslog(LOG_INFO, "arp reply %s is-at %s", |
71 syslog(LOG_INFO, "arp reply %s is-at %s", |
26 @@ -284,7 +284,7 @@ |
72 @@ -282,7 +293,7 @@ |
27 int error; |
73 int error; |
28 |
74 |
29 if (addr_cmp(addr, &arpd_ifent.intf_addr) == 0) { |
75 if (addr_cmp(addr, &arpd_ifent.intf_addr) == 0) { |
30 - syslog(LOG_DEBUG, __FUNCTION__ ": %s at %s", |
76 - syslog(LOG_DEBUG, __FUNCTION__ ": %s at %s", |
31 + syslog(LOG_DEBUG, "%s: %s at %s", __FUNCTION__, |
77 + syslog(LOG_DEBUG, "%s: %s at %s", __FUNCTION__, |
32 addr_ntoa(addr), addr_ntoa(&arpd_ifent.intf_link_addr)); |
78 addr_ntoa(addr), addr_ntoa(&arpd_ifent.intf_link_addr)); |
33 return (0); |
79 return (0); |
34 } |
80 } |
35 @@ -293,10 +293,10 @@ |
81 @@ -291,10 +302,10 @@ |
36 error = arp_get(arpd_arp, &arpent); |
82 error = arp_get(arpd_arp, &arpent); |
37 |
83 |
38 if (error == -1) { |
84 if (error == -1) { |
39 - syslog(LOG_DEBUG, __FUNCTION__ ": no entry for %s", |
85 - syslog(LOG_DEBUG, __FUNCTION__ ": no entry for %s", |
40 + syslog(LOG_DEBUG, "%s: no entry for %s", __FUNCTION__, |
86 + syslog(LOG_DEBUG, "%s: no entry for %s", __FUNCTION__, |
43 - syslog(LOG_DEBUG, __FUNCTION__ ": %s at %s", |
89 - syslog(LOG_DEBUG, __FUNCTION__ ": %s at %s", |
44 + syslog(LOG_DEBUG, "%s: %s at %s", __FUNCTION__, |
90 + syslog(LOG_DEBUG, "%s: %s at %s", __FUNCTION__, |
45 addr_ntoa(addr), addr_ntoa(&arpent.arp_ha)); |
91 addr_ntoa(addr), addr_ntoa(&arpent.arp_ha)); |
46 } |
92 } |
47 return (error); |
93 return (error); |
48 @@ -425,7 +425,7 @@ |
94 @@ -423,7 +434,7 @@ |
49 if ((req = SPLAY_FIND(tree, &arpd_reqs, &tmp)) != NULL) { |
95 if ((req = SPLAY_FIND(tree, &arpd_reqs, &tmp)) != NULL) { |
50 addr_pack(&src.arp_ha, ADDR_TYPE_ETH, ETH_ADDR_BITS, |
96 addr_pack(&src.arp_ha, ADDR_TYPE_ETH, ETH_ADDR_BITS, |
51 ethip->ar_sha, ETH_ADDR_LEN); |
97 ethip->ar_sha, ETH_ADDR_LEN); |
52 - syslog(LOG_DEBUG, __FUNCTION__ ": %s at %s", |
98 - syslog(LOG_DEBUG, __FUNCTION__ ": %s at %s", |
53 + syslog(LOG_DEBUG, "%s: %s at %s", __FUNCTION__, |
99 + syslog(LOG_DEBUG, "%s: %s at %s", __FUNCTION__, |
54 addr_ntoa(&req->pa), addr_ntoa(&src.arp_ha)); |
100 addr_ntoa(&req->pa), addr_ntoa(&src.arp_ha)); |
55 |
101 |
56 /* This address is claimed */ |
102 /* This address is claimed */ |
|
103 @@ -445,9 +456,6 @@ |
|
104 void |
|
105 terminate_handler(int sig) |
|
106 { |
|
107 - extern int event_gotsig; |
|
108 - |
|
109 - event_gotsig = 1; |
|
110 arpd_sig = sig; |
|
111 } |
|
112 |
|
113 @@ -464,7 +472,6 @@ |
|
114 main(int argc, char *argv[]) |
|
115 { |
|
116 struct event recv_ev; |
|
117 - extern int (*event_sigcb)(void); |
|
118 char *dev; |
|
119 int c, debug; |
|
120 FILE *fp; |
|
121 @@ -524,7 +531,6 @@ |
|
122 perror("signal"); |
|
123 return (-1); |
|
124 } |
|
125 - event_sigcb = arpd_signal; |
|
126 |
|
127 event_dispatch(); |
|
128 |