networking · advanced · ~15 min
Implement the checksum used by IP/UDP/TCP.
Implement unsigned short inet_checksum(const unsigned char *data, int n) computing the standard 16-bit ones-complement Internet checksum over n bytes (big-endian 16-bit words, end-around carry, then bitwise NOT).
unsigned short inet_checksum(const unsigned char *data, int n) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.