Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Protocol Analysis: IP check and algorithm

2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Definition: a checksum is an error correction field for the IP header. Checksums do not calculate the encapsulated data. UDP, TCP, and ICMP all have their own checksums. The header checksum field contains a 16-bit binary complement sum, which is calculated by the packet sender. The recipient will recalculate the 16-bit binary complement sum together with the original checksum. If there are no errors in the packet transmission, the result should be 1 for all 16 bits.

Code:

Unsigned short csum (unsigned char * addr,int count)

{

/ * ComputeInternet Checksum for "count" bytes beginning at location "addr". , /

Registerlong sum = 0

While (count > 1)

{

/ * This is the inner loop * /

Sum + = * (unsigned short) addr++

Count-= 2

}

/ * Add leftover byte,if any * /

If (count > 0) / / Odd byte, considering whether the CPU mode is large or small

# if BIG_ENDIAN

Sum+= (* (unsigned char *) addr) 16)

Sum = (sum & 0xffff) + (sum > > 16)

Return ~ sum

}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report