Linux Network programming series-TCP/IP model

Source: Internet
Author: User
Tags ack connection reset

# # # Osi:open System Interconnection # # #开放系统互联网模型是由ISO国际标准化组织定义的网络分层模型, total seven levels

1. Physical layer: Physical definition of all electronic and physical equipment specifications, data transmission unit is bit (b), this layer definition specification has Eia/tia RS-232, RJ-45, etc., is actually by equipment such as network card etc.
2. Data Link layer: Data is framed for the bit streams received by the physical layer. Provide reliable data transfer service for error-free data transmission. The data unit for this layer is frame. This layer regulates SDLC, PPP, STP, etc., using devices such as switch switches, etc.
3. Network layer: The data between the various subnets routing, grouping and reorganization. The data transmission unit for this layer is a packet (packet). The specifications that belong to this layer are IP, IPX, IGMP, and so on. Using devices such as routers
4. Transport Layer: Provides reliable data transfer service, detects packets discarded by the router, and then generates a retransmission request that can reorder packets received in order
5. Session Layer: Managing the session between hosts, including session setup, termination, and management during sessions, transmission units (SPDU)
6. Presentation layer: Transform the data transmitted by the network, so that the information transmitted between multiple hosts can understand each other, including data compression, encryption, format conversion, etc., Transmission Unit (PPDU)
7. Application layer: The application layer communicates with the application interface for the purpose of presenting to the user, where the common protocols are: HTTP, HTTPS, FTP, SSH, pop, etc., Transmission Unit (APDU)

# # # TCP/IP four Layer Model # # #

1. Link Layer: A collection similar to the physical layer and data link layer in the OSI, main specification: ARP, RARP
2. Network layer: Similar to the OSI Network layer, the main specification: IP, ICMP, IGMP
3. Transport layer: Similar to the OSI Transport layer, the main specification: TCP, UDP
4. Application layer: A collection of conversational, presentation, and application tiers similar to OSI, with major protocols such as: FTP, Telet, QQ, etc.


# # # port # # #

1. Known ports (well known Ports): from 0 to 1023, these ports are assigned and controlled by the IANA, usually these ports clearly indicate a certain service, for example: 21 Port for FTP service
2. Register ports: from 1024 to 49151, these ports are not controlled by the IANA, but have the IANA register and provide a usage checklist, and many services are bound to these ports, which are also used for many other purposes, such as: 1433 Microsoft SQL Service port
3. Dynamic or Private ports: 49152 to 65535,iana regardless of these ports, in fact, the machine usually allocates dynamic ports from 1024, with exceptions, Sun's RPC ports start at 32768

# # # # Protocol description, encapsulation, split # # # # #

MTU: Ethernet Maximum data transmission Unit
ICMP: Transmission error information, time, network information and other control data
ARP: Address Resolution Protocol, map IP address to MAC address
RARP: Address Resolution Protocol, map MAC address to IP address
Package: Link layer with Application layer (IP address converted to MAC address)
Split: Application layer, link layer (MAC address converted to IP address)

# # # # Host a ping Host B data in the network Transmission Description # # # #

1. The application determines whether the ping is the hostname or IP address, if the host name is called gethostbyname () to resolve Host B, the host name is converted to a 32-bit IP address, this process is called DNS domain name resolution
2. Ping program sends an ICMP ECHO packet to the destination IP address
3. Convert the destination host's IP address to a 48-bit hardware address, send ARP request broadcasts within the LAN, and find the hardware address of Host B
4. After the ARP protocol layer of Host B receives the ARP request from host A, the hardware address of this machine is populated to the answering packet, and the ARP reply is sent to host a
5. Sending ICMP packets to Host B
6. Host B receives ICMP packets from host A, sends a response packet
7. Host a receives an ICMP response packet to Host B

# # # IP Datagram Format # # #

1. Version: IPv4 field value is 4,ipv6 field value is 6
2. First length: In 32-bit words, the field length is 4 bits and the maximum value is 15, so the maximum ministerial degree is 60 bytes
3. Total length: The field length is 16 bits, in bytes, the field length contains the IP header and data portion, the IP datagram can be up to 65,535 bytes
4. Identification: 16-bit identification, used to identify an IP packet, each sending one this value will add 1
5. TTL (Time to Live): Indicates the number of routers that the datagram can pass through, each router, the TTL value minus 1, minus 0 o'clock drops, and sends the ICMP message to the source host, TTL can avoid the datagram in the continuous cycle between the routers
6. Protocol type: Indicates which high-level protocol is hosted on the IP layer, which layer is known to be assigned to the protocol processing, 1 ICMP 2 IGMP 6 TCP + UDP
7. Internet checksum: The receiver receives the sender's data and verifies the data in accordance with the verification algorithm, and verifies whether the data has errors in the transmission process.

# # # TCP Message Format # # #

1. Source port number and destination port number: Source port number and destination port number, plus IP header source IP address and destination IP address uniquely determine a TCP connection
2. Serial Number: Serial number indicates the first data byte ordinal in this message segment
3. Confirmation Number: Only if the ACK flag is 1 o'clock valid, the confirmation number indicates the ordinal of the next byte expected to be received
4. Head Length: 4 bits, TCP header up to 60 bytes
5. Reserved bit: 6 bits, must be 0
6.6 Flags: urg-Emergency pointer valid, ack-confirm the serial number is valid, syn-send the connection synchronization sequence number, fin-means to terminate a connection, rst-connection reset, psh-receiver sends this message to the application layer
7. Window size: Through the window size to achieve flow control
8. Checksum: Verifying the TCP header and data

# # # TCP connections Build Three handshake # # #

TCP A sends A syn A->TCP B//a request to establish a connection
TCP b sends syn b ACK a+1->tcp A//confirms receipt of request and requests a reply
TCP A sends ack b+1->TCP b//reply to B's request

# # # TCP connection terminated four handshake # # #

TCP A sends fin x ACK y->tcp B//a Request termination Connection
TCP B sends an ACK x+1->TCP a//b receives the termination request and replies to a
TCP B sends a fin y ACK x+1->tcp a//b request to terminate the connection according to the termination request of a
TCP A sends an ACK Y+1->TCP B//a receives the termination request and replies to B

# # # Sliding Window Protocol (flow control) # # #

1. Notification Receive window: Prevents the application from sending more data than the other party's buffer, the receiver uses the traffic control
2. Congestion window (CWnd): Prevent the application from sending more data than the network can withstand, the traffic control used by the sender
3. Send window to take a smaller value
4. Slow start threshold (ssthresh:slow start threshold)
5. Slow start stage: CWnd grows exponentially from 1 to Ssthresh
6. Congestion avoidance phase: CWnd grows linearly until it is congested, halving cwnd=1,ssthresh

Linux Network programming series-TCP/IP model

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.