3. IP address, structure, and data arrangement
The following section determines that we need to change it.
First, let's not talk about the code! First, let's talk about IP addresses and ports. Of course, we will talk about how to store and maintain IP addresses and other data in socket APIs.
3.1 IP address, version 4 and 6
On a good day in the past, when BenKenobi is preparing to call the Obi Wan Kenobi, it is necessary to use the IPv4 routing system. Format: 192.0.2.111.
In fact, most of the Internet is still using IPv4.
Omitted here...
Due to IPv4 address restrictions, IPv6 is required. (IPv4 addresses are 32bit, while IPv6 addresses are 128bit)
The IPv6 format is 2001: 0db8: c9d2: aee5: 73e3: 934a: a5ae: 9551.
IPv4 to IPv6. For example, if the IPv4 address is 192.0.2.33, the IPv6 address is: ffff: 192.0.2.33.
3.1.1. Mask
Subnet Mask: mask the "full 1" bits of the Network part of an IP address. For Class A addresses, the default subnet mask is 255.0.0.0; for Class B addresses, the default subnet mask is 255.255.0.0; For Class C addresses, the default subnet mask is 255.255.255.0. The subnet mask can be used to divide a large network into subnets, or merge small networks into large networks.
The Internet is composed of many small networks, each of which has many hosts, thus forming a hierarchical structure. When designing an IP address, considering the hierarchical features of Address Allocation, each IP address is divided into two parts: the network number and the host number to facilitate IP address addressing.
What are the network numbers and host numbers of IP addresses? If this parameter is not specified, you do not know which bits are the network numbers and which are the host numbers. This requires subnet masks.
The subnet mask must be set according to certain rules. Like a binary IP address, the subnet mask consists of 1 and 0, and 1 and 0 are consecutive. The subnet mask length is also 32 bits, and the network bits on the left are represented by the binary number "1". The number of 1 is equal to the length of the network bits, and the host bits on the right, the binary number "0" indicates that the number of 0 is equal to the length of the host bit. The purpose of this operation is to allow the mask and ip address to mask the number of original hosts with 0, without changing the number of original network segments, in addition, it is easy to determine the number of hosts in the subnet through the number of digits 0 (the number of hosts in 2 is the power of-2, because when the host number is all 1, it indicates the network broadcast address, if the value is 0, it indicates the network number of the network, which is two special addresses ). Only the subnet mask can be used to indicate the relationship between the subnet of a host and other subnets, so that the network works normally.
The term subnet mask is that the extended network prefix is not an address, but you can determine which part of a network address is a network number, which part is a host number, and 1 represents a network number, the part with a mask of 0 represents the host number. The subnet mask is used to obtain the network address information of the Host IP address. It is used to distinguish the communication between hosts and select different routes. According to the subnet mask format, we can find that the subnet mask includes: 0.0.0.0; 255.0.0.0; 255.255.255.0.0; 255.255.255.255.255. The default subnet mask of Class A addresses is 255.0.0.0; the default subnet mask of Class B addresses is 255.0.0; the default subnet mask of class C addresses is 255.255.255.0.
3.1.2 Port
The IP address is like a hotel in a street, and the port is like the room number of the hotel.
(Think of the IP address as the street address of ahotel, and the port number as the room number .)
From the column xiaobin_HLJ80