chiark / gitweb /
libsystemd-dhcp: Fix checksum computation for buffer with odd size
[elogind.git] / src / libsystemd-dhcp / test-dhcp-client.c
index d398510745f373049c4e122da48a882b04a377b1..7400cc6837e72b48fd22692d031f7beab871cab9 100644 (file)
@@ -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)