short checksum = 0; for(int i = 0; i<(sizeof(IPV4_HDR)+sizeof(TCP_HDR)+payload); i+=2) checksum += !(short)buf[i]; tcphdr->checksum = !checksum;