Sum_total = sum ( data_sum ) #Calculate the sum of all numbers append ( int ( part_all, 16 ) ) # print(data_sum) #If converted to hexadecimal, only 1 bit needs high-order complement 0 operation, use the zfill method #First, you need to merge the two numbers into a 16-bit hexadecimal number for num in range ( 0, len ( self. append ( 0x00 ) def check_process ( self ) : check_content ) % 2 = 1 : # The length of the entire message is odd and needs to be added 0 check_content = 0 #Set the original checksum to 0 IP_content ) def set_and_fill_zero ( self ) : # udp added to the contents of the check section for I in Range ( udp_content_len ) : IP_content ) DEF add_udp_content ( Self ) : length #udp content IP_content ) #UDP data length is the 5th and 6th bytes in the UDP message, the length field of the pseudo header Append ( 0x00 ) #The protocol type is the 10th byte of the IP message, that is, the protocol type field of the pseudo header IP_content ) #UDP The third field of the pseudo header is 0x00 IP_content ) #IP destination address is the 17, 18, 19, 20 bytes of the IP message, that is, the destination IP address field of the pseudo header check_content = #UDP Checksum Section # UDP checksum part = UDP pseudo header + UDP content (UDP header + UDP data part) def add_udp_pseudo_header_content ( self ) : # UDP pseudo header = source IP address + destination IP address + 0x00 + protocol field + UDP length #IP source address is the 13, 14, 15, 16 bytes of the IP message, that is, the source IP address field of the pseudo header Simple and detailed explanation of binary mid-complement calculationĬlass Udp_check ( ) : def _init_ ( self, IP_content ) :.Otherwise, it indicates that there is an error, and the receiver should discard the UDP datagram (it can also be handed over to the application layer, but attach a warning that an error has occurred) When there are no errors, the result should be all ones.Press binary one calculates these 16-bit words and.If the UDP user data part is not an even number of bytes, it must be filled with all 0 bytes (but this byte is not sent). Think of the parity part as a series of 16-bit words. Pseudo header (12 bytes) = source IP address (4 Byte) + destination IP address (4 bytes) + 0x00 (1 byte) + protocol number (1 byte) + UDP length (2 bytes)Īfter spelling out the UDP checksum, set the checksum to 0. UDP checksum part = pseudo header (12 bytes) + UDP header (8 bytes) + data (n bytes) But the difference is: IP packet inspection and test only the header of an IP datagram, but the UDP checksum is the header and data portion of the test together. UDP calculation test and method of calculation and IP datagram header checksum method is similar.
0 Comments
Leave a Reply. |