Memra

Addresses, ports, and names

◈ 5 cards

IPv4 and IPv6 address formats, the addresses that mean something special, the three port ranges, and what DNS adds — with a service defined as the pair (address, port).

An address names an interface, not a machine

An IPv4 address is four bytes, written as a dotted quad like 199.1.32.90, each part an unsigned byte from 0 to 255 — a little over four billion addresses in total, which ran out years ago. An IPv6 address is sixteen bytes, written as eight groups of four hexadecimal digits separated by colons. Leading zeros in a group may be dropped, and a single :: (at most one per address) stands for a run of all-zero groups, so FEDC:0000:0000:0000:00DC:0000:7076:0010 may be written FEDC::DC:0:7076:10.

The important habit: an address belongs to a network interface, not to a computer. A laptop with Wi-Fi and Ethernet has two addresses; a server may have several on one interface; a host may have IPv4 and IPv6 addresses at once. Addresses also change — a DHCP lease expires, a laptop moves — so never store one as if it were an identity.

The addresses that mean something special

  • 127.0.0.1 (IPv6 ::1) is the loopback: it always means this host, and traffic to it never touches network hardware. Its usual name is localhost.
  • 0.0.0.0 (IPv6 ::) is the wildcard: legal as a source, never as a destination. A server that binds to it accepts on every interface.
  • 10.x.x.x, 172.16.x.x through 172.31.x.x, and 192.168.x.x are the private IPv4 blocks. They work inside a network and no host using one is allowed onto the global internet directly.
  • 169.254.x.x is self-assigned link-local — it usually means DHCP failed.
  • 224.0.0.0 through 239.255.255.255 are multicast groups (module 13).
  • 255.255.255.255 is the limited broadcast address; every host on the local network receives it and no router forwards it. That is how a booting laptop finds a DHCP server.

Ports: 65,535 of them, per protocol

An address gets you to a host; a port gets you to the right program on it. Ports are pure abstractions numbered 1 to 65535, and they are per transport protocol — TCP 80 and UDP 80 are unrelated mailboxes. They come in three ranges: well-known (below 1024) which on Unix and macOS only a process running as root may bind, though anyone may send to them; registered (1024–49151); and dynamic or ephemeral (49152–65535), which is where the OS gets the temporary source port for your client connections.

A service is therefore the pair (address, port). A single TCP connection is identified by the four-tuple of both addresses and both ports, which is why one server on port 80 can hold thousands of simultaneous connections.

Names: DNS is a network call

Humans do not remember dotted quads, so the Domain Name System maps names to addresses. Three properties matter for your code. One name may map to many addresses (load balancing) and many names to one address (virtual hosting, module 5). The mapping changes over time, and the change takes hours to propagate. And a lookup is a network round trip, cached at several levels but potentially costing seconds when it is not.

That last point is not trivia — it is the entire motivation for A1's thread pool. A weblog with 100,000 lines is 100,000 potential lookups, and done one after another that is a program you start before lunch.

Worked example — read a service out of a URL

Take http://www.athabascau.ca/calendar/index.html.

The scheme is http, and the scheme — not the URL text — supplies the default port 80. The host is www.athabascau.ca, which is a name, not an address, so something must resolve it: one DNS round trip returning possibly several addresses. Pick one and you finally have the pair to connect to: (that address, 80).

Change the URL to https://www.athabascau.ca:8443/calendar/index.html and two things move: the scheme's default becomes 443, and the explicit :8443 overrides it. The host is untouched. So the (address, port) pair a socket needs is always derived — one part from a lookup, the other from the scheme unless the URL says otherwise.

PortServiceWhere it appears13daytimemodule 6 — first client25SMTPmodule 11 — sending37timemodule 6 — binary reply43whoisa directory service80HTTPmodules 5, 7, 8110POP3module 11 — download143IMAPmodule 11 — server-side443HTTPSmodule 13 — TLS1099RMI registrymodule 10 — RMI2628dictmodule 6 — request/replyA port number is a convention, not a promise about what listens there.
Every port this course connects to or binds, and where it turns up. Learn 25, 80, 110, 143, 443 and 1099 cold; the small numbers (13, 37, 43) are the toy protocols module 6 uses to teach socket clients without a protocol getting in the way.

source Harold 4e ch1 §Ports (Table 1-1); JDK javadoc java.rmi.registry.Registry (REGISTRY_PORT)

source Harold 4e ch1 §IP Addresses and Domain Names; JDK javadoc java.net.URL

NORMAL ~/memra/learn/comp-348/addresses-ports-and-names utf-8 LF