summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd-dhcp/dhcp-client.c7
-rw-r--r--src/libsystemd-dhcp/test-dhcp-client.c7
2 files changed, 10 insertions, 4 deletions
diff --git a/src/libsystemd-dhcp/dhcp-client.c b/src/libsystemd-dhcp/dhcp-client.c
index 7dc1546128..68a3b1a1b6 100644
--- a/src/libsystemd-dhcp/dhcp-client.c
+++ b/src/libsystemd-dhcp/dhcp-client.c
@@ -382,10 +382,13 @@ static uint16_t client_checksum(void *buf, int len)
if (len & 0x01) {
odd = buf;
- sum += odd[len];
+ sum += odd[len - 1];
}
- return ~((sum & 0xffff) + (sum >> 16));
+ while (sum >> 16)
+ sum = (sum & 0xffff) + (sum >> 16);
+
+ return ~sum;
}
static void client_append_ip_headers(DHCPPacket *packet, uint16_t len)
diff --git a/src/libsystemd-dhcp/test-dhcp-client.c b/src/libsystemd-dhcp/test-dhcp-client.c
index d398510745..7400cc6837 100644
--- a/src/libsystemd-dhcp/test-dhcp-client.c
+++ b/src/libsystemd-dhcp/test-dhcp-client.c
@@ -102,10 +102,13 @@ static uint16_t client_checksum(void *buf, int len)
if (len & 0x01) {
odd = buf;
- sum += odd[len];
+ sum += odd[len - 1];
}
- return ~((sum & 0xffff) + (sum >> 16));
+ while (sum >> 16)
+ sum = (sum & 0xffff) + (sum >> 16);
+
+ return ~sum;
}
static void test_checksum(void)