aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-10-20 10:34:05 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2011-10-20 10:34:05 +0200
commit7981d79ef0bea5c8224edd949157be57ffd1173a (patch)
treefd41443d7b60b72902ecb45eb0d905a48cecdc37 /networking
parentf461385521c40a8295e9a36cd2f3f67512984124 (diff)
downloadbusybox-w32-7981d79ef0bea5c8224edd949157be57ffd1173a.tar.gz
busybox-w32-7981d79ef0bea5c8224edd949157be57ffd1173a.tar.bz2
busybox-w32-7981d79ef0bea5c8224edd949157be57ffd1173a.zip
udhcpc: small code shrink
function old new delta udhcp_recv_raw_packet 430 425 -5 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking')
-rw-r--r--networking/udhcp/dhcpc.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 311d4867a..b84196926 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -802,7 +802,8 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
802 bytes = ntohs(packet.ip.tot_len); 802 bytes = ntohs(packet.ip.tot_len);
803 803
804 /* make sure its the right packet for us, and that it passes sanity checks */ 804 /* make sure its the right packet for us, and that it passes sanity checks */
805 if (packet.ip.protocol != IPPROTO_UDP || packet.ip.version != IPVERSION 805 if (packet.ip.protocol != IPPROTO_UDP
806 || packet.ip.version != IPVERSION
806 || packet.ip.ihl != (sizeof(packet.ip) >> 2) 807 || packet.ip.ihl != (sizeof(packet.ip) >> 2)
807 || packet.udp.dest != htons(CLIENT_PORT) 808 || packet.udp.dest != htons(CLIENT_PORT)
808 /* || bytes > (int) sizeof(packet) - can't happen */ 809 /* || bytes > (int) sizeof(packet) - can't happen */
@@ -831,15 +832,17 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
831 return -2; 832 return -2;
832 } 833 }
833 834
834 memcpy(dhcp_pkt, &packet.data, bytes - (sizeof(packet.ip) + sizeof(packet.udp))); 835 if (packet.data.cookie != htonl(DHCP_MAGIC)) {
835
836 if (dhcp_pkt->cookie != htonl(DHCP_MAGIC)) {
837 bb_info_msg("Packet with bad magic, ignoring"); 836 bb_info_msg("Packet with bad magic, ignoring");
838 return -2; 837 return -2;
839 } 838 }
839
840 log1("Got valid DHCP packet"); 840 log1("Got valid DHCP packet");
841 udhcp_dump_packet(dhcp_pkt); 841 udhcp_dump_packet(&packet.data);
842 return bytes - (sizeof(packet.ip) + sizeof(packet.udp)); 842
843 bytes -= sizeof(packet.ip) + sizeof(packet.udp);
844 memcpy(dhcp_pkt, &packet.data, bytes);
845 return bytes;
843} 846}
844 847
845 848