|
Lines 1-6
Link Here
|
| 1 |
--- src/dhcp_probe.c.orig 2015-01-03 11:16:23.000000000 -0500 |
1 |
--- src/dhcp_probe.c.orig 2021-01-18 19:17:29 UTC |
| 2 |
+++ src/dhcp_probe.c 2015-01-17 11:44:33.000000000 -0500 |
2 |
+++ src/dhcp_probe.c |
| 3 |
@@ -69,7 +69,7 @@ |
3 |
@@ -70,7 +70,7 @@ pcap_dumper_t *pcap_dump_d = NULL; /* libpcap - dump d |
| 4 |
enum dhcp_flavor_t packet_flavors[] = {BOOTP, DHCP_INIT, DHCP_SELECTING, DHCP_INIT_REBOOT, DHCP_REBINDING}; |
4 |
enum dhcp_flavor_t packet_flavors[] = {BOOTP, DHCP_INIT, DHCP_SELECTING, DHCP_INIT_REBOOT, DHCP_REBINDING}; |
| 5 |
|
5 |
|
| 6 |
char *ifname; |
6 |
char *ifname; |
|
Lines 9-54
Link Here
|
| 9 |
|
9 |
|
| 10 |
int use_8021q = 0; |
10 |
int use_8021q = 0; |
| 11 |
int vlan_id = 0; |
11 |
int vlan_id = 0; |
| 12 |
@@ -96,7 +96,7 @@ |
12 |
@@ -95,7 +95,7 @@ main(int argc, char **argv) |
| 13 |
bpf_u_int32 netnumber, netmask; |
13 |
/* for libpcap */ |
| 14 |
struct bpf_program bpf_code; |
14 |
struct bpf_program bpf_code; |
| 15 |
int linktype; |
15 |
int linktype; |
| 16 |
- char pcap_errbuf[PCAP_ERRBUF_SIZE], pcap_errbuf2[PCAP_ERRBUF_SIZE]; |
16 |
- char pcap_errbuf[PCAP_ERRBUF_SIZE], pcap_errbuf2[PCAP_ERRBUF_SIZE]; |
| 17 |
+ char pcap_errbuf[PCAP_ERRBUF_SIZE]; |
17 |
+ char pcap_errbuf[PCAP_ERRBUF_SIZE]; |
| 18 |
|
18 |
|
| 19 |
/* for libnet */ |
19 |
/* get progname = last component of argv[0] */ |
| 20 |
char libnet_errbuf[LIBNET_ERRBUF_SIZE]; |
20 |
prog = strrchr(argv[0], '/'); |
| 21 |
@@ -228,6 +228,7 @@ |
21 |
@@ -416,7 +416,7 @@ main(int argc, char **argv) |
| 22 |
/* ignore SIGHUP */ |
|
|
| 23 |
sigemptyset(&sa.sa_mask); |
| 24 |
sa.sa_handler = SIG_IGN; |
| 25 |
+ sa.sa_flags = 0; |
| 26 |
if (sigaction(SIGHUP, &sa, NULL) < 0) { |
| 27 |
report(LOG_ERR, "sigaction: %s", get_errmsg()); |
| 28 |
my_exit(1, 0, 1); |
| 29 |
@@ -236,6 +237,7 @@ |
| 30 |
/* ignore SIGUSR1 */ |
| 31 |
sigemptyset(&sa.sa_mask); |
| 32 |
sa.sa_handler = SIG_IGN; |
| 33 |
+ sa.sa_flags = 0; |
| 34 |
if (sigaction(SIGUSR1, &sa, NULL) < 0) { |
| 35 |
report(LOG_ERR, "sigaction: %s", get_errmsg()); |
| 36 |
my_exit(1, 0, 1); |
| 37 |
@@ -243,12 +245,12 @@ |
| 38 |
/* ignore SIGUSR2 */ |
| 39 |
sigemptyset(&sa.sa_mask); |
| 40 |
sa.sa_handler = SIG_IGN; |
| 41 |
+ sa.sa_flags = 0; |
| 42 |
if (sigaction(SIGUSR2, &sa, NULL) < 0) { |
| 43 |
report(LOG_ERR, "sigaction: %s", get_errmsg()); |
| 44 |
my_exit(1, 0, 1); |
| 45 |
} |
| 46 |
|
| 47 |
- |
| 48 |
/* write pid file as soon as possible after (possibly) forking */ |
| 49 |
if ((pid_fp = open_for_writing(pid_file)) == NULL) { |
| 50 |
report(LOG_ERR, "could not open pid file %s for writing", pid_file); |
| 51 |
@@ -401,7 +403,7 @@ |
| 52 |
*/ |
22 |
*/ |
| 53 |
pcap_errbuf[0] = '\0'; /* so we can tell if a warning was produced on success */ |
23 |
pcap_errbuf[0] = '\0'; /* so we can tell if a warning was produced on success */ |
| 54 |
if ((pd_template = pcap_open_live(ifname, snaplen, 0, 1, pcap_errbuf)) == NULL) { |
24 |
if ((pd_template = pcap_open_live(ifname, snaplen, 0, 1, pcap_errbuf)) == NULL) { |
|
Lines 57-63
Link Here
|
| 57 |
my_exit(1, 1, 1); |
27 |
my_exit(1, 1, 1); |
| 58 |
} |
28 |
} |
| 59 |
if (pcap_errbuf[0] != '\0') |
29 |
if (pcap_errbuf[0] != '\0') |
| 60 |
@@ -470,8 +472,8 @@ |
30 |
@@ -485,8 +485,8 @@ main(int argc, char **argv) |
| 61 |
it's possible there's a server out there that does it wrong, and might therefore mistakenly |
31 |
it's possible there's a server out there that does it wrong, and might therefore mistakenly |
| 62 |
send responses to ether_src. So lets also listen promiscuously if ether_src != my_eaddr. |
32 |
send responses to ether_src. So lets also listen promiscuously if ether_src != my_eaddr. |
| 63 |
*/ |
33 |
*/ |
|
Lines 68-99
Link Here
|
| 68 |
promiscuous = 1; |
38 |
promiscuous = 1; |
| 69 |
else |
39 |
else |
| 70 |
promiscuous = 0; |
40 |
promiscuous = 0; |
| 71 |
@@ -699,8 +701,8 @@ |
41 |
@@ -775,9 +775,9 @@ process_response(u_char *user, const struct pcap_pkthd |
| 72 |
When we return, control returns to pcap_dispatch() so it can continue capturing packets. |
42 |
When we return, control returns to pcap_dispatch() so it can continue capturing packets. |
| 73 |
*/ |
43 |
*/ |
| 74 |
|
44 |
|
| 75 |
- struct ether_header *ether_header; /* access ethernet header */ |
45 |
- struct ether_header *ether_header; /* access ethernet header */ |
| 76 |
- struct ip *ip_header; /* access ip header */ |
|
|
| 77 |
+ struct libnet_ethernet_hdr *ether_header; /* access ethernet header */ |
46 |
+ struct libnet_ethernet_hdr *ether_header; /* access ethernet header */ |
|
|
47 |
struct my_ether_vlan_header *my_ether_vlan_header; /* possibly access ethernet 802.1Q header */ |
| 48 |
- struct ip *ip_header; /* access ip header */ |
| 78 |
+ struct libnet_ipv4_hdr *ip_header; /* access ip header */ |
49 |
+ struct libnet_ipv4_hdr *ip_header; /* access ip header */ |
| 79 |
bpf_u_int32 ether_len; /* bpf_u_int32 from pcap.h */ |
50 |
bpf_u_int32 ether_len; /* bpf_u_int32 from pcap.h */ |
| 80 |
struct udphdr *udp_header; /* access UDP header */ |
51 |
struct udphdr *udp_header; /* access UDP header */ |
| 81 |
struct bootp *bootp_pkt; /* access bootp/dhcp packet */ |
52 |
struct bootp *bootp_pkt; /* access bootp/dhcp packet */ |
| 82 |
@@ -710,7 +712,7 @@ |
53 |
@@ -787,10 +787,10 @@ process_response(u_char *user, const struct pcap_pkthd |
| 83 |
int isLegalServer; /* boolean */ |
54 |
int isLegalServer; /* boolean */ |
| 84 |
|
55 |
|
| 85 |
/* fields parsed out from packet*/ |
56 |
/* fields parsed out from packet*/ |
| 86 |
- struct ether_addr ether_dhost, ether_shost; |
57 |
- struct ether_addr ether_dhost, ether_shost; |
| 87 |
+ struct libnet_ether_addr ether_dhost, ether_shost; |
58 |
+ struct libnet_ether_addr ether_dhost, ether_shost; |
|
|
59 |
uint16_t ether_type, ether_type_inner; |
| 60 |
uint16_t ether_vid; |
| 61 |
- size_t ether_or_vlan_header_len; /* = sizeof(struct ether_header) or sizeof(struct my_ether_vlan_header) depending on response packet */ |
| 62 |
+ size_t ether_or_vlan_header_len; /* = sizeof(struct libnet_ethernet_hdr) or sizeof(struct my_ether_vlan_header) depending on response packet */ |
| 88 |
struct in_addr ip_src, ip_dst, yiaddr; |
63 |
struct in_addr ip_src, ip_dst, yiaddr; |
| 89 |
/* string versions of same */ |
64 |
/* string versions of same */ |
| 90 |
char ether_dhost_str[MAX_ETHER_ADDR_STR], ether_shost_str[MAX_ETHER_ADDR_STR]; |
65 |
char ether_dhost_str[MAX_ETHER_ADDR_STR], ether_shost_str[MAX_ETHER_ADDR_STR]; |
| 91 |
@@ -729,13 +731,13 @@ |
66 |
@@ -810,13 +810,13 @@ process_response(u_char *user, const struct pcap_pkthd |
| 92 |
return; |
67 |
return; |
| 93 |
} |
68 |
} |
| 94 |
|
69 |
|
| 95 |
- if ((ether_len < sizeof(sizeof(struct ether_header))) && (debug > 1)) { |
70 |
- if ((ether_len < sizeof(struct ether_header)) && (debug > 1)) { |
| 96 |
+ if ((ether_len < sizeof(sizeof(struct libnet_ethernet_hdr))) && (debug > 1)) { |
71 |
+ if ((ether_len < sizeof(struct libnet_ethernet_hdr)) && (debug > 1)) { |
| 97 |
report(LOG_WARNING, "interface %s, short packet (got %d bytes, smaller than an Ethernet header)", ifname, ether_len); |
72 |
report(LOG_WARNING, "interface %s, short packet (got %d bytes, smaller than an Ethernet header)", ifname, ether_len); |
| 98 |
return; |
73 |
return; |
| 99 |
} |
74 |
} |
|
Lines 102-154
Link Here
|
| 102 |
- ether_header = (struct ether_header *) packet; |
77 |
- ether_header = (struct ether_header *) packet; |
| 103 |
+ ether_header = (struct libnet_ethernet_hdr *) packet; |
78 |
+ ether_header = (struct libnet_ethernet_hdr *) packet; |
| 104 |
|
79 |
|
| 105 |
/* parse fields out of ethernet header for easier access */ |
80 |
/* we may use my_ether_vlan_header to access the Ethernet 801.Q header */ |
| 106 |
bcopy(&(ether_header->ether_dhost), ðer_dhost, sizeof(ether_dhost)); |
81 |
my_ether_vlan_header = (struct my_ether_vlan_header *) packet; |
| 107 |
@@ -747,13 +749,13 @@ |
82 |
@@ -835,7 +835,7 @@ process_response(u_char *user, const struct pcap_pkthd |
| 108 |
if (debug > 10) |
83 |
report(LOG_DEBUG, " interface %s, from ether %s to %s type %s", ifname, ether_shost_str, ether_dhost_str, ether_type_str); |
| 109 |
report(LOG_DEBUG, " interface %s, from ether %s to %s", ifname, ether_shost_str, ether_dhost_str); |
|
|
| 110 |
|
84 |
|
| 111 |
- if (ether_len < sizeof(sizeof(struct ether_header)) + sizeof(struct ip)) { |
85 |
if (ether_type == ETHERTYPE_IP) { |
| 112 |
+ if (ether_len < sizeof(sizeof(struct libnet_ethernet_hdr)) + sizeof(struct libnet_ipv4_hdr)) { |
86 |
- ether_or_vlan_header_len = sizeof(struct ether_header); |
| 113 |
report(LOG_WARNING, "interface %s, ether src %s: short packet (got %d bytes, smaller than IP header in Ethernet)", ifname, ether_shost_str, ether_len); |
87 |
+ ether_or_vlan_header_len = sizeof(struct libnet_ethernet_hdr); |
| 114 |
return; |
|
|
| 115 |
} |
| 116 |
|
88 |
|
| 117 |
/* we use ip_header to access the IP header */ |
89 |
} else if (ether_type == ETHERTYPE_VLAN) { |
| 118 |
- ip_header = (struct ip *) (packet + sizeof(struct ether_header)); |
|
|
| 119 |
+ ip_header = (struct libnet_ipv4_hdr *) (packet + sizeof(struct libnet_ethernet_hdr)); |
| 120 |
|
90 |
|
| 121 |
/* parse fields out of ip header for easier access */ |
91 |
@@ -880,13 +880,13 @@ process_response(u_char *user, const struct pcap_pkthd |
| 122 |
bcopy(&(ip_header->ip_src), &ip_src, sizeof(ip_header->ip_src)); |
92 |
Else if the frame is tagged, ether_or_vlan_header_len is now set to the length of the ethernet VLAN header. |
| 123 |
@@ -768,15 +770,15 @@ |
93 |
*/ |
| 124 |
ip_header_len_bytes = ip_header->ip_hl << 2; |
|
|
| 125 |
|
94 |
|
| 126 |
/* Repeat the packet size check (through IP header), but taking into account ip_header_len_bytes */ |
95 |
- if (ether_len < ether_or_vlan_header_len + sizeof(struct ip)) { |
| 127 |
- if (ether_len < sizeof(sizeof(struct ether_header)) + ip_header_len_bytes) { |
96 |
+ if (ether_len < ether_or_vlan_header_len + sizeof(struct libnet_ipv4_hdr)) { |
| 128 |
+ if (ether_len < sizeof(sizeof(struct libnet_ethernet_hdr)) + ip_header_len_bytes) { |
97 |
report(LOG_WARNING, "interface %s, ether src %s type %s: short packet (got %d bytes, smaller than IP header in Ethernet)", ifname, ether_shost_str, ether_type_str, ether_len); |
| 129 |
report(LOG_WARNING, "interface %s, short packet (got %d bytes, smaller than IP header in Ethernet)", ifname, ether_len); |
|
|
| 130 |
return; |
98 |
return; |
| 131 |
} |
99 |
} |
| 132 |
|
100 |
|
| 133 |
/* we use udp_header to access the UDP header */ |
101 |
/* we use ip_header to access the IP header */ |
| 134 |
- udp_header = (struct udphdr *) (packet + sizeof(struct ether_header) + ip_header_len_bytes); |
102 |
- ip_header = (struct ip *) (packet + ether_or_vlan_header_len); |
| 135 |
+ udp_header = (struct udphdr *) (packet + sizeof(struct libnet_ethernet_hdr) + ip_header_len_bytes); |
103 |
+ ip_header = (struct libnet_ipv4_hdr *) (packet + ether_or_vlan_header_len); |
| 136 |
|
|
|
| 137 |
- if (ether_len < sizeof(sizeof(struct ether_header)) + ip_header_len_bytes + sizeof(struct udphdr)) { |
| 138 |
+ if (ether_len < sizeof(sizeof(struct libnet_ethernet_hdr)) + ip_header_len_bytes + sizeof(struct udphdr)) { |
| 139 |
report(LOG_WARNING, "interface %s ether src %s: short packet (got %d bytes, smaller than UDP/IP header in Ethernet)", ifname, ether_shost_str, ether_len); |
| 140 |
return; |
| 141 |
} |
| 142 |
@@ -800,7 +802,7 @@ |
| 143 |
} |
| 144 |
|
| 145 |
/* we use bootp_pkt to access the bootp/dhcp packet */ |
| 146 |
- bootp_pkt = (struct bootp *) (packet + sizeof(struct ether_header) + ip_header_len_bytes + sizeof(struct udphdr)); |
| 147 |
+ bootp_pkt = (struct bootp *) (packet + sizeof(struct libnet_ethernet_hdr) + ip_header_len_bytes + sizeof(struct udphdr)); |
| 148 |
|
104 |
|
| 149 |
/* Make sure the packet is in response to our query, otherwise ignore it. |
105 |
/* parse fields out of ip header for easier access */ |
| 150 |
Our query had bootp_htype=HTYPE_ETHER, bootp_hlen=HLEN_ETHER, and bootp_chaddr=GetChaddr(). |
106 |
bcopy(&(ip_header->ip_src), &ip_src, sizeof(ip_header->ip_src)); |
| 151 |
@@ -820,7 +822,7 @@ |
107 |
@@ -953,7 +953,7 @@ process_response(u_char *user, const struct pcap_pkthd |
| 152 |
|
108 |
|
| 153 |
if (bcmp(bootp_pkt->bootp_chaddr, GetChaddr(), HLEN_ETHER)) { |
109 |
if (bcmp(bootp_pkt->bootp_chaddr, GetChaddr(), HLEN_ETHER)) { |
| 154 |
if (debug > 10) { |
110 |
if (debug > 10) { |