Hot Downloads

Welcome, Guest
Username: Password: Remember me

TOPIC: tcp checksum

tcp checksum 13 years 9 months ago #4513

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
struct pseudohdr
unsigned int sourceIP;
unsigned int destIP;
unsigned char placholder;
unsigned char proto;
unsigned short tcp_len;
} pshdr;
// checksum function:
USHORT checksum(USHORT *buffer, int size)
unsigned long cksum=0;
while (size > 1)
cksum += *buffer++;
size -= sizeof(USHORT);
if (size)
cksum += *(UCHAR*)buffer;
cksum = (cksum >> 16) + (cksum & 0xffff);
cksum += (cksum >>16);
return (USHORT)(~cksum);
} // special thanks to the author (who i don't know) for
// providing this function
/////////rest of code///////////////
pTcpheader->th_sum = 0;

pshdr.destIP = pIpheader->destIP;
pshdr.sourceIP = pIpheader->sourceIP;
pshdr.placholder = 0;
pshdr.proto = IPPROTO_TCP;
pshdr.tcp_len = htons(ntohs(pIpheader->total_len) - sizeof(IP_HDR));

void *pphdr;
pphdr=malloc( sizeof(pseudohdr)+ntohs(pshdr.tcp_len) );
memcpy((char *)pphdr+sizeof(pseudohdr),pTcpheader,

checksum((USHORT *)pphdr,sizeof(pseudohdr)+ntohs(pshdr.tcp_len)) );
// unfortunately this gives me the wrong result
The administrator has disabled public write access.

Re: tcp checksum 13 years 9 months ago #4515

  • Chris
  • Chris's Avatar
  • Offline
  • Administrator
  • Posts: 1447
  • Thank you received: 13
  • Karma: 8
Hmm.... Tfs and Sahir have programming knowledge, they should be able to help you out on this one. You could also consider posting the question to a revelant news groups.

Chris Partsenidis.
Founder & Editor-in-Chief
The administrator has disabled public write access.

got it....stupid me 13 years 9 months ago #4522

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.
The administrator has disabled public write access.
Time to create page: 0.113 seconds


Cisco Routers

  • SSL WebVPN
  • Securing Routers
  • Policy Based Routing
  • Router on-a-Stick

VPN Security

  • Understand DMVPN
  • GRE/IPSec Configuration
  • Site-to-Site IPSec VPN
  • IPSec Modes

Cisco Help

  • VPN Client Windows 8
  • VPN Client Windows 7
  • CCP Display Problem
  • Cisco Support App.

Windows 2012

  • New Features
  • Licensing
  • Hyper-V / VDI
  • Install Hyper-V


  • File Permissions
  • Webmin
  • Groups - Users
  • Samba Setup