#include #include #define BUF 64 typedef struct { char data[BUF]; unsigned checksum; } Packet; unsigned compute_cs(const char *d) { unsigned s = 0; for (int i = 0; d[i]; i++) s += (unsigned char)d[i]; return s; } int main(void) { Packet p; strcpy(p.data, "hello"); p.checksum = compute_cs(p.data); printf("Client: sending '%s' cs=%u\n", p.data, p.checksum); for (int try = 1; try <= 2; try++) { printf("Try %d: ", try); if (try == 1) { printf("lost\n"); continue; } printf("ok\n"); unsigned rcs = compute_cs(p.data); if (rcs == p.checksum) { printf("Server: got '%s' ok, reply 'ack'\n", p.data); } } return 0; }