Iso/osi Seven-layer Reference Model
1. Physical layer: The main definition of physical equipment standards, such as the interface type of network cable, the interface type of optical fiber, the transmission rate of various transmission media. Its main role is to transmit the bitstream (that is, 1, 0 is converted to the current strength to carry out transmission, to the destination and then converted to 1, 0, that is, we often say the digital-to-analog conversion and A/D conversion). This layer of data is called a bit. (Mark: RJ-45)2. Data Link layer: Defines how to make data formatted for transmission and how to control access to physical media. This layer also often provides error detection and correction to ensure reliable data transmission, and the switch belongs to this layer. 3. Network layer: Provides connectivity and path selection between two host systems located in geographically diverse networks. The development of the Internet has greatly increased the number of users accessing information from various sites around the world, and the network layer is the layer that manages this connection. (Flag: Route selection, IP/OSPF,ICMP,IGMP)4. Transport Layer: Defines some transfer data protocol and port number (WWW port 80, etc.), such as: TCP (Transmission Control Protocol, transmission efficiency is low, reliable, for transmission reliability, high data volume data), UDP (User Datagram Protocol, the opposite of TCP characteristics, For transmission reliability requirements are not high, data volume of small data, such as QQ chat data is transmitted in this way. The main point is to segment and transmit the data received from the lower layer, and then reorganize after reaching the destination address. This layer of data is often called a segment. 5. Session Layer: The path of data transmission is established through the Transport Layer (port number: Transport port and receive port). It is primarily the initiation of a session between your systems or the acceptance of a session request (the device needs to know each other, either IP or Mac or host name). 6. Presentation layer: Ensures that the information sent by the application layer of one system can be read by the application layer of the other system. For example, a PC program communicates with another computer, where one computer uses an extended 210 binary interchange (EBCDIC), and the other uses the U.S. Information Interchange Standard Code (ASCII) to represent the same characters. If necessary, the presentation layer enables conversion between multiple data formats by using a pass-through format. 7. Application layer: The OSI layer closest to the user. This layer provides network services for user applications such as e-mail, file transfer, and terminal emulation. (Mark:http,https,ftp,telnet,ssh,smtp,pop3)
TCP/IP four layer model
The Large and complex OSI reference model developed by ISO has attracted many criticisms. In contrast, the TCP/IP protocol stack developed by the technician has been widely used .
Application layer: ftp,telnet in order to complete a certain user needs, custom protocol,QQ Protocol
Transport Layer:TCP UDP
Network layer: ICMP,IP,IGMP
Data Link layer: arp,rarp Hardware interface
Two hosts running the FTP protocol:
Each level has its own protocol, which communicates between each layer; their language is consistent, and we can be seen as peer-to-peer communication between A and B processes, which is the logical flow of virtual circuits (not really connecting lines) for peer data transfer, for example, two people now communicate via mobile phones, Seems to be in the ear, in fact, through the electromagnetic waves.
Packaging:
divided by :
Port:
Ports are assigned and controlled by the IANA they bind some services tightly: 0~1023
Register port: 1024~49151, between this port loosely bound some services
Dynamic or private (temporary) port 49152~65535 (actually starting from 1024) distribution
Link Layer:
Frame format for Ethernet
link Layer packet, called Ethernet frame, link layer does not recognize IP address [because IP address is logical address], link layer recognitionPhysical NIC MAC address [hardware address]; you need to find the MAC address of each other based on the IP address (logical address) (ARP Address Resolution Protocol) [mac-> IP address Direction Address resolution];Mac->ipReverse Address Resolution (RARPagreement);Type (2bytes) to differentiate Ip,arp,rarp.
Ethernet Header Code struct ETHERNET_HDR { char dest_mac[6]; Char src_mac[6]; Short protocol; };
mtu/ path MTU
link layer with maximum transmission unitMTUthis feature, which limits the maximum length of a data frame, has an upper value for different network types. of EthernetMTUis a the, you can usenetstat-icommand to view this value. IfIPlayer has packets to pass, and the packet length exceeds theMTU, thenIPlayer will fragment the packet (Fragmentation) operation so that each piece is less than or equal to the lengthMTU. In addition,The link layer for multiple networks may have differentMTU, select the smaller of the communication pathMTU, called a pathMTU, butSharding can reduce the communication efficiency of the network and should be avoided as much as possible.
ARP Address Resolution Protocol
Local ARP cache
ARP header code struct ARP_HDR { unsigned short hwtype; Fixed 1 unsigned short protype;//fixed 0x0800 (on behalf of IP protocol requests) unsigned char hwaddrlen; Fixed 6 (that is, MAC address length) unsigned char proaddrlen; Fixed 4 (i.e. IP address length) unsigned short opcode; Request-1, reply-0x0002 unsigned char sender_mac[6]; Sender mac unsigned char sender_ip[4];//Sender IP unsigned char dest_mac[6]; Recipient Mac unsigned char dest_ip[4]; Recipient IP };
The ARP buffers are added to both the source and destination sides .
RARP Reverse Address Resolution protocol for diskless workstations whereIP is generally stored in the configuration file
This time to obtain an IP address, through the RARP protocol, by sending a request to the RARP Server
Network layer:
IP datagram
The first maximum length is 15*4=60 bytes, which is the most units, with an option of up to Nine bytes.
Protocol type 8 -bit to determine whether the high-level is TCP or UDP, the head check and verify IP The integrity of the head does not verify the integrity of the data.
Service Type:
IP datagram up to 65535; Shard share an identification number
Internet checksum algorithm: http://blog.csdn.net/zhq651/article/details/8515575
IP header Code struct IP_HDR { char ver_hl; Char tos; unsigned short len; unsigned short ID; unsigned short fragment; char ttl; char protocol; unsigned short hdr_chksum; Char src_ip [4]; Char dest_ip [4]; };
Routing Process:
Order: Search for matching host addresses
Search Network Address
Search Default Table Entries
ICMP protocol
ICMP protocol is used to transmit error information, time, ECHO, network information and other control data, work in the network layer (IP),ping program using ICMP protocol implementation.
ICMP header code struct ICMP_HDR { char type; ICMP message type char code; "Subtype" unsigned short icmpchksum;//Checksum };
UDP message Format
UDP header Code struct UDP_HDR { unsigned short src_port; unsigned short dest_port; unsigned short len; unsigned short chksum;
TCP Packet Header:
Connect to build three handshake
Connection terminated four times wave
Note: Slow start slow refers to the relatively small cardinality.
Step A: The application ping will determine whether the host name or IP address is being sent, call the function gethostbyname () to resolve Host B, and convert the hostname to a 32-bit IP address. This process is called DNS domain name resolution .
Step b:ping program sends an ICMP echo packet to the destination IP address
Step c: 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.
Step d: After the ARP protocol layer of Host B receives the ARP request from host A, the hardware address of the native is populated to the answering packet, and the ARP reply is sent to host a.
step e: Send ICMP packets to Host B
Step f: Host B receives the ICMP packet from host A and sends a response packet.
Step g: Host a receives an ICMP packet response packet to Host B.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Socket programming Practice under Linux (i) Network basics and TCP/IP brief