Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

77.3. iana-etc-20260911

/etc/services, /etc/protocols and /etc/rpc, generated from IANA's registries

Version 20260911, release 1
Shelf base — The minimal userland and system daemons that every KDOS image boots with
Phase 41_system (System), 196 of 1047 in build order
Licence LicenseRef-IANA-Registries
Homepage https://www.iana.org/protocols
Build time 0.1 SBU
Installed size 325.2 KiB in 3 files
Recipe ports/core/base/iana-etc/kpkgbuild

About

iana-etc installs three network databases: /etc/services (service names and ports, which musl’s getservbyname() reads), /etc/protocols (IP protocol numbers) and /etc/rpc (ONC RPC program numbers, which libtirpc’s getrpcbyname() reads). musl’s getprotobyname() answers from a table compiled into the C library and does not open /etc/protocols. The port carries no generated text: its three sources are IANA’s own registry files in XML, and build.sh turns them into the tables, which is why it is long.

Sources

Dependencies

Depends on: gawk.

Required by: no port names it.

Installation

From the repository root, inside the build container, this is the line kdosbuild runs for the port:

script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install iana-etc'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/base/iana-etc.

1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.

cd /ports/core/base/iana-etc
echo '59cdd7930cd6152bd11713b8883503511fffb2add72345d21d043cecb969803b  protocol-numbers-20260911.xml' | sha256sum -c -
echo '30a69353af6e017ffd9e141d079f90a7b7117f113f122d2d89ee20ffb587da19  service-names-port-numbers-20260911.xml' | sha256sum -c -
echo 'fb8db0a6811a83dc9017b6349372895fdb4d384f3e34bc92de40fa4d724d7506  rpc-program-numbers-20260911.xml' | sha256sum -c -

2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.

SRC_ROOT=/var/cache/kpkg/work/iana-etc
SRC=$SRC_ROOT/iana-etc-20260911
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
cp protocol-numbers-20260911.xml "$SRC"
cp service-names-port-numbers-20260911.xml "$SRC"
cp rpc-program-numbers-20260911.xml "$SRC"

Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.

3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the recipe’s helpers _reg and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

gawk -F '[<>]' -v URL="$_reg/protocol-numbers/protocol-numbers.xml" -v V="$version" '
	BEGIN {
		print "# /etc/protocols, IANA registry as of " V
		print "# Source: " URL
	}
	/<record/ {v = n = ""}
	/<value/ {v = $3}
	/<name/ && $3 !~ / / {n = $3}
	/<\/record/ && n && v != "" {
		printf "%-12s %3i %s\n", tolower(n), v, n
	}
' < protocol-numbers-$version.xml > protocols

gawk -F '[<>]' -v URL="$_reg/service-names-port-numbers/service-names-port-numbers.xml" -v V="$version" '
	BEGIN {
		print "# /etc/services, IANA registry as of " V
		print "# Source: " URL
	}
	/<record/ {n = u = p = c = ""}
	/<name/ && !/\(/ {n = $3}
	/<number/ {u = $3}
	/<protocol/ {p = $3}
	/Unassigned/ || /Reserved/ || /historic/ {c = 1}
	/<\/record/ && n && u && p && !c {
		printf "%-15s %5i/%s\n", n, u, p
	}
' < service-names-port-numbers-$version.xml > services

gawk -F '[<>]' -v URL="$_reg/rpc-program-numbers/rpc-program-numbers.xml" -v V="$version" '
	BEGIN {
		print "# /etc/rpc, IANA registry as of " V
		print "# Source: " URL
	}
	/<record/ {v = n = c = ""}
	/<value/ {v = $3}
	/<name/ {n = $3}
	/Unassigned/ || /Reserved/ || /\[unknown\]/ {c = 1}
	/<\/record/ && n && v != "" && !c {
		sub(/#.*/, "", n)
		gsub(/[[:space:]]+/, " ", n)
		sub(/^ /, "", n)
		sub(/ $/, "", n)
		if (n == "") next
		if (v == "100000" && n !~ /portmapper/) n = n " portmapper sunrpc"
		if (v == "100001" && n !~ /rstatd/) n = "rstatd " n
		if (v == "100002" && n !~ /rusersd/) n = "rusersd " n
		if (v == "100005" && n !~ /mountd/) n = "mountd " n " mount"
		if (v == "100008" && n !~ /rwalld/) n = "rwalld " n " rwall"
		split(n, names, " ")
		delete seen
		printf "%-15s %s", names[1], v
		seen[names[1]] = 1
		for (i = 2; i <= length(names); i++) {
			if (names[i] in seen) continue
			printf " %s", names[i]
			seen[names[i]] = 1
		}
		printf "\n"
	}
' < rpc-program-numbers-$version.xml > rpc

for _f in services protocols rpc; do
	if ! grep -qv '^#' "$_f"; then
		echo "ERROR: iana-etc: $_f came out empty" >&2
		exit 1
	fi
done
grep -q '^ssh  *22/tcp$' services || { echo "ERROR: iana-etc: services has no ssh" >&2; exit 1; }
grep -q '^tcp  *6 TCP$' protocols || { echo "ERROR: iana-etc: protocols has no tcp" >&2; exit 1; }

install -d -m 755 $PKG/etc
install -m 644 services protocols rpc $PKG/etc

The common switches of each build system are explained in the Flag glossary.

4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/iana-etc, prunes what the image does not ship, lints the tree and rolls it reproducibly:

tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
    --mtime=@$SOURCE_DATE_EPOCH \
    --use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
    -cf iana-etc-20260911-1.tar.xz -C "$PKG" .

5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/iana-etc, and runs the triggers its paths call for.

Notes