+uint16_t dhcp_packet_checksum(void *buf, size_t len) {
+ uint64_t *buf_64 = buf;
+ uint64_t *end_64 = (uint64_t*)buf + (len / sizeof(uint64_t));
+ uint32_t *buf_32;
+ uint16_t *buf_16;
+ uint8_t *buf_8;
+ uint64_t sum = 0;
+
+ while (buf_64 < end_64) {
+ sum += *buf_64;
+ if (sum < *buf_64)
+ sum++;
+
+ buf_64 ++;
+ }
+
+ buf_32 = (uint32_t*)buf_64;
+
+ if (len & sizeof(uint32_t)) {
+ sum += *buf_32;
+ if (sum < *buf_32)
+ sum++;
+
+ buf_32 ++;
+ }