Friday 10 July 2015

Udp Checksum Calculation

The UDP checksum is a security measure for data transmissions.


The User Datagram Protocol, or UDP, packages data in packets for transport across networks. A data packet contains the data in the packet body, and has a series of headers in front of the data that help the packet get to its destination. The UDP header is short, but it contains a complicated method for calculating a checksum. The checksum enables the receiver to verify that the data packet has arrived intact.


Function


UDP is a transport protocol and is part of the network protocol suite called TCP/IP. TCP/IP stands for Transmission Control Protocol/Internet Protocol. The best known protocol of this suite is the Internet Protocol, which defines the IP address. The IP header is placed at the front of a data packet. Behind this, and before the data is the UDP header. Whereas the IP header contains the source and destination address of the two computers in the network transaction, the UDP header identifies the sending and receiving applications. These applications are recorded not by name, but by a reference number, called a port number.


UDP Header


A UDP header contains only two words. A "word" is a 32-bit binary number, which covers 4 bytes of data. The first work contains the source and destination port number. Each of these fields is 16 bits long. The second word also contains two fields, each 16 bits in length. These are the UDP Length field and the Checksum field. The UDP Length field records the size of the UDP header and the data body of the packet in bytes. The UDP checksum field is optional.


Checksum Calculation


The checksum in the UDP header is the "ones compliment" sum of sixteen bit words in the UDP header and the data body of the packet. The formula cannot cope with an odd number of bytes and so if the number of bytes in the data section of the packet is odd, the calculating program adds an all-zero padding byte to the end of the data. This ensures that the packet contains complete 16-bit words. The padding byte is only for the purpose of calculating the checksum. It is not transmitted with the packet. Next, the program creates a "pseudo header"which goes on the front of the UDP header. This contains address information taken from the IP header. Next, the number of 16-bit chunks of data are counted and the resulting number, expressed as binary is flipped over so that ones become zeros and zeros become ones.


Confirmation


The receiving program performs the same calculation. If the results are not the same, the packet is discarded, though no error message is sent back to the sender.

Tags: data packet, body packet, bytes data, calculating checksum, Checksum Calculation, contains source