[Network programming] TCP/IP protocol

Source: Internet
Author: User
Tags file transfer protocol ftp protocol

The abbreviation of Transmission Control Protocol/Internet Protocol is the Transmission Control Protocol/Internet Interconnection protocol, also known as network communication protocol. It is the basis of the most basic Internet protocol and internet Internet, it consists of the IP protocol of the network layer and the TCP protocol of the transport layer. TCP/IP defines how electronic devices connect to the Internet and how data is transmitted between them. The protocol uses a layer-4 hierarchy. Each layer calls the protocol provided by the next layer to fulfill its own needs. In general: TCP is responsible for discovering transmission problems. When there is a problem, it sends a signal and requires a re-transmission until all data is securely and correctly transmitted to the destination. The IP address specifies an address for each Internet device on the Internet.

 

IP

The IP layer receives a packet from a lower layer (network interface layer, such as an Ethernet device driver) and sends the packet to a higher layer-TCP or UDP layer, the IP layer also sends packets received from the TCP or UDP layer to the lower layer. IP data packets are unreliable, because the IP does not do anything to confirm whether the data packets are sent in order or are damaged. The IP data packets contain the host address (Source Address) that sends the data packets) and the host address (Destination Address) that receives it ).
When receiving data packets, high-level TCP and UDP services generally assume that the source address in the packet is valid. It can also be said that IP addresses form the authentication basis for many services. These services believe that data packets are sent from a valid host. IP validation contains an option called IP source routing, which can be used to specify a direct path between the source address and the destination address. For some TCP and UDP services, the IP packet using this option seems to be transmitted from the last System in the path, rather than from its real location. This option exists for testing, indicating that it can be used to fool the system for a normally prohibited connection. Therefore, many services that rely on the IP Source Address for confirmation will have problems and will be illegally infiltrated.

 

TCP

TCP is a connection-oriented communication protocol. When a connection is established through a three-way handshake, the connection must be removed when the communication is complete. Because TCP is connection-oriented, it can only be used for end-to-end communication.
TCP provides a reliable data stream service, and adopts the "positive validation with retransmission" technology to achieve transmission reliability. TCP also uses a method called "Sliding Window" for traffic control. The so-called window actually represents the receiving capability, which is used to limit the sending speed of the sender.
If an IP packet contains a TCP packet that has been blocked, the IP will send them to the upper layer. TCP sorts packets and checks errors to connect virtual circuits. TCP packets include serial numbers and validation, so packets not received in order can be sorted, and damaged packets can be re-transmitted.
TCP sends its information to higher-level applications, such as telnet service programs and customer programs. Applications send information back to the TCP layer in turn, and the TCP layer forwards them down to the IP layer, device drivers and physical media, and finally to the receiver.
Connection-oriented services (such as telnet, FTP, rlogin, X Windows, and SMTP) require high reliability, so they use TCP. In some cases, DNS uses TCP (sending and receiving domain name databases), But UDP is used to transmit information about a single host.

 

UDP

UDP is a connectionless communication protocol. UDP data includes the destination port number and source port number information. Because communication does not require connection, broadcast transmission can be implemented.
UDP communication does not require confirmation from the receiver. It is an unreliable transmission and may cause packet loss. In practice, programmers are required to perform programming verification.
UDP and TCP are on the same layer, regardless of the packet sequence, error, or resend. Therefore, UDP is not applied to connection-oriented services that use virtual circuits. UDP is mainly used for query-oriented services, such as NFS. Compared with FTP or telnet, these services require less information to be exchanged. Services that use UDP include NTP (Network Time Protocol) and DNS (DNS also uses TCP ).
Spoofing UDP packets is easier than spoofing TCP packets because UDP does not establish an initial connection (also known as a handshake) (because there is no virtual circuit between the two systems). That is to say, UDP-related services face greater risks.

 

ICMP

ICMP and IP are on the same layer. It is used to transmit IP control information. It is mainly used to provide information about the path to the destination address. ICMP's 'redirection' information notifies the host of a more accurate path to other systems, while the 'unreachable' information indicates that the path is faulty. In addition, if the path is unavailable, ICMP can terminate the TCP connection in a decent manner. Ping is the most common ICMP-based service.

 

Communication Port

TCP and UDP services usually have a relationship between customers and servers. For example, a Telnet service process starts to be idle on the system and waits for a connection. The user uses the Telnet client program to establish a connection with the service process. The customer program writes information to the service process. The service process reads the information and sends a response. The customer program reads the response and reports it to the user. Therefore, this connection is duplex and can be used for reading and writing.
How are the multiple Telnet connections between the two systems confirmed and coordinated? The TCP or UDP connection uniquely uses the following four items in each information for confirmation:
The IP address of the packet sent from the source IP address.
The IP address of the destination IP address receiving package.
The port connecting to the source system.
The port connecting to the target system.
A port is a software structure used by a client program or service process to send and receive information. A port corresponds to a 16-bit number. A service process usually uses a fixed port, for example, SMTP uses 25 and xwindows uses 6000. These port numbers are 'widely known 'because they need to communicate with the destination address when establishing a connection with a specific host or service.

 

