shredder12
August 15th, 2009, 03:19 PM
This is my first post to code guru forums..
I am new to networking as well as socket programming.. and i am having some problems while learning them.
I am pretty confused about the purpose of checksums. What are they basically used for ??
and,
while I was reading a simple implementation of sending raw sockets from this page..
http://mixter.void.ru/rawip.html
I came across a function to calculate header checksums..
unsigned short /* this function generates header checksums */
csum (unsigned short *buf, int nwords)
{
unsigned long sum;
for (sum = 0; nwords > 0; nwords--)
sum += *buf++;
sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >> 16);
return ~sum;
}
As the comment says it is used to generate check sums but I am unable to understand how is it happening in this function ??
I can definitely use some help here..
I am new to networking as well as socket programming.. and i am having some problems while learning them.
I am pretty confused about the purpose of checksums. What are they basically used for ??
and,
while I was reading a simple implementation of sending raw sockets from this page..
http://mixter.void.ru/rawip.html
I came across a function to calculate header checksums..
unsigned short /* this function generates header checksums */
csum (unsigned short *buf, int nwords)
{
unsigned long sum;
for (sum = 0; nwords > 0; nwords--)
sum += *buf++;
sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >> 16);
return ~sum;
}
As the comment says it is used to generate check sums but I am unable to understand how is it happening in this function ??
I can definitely use some help here..