diff options
| author | Roy Marples <roy@marples.name> | 2008-11-19 15:01:20 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2008-11-19 15:01:20 +0000 |
| commit | 0b10229bc6ae7eadcc84a3c5e5710aac11c4f163 (patch) | |
| tree | 9b57dd736697bf4a8dd41e1162dccc1abd303527 /net.c | |
| parent | c5cf49e71a87e064a503ca8dfe771c41cb8db26b (diff) | |
| download | dhcpcd-0b10229bc6ae7eadcc84a3c5e5710aac11c4f163.tar.xz | |
Zeroing each field is cheaper than using memset/memcpy.
Diffstat (limited to 'net.c')
| -rw-r--r-- | net.c | 21 |
1 files changed, 9 insertions, 12 deletions
@@ -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; } |
