Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- u_short ip_sum_calc( u_short len_ip_header, u_short * buff )
- {
- u_short word16;
- u_int sum = 0;
- u_short i;
- // make 16 bit words out of every two adjacent 8 bit words in the packet
- // and add them up
- for( i = 0; i < len_ip_header; i = i+2 )
- {
- word16 = ( ( buff[i]<<8) & 0xFF00 )+( buff[i+1] & 0xFF );
- sum = sum + (u_int) word16;
- }
- // take only 16 bits out of the 32 bit sum and add up the carries
- while( sum >> 16 )
- sum = ( sum & 0xFFFF ) + ( sum >> 16 );
- // one's complement the result
- sum = ~sum;
- return ((u_short) sum);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement