UDP Header

UDP consist of header and body, just like IP datagrams. The body part contains whatever data was provided by the application, white the header contains the fields that tell the destination UDP software what to do with the data.

The Structure

The total size of the header will vary according to the size of the data in the body part. The fields in a UDP massage are shows in the table bellow, along with their size (in bytes) and their usage

Field  Byte Details
Source Port 2 16 bit port number in use by the application that is sending the data
Destination Port 2 16 bit target port number of the application that is to receive this data
Length 2 Specifies the size of the total UDP message, including both the header and data segments
Data varies the data portion of the UDP message

UDP Header does not provide any fields for source or destinations IP addresses, or for any other service that are not specifically related to UDP. this is because those service are provided by lower layer (IP) or by higher layer (Application).

Header Size

Theoretically the minimum size of UDP header is 8 byte. Although this will not leave any space for data in the message. In reality, no UDP message should ever be generated that does not contain at least some data.

Simulation

Here we using the command prompt with two different application (sendudp1, sendudp1). each application create different UDP header. The UDP header is not a real one. the length of the header in the simulation is determine by the size of the header plus 1 for each char you sent. the checksum header is calculated on all the header including the data and the header but it does not reflect the reality


osischool.com

Embedding:
Do not change the code.