Each computer has a host number, which has two special meanings when its bits are all zeros or all ones. All 0 host numbers represent the entire subnet, not a device in the subnet. In addition, if all the host numbers are 1, packets are sent to all devices on the subnet, that is, broadcast. Host ID of the IP address All 0: indicates the entire subnet. All 1: indicates that packets are sent to all devices on the subnet, that is, broadcast.

DNS Domain name Resolution

For a DNS server, there must be a CORRESPONDING DNS client on our computer, and the part of the DNS client is called the DNS parser, or simply the parser. The resolution function performed by DNS is called a resolver. The resolution function performed by DNS is called a resolver.

The following is the DNS server resolution process:

The SENDING of messages by the DNS parser is not performed by the parser itself, but is delegated to the protocol stack within the operating system.

When sending a message to the DNS server, we also need to know the IP address of the DNS server. However, the IP address is set up as a TCP/IP setup item, so there is no need to query it

When a client requests a DNS server, it contains the domain name, class, and record type

Class: DNS applications on networks other than the Internet were considered when DNS was first designed, and class is used to identify network information. However, there are no other networks nowadays, so the value of Class is always IN for the Internet

Record type: Indicates the record type of the domain name. For example, if the type is A, the domain name corresponds to an IP address. If the type is MX, the domain name corresponds to the mail server. The server returns different information to the client for different record types

In the domain name, the position on the right indicates a higher level. For example, if the domain name www.lab.glasscom.com is in accordance with the organizational structure of the company, it is probably “WWW of lab Division, Glasscom Department, COM Enterprise Group”

DNS server query process:

A DNS server can store one or more domains, but a domain cannot be placed on different servers. In www.baidu.com, WWW, baidu, com are three fields

In the Internet, com and JP have one more level of domain above them, called the root domain. The root domain does not have its own name like com or JP, so it is often omitted when writing a domain name. To specify the root domain, use www.lab.glasscom.com. This adds a period to the end of the domain name, and this final period represents the root domain.

DNS server information of the root domain is stored in all DNS servers on the Internet. This way, any DNS server can find and access the root domain DNS server.

There are only 13 IP addresses assigned to the root DNS server in the world, and these addresses rarely change, so it is not difficult to keep them in all DNS servers. In fact, the information about the root DNS server is already included in the configuration file of the DNS server program, so it is automatically configured as soon as the DNS server program is installed.

The DNS server caches queried domain names and their CORRESPONDING IP addresses

DNS server cache query process:

One thing to note about this caching mechanism is that after the information is cached, the original registration information may change, and the information in the cache may be incorrect. Therefore, the information stored in the DNS server has a validity period. When the validity period expires, the data is deleted from the cache. Also, when responding to a query, the DNS server tells the client whether the result of the response is from the cache or from the DNS server that manages the domain name.

Socket creation, connection process

The operation of sending and receiving data is divided into several stages, which can be roughly summarized as the following four stages. (1) Create socket (create socket stage) (2) connect pipe to socket on server side (Connect stage) (3) Send and receive data (communication stage) (4) Disconnect pipe and delete socket (Disconnect stage)

The previous four operations are performed by the protocol stack in the operating system. Applications such as browsers do not pipe and place data themselves, but delegate it to the protocol stack

In addition, the operation of these delegates is performed by calling the program components in the Socket library, but these data communication program components actually only act as a bridge role, and do not perform any substantive operation, the application program’s delegation content will be passed to the protocol stack.

When connect is called, the protocol stack performs the connection operation. When the connection is successful, the protocol stack stores the IP address and port number of the other party in the socket so that we can start sending and receiving data.

The next half is the part that uses IP protocol to control network packet sending and receiving operation. When data is transmitted over the Internet, the data is divided into network packets, and IP is responsible for sending network packets to communication objects. In addition, IP includes ICMP and ARP. ICMP informs the network of errors and various control messages during packet transmission. ARP queries Ethernet MAC addresses based on IP addresses.

In the protocol stack, there is a memory space for storing control information, which records the control information used to control communication operations, such as the IP address of the communication object, port number, and the status of communication operations. A socket is simply a concept and does not have an entity. If we must give it an entity, we can say that the control information is the entity of the socket, or that the memory space in which the control information is stored is the entity of the socket.

Run the following command to query existing sockets:

The socket records the control information used to control the communication operation, and the protocol stack needs to determine the next action based on this information. This is the function of the socket.

When you create a socket, you first allocate the memory space required by a socket, and then write the initial state to it.

Next, you need to inform the application of the descriptor that represents this socket. Descriptors are the number tags used to distinguish multiple sockets in a protocol stack

The client communicates the request to the server to begin communication, which is one of the purposes of the connection operation.

A connection is actually a sequence of operations in which two communicating parties exchange control information, record the necessary information in a socket, and prepare the data for sending and receiving.

The process of the client telling the server the IP address and port number is a concrete example of exchanging control information

In addition, when performing data sending and receiving operations, we also need to temporarily store the data to be sent and receiving. This memory space, called the buffer, is also allocated during the connection operation.

The first is the control information exchanged when the client and server communicate with each other. This information is required not only during the connection, but also during the entire communication process, including data sending and receiving and disconnection operations. These information is defined in the TCP protocol specifications.

This information is added to the beginning of the network packet passed between the client and server, where the three-way handshake for the TCP connection begins

The control information used in communication operations falls into two categories. (1) information recorded in the header (2) information recorded in the socket (memory space in the protocol stack)

The process starts when the application calls CONNECT from the Socket library. Connect (,…) The above call provides the IP address and port number of the server, which is passed to the TCP module in the protocol stack. The TCP module then exchanges control information with the object corresponding to the IP address, that is, with the SERVER’s TCP module

First, the client creates a header containing control information to begin the data send and receive operation. As shown in Table 2.1, the header contains many fields, and the main focus here is on the sender and receiver port numbers. At this point, the client’s (sender’s) socket has found the server’s (receiver’s) socket exactly, which socket I should connect to.

We then set the SYN bit in the control bit in the header to 1, which you can assume represents a connection. You also need to set the appropriate sequence number and window size, which we’ll cover in more detail later. The first step in connection operations is to create a header in the TCP module that represents connection control information.

After the TCP header is created, the TCP module then passes the information to the IP module and delegates it to send

When a socket is found, information is written to the socket and the state changes to being connected

After the preceding operations are complete, the TCP module of the server returns a response. This process is the same as that of the client. You need to set the sender and receiver port numbers and SYN bits in the TCP header. In addition, the ACK control bit needs to be set to 1 when the response is returned, indicating that the corresponding network packet has been received

Network packets can also be lost. Therefore, when communicating with each other, the two parties must confirm whether the network packet has been delivered. The ACK bit is used to confirm this.

Next, the server TCP module passes the TCP header to the IP module and delegates the IP module to return a response to the client.

The network packet will return to the client, through the IP module to the TCP module, and confirm the connection to the server through the TCP header information. If the SYN value is 1, the connection succeeds. In this case, the IP address and port number of the server are written to the socket and the status changes to Connection Completed.

There is one last step left. The server just returned the response with the ACK bit set to 1. Accordingly, the client also needs to set the ACK bit set to 1 and send back to the server to tell the server that the response packet was received.

The socket is now ready to send and receive data

After the connection is established, the stack connection is finished, that is, the connect has been executed and the control flow is handed back to the application.

Diagram of the entire hardware: