It is well-known that, on most systems, using 0 for the UDP destination port or for the TCP source or destination ports is disallowed. Is this required by RFCs, or is this just common practice? If it's required, which RFCs require it?
IANA has reserved both TCP and UDP port 0. See the IANA Service Name and Transport Protocol Port Number Registry. IANA is the Internet Assigned Numbers Authority, so all internet numbers, including port numbers, are assigned by IANA.
OSes have reserved that port number for an application to request an ephemeral port number by using it as a source port number, but that is off-topic here.
Port zero has been included in the "Network Wide Standard Functions" range since RFC433 in 1972, but has never been assigned.
Here the range is given as 0-63, but the first assignment is port 1. I can find no "Assigned Numbers" RFC which assigns port 0.
In October 1983, for the first time, it was explicitly listed as "reserved" in RFC870.
It's probably not a coincidence that this is about the same time the BSD sockets API was released.
- The release of BSD is mentioned as a conforming system
Within the R&D community, it will be the policy that network identifiers will only be granted to applicants who show evidence that they are acquiring standard Bolt Beranek and Newman gateway software or have implemented or are acquiring a gateway meeting the Exterior Gateway Protocol requirements. Acquisition of the Berkeley BSD 4.2 UNIX software might be considered evidence of the latter.
- The BSD sockets API uses port zero to mean the operating system should assign an available port.
- If BSD conforms, then it follows that port 0 cannot be used.
It may well be that other systems were already using this convention in their APIs, or that this was agreed somewhere, but I haven't found any documentation to prove that.