Test of IP datagram:
In order to calculate the I P test of a datagram, the test field is set to 0. Then, for each 16-bit in the header, the binary inverse sum and the entire header are regarded as composed of a string of 16-bit characters. The result is included in the test and field.
When an I P datagram is received, the sum of the binary anticode for each 16 bit in the header is also carried out. Because the receiver contains a checksum in the sender's header during the computation process, if the header has no errors during transmission, the receiver's computation result should be 1 in total.
This is the original article. When I looked at the source code of some network programs, I found that almost all of them were computed and tested using the same program:
USHORT checksum (USHORT * buffer, int size ){ Unsigned long cksum = 0; While (size> 1 ){ Cksum + = * buffer ++; Size-= sizeof (USHORT ); } If (size ){ Cksum + = * (UCHAR *) buffer; } Cksum = (cksum> 16) + (cksum & 0 xffff ); Cksum + = (cksum> 16 ); Return (USHORT )(~ Cksum ); } ICMP protocol, basic format: | -------- IP datagram ---------- + + -- 20 bytes -- + ---------------- + + IP header + ICMP packet + + ------------------------------ + ICMP packets are sent through IP packets. ICMP format: + ---- 8 --- + ---- 8 --- + -------- + + 8-bit type + 8-bit code + 16-bit verification + + ----------------------------------- + + Different types have different content and lengths + + ----------------------------------- + |
There are many types of ICMP messages, and each type has multiple types of code.
The packet is divided into query messages and error messages. Error messages are not nested. The error message contains the first eight bytes of the IP header and data that cause the error, and is associated with the specific Protocol and process accordingly. Because the first eight bytes of TCP and UDP contain the source port and destination port, you can find the user process associated with the port. In most implementations, only 8 bytes are returned, and the first 64 bytes are returned. If an error occurs in a UDP packet and the user process does not connect to the specified port through connect in advance, the user process will not receive the error message. The kernel will be discarded after processing.
The simple error retransmission mechanism in some tftp implementations is discussed. Five seconds after retransmission, it has been disabled by RFC. I still use this simple retransmission method in serial communication. It seems that I want to change it.
The process of time-based Request Interception and response, as well as the format of the Address Mask Request and response packet are discussed in detail. Port accessibility error. error message:
+ ----------------- ICMP error messages that are inaccessible to the port ----------------------------- +
+ Ethernet header + IP header + ICMP header + IP header that produces errors + IP reporting data domain +
+-14 bytes + --- 20 bytes --- + 8 bytes + ---- 20 bytes ---- + -- 8 bytes-+
According to the standard, error messages are not generated in five cases, basically to avoid ICMP broadcast storms.
This Protocol is too complex because of its type and specific details, but it is also relatively simple. Without protocol analysis, you do not need to be very clear about each type. It seems that there is not much space to use. However, what if a disguised ICMP packet is sent to a host trying to initiate a connection to tell it that the port is "inaccessible? It is worth trying.
Chapter 4 HTTP protocol
This chapter briefly introduces HTTP request and response formats. Since all transmitted content is based on ASCII, although other binary, slice, and MIME files are also transmitted, the transfer type can still be seen from the request or response header, it is no longer difficult to analyze. You can use telnet or nc to perform a real session. After reading the HTTP server grouping in the next chapter, we will prepare ourselves to create a small Web server. The company's next plan is to make most of the hardware available in a browser. These must be driven by a web server. I am a software engineer and I don't need to care about it. But it's not a bad thing to do it yourself, and you can talk with them.
Related Articles]
- TCP/IP protocol details volume 1 Study Notes series 3-IP Routing
- TCP/IP protocol details volume 1 Study Notes Series 2
- Introduction to TCP/IP Protocol 2