Functional Weave
Code in Rust

net.port@1.0.0

README.md

2,332 bytes · view raw

# net.port

Two functions for TCP and UDP port numbers:

- `isPort(value)` answers whether a number is a port you can connect to: a
  whole number from 1 to 65535. It never throws, so it is the check to use when
  validating input.
- `portService(port, protocol)` says which RFC 6335 range the port is in and
  which service IANA registered on it for `tcp` or `udp`. It throws on a port
  `isPort` refuses or an unknown protocol.

They are a group because `portService` is only defined on what `isPort`
accepts; a caller validating an inventory wants the first, one labelling a
report wants the second.

## Ranges (RFC 6335 section 6)

| range | ports | |
|-------|-------|--|
| `system` | 0-1023 | assigned by IETF review; binding needs privilege on Unix |
| `user` | 1024-49151 | assigned by IANA on request |
| `dynamic` | 49152-65535 | never assigned; ephemeral client ports |

Port 0 is reserved and means "let the OS pick", so `isPort(0)` is false.

## The service table

`data/services.json` holds 144 rows (76 ports, tcp and udp) copied verbatim
from the IANA Service Name and Transport Protocol Port Number Registry: the
service name and description exactly as IANA writes them, including its
capitalisation. It is a subset: the ports an operations team meets (ssh, dns,
http/https, mail, directory, databases, message brokers, remote access, VPN).
A port not in the table has `service: null`, which means "not in this table",
not necessarily "unassigned".

Choices where IANA lists more than one name on a port/protocol:

- 80: `http` (IANA also lists `www` and `www-http` as aliases).
- 465/tcp: `submissions` (RFC 8314), not the historical `urd`.
- 2049: `nfs`, not `shilp`.
- Everywhere else, the first name IANA lists. Rows IANA marks `Reserved`
  (e.g. 6379/udp, 993/udp) are left out, so they have no service.

Notable answers: 5433 is registered to `pyrrho` (Pyrrho DBMS), not to a second
PostgreSQL, however often Postgres is run there; 4874 is unassigned (IANA
lists 4872-4875 as Unassigned).

Source: IANA, "Service Name and Transport Protocol Port Number Registry",
https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv,
fetched 2026-09-26. RFC 6335 (Procedures for the Management of the Service
Name and Transport Protocol Port Number Registry), section 6, for the ranges.