Data format

Data frame: frame header + IP packet + frame end (the frame header includes the MAC address and type of the source and target hosts, and the frame end is a verification word)
IP packet: IP header + TCP data information (the IP header includes the IP addresses, types, and lifetime of the source and target hosts)
TCP Data Information: TCP Header + actual data (the TCP Header includes the source and target host port numbers, sequence numbers, validation numbers, and verification characters)

 

IP address

All computers connected to the Internet, from the mainframe to the microcomputer, appear independently. We call it a host. Each host must have a unique network address for communication between hosts. It's like every house has a unique portal card, so it won't be in disorder during data transmission. The Internet address refers to the address number of the computer connected to the Internet. Therefore, in an Internet network, a network address uniquely identifies a computer. We all know that the Internet is made up of tens of millions of computers connected to each other. We need to confirm that each computer on the network depends on the network address that uniquely identifies the computer. This address is called an IP address (short for Internet Protocol, that is, the address in the Internet Protocol language. In the Internet, IP addresses are a 32-bit binary address. To facilitate memory, they are divided into four groups, each group of eight digits separated by the decimal point, expressed in four bytes, the value range of each byte separated by vertices is 0 ~ 255, such as 202.116.0.1. This writing method is called the point representation.

 

Level

The TCP/IP protocol is not the combination of the TCP/IP protocol and the IP protocol, but the entire TCP/IP protocol family of the Internet.

In terms of protocol layered model, TCP/IP consists of four layers: network interface layer, network layer, transmission layer, and application layer.
The TCP/IP protocol does not fully comply with the OSI Layer-7 Reference Model. OSI (Open System Interconnect) is a traditional reference model for Open System Interconnection, it is a layer-7 abstract reference model for communication protocols, where each layer executes a specific task. This model aims to make various hardware communicate with each other at the same level. These seven layers are: physical layer, data link layer (network interface layer), network layer (network layer), transmission layer (transport layer), Session Layer, presentation layer and application layer (Application Layer ). The TCP/IP communication protocol uses a layer-4 hierarchy. Each layer calls the network provided by its next layer to meet its own needs. Arpanet designers focus on network interconnection and allow the Communication Subnet (Network Interface Layer) to use existing or future protocols. Therefore, no special protocols are provided at this layer. In fact, TCP/IP can be connected to any network through the network interface layer, such as X.25 or IEEE802 LAN.

 

Network Interface Layer

The physical layer defines various characteristics of the physical medium: 1. Mechanical properties;
2. Electronic features;
3. Features;
4. procedure features.
The data link layer is responsible for receiving IP data packets and sending them over the network, or receiving physical frames from the network, extracting IP data packets, and handing them over to the IP layer.
ARP is a forward Address Resolution Protocol. It uses known IP addresses to find the MAC address of the corresponding host.
RARP is a Reverse Address Resolution Protocol that determines the IP address through the MAC address. For example, a diskless workstation also has a DHCP service.
Common interface layer protocols include:
Ethernet 802.3, Token Ring 802.5, X.25, frame relay, HDLc, and ppp atm.

 

Network Layer

Responsible for communication between adjacent computers. Its functions include three aspects.
Process the packet sending request from the transport layer. After receiving the request, load the packet into an IP datagram, fill in the header, select the path to the sink, and then send the datagram to the appropriate network interface.
Process the input datagram: first check its validity, and then perform a path-if the datagram has arrived at the sink, remove the header and hand over the remaining part to the appropriate transmission protocol; if the datagram has not reached the destination, it is forwarded.
Handle problems such as path, traffic control, and congestion.
The network layer includes the IP (Internet Protocol) protocol and ICMP (Internet Control Message Protocol) protocol)
Control Packet protocol, Address Resolution Protocol (ARP) address translation protocol, and RARP (reverse ARP) reverse address translation protocol.
IP address is the core of the network layer. The next IP address is encapsulated by routing and then handed over to the interface layer. IP datagram is a connectionless service.
ICMP is a supplement to the network layer and can send packets back. Used to check whether the network is smooth.
The Ping Command sends an icmp echo packet and tests the network by sending the echo relay.

 

Transport Layer

Provides communication between applications. Its functions include: 1. formatting information flows; 2. reliable transmission. To implement the latter, the transport layer protocol requires the receiving end to send back the confirmation, and if the group is lost, it must be re-sent, that is, the familiar "three-way handshake" process, so as to provide reliable data transmission.
Transport layer protocols are mainly Transmission Control Protocol (TCP) and User Datagram Protocol (UDP ).

 

Application Layer

