[git commit] udhcpc: small code shrink

Denys Vlasenko vda.linux at googlemail.com
Thu Oct 20 08:34:05 UTC 2011


commit: http://git.busybox.net/busybox/commit/?id=7981d79ef0bea5c8224edd949157be57ffd1173a
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
udhcp_recv_raw_packet                                430     425      -5

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 networking/udhcp/dhcpc.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 311d486..b841969 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)
 	bytes = ntohs(packet.ip.tot_len);
 
 	/* make sure its the right packet for us, and that it passes sanity checks */
-	if (packet.ip.protocol != IPPROTO_UDP || packet.ip.version != IPVERSION
+	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(packet) - can't happen */
@@ -831,15 +832,17 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
 		return -2;
 	}
 
-	memcpy(dhcp_pkt, &packet.data, bytes - (sizeof(packet.ip) + sizeof(packet.udp)));
-
-	if (dhcp_pkt->cookie != htonl(DHCP_MAGIC)) {
+	if (packet.data.cookie != htonl(DHCP_MAGIC)) {
 		bb_info_msg("Packet with bad magic, ignoring");
 		return -2;
 	}
+
 	log1("Got valid DHCP packet");
-	udhcp_dump_packet(dhcp_pkt);
-	return bytes - (sizeof(packet.ip) + sizeof(packet.udp));
+	udhcp_dump_packet(&packet.data);
+
+	bytes -= sizeof(packet.ip) + sizeof(packet.udp);
+	memcpy(dhcp_pkt, &packet.data, bytes);
+	return bytes;
 }
 
 


More information about the busybox-cvs mailing list