summaryrefslogtreecommitdiff
path: root/networking/udhcp/clientpacket.c
diff options
context:
space:
mode:
authorDenis Vlasenko2007-12-24 17:32:22 +0000
committerDenis Vlasenko2007-12-24 17:32:22 +0000
commit8e5b6f58a27d840cabf491634e956407d147ddb6 (patch)
tree86c65a2ce32290b19212c6d95600ae3a7eb046c0 /networking/udhcp/clientpacket.c
parent299c5c379e006ce2c3a39c42a323f297e4a4fb18 (diff)
downloadbusybox-8e5b6f58a27d840cabf491634e956407d147ddb6.zip
busybox-8e5b6f58a27d840cabf491634e956407d147ddb6.tar.gz
Makefile: change version to 1.10.0.svn
udhcpc: make UDP packet sending the same as raw sending in regards to error messages. Minor code size shrink. Total size grows due to added messages: text data bss dec hex filename 770312 683 7244 778239 bdfff busybox_old 770327 683 7244 778254 be00e busybox_unstripped
Diffstat (limited to 'networking/udhcp/clientpacket.c')
-rw-r--r--networking/udhcp/clientpacket.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c
index 0347310..b8190ba 100644
--- a/networking/udhcp/clientpacket.c
+++ b/networking/udhcp/clientpacket.c
@@ -167,39 +167,40 @@ int send_release(uint32_t server, uint32_t ciaddr)
}
-/* return -1 on errors that are fatal for the socket, -2 for those that aren't */
+/* Returns -1 on errors that are fatal for the socket, -2 for those that aren't */
int get_raw_packet(struct dhcpMessage *payload, int fd)
{
int bytes;
struct udp_dhcp_packet packet;
uint16_t check;
- memset(&packet, 0, sizeof(struct udp_dhcp_packet));
- bytes = read(fd, &packet, sizeof(struct udp_dhcp_packet));
+ memset(&packet, 0, sizeof(packet));
+ bytes = safe_read(fd, &packet, sizeof(packet));
if (bytes < 0) {
DEBUG("Cannot read on raw listening socket - ignoring");
sleep(1); /* possible down interface, looping condition */
- return -1;
+ return bytes; /* returns -1 */
}
- if (bytes < (int) (sizeof(struct iphdr) + sizeof(struct udphdr))) {
- DEBUG("Message too short, ignoring");
+ if (bytes < (int) (sizeof(packet.ip) + sizeof(packet.udp))) {
+ DEBUG("Packet is too short, ignoring");
return -2;
}
if (bytes < ntohs(packet.ip.tot_len)) {
- DEBUG("Truncated packet");
+ /* packet is bigger than sizeof(packet), we did partial read */
+ DEBUG("Oversized packet, ignoring");
return -2;
}
/* ignore any extra garbage bytes */
bytes = ntohs(packet.ip.tot_len);
- /* Make sure its the right packet for us, and that it passes sanity checks */
+ /* make sure its the right packet for us, and that it passes sanity checks */
if (packet.ip.protocol != IPPROTO_UDP || packet.ip.version != IPVERSION
|| packet.ip.ihl != (sizeof(packet.ip) >> 2)
|| packet.udp.dest != htons(CLIENT_PORT)
- || bytes > (int) sizeof(struct udp_dhcp_packet)
+ /* || bytes > (int) sizeof(packet) - can't happen */
|| ntohs(packet.udp.len) != (uint16_t)(bytes - sizeof(packet.ip))
) {
DEBUG("Unrelated/bogus packet");
@@ -211,12 +212,12 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
packet.ip.check = 0;
if (check != udhcp_checksum(&packet.ip, sizeof(packet.ip))) {
DEBUG("Bad IP header checksum, ignoring");
- return -1;
+ return -2;
}
/* verify UDP checksum. IP header has to be modified for this */
memset(&packet.ip, 0, offsetof(struct iphdr, protocol));
- /* fields which are not memset: protocol, check, saddr, daddr */
+ /* ip.xx fields which are not memset: protocol, check, saddr, daddr */
packet.ip.tot_len = packet.udp.len; /* yes, this is needed */
check = packet.udp.check;
packet.udp.check = 0;
@@ -228,7 +229,7 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
memcpy(payload, &packet.data, bytes - (sizeof(packet.ip) + sizeof(packet.udp)));
if (payload->cookie != htonl(DHCP_MAGIC)) {
- bb_error_msg("received bogus message (bad magic) - ignoring");
+ bb_error_msg("received bogus message (bad magic), ignoring");
return -2;
}
DEBUG("Got valid DHCP packet");