diff options
Diffstat (limited to 'networking/udhcp/clientpacket.c')
-rw-r--r-- | networking/udhcp/clientpacket.c | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c index 6838c07e8..5b27004f9 100644 --- a/networking/udhcp/clientpacket.c +++ b/networking/udhcp/clientpacket.c | |||
@@ -18,7 +18,7 @@ | |||
18 | * along with this program; if not, write to the Free Software | 18 | * along with this program; if not, write to the Free Software |
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <string.h> | 22 | #include <string.h> |
23 | #include <sys/socket.h> | 23 | #include <sys/socket.h> |
24 | #include <features.h> | 24 | #include <features.h> |
@@ -73,7 +73,7 @@ static void init_packet(struct dhcpMessage *packet, char type) | |||
73 | char vendor, length; | 73 | char vendor, length; |
74 | char str[sizeof("udhcp "VERSION)]; | 74 | char str[sizeof("udhcp "VERSION)]; |
75 | } vendor_id = { DHCP_VENDOR, sizeof("udhcp "VERSION) - 1, "udhcp "VERSION}; | 75 | } vendor_id = { DHCP_VENDOR, sizeof("udhcp "VERSION) - 1, "udhcp "VERSION}; |
76 | 76 | ||
77 | init_header(packet, type); | 77 | init_header(packet, type); |
78 | memcpy(packet->chaddr, client_config.arp, 6); | 78 | memcpy(packet->chaddr, client_config.arp, 6); |
79 | add_option_string(packet->options, client_config.clientid); | 79 | add_option_string(packet->options, client_config.clientid); |
@@ -112,7 +112,7 @@ int send_discover(unsigned long xid, unsigned long requested) | |||
112 | 112 | ||
113 | add_requests(&packet); | 113 | add_requests(&packet); |
114 | LOG(LOG_DEBUG, "Sending discover..."); | 114 | LOG(LOG_DEBUG, "Sending discover..."); |
115 | return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, | 115 | return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, |
116 | SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); | 116 | SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); |
117 | } | 117 | } |
118 | 118 | ||
@@ -128,11 +128,11 @@ int send_selecting(unsigned long xid, unsigned long server, unsigned long reques | |||
128 | 128 | ||
129 | add_simple_option(packet.options, DHCP_REQUESTED_IP, requested); | 129 | add_simple_option(packet.options, DHCP_REQUESTED_IP, requested); |
130 | add_simple_option(packet.options, DHCP_SERVER_ID, server); | 130 | add_simple_option(packet.options, DHCP_SERVER_ID, server); |
131 | 131 | ||
132 | add_requests(&packet); | 132 | add_requests(&packet); |
133 | addr.s_addr = requested; | 133 | addr.s_addr = requested; |
134 | LOG(LOG_DEBUG, "Sending select for %s...", inet_ntoa(addr)); | 134 | LOG(LOG_DEBUG, "Sending select for %s...", inet_ntoa(addr)); |
135 | return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, | 135 | return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, |
136 | SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); | 136 | SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); |
137 | } | 137 | } |
138 | 138 | ||
@@ -149,12 +149,12 @@ int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr) | |||
149 | 149 | ||
150 | add_requests(&packet); | 150 | add_requests(&packet); |
151 | LOG(LOG_DEBUG, "Sending renew..."); | 151 | LOG(LOG_DEBUG, "Sending renew..."); |
152 | if (server) | 152 | if (server) |
153 | ret = kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); | 153 | ret = kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); |
154 | else ret = raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, | 154 | else ret = raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, |
155 | SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); | 155 | SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); |
156 | return ret; | 156 | return ret; |
157 | } | 157 | } |
158 | 158 | ||
159 | 159 | ||
160 | /* Unicasts a DHCP release message */ | 160 | /* Unicasts a DHCP release message */ |
@@ -165,7 +165,7 @@ int send_release(unsigned long server, unsigned long ciaddr) | |||
165 | init_packet(&packet, DHCPRELEASE); | 165 | init_packet(&packet, DHCPRELEASE); |
166 | packet.xid = random_xid(); | 166 | packet.xid = random_xid(); |
167 | packet.ciaddr = ciaddr; | 167 | packet.ciaddr = ciaddr; |
168 | 168 | ||
169 | add_simple_option(packet.options, DHCP_REQUESTED_IP, ciaddr); | 169 | add_simple_option(packet.options, DHCP_REQUESTED_IP, ciaddr); |
170 | add_simple_option(packet.options, DHCP_SERVER_ID, server); | 170 | add_simple_option(packet.options, DHCP_SERVER_ID, server); |
171 | 171 | ||
@@ -189,20 +189,20 @@ int get_raw_packet(struct dhcpMessage *payload, int fd) | |||
189 | usleep(500000); /* possible down interface, looping condition */ | 189 | usleep(500000); /* possible down interface, looping condition */ |
190 | return -1; | 190 | return -1; |
191 | } | 191 | } |
192 | 192 | ||
193 | if (bytes < (int) (sizeof(struct iphdr) + sizeof(struct udphdr))) { | 193 | if (bytes < (int) (sizeof(struct iphdr) + sizeof(struct udphdr))) { |
194 | DEBUG(LOG_INFO, "message too short, ignoring"); | 194 | DEBUG(LOG_INFO, "message too short, ignoring"); |
195 | return -2; | 195 | return -2; |
196 | } | 196 | } |
197 | 197 | ||
198 | if (bytes < ntohs(packet.ip.tot_len)) { | 198 | if (bytes < ntohs(packet.ip.tot_len)) { |
199 | DEBUG(LOG_INFO, "Truncated packet"); | 199 | DEBUG(LOG_INFO, "Truncated packet"); |
200 | return -2; | 200 | return -2; |
201 | } | 201 | } |
202 | 202 | ||
203 | /* ignore any extra garbage bytes */ | 203 | /* ignore any extra garbage bytes */ |
204 | bytes = ntohs(packet.ip.tot_len); | 204 | bytes = ntohs(packet.ip.tot_len); |
205 | 205 | ||
206 | /* Make sure its the right packet for us, and that it passes sanity checks */ | 206 | /* Make sure its the right packet for us, and that it passes sanity checks */ |
207 | if (packet.ip.protocol != IPPROTO_UDP || packet.ip.version != IPVERSION || | 207 | if (packet.ip.protocol != IPPROTO_UDP || packet.ip.version != IPVERSION || |
208 | packet.ip.ihl != sizeof(packet.ip) >> 2 || packet.udp.dest != htons(CLIENT_PORT) || | 208 | packet.ip.ihl != sizeof(packet.ip) >> 2 || packet.udp.dest != htons(CLIENT_PORT) || |
@@ -219,7 +219,7 @@ int get_raw_packet(struct dhcpMessage *payload, int fd) | |||
219 | DEBUG(LOG_INFO, "bad IP header checksum, ignoring"); | 219 | DEBUG(LOG_INFO, "bad IP header checksum, ignoring"); |
220 | return -1; | 220 | return -1; |
221 | } | 221 | } |
222 | 222 | ||
223 | /* verify the UDP checksum by replacing the header with a psuedo header */ | 223 | /* verify the UDP checksum by replacing the header with a psuedo header */ |
224 | source = packet.ip.saddr; | 224 | source = packet.ip.saddr; |
225 | dest = packet.ip.daddr; | 225 | dest = packet.ip.daddr; |
@@ -235,14 +235,14 @@ int get_raw_packet(struct dhcpMessage *payload, int fd) | |||
235 | DEBUG(LOG_ERR, "packet with bad UDP checksum received, ignoring"); | 235 | DEBUG(LOG_ERR, "packet with bad UDP checksum received, ignoring"); |
236 | return -2; | 236 | return -2; |
237 | } | 237 | } |
238 | 238 | ||
239 | memcpy(payload, &(packet.data), bytes - (sizeof(packet.ip) + sizeof(packet.udp))); | 239 | memcpy(payload, &(packet.data), bytes - (sizeof(packet.ip) + sizeof(packet.udp))); |
240 | 240 | ||
241 | if (ntohl(payload->cookie) != DHCP_MAGIC) { | 241 | if (ntohl(payload->cookie) != DHCP_MAGIC) { |
242 | LOG(LOG_ERR, "received bogus message (bad magic) -- ignoring"); | 242 | LOG(LOG_ERR, "received bogus message (bad magic) -- ignoring"); |
243 | return -2; | 243 | return -2; |
244 | } | 244 | } |
245 | DEBUG(LOG_INFO, "oooooh!!! got some!"); | 245 | DEBUG(LOG_INFO, "oooooh!!! got some!"); |
246 | return bytes - (sizeof(packet.ip) + sizeof(packet.udp)); | 246 | return bytes - (sizeof(packet.ip) + sizeof(packet.udp)); |
247 | 247 | ||
248 | } | 248 | } |