diff options
Diffstat (limited to 'networking/udhcp/clientpacket.c')
-rw-r--r-- | networking/udhcp/clientpacket.c | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c index 4299c2dbd..15cbda2f5 100644 --- a/networking/udhcp/clientpacket.c +++ b/networking/udhcp/clientpacket.c | |||
@@ -8,8 +8,6 @@ | |||
8 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 8 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <string.h> | ||
12 | #include <sys/socket.h> | ||
13 | #include <features.h> | 11 | #include <features.h> |
14 | #if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined _NEWLIB_VERSION | 12 | #if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined _NEWLIB_VERSION |
15 | #include <netpacket/packet.h> | 13 | #include <netpacket/packet.h> |
@@ -19,19 +17,11 @@ | |||
19 | #include <linux/if_packet.h> | 17 | #include <linux/if_packet.h> |
20 | #include <linux/if_ether.h> | 18 | #include <linux/if_ether.h> |
21 | #endif | 19 | #endif |
22 | #include <stdlib.h> | ||
23 | #include <time.h> | ||
24 | #include <unistd.h> | ||
25 | #include <netinet/in.h> | ||
26 | #include <arpa/inet.h> | ||
27 | #include <fcntl.h> | ||
28 | |||
29 | 20 | ||
21 | #include "common.h" | ||
30 | #include "dhcpd.h" | 22 | #include "dhcpd.h" |
31 | #include "clientpacket.h" | ||
32 | #include "options.h" | ||
33 | #include "dhcpc.h" | 23 | #include "dhcpc.h" |
34 | #include "common.h" | 24 | #include "options.h" |
35 | 25 | ||
36 | 26 | ||
37 | /* Create a random xid */ | 27 | /* Create a random xid */ |
@@ -59,7 +49,7 @@ static void init_packet(struct dhcpMessage *packet, char type) | |||
59 | udhcp_init_header(packet, type); | 49 | udhcp_init_header(packet, type); |
60 | memcpy(packet->chaddr, client_config.arp, 6); | 50 | memcpy(packet->chaddr, client_config.arp, 6); |
61 | if (client_config.clientid) | 51 | if (client_config.clientid) |
62 | add_option_string(packet->options, client_config.clientid); | 52 | add_option_string(packet->options, client_config.clientid); |
63 | if (client_config.hostname) add_option_string(packet->options, client_config.hostname); | 53 | if (client_config.hostname) add_option_string(packet->options, client_config.hostname); |
64 | if (client_config.fqdn) add_option_string(packet->options, client_config.fqdn); | 54 | if (client_config.fqdn) add_option_string(packet->options, client_config.fqdn); |
65 | add_option_string(packet->options, client_config.vendorclass); | 55 | add_option_string(packet->options, client_config.vendorclass); |
@@ -97,7 +87,7 @@ int send_discover(unsigned long xid, unsigned long requested) | |||
97 | add_requests(&packet); | 87 | add_requests(&packet); |
98 | bb_info_msg("Sending discover..."); | 88 | bb_info_msg("Sending discover..."); |
99 | return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, | 89 | return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, |
100 | SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); | 90 | SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); |
101 | } | 91 | } |
102 | 92 | ||
103 | 93 | ||
@@ -188,10 +178,12 @@ int get_raw_packet(struct dhcpMessage *payload, int fd) | |||
188 | bytes = ntohs(packet.ip.tot_len); | 178 | bytes = ntohs(packet.ip.tot_len); |
189 | 179 | ||
190 | /* Make sure its the right packet for us, and that it passes sanity checks */ | 180 | /* Make sure its the right packet for us, and that it passes sanity checks */ |
191 | if (packet.ip.protocol != IPPROTO_UDP || packet.ip.version != IPVERSION || | 181 | if (packet.ip.protocol != IPPROTO_UDP || packet.ip.version != IPVERSION |
192 | packet.ip.ihl != sizeof(packet.ip) >> 2 || packet.udp.dest != htons(CLIENT_PORT) || | 182 | || packet.ip.ihl != sizeof(packet.ip) >> 2 |
193 | bytes > (int) sizeof(struct udp_dhcp_packet) || | 183 | || packet.udp.dest != htons(CLIENT_PORT) |
194 | ntohs(packet.udp.len) != (uint16_t) (bytes - sizeof(packet.ip))) { | 184 | || bytes > (int) sizeof(struct udp_dhcp_packet) |
185 | || ntohs(packet.udp.len) != (uint16_t)(bytes - sizeof(packet.ip)) | ||
186 | ) { | ||
195 | DEBUG("Unrelated/bogus packet"); | 187 | DEBUG("Unrelated/bogus packet"); |
196 | return -2; | 188 | return -2; |
197 | } | 189 | } |