IP Header Checksum Calculation Implementation
![Udp Checksum C Program Udp Checksum C Program](/uploads/1/2/5/8/125880901/422212910.JPG)
Thank you so much. This is the best example of using udp I have found. I was using Borland C Builder 6: TNMUDP. I could specify ports, hosts and the receive event, and call Activate, and then I could send a char. buffer and react to such in the receive event. Checksum is an error-detecting technique that can be applied to message of any length. It is used mostly at the network and transport layers of the TCP/IP protocol suite. Here, we have considered decimal data that is being sent by the sender to the receiver using socket programming.
To calculate the IP checksum, one can use the code below, The method compute_ip_checksum initialize the checksum field of IP header to zeros. Then calls a method compute_checksum. The mothod compute_checksum accepts the computation data and computation length as two input parameters. It sum up all 16-bit words, if there’s odd number of bytes, it adds a padding byte. After summing up all words, it folds the sum to 16 bits by adding the carrier to the results. At last, it takes the one’s complement of sum and cast it to 16-bit unsigned short type.