IP-TCP-UDP packet format

IP packet format

IP protocol:
basic concepts:

Host: with an IP address, the device does not perform routing control of
the router: with an IP address, routing control device can be
host and router collectively: Node
Function IP protocol

Addressing and routing (based on IP address To find the best path to transmit information)
delivery service
is unreliable (IP protocol only do their best to deliver reliable is provided by the upper layer TCP protocol)
no connection (no advance establish a session)
data packet fragmentation and reassembly of
the IP protocol header format: 

4 Version Number: Specifies the version of the IP protocol, for IPV4 concerned, is 4
4 header length: IP header length is how much each 32bit, is the number of bytes in length * 4, the maximum length of the IP header is 60 bytes
service type 8:
   3 priority field (deprecated)

   4 TOS field: minimum delay, maximum throughput, maximum reliability, minimum cost (these four conflicts, choose only one)

   A reserved field, must be 0

16 Total length: IP data packets representing a whole number of bytes
is an identifier that uniquely identifies host sends a packet, if the IP packet in the data link layer is a fragmented (IP packet is larger than MTU: 16 bit identifier ), each one in this identification (id) are the same
three signs:
   first: reserved

   Second: whether to allow slicing (set to 0: enabled, setting: not allowed), if set, but the IP packet length exceeds the MTU is discarded

   Third place: the end flag (the last one set, indicating that is done, the rest of the set to zero)

13 chip offset: fragment relative to the original IP packet offset (which actually represents the position of the current slice in the original packet)
Note: The packet sending is too large, it needs to be fragmented and processed each slice will include an identification (IP address + identifies) the destination is a recombinant

 

8 survival time (TTL): the maximum number of hops a data packet to a destination packet, generally 64, each time through a route, TTL- = 1; has been reduced to 0, did not reach discarded. Appears primarily used to prevent routing loops
8 Protocol: upper layer protocol type
16-bit header checksum: CRC is used to check whether the differential head damage
32-bit source IP address, destination IP address 32: represents the sending and receiving end end
options: variable length, up to 40 bytes

TCP packet format

TCP Header
TCP packet format

Source port (Source port) and destination port (Destination port)
each of 16 bits. IP addresses to identify the Internet in different terminals, port number identifies the application process different terminal, has local significance. 32-bit IP + 16 = 48-bit port number socket. 
Port by the allocation of Internet Assigned Numbers mechanism (Internet Assigned Numbers Authority, IANA) , TCP and UDP port number list .

Well-known port number (Well-known) registered port number (Registered) dynamic port number (Dynamic)
0 ~ 1023 1024 ~ 49151 49152 ~ 65535
IANA unified allocation to IANA application for registration of a local distribution
- serial number (Sequence Number) and confirmation number (Acknowledgment Number )

Each 32 bits. TCP byte stream transport connection in each byte has a sequence number. SN indicates a sequence number of the data byte transmitted with this segment. AN indicates the first byte of a desired partner of the next packet sequence number, AN less than all the packets are received correctly.

Header length (the Data offset)
. 4 bits, in units of 32-bit words. TCP minister first short, is offset part of the TCP packet data. 5 to 15, i.e., 20 bytes ~ 60 bytes. options section allows a maximum of 40 bytes.

Reserved (Resevered)
3 bits, for future use, should now be set to zero.

Flag (Flags)
URG = 1, indicating there is an emergency message data to be transmitted (the equivalent of high-priority data) as soon as possible. 
PSH = 1, to be delivered as soon as possible after receiving the application process to receive. 
RST = 1, a serious error (such as a host crash), you must release the connection occurred in the connection TCP, re-establish the connection. 
FIN = 1, the transmission side data transfer has been completed, the connection release request. 
SYN = 1, in the TCP connection establishment procedure. 
ACK = 1, the acknowledgment number (AN) is valid.

Window (the Window size)
16 bits, the size of the receiving window. Receiving end of the desired number of bytes received.

Checksum (Checksum)
16 bits, the packet header parity, data.

Urgent pointer (the Urgent pointer)
16 bits, if URG = 1, this field indicates the size of the urgent data (offset with respect to SN), the emergency data in the data portion of the top.

Options (Options)
TCP packet fields to achieve the TCP function, ID process, byte stream splitting assembly, error control, flow control, establish and release connections.

UDP packet format


Source Port (Source port) and destination port (Destination port)

Packet length (the Length)

16 bits, indicating the UDP packet (header and data) in total length. Minimum 8 bytes, only the first part, there is no data . Bytes maximum value is 65535 . In fact, since the maximum length of the data packet is IPv4 (65535 - 20 = 65515) bytes , UDP packet length is 65515 bytes. IPv6 allows UDP length than 65,535, then the length field is set to zero .

Checksum (Checksum)
Reference: 
http://www.xuetangx.com/courses/course-v1:UST+UST001+sp/courseware/a4bb2456afc54cdc94defd1ab13b0389/ 
https://en.wikipedia.org/wiki/Transmission_Control_Protocol 
HTTPS: / /en.wikipedia.org/wiki/User_Datagram_Protocol

Published 377 original articles · won praise 145 · views 210 000 +

Guess you like

Origin blog.csdn.net/Windgs_YF/article/details/104534289