![](https://csdnimg.cn/release/download_crawler_static/10380946/bg10.jpg)
1.2 About Addresses 5
(Ethernet) and wireless (WiFi) networks. Because each such network connection belongs to a
single host, an Internet address identifies a host as well as its connection to the network.
However, the converse is not true, because a single host can have multiple interfaces, and each
interface can have multiple addresses. (In fact, the same interface can have both IPv4 and IPv6
addresses.)
The port number in TCP or UDP is always interpreted relative to an Internet address.
Returning to our earlier analogies, a port number corresponds to a room number at a given
street address, say, that of a large building. The postal service uses the street address to get the
letter to a mailbox; whoever empties the mailbox is then responsible for getting the letter to the
proper room within the building. Or consider a company with an internal telephone system:
to speak to an individual in the company, you first dial the company’s main phone number to
connect to the internal telephone system and then dial the extension of the particular telephone
of the individual you wish to speak with. In these analogies, the Internet address is the street
address or the company’s main number, whereas the port corresponds to the room number
or telephone extension. Port numbers are 16-bit unsigned binary numbers, so each one is in
the range 1 to 65,535. (0 is reserved.)
In each version of IP, certain special-purpose addresses are defined. One of these that
is worth knowing is the loopback address, which is always assigned to a special loopback
interface, a virtual device that simply echoes transmitted packets right back to the sender.
The loopback interface is very useful for testing because packets sent to that address are
immediately returned back to the destination. Moreover, it is present on every host, and can
be used even when a computer has no other interfaces (i.e., is not connected to the network).
The loopback address for IPv4 is 127.0.0.1;
1
for IPv6 it is 0:0:0:0:0:0:0:1.
Another group of IPv4 addresses reserved for a special purpose includes those reserved
for “private use.” This group includes all IPv4 addresses that start with 10 or 192.168, as well
as those whose first number is 172 and whose second number is between 16 and 31. (There is
no corresponding class for IPv6.) These addresses were originally designated for use in private
networks that are not part of the global Internet. Today they are often used in homes and small
offices that are connected to the Internet through a network address translation (NAT) device.
Such a device acts like a router that translates (rewrites) the addresses and ports in packets as
it forwards them. More precisely, it maps (private address, port) pairs in packets on one of its
interfaces to (public address, port) pairs on the other interface. This enables a small group of
hosts (e.g., those on a home network) to effectively “share” a single IP address. The importance
of these addresses is that they cannot be reached from the global Internet. If you are trying out
the code in this book on a machine that has an address in the private-use class, and you are
trying to communicate with another host that does not have one of these addresses, typically
you will only succeed if the host with the private address initiates communication.
A related class contains the link-local, or “autoconfiguration” addresses. For IPv4, such
addresses begin with 169.254. For IPv6, any address whose first 16-bit chunk starts with FE8
1
Technically any IPv4 address beginning with 127 should loop back.