Network Protocols and IP

Source: Internet
Author: User

The IP protocol is used to connect multiple packet-switched networks, which transmits a thing called a packet between the source address and the destination address, and it also provides the ability to reassemble the data size to suit the packet size requirements of different networks. The responsibility of IP is to transfer data from the source to the destination. It is not responsible for ensuring delivery reliability, flow control, packet sequencing, and other services that are common to host-to-host protocols.

IP protocol is one of the two major TCP/IP protocols, and the IP address is located in the header of the IP datagram, the network layer and above using the IP address, so at the data link layer is not invisible datagram IP address, the first part of the header is fixed length, a total of 20 bytes. In the TCP/IP standard, a variety of data formats are often described in 32-bit units, by analyzing the format of the IP datagram to know what the IP protocol is capable of

The IPv4 version is seen from the captured packet, the header length is 20 bytes, the secondary length is fixed length, total length:60 all length is byte differentiated Services Field:0xoo indicates the service type; flags Flag F Ragment offset:0 chip offset is zero. Time to live:64 lifetime, also known as hop count. Header Checksum:oxee19 Checksum, can verify the packet error, source:172.28.15.1 the original address of the IP destination:172.28.15.55 for the destination address IP.

IP uses four key technologies to provide services: service type, time-to-live, options, and header check codes. Service type refers to the quality of service you want. A service type is a set of parameters that represent the services that the Internet can provide. This type of service is used by the gateway to select the actual routing parameters for a particular network, or for the next network to go through, or the next gatekeeper to route the datagram. The time to live is the maximum amount of time the datagram can survive. It is set by the sender and processed by the routed place. If the time to live is zero when it arrives, discard the datagram. The option is important for the control function, but it is not necessary for the usual communication. Options include timestamp, security, and special routing. The header check code guarantees the correct transmission of the data. If the checksum is wrong, discard the entire datagram .

IP does not provide reliable transport services, it does not provide end-to-end or (routing) node-to-(routing) node confirmation, no error control on the data, it uses only the checksum of the header, it does not provide retransmission and flow control. If an error can be reported via ICMP, ICMP is implemented in the IP module.

Next is the calculation of the checksum:

calculation method of IP header checksum

1. Chingqing the checksum word to zero.

2. Then the binary code for each 16 bits (2 bytes) is summed, the meaning of the inverse code summation is to sum each of the 16 bits, and then the resulting and converted to anti-code.

The following is an example on the Web:

When the receiver makes the checksum, it also sums the binary inverse code for every 16 bits. The receiver calculates the checksum at the first time compared to the header when the sender calculates the checksum, and a sender calculates the checksum. Therefore, if the header does not occur in the transmission process error, then the receiver calculates the result should be all one, because the receiver calculates the value of the other than the checksum is a checksum of the inverse code, plus the more out of the checksum is of course all one.

at last, we give an example of the above process: First Officer and field 0;

IP Header:

from

F5 xx

6E 06 00 00 (check field)

DE B7 5D-222.183.69.93

C0 A8 DC-192.168.0.220

Calculation:

4500 + 0031 +89f5 + 0000 + 6e06+ 0000 + DEB7 + 455D + c0a8 + 00DC =3 22c4

0003 + 22c4 = 22c7

~22c7 = DD38, which is the checksum to be populated

When the IP packet is received, to check the IP header is correct, the IP header is inspected, the same way:

Calculation:

4500 + 0031 +89f5 + 0000 + 6e06+ DD38 + DEB7 + 455D + c0a8 + 00DC =3 FFFC

0003 + FFFC = FFFF

The results are all one, right .

Job

Algorithms and procedures for verifying the checksum:

Algorithm:

Short 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&0XFFFF);
cksum + = (cksum>>16);
return (USHORT) (~cksum);
}

Network Protocols and IP

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.