arpコマンドの「/etc/ethers」はnet-tools専用というお話

■arpコマンドの「/etc/ethers」はnet-tools専用というお話
 arpで「/etc/ethers」はデフォルトで使われるけど、「公式のものではない」という説明が気になった。
 manマニュアルは英語のものをそのまま翻訳している様子。

$ man arp | grep -A 5  "\-f filename" | sed s/"  *"/" "/g
 -f filename, --file filename
 -s オプションと似ているが、このオプションの場合、アドレスの情報がファイル filename から与えられる。
 これは、多数のホストに対して ARP エントリーを設定しなければならない場合に使われる。 データファイルの名前には
 /etc/ethers がよく使われるが、これは公式のものではない。 filename が指定されない場合、
 /etc/ethers がデフォルトとして使われる。

$ env LANG=C man arp | grep -A 5 "\-f filename"
       -f filename, --file filename
              Similar to the -s option, only this time  the  address  info  is
              taken from file filename.  This can be used if ARP entries for a
              lot of hosts have to be set up.  The name of the  data  file  is
              very often /etc/ethers, but this is not official. If no filename
              is specified /etc/ethers is used as default.

■バージョンは以下の通り。

$ /usr/sbin/arp -V
net-tools 1.60
arp 1.88 (2001-04-04)
+I18N
AF: (inet) +UNIX +INET +INET6 +IPX +AX25 +NETROM +X25 +ATALK +ECONET +ROSE
HW: (ether) +ETHER +ARC +SLIP +PPP +TUNNEL +TR +AX25 +NETROM +X25 +FR +ROSE +ASH +SIT +FDDI +HIPPI +HDLC/LAPB +EUI64

■「arp」コマンドは以下にあり、helpオプションからは「/etc/ethers」の記述が見える。

$ dpkg -L net-tools | grep 'sbin/arp'
/usr/sbin/arp

$ /usr/sbin/arp --help 2>&1 | grep -A 7 '\-f\,' | sed s/"^ *"//g
-f, --file         /etc/ethersファイルから新規エントリを読み込む

<HW>=ハードウェアアドレスタイプを指定するには'-H <hw>'を使って下さい。標準: ether
(ARPをサポートした)指定可能なハードウェアタイプのリスト:
strip (Metricom Starmode IP) ash (Ash) ether (イーサネット)
tr (16/4 Mbpsトークンリング) tr (16/4 Mbpsトークンリング()) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) rose (AMPR ROSE) arcnet (ARCネット)
dlci (フレームリレーDLCI) fddi (Fiber Distributed Data Interface) hippi (HIPPI)

$ env LANG=C /usr/sbin/arp --help 2>&1 | grep -A 7 "\-f\,"
        -f, --file               read new entries from file or from /etc/ethers

  <HW>=Use '-H <hw>' to specify hardware address type. Default: ether
  List of possible hardware types (which support ARP):
    strip (Metricom Starmode IP) ash (Ash) ether (Ethernet)
    tr (16/4 Mbps Token Ring) tr (16/4 Mbps Token Ring (New)) ax25 (AMPR AX.25)
    netrom (AMPR NET/ROM) rose (AMPR ROSE) arcnet (ARCnet)
    dlci (Frame Relay DLCI) fddi (Fiber Distributed Data Interface) hippi (HIPPI)

■「arp.c」だけ取り出します。

$ test -d temp || mkdir temp && cd temp
$ sudo apt-get source --download-only net-tools
$ ls
net-tools_1.60-23.diff.gz  net-tools_1.60-23.dsc  net-tools_1.60.orig.tar.gz

■「fprintf」は「--help」時の記述と同一、「what」行は「case」文でスイッチしたルーティン。

$ grep '\/etc\/ethers' net-tools-1.60/arp.c
    fprintf(stderr, _("        -f, --file               read new entries from file or from /etc/ethers\n\n"));
        what = arp_file(argv[optind] ? argv[optind] : "/etc/ethers");

$ tar ztvf net-tools_1.60.orig.tar.gz | grep arp | grep -v man
-rw-r--r-- pb/pb         20906 2001-04-09 02:05 net-tools-1.60/arp.c
-rw-r--r-- pb/pb          7663 2001-04-09 02:05 net-tools-1.60/rarp.c

$ gunzip -c net-tools_1.60.orig.tar.gz | tar xvf - net-tools-1.60/arp.c
net-tools-1.60/arp.c

■全文から検索。

$ tar zxvf net-tools_1.60.orig.tar.gz
$ find net-tools-1.60/ -type f -print | grep '\/etc\/ethers' `xargs` | grep -v '\/po\/\|\/man\/' | sed s/"  *\|\t"/" "/g
net-tools-1.60/lib/pathnames.h:#define _PATH_ETHERS   "/etc/ethers"
net-tools-1.60/rarp.c: * rarp -f Add frop /etc/ethers
net-tools-1.60/rarp.c: fprintf(stderr, _(" rarp -f add entries from /etc/ethers.\n"));
net-tools-1.60/arp.c: fprintf(stderr, _(" -f, --file read new entries from file or from /etc/ethers\n\n"));
net-tools-1.60/arp.c: what = arp_file(argv[optind] ? argv[optind] : "/etc/ethers");

■「/proc」以外に参照しているのは、「/etc/ethers」と「/dev/route」

$ grep -v "\/proc\|^\$" net-tools-1.60/lib/pathnames.h
/*
 * lib/pathnames.h    This file contains the definitions of the path
 *                      names used by the NET-LIB.
 *
 * NET-LIB
 *
 * Version:     lib/pathnames.h 1.37 (1997-08-23)
 *
 * Author:      Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
 */
/* pathnames of the procfs files used by NET. */
#define _PATH_ETHERS                    "/etc/ethers"
/* pathname for the netlink device */
#define _PATH_DEV_ROUTE "/dev/route"
/* End of pathnames.h */

$ ls -l /dev/route
ls: cannot access /dev/route: そのようなファイルやディレクトリはありません
$ ls -l /etc/ethers
ls: cannot access /etc/ethers: そのようなファイルやディレクトリはありません

■要は「net-tools」だけで使っているという意味のようですね。
 分かりにくいw。。。修正するとしたら、以下のような意味でしょうか。

データファイルの名前には /etc/ethers がよく使われるが、「kernel」にとって、これは公式のものではない。