[email protected], Welcome to technical exchange , This blog is mainly my own learning experience , Just to make a ...">

当前位置:网站首页>UDP summary (tcp/ip details volume 1/2)

UDP summary (tcp/ip details volume 1/2)

2022-06-12 15:21:00 QQ851301776

Created by QQ:851301776, mailbox :[email protected], Welcome to technical exchange , This blog is mainly my own learning experience , Just to make a little progress every day !

Personal motto :
1. No one was born , As long as it is thick, it will happen .
2. You can have a low degree , You can skip school , But you have to learn

Summary of this blog , It is mainly to facilitate future viewing and learning
 

One 、 brief introduction

UDP Is a simple datagram oriented transport layer protocol : Each output operation of the process produces exactly one UDP The datagram , And assemble a copy of the IP The datagram . This is different from the stream character oriented protocol , Such as T C P, The whole data generated by the application and the single data actually sent I P The datagram may not have any connection .

U D P No reliability : It passes the application to I P Layer data sent out , But there is no guarantee that they will reach their destination .

Two 、UDP The first one

          Port number Express Sending and receiving processes . because I P The layer has put I P A datagram is assigned to T C P or U D P( according to I P Protocol field value in the first part ), therefore T C P Port number from T C P Check it out. , and U D P Port number from U D P Check it out. .T C P Port number and U D P Port numbers are independent of each other .
         In spite of their independence , If T C P and U D P At the same time provide some well-known Services , Two protocols usually choose the same port number . It's just for convenience , Not the requirements of the agreement itself .

        U D P length Field refers to U D P The first one and U D P Byte length of data . The minimum value of this field is 8 byte ( Send a copy of 0 Bytes of U D P The datagram is O K). This U D P Length is redundant . I P Datagram length refers to the total length of datagram , therefore U D P The length of the datagram is the total length minus I P The length of the head .
        UDP Inspection and :U D P Inspection and coverage U D P The first and U D P data . To recall I P The inspection of the first part and , It only covers I P The first — It doesn't cover I P Any data in a datagram .U D P and T C P In the header, there are tests and . U D P And is optional , and T C P And is necessary .

Even though U D P The basic calculation method and I P The first test is similar to the calculation method (16 bit The binary inverse of a word and ), But there are differences between them .

  • U D P The length of datagram can be odd bytes , But the test and algorithm is to put a number of 16 bit Add words . The solution is to add padding bytes at the end if necessary 0, It's just for checking and calculating ( in other words , Possible additional padding bytes are not transmitted ).
  • U D P Datagram and T C P Segment contains one 1 2 Byte long pseudo header , It's set up to calculate the checksums . Pseudo header contains I P First some fields . The purpose is to make U D P Check twice whether the data has arrived at the destination correctly ( for example , I P No accepted address is not the datagram of the host , as well as I P Did not transmit the data report that should be transmitted to another senior level to U D P).U D P The format of pseudo header in datagram is as shown in figure 11 - 3 Shown .

 

          In this diagram , We give an example of odd length datagram , Therefore, we need to add padding bytes when calculating checksums . Be careful ,U D P The length of the datagram appears twice in the process of inspection and calculation . If the test sum is calculated as 0, Then the stored value is all 1(6 5 5 3 5), This is equivalent in the calculation of binary inverse code . If the test sum of the transmission is 0, Note that the sender does not calculate the check and .

         If the sender does not calculate the check sum and the receiver detects the check sum error , that U D P Datagrams will be quietly discarded . No error messages are generated ( When I P Layer detected I P Do the same for the first inspection and when there is an error ).U D P Inspection and is an end-to-end inspection and . It's calculated by the sender , Then it is verified by the receiver . The aim is to discover U D P Any changes in the header and data between the sending end and the receiving end .

         Even though U D P Test and are optional , But they should always be in use . stay 8 0 years , Some computer manufacturers turn off... By default U D P The function of inspection and , To improve the use of U D P Agreed N F S(Network File System) The speed of . This may be acceptable in a single LAN , But when the datagram goes through the router , Through the cyclic redundancy test of the link layer data frame ( Such as Ethernet or token ring data frame ) Most errors can be detected , Cause the transmission to fail . Believe it or not , There are also software and hardware errors in routers , So as to modify the data in the datagram . If end-to-end U D P Inspection and function , So these mistakes are U D P The datagram can't be detected . in addition , Some DLL protocols ( Such as S L I P) There is no form of data link verification and .

        Host Requirements RFC Statement ,U D P Checks and options are on by default . It also states , If the sender has calculated the check and , Then the receiver must check the received check and ( If received inspection and not for 0). however , Many systems do not comply with this , The received inspection sum is verified only when the export inspection sum option is turned on .

  3、 ... and 、 Code implementation

struct udphdr {
	__be16	source; // Source port 
	__be16	dest;   // Destination port 
	__be16	len;    //UDP Header and application data length 
	__sum16	check;  // check 
};

原网站

版权声明
本文为[QQ851301776]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206121515216481.html