TCP/IP Detailed learning notes (6)-UDP protocol

Source: Internet
Author: User
1.UDP Brief Introduction

UDP is a transport layer protocol, and TCP protocol is in a hierarchy, but unlike the TCP protocol, UDP protocol does not provide timeout retransmission, error retransmission and other functions, that is, it is unreliable protocol. 2.UDP Protocol Header 2.1.UDP Port number

Because a lot of software needs to use the UDP protocol, the UDP protocol must be used to differentiate the packets required by different programs through a flag. The function of the port number is this, for example, a certain UDP program A in the system registered 3000 ports, then the incoming from the outside of the destination port number of 3000 UDP packets will be given to the program. The port number can theoretically have 2^16 so much. Because its length is 16 bit 2.2.UDP test and

This is an optional option, not all systems are testing UDP packets and data (relative to TCP protocol must), but the RFC standard requires that the sender compute the test and.

UDP examines and overwrites UDP protocol headers and data, which are different from IP verification and IP protocol testing and simply overwriting IP headers and not covering all data. Both UDP and TCP contain a pseudo header, which is filmed to compute the test and. The pseudo header even contains information that is contained in IP protocols such as IP addresses, and is designed to allow UDP to check two times whether the data has reached its destination correctly. If the sender does not open the test and the option, and the receiver calculates the test and the error, the UDP data will be silently discarded (not guaranteed to be delivered) without any error messages being generated. 2.3.UDP Length

UDP can be very long and can be as long as 65535 bytes. But when the general network is transmitting, a general transmission of such a long protocol (related to the MTU problem), you have to data fragmentation, of course, these are the UDP and other superior protocols transparent, UDP does not need to care about the IP protocol layer on the data fragmentation, the next chapter will slightly discuss some of the fragmented strategy. 3.IP Fragmentation

IP after receiving data from the upper layer, the IP address is used to determine the data sent from that interface (through the selection route), and the MTU query, if the data size exceeds the MTU for data fragmentation. The fragmentation of the data is transparent to the upper and lower layers, and the data will only arrive at the destination and be reassembled, but don't worry, the IP layer provides enough information for the data to be reassembled.

Within the IP header, the 16bit identification number uniquely records the ID of an IP packet, IP slices with the same ID are reassembled, while the 13-bit offset records the position of an IP slice relative to the entire packet, while the middle 3bit flag indicates whether there is a new fragment behind the fragment. These three marks form all the information of the IP fragment, which can be used by the receiving party to rearrange the IP data (even if the latter fragment precedes the previous fragment, this information is sufficient).

Because the slice technology is used frequently on the network, so the software and the person that the counterfeit IP fragment packet carries on the rogue attack is endless.

You can use the Trancdroute program for simple MTU detection. Please refer to the textbook. Interactive use between 3.UDP and ARP

This is a small detail that is not often noticed, and this is for some systematic implementation. When the ARP cache is still empty. UDP before being sent must send an ARP request to obtain the destination host's MAC address, if this UDP packet large enough to the IP layer must be fragmented, imagine that the first fragment of the UDP packet will issue an ARP query request, All the Shard Du Hui wait until this query is complete before sending. Actually, is that so?

As a result, some systems will allow each fragment to send an ARP query, all the fragments are waiting, but received the first response, the host has only sent the last piece of data and abandoned the other, it is really incredible. This way, because the fragmented data cannot be assembled in time, the receiving host will discard IP packets that will never be assembled for a period of time, and send an ICMP message that assembles the timeout (in fact, many systems do not produce this error) to ensure that the receiving host's own receiver cache is not filled by fragments that are never assembled. 4.ICMP Source Station suppression error

When the target host's processing speed can not catch up with the speed of data reception, because the host's IP layer cache will be full, so the host will send a "I can't Stand" an ICMP message. 5.UDP Server Design

Some of the features of the UDP protocol will affect our server programming, broadly summarized as follows: About client IP and address: The server must have the ability to determine whether the packet is legitimate based on the client's IP address and port number (which seems to require every server) About Destination Address: The server must have the ability to filter broadcast addresses. About data entry: usually every port of the server system corresponds to an input buffer, incoming input according to the principle of arrival waiting for the server processing, so there will inevitably be a buffer overflow problem, in which case, UDP packets may be discarded, and the application server program itself does not know the problem. The server should limit the local IP address, which means it should be able to bind itself to a certain port on a network interface.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.