From 0bbc2c1f3b8f01eac7826dab1a3e1e073f63da8a Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Mon, 16 Jun 2014 15:24:28 +0200 Subject: sd-dhcp: checksum - make endianess-neutral For efficiency, we group bytes together before adding them up. This is guaranteed to always work (regardless of the byte order) as long as the i-th byte in each group lign up with the i-th byte in each other group. On big-endian machines this broke when handling the trailing few bytes which did not make up a full group of 4 bytes. This patch fixes the problem by explicitly creating a 4 byte zero-padded group out of the trailing bytes. Reported and tested by Thomas Ritter . --- src/libsystemd-network/test-dhcp-client.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/libsystemd-network/test-dhcp-client.c') diff --git a/src/libsystemd-network/test-dhcp-client.c b/src/libsystemd-network/test-dhcp-client.c index 599bda1a5e..450b6d4d3c 100644 --- a/src/libsystemd-network/test-dhcp-client.c +++ b/src/libsystemd-network/test-dhcp-client.c @@ -128,7 +128,7 @@ static void test_checksum(void) if (verbose) printf("* %s\n", __FUNCTION__); - assert_se(dhcp_packet_checksum(&buf, 20) == be16toh(0x78ae)); + assert_se(dhcp_packet_checksum((uint8_t*)&buf, 20) == be16toh(0x78ae)); } static int check_options(uint8_t code, uint8_t len, const uint8_t *option, @@ -175,13 +175,13 @@ int dhcp_network_send_raw_socket(int s, const union sockaddr_union *link, discover->ip.ttl = 0; discover->ip.check = discover->udp.len; - udp_check = ~dhcp_packet_checksum(&discover->ip.ttl, len - 8); + udp_check = ~dhcp_packet_checksum((uint8_t*)&discover->ip.ttl, len - 8); assert_se(udp_check == 0xffff); discover->ip.ttl = IPDEFTTL; discover->ip.check = ip_check; - ip_check = ~dhcp_packet_checksum(&discover->ip, sizeof(discover->ip)); + ip_check = ~dhcp_packet_checksum((uint8_t*)&discover->ip, sizeof(discover->ip)); assert_se(ip_check == 0xffff); assert_se(discover->dhcp.xid); -- cgit v1.2.3-54-g00ecf