>судя по привиденному выше в сообщениях коду эта операция бессмысленна, т.е. надо чтобы в псевдопакете поле сумма было равно 0. а строка tcp->th_sum = 0; - это обнуление не в псевдопакете, а в некой структуре которая в самом расчете не принимает участия :)
http://www.security.nnov.ru/files/stream3.cinline u_short tcp_checksum(u_short *addr, int len)
{
register int nleft = len;
register u_short *w = addr;
register int sum = 0;
u_short answer = 0;
/* Our algorithm is simple, using a 32 bit accumulator (sum), we add
* sequential 16 bit words to it, and at the end, fold back all the
* carry bits from the top 16 bits into the lower 16 bits. */
while (nleft > 1) {
sum += *w++;
nleft -= 2;
}
/* mop up an odd byte, if necessary */
if (nleft == 1) {
*(u_char *)(&answer) = *(u_char *) w;
sum += answer;
}
/* add back carry outs from top 16 bits to low 16 bits */
sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
sum += (sum >> 16); /* add carry */
answer = ~sum; /* truncate to 16 bits */
return(answer);
}
struct _pseudoheader {
struct in_addr source_addr;
struct in_addr destination_addr;
u_char zero; /* зеpо */
u_char protocol;
u_short length;
} pseudoheader;
u_char *pseudopacket;
pseudoheader.source_addr = iph->ip_src;
pseudoheader.destination_addr = iph->ip_dst;
pseudoheader.zero = 0;
pseudoheader.protocol = IPPROTO_TCP;
pseudoheader.length = htons(size_tcp + size_payload);
pseudopacket = (char *)malloc(sizeof(pseudoheader) + sizeof(struct tcphdr) + size_payload);
if ( !pseudopacket ) {
perror ("malloc");
exit (1);
}
memcpy (pseudopacket, &pseudoheader, sizeof (pseudoheader));
memcpy (pseudopacket + sizeof (pseudoheader),packet + size_ethernet + size_ip, size_tcp);
memcpy (pseudopacket + sizeof (pseudoheader) + size_tcp,packet + size_ethernet + size_ip + size_tcp, size_payload);
tcph->th_sum = 0;
tcph->th_sum = tcp_checksum ((u_short *)pseudopacket, sizeof (pseudoheader)+ size_tcp + size_payload);