i've done some searching on how to calculate the tcp checksum, and this is what i came up with...
NOTE: i used the checksum function below to calculate the ip header checksum and it gave me correct results (i used a packet sniffer and looked at iphdr checksums and recalculated them to verify that)
// pseudo header
unsigned int sourceIP;
unsigned int destIP;
unsigned char placholder;
unsigned char proto;
unsigned short tcp_len;
// checksum function:
USHORT checksum(USHORT *buffer, int size)
unsigned long cksum=0;
while (size > 1)
cksum += *buffer++;
size -= sizeof(USHORT);
cksum += *(UCHAR*)buffer;
cksum = (cksum >> 16) + (cksum & 0xffff);
cksum += (cksum >>16);
} // special thanks to the author (who i don't know) for
// providing this function
/////////rest of code///////////////
pTcpheader->th_sum = 0;
i'm so0o0o0o0o0o sorry for bothering you guys...
the mistake was somewhere else.
The code i posted is correct. Hope someone could make use of it.
Now i have just done my first packet crafting program in C, thanx to the full raw socket support billy has provided windows users with, we don't have to do it the hard way to craft packets.