Provides users with a set of common applications, such as email, file transfer access, and remote logon. Remote logon Telnet provides interfaces registered on other hosts in the network using the Telnet protocol. The telnet session provides a character-based virtual terminal. File Transfer access FTP uses the FTP protocol to provide the file copy function between machines in the network.
The application layer protocols include FTP, telnet, DNS, SMTP, NFS, and HTTP.
  • FTP (file transfer protocol) is a File Transfer Protocol. FTP is used for uploading and downloading. The data port is 20 h and the control port is 21 h.
  • The Telnet service is a remote Logon Service. It uses port 23 and plain code for transmission, which provides poor confidentiality and convenience.
  • DNS (Domain Name Service) is a domain name resolution service that provides translation between domain names and IP addresses, using port 53.
  • SMTP (Simple Mail Transfer Protocol) is a simple mail transmission protocol used to control the sending and transfer of letters. Port 25 is used.
  • Network File System (NFS) is a network file system used for file sharing between different hosts in the network.
  • HTTP (Hypertext Transfer Protocol) is a hypertext transfer protocol used to implement WWW services on the Internet, using port 80.
Layers in OSI Function TCP/IP protocol family
Application Layer File transmission, email, file service, virtual terminal TFTP, HTTP, SNMP, FTP, SMTP, DNS, telnet, etc.
Presentation Layer Data formatting, code conversion, and Data Encryption No agreement
Session Layer Release or establish contact with other contacts No agreement
Transport Layer Provides end-to-end Interfaces TCP, UDP
Network Layer Select a route for a data packet IP, ICMP, OSPF, OSPF, IGMP
Data Link Layer Transmitted frame with address and Error Detection Function Slip, cslip, PPP, MTU
Physical Layer Transmit data on physical media in the form of binary data Iso2110, IEEE802, and 802.2

The protocols at the network layer mainly include IP, ICMP, and IGMP. because they contain IP protocol modules, they are the core of all TCP/IP-based networks. At the network layer, the IP module completes most of the functions. ICMP, IGMP, and other protocols that support IP addresses help IP addresses complete specific tasks, such as transmitting error control information and control messages between hosts and routers. The network layer is responsible for information transmission between hosts in the network. The main protocols on the transport layer are TCP and UDP. Just as the network layer controls data transmission between hosts, the transport layer controls the data that will enter the network layer. The two protocols are the two methods for managing the data: TCP is a connection-based protocol, and UDP is the management method for the connectionless service.

 

Main features

(1) the TCP/IP protocol does not depend on any specific computer hardware or operating system and provides open protocol standards. Even if Internet is not considered, the TCP/IP protocol has been widely supported. Therefore, TCP/IP becomes a practical system that integrates various hardware and software.
(2) the TCP/IP protocol does not depend on specific network transmission hardware. Therefore, the TCP/IP protocol can be integrated into various networks. Users can use Ethernet, Token Ring Network, dial-up line, X.25, and all network transmission hardware.
(3) Unified Network Address allocation scheme, so that the entire TCP/IP device has a unique address in the Network
(4) Standardized high-level agreements provide a variety of Reliable User Services.

 

Protocol advantages

In the long-term development process, IP addresses gradually replace other networks. Here is a simple explanation. IP Address Transmission of common data. Data can be used for any purpose and can easily replace data previously transmitted by a VPC. The following is a common process:
A proprietary network is developed for specific purposes. If it works fine, the user will accept it.
To facilitate the provision of IP services, it is often used to access emails or chats. It is usually implemented through a VPC tunnel in some way. Tunnel mode may be inefficient at first, because email and chat only require low bandwidth.
With a little investment in IP infrastructure, it gradually appears around the VPC.
The need to replace a private service with an IP address is often a user requirement.
The IP substitution process is distributed across the Internet, which makes the IP substitution more valuable than the original VPC (due to the network effect ).
The VPC is under suppression. Many users begin to maintain copies using IP substitutes.
The indirect overhead of the IP package is small, less than 1%, which is very competitive in cost. People have developed a non-expensive transmission medium that can bring IP addresses to VPC for most users.
Most users cancel the VPC to reduce the overhead.

 

Main disadvantages

First, it is not clear about the differences between services, interfaces, and protocols. A good software project should distinguish functions from implementation methods, and TCP/IP does not do well in this regard, the guidance of the TCP/IP Reference Model on the use of new technologies is insufficient. The TCP/IP reference model is not suitable for other non-TCP/IP protocol clusters.
Second, the host-network layer is not an actual layer. It defines interfaces between the network layer and the data link layer. The division of the physical layer and the data link layer is necessary and reasonable. A good reference model should separate them, but the TCP/IP reference model does not.

 

References

Http://baike.baidu.com/view/7649.htm? Fr = Aladdin
Http://xuxd32.blog.163.com/blog/static/4812193320114885118923/
Http://blog.163.com/?email protected]/blog/static/131005870201383113440845/
Http://zyc-to.blog.163.com/blog/static/17152400201338354067/
Http://wenku.baidu.com/link? Url = ivhDiRKISz4ExalEuczUeUHB_YB9UYCKyxnUYQMk5QcDYNyiwYK-IJN7iDyJKe3gERRabgBEQ4w22SuaC3bY_NKqKEQrP_U2dkaP1UUSpVa
Http://blog.csdn.net/hondrif82q/article/details/1447845

[Network programming] TCP/IP protocol

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.