Subject: Re: misc/11532: a script to keep /etc/protocols up-to-date
To: None <misc-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: Greg A. Woods <woods@weird.com>
List: netbsd-bugs
Date: 02/08/2005 00:11:01
The following reply was made to PR misc/11532; it has been noted by GNATS.
From: "Greg A. Woods" <woods@weird.com>
To: NetBSD GNATS submissions and followups <gnats-bugs@netbsd.org>
Cc:
Subject: Re: misc/11532: a script to keep /etc/protocols up-to-date
Date: Mon, 7 Feb 2005 19:10:15 -0500 (EST)
attached is an updated version of my script, plus a "new" manual page for it.
--
Greg A. Woods
H:+1 416 218-0098 W:+1 416 489-5852 x122 VE3TCP RoboHack <woods@robohack.ca>
Planix, Inc. <woods@planix.com> Secrets of the Weird <woods@weird.com>
# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# update-protocols.sh
# update-protocols.8
# Makefile
#
echo x - update-protocols.sh
sed 's/^X//' >update-protocols.sh << 'END-of-update-protocols.sh'
X#! /bin/sh
X#
X#ident "@(#)$NetBSD$"
X#
X# update-protocols
X#
X# retrieve the official protocol-numbers from IANA and transform
X# it into a unix-style /etc/protocols file
X#
X# Note that the IANA file is kinda messy and needs some fancy fixing up!
X#
X# This script last updated for IANA input hacking on 2005/02/07.
X#
X# Written 2000/11/19 by Greg A. Woods <woods@planix.com>
X#
X# Copyright is hereby assigned to the Public Domain
X
XSOURCE_URL="ftp://ftp.iana.org/assignments/protocol-numbers"
X
Xcat <<EOF
X# \$NetBSD\$
X#
X# Internet (IP) protocols -- see protocols(5)
X#
X# Updated on $(date)
X# using $0
X# from $SOURCE_URL
X#
X# name P# alias(es) # comment [reference]
X#------------- --- -------------- --------- -----------
X#
Xip 0 IP # internet protocol [pseudo protocol]
XEOF
X
Xftp -a -V -o - $SOURCE_URL |
X expand |
X tr '\r' '\n' |
X sed -E -e '1,/^---/d' \
X -e 's/://g' \
X -e 's/^ +//' \
X -e 's/ +$//' \
X -e '/^$/d' \
X -e '/^REFERENCES/,$d' |
X sed -E -e '/^(61|63|68|99|114|253|254|255) /s/^([0-9]*) /\1 PRIV-\1/' \
X -e '/^124 /s/ISIS over IPv4 /ISIS-IPv4 ISIS over IPv4/' \
X -e '/^135 /s/Mobility Header {21}/IPv6-MBLTY-HDR IPv6 Mobility Header/' |
X sed -E -e 's/^([ ]*[0-9]+) [ ]*([^ ]+) [ ]*/\1:\2:/' |
X awk -F: '
Xfunction print_entry(number, name, comment)
X{
X # traditionally the all-lower version of the official name is used
X # as the official name on Unix and we keep the real official name
X # in preserved case as an alias
X #
X printf("%-14s %3d %-14s # %s\n", tolower(name), number, name, comment);
X}
X
X# first: check for, and fill in, the/any unassigned range
X#
X$1 ~ /Unassigned/ {
X sub(/[ ]*Unassigned/, "", $1);
X split($1, rng, "-");
X for (i = rng[1]; i <= rng[2]; i++) {
X print_entry(i, toupper(sprintf("unasgnd-%d", i)), $3);
X }
X next;
X}
X
X# then: ignore the multi-line comments that sometimes appear
X#
X$2 == "" {
X # XXX ideally we would append these to the previous line
X next;
X}
X
X# the "normal" entries
X#
X{
X # type co-ersion
X #
X $1 = $1 + 0;
X
X # extraneous error checking
X #
X if ($1 > 255) {
X printf("#");
X $3 = sprintf("ILLEGAL NUMBER! - %s", $3);
X }
X
X if ($1 == 4) {
X $2 = "IPENCAP"; # should have alias "IP-ENCAP" and/or "IP-IP"?
X }
X if ($1 == 89) {
X $2 = "OSPF"; # should have alias "OSPFIGP"?
X }
X if ($1 == 253) {
X $2 = "EXPERIMENTAL-253";
X }
X if ($1 == 254) {
X $2 = "EXPERIMENTAL-254";
X }
X if ($1 == 255) {
X $2 = "RESERVED-255";
X }
X
X print_entry($1, $2, $3);
X}'
END-of-update-protocols.sh
echo x - update-protocols.8
sed 's/^X//' >update-protocols.8 << 'END-of-update-protocols.8'
X.\"
X.\" Written 2000/11/19 by Greg A. Woods <woods@planix.com>
X.\"
X.\" Copyright is hereby assigned to the Public Domain
X.\"
X.Dd February 7, 2005
X.Dt UPDATE-PROTOCOLS 8
X.Os
X.Sh NAME
X.Nm update-protocols
X.Nd update /etc/protocols from the official published list
X.Sh SYNOPSIS
X.Nm
X.Sh DESCRIPTION
XThe
X.Nm
Xprogram retrieve the official protocol-numbers from IANA and transforms
Xit into output in the form of
X.Xr protocols 5 ,
Xsuitable for replacing the content of
X.Pa /etc/protocols .
X.Sh FILES
X.Bl -tag -width /etc/protocols -compact
X.It Pa /etc/protocols
X.El
X.\"
X.\".Sh EXAMPLES
X.\"
X.\".Sh DIAGNOSTICS
X.\"
X.Sh SEE ALSO
X.Xr protocols 5
X.Pp
X.Aq Li URL:ftp://ftp.iana.org/assignments/protocol-numbers
X.\"
X.\"
X.Sh STANDARDS
XThis command does not adhere to any known standards, but it does try to
Xtranslate an IANA published standard into a usable configuration file.
X.\"
X.\".Sh HISTORY
X.\"
X.Sh AUTHORS
XGreg A. woods
X.Aq Li woods@planix.com
X.\"
X.Sh BUGS
X.\"
XThe IANA file is kinda messy and needs some fancy fixing up!
END-of-update-protocols.8
echo x - Makefile
sed 's/^X//' >Makefile << 'END-of-Makefile'
X#ident "$Name$:$Id$"
X
XMAN= update-protocols.8
XSCRIPTS=update-protocols
X
X.include <bsd.prog.mk>
END-of-Makefile
exit