]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Zeroing each field is cheaper than using memset/memcpy.
authorRoy Marples <roy@marples.name>
Wed, 19 Nov 2008 15:01:20 +0000 (15:01 +0000)
committerRoy Marples <roy@marples.name>
Wed, 19 Nov 2008 15:01:20 +0000 (15:01 +0000)
net.c

diff --git a/net.c b/net.c
index 291f40cca23d36827b034a3685997e88dbdae916..45dab802acc829c783318a1f6bf13cd8d7ad3254 100644 (file)
--- a/net.c
+++ b/net.c
@@ -638,8 +638,6 @@ valid_udp_packet(const uint8_t *data)
 {
        struct udp_dhcp_packet packet;
        uint16_t bytes, udpsum;
-       struct in_addr dest, source;
-       int retval = 0;
 
        memcpy(&packet, data, sizeof(packet));
        if (checksum(&packet.ip, sizeof(packet.ip)) != 0) {
@@ -648,22 +646,21 @@ valid_udp_packet(const uint8_t *data)
        }
 
        bytes = ntohs(packet.ip.ip_len);
-       packet.ip.ip_sum = 0;
-       memcpy(&source, &packet.ip.ip_src, sizeof(packet.ip.ip_src));
-       memcpy(&dest, &packet.ip.ip_dst, sizeof(packet.ip.ip_dst));
-       memset(&packet.ip, 0, sizeof(packet.ip));
        udpsum = packet.udp.uh_sum;
        packet.udp.uh_sum = 0;
-
-       packet.ip.ip_p = IPPROTO_UDP;
-       memcpy(&packet.ip.ip_src, &source, sizeof(packet.ip.ip_src));
-       memcpy(&packet.ip.ip_dst, &dest, sizeof(packet.ip.ip_dst));
+       packet.ip.ip_hl = 0;
+       packet.ip.ip_v = 0;
+       packet.ip.ip_tos = 0;
        packet.ip.ip_len = packet.udp.uh_ulen;
+       packet.ip.ip_id = 0;
+       packet.ip.ip_off = 0;
+       packet.ip.ip_ttl = 0;
+       packet.ip.ip_sum = 0;
        if (udpsum && checksum(&packet, bytes) != udpsum) {
                errno = EINVAL;
-               retval = -1;
+               return -1;
        }
 
-       return retval;
+       return 0;
 }