Hi, The following diff adds the option -e to ndp(8), which resolved printed hostnames via /etc/ethers. You are able to recognise hosts with IPv6 auto privacy extension addresses on local IPv6 routers. Also hosts inside of a yp(8) domain are able to lookup their neighbors via the shared /etc/ethers database. (Yes, I run a yp domain :-)
This helps me, to keep track of known and unknown IPv6 hosts in my network. The ndp(8) implementations of FreeBSD, NetBSD and Linux don't have an option named -e or a feature like this. Thus, there shouldn't be any problem or misbehavior by existing scripts around ndp(8) with this new option. What's your opinion about this feature? Bye, Jan Index: ndp.8 =================================================================== RCS file: /cvs/src/usr.sbin/ndp/ndp.8,v retrieving revision 1.45 diff -u -p -r1.45 ndp.8 --- ndp.8 9 Aug 2017 14:36:00 -0000 1.45 +++ ndp.8 22 Oct 2018 21:32:46 -0000 @@ -36,7 +36,7 @@ .Nd control/diagnose IPv6 Neighbor Discovery Protocol (NDP) .Sh SYNOPSIS .Nm ndp -.Op Fl acnt +.Op Fl acent .Op Fl A Ar wait .Op Fl d Ar hostname .Op Fl f Ar filename @@ -112,6 +112,12 @@ the node has sent during the current sta Erase all the NDP entries. .It Fl d Ar hostname Delete the specified NDP entry. +.It Fl e +Use the mappings of ethernet addresses in +.Pa /etc/ethers +to resolve hostnames. +This is useful to resolve hostnames of privacy externsion addresses on local +routers. .It Fl f Ar filename Parse entries from .Ar file Index: ndp.c =================================================================== RCS file: /cvs/src/usr.sbin/ndp/ndp.c,v retrieving revision 1.90 diff -u -p -r1.90 ndp.c --- ndp.c 13 Jul 2018 09:03:44 -0000 1.90 +++ ndp.c 22 Oct 2018 21:38:54 -0000 @@ -86,6 +86,7 @@ #include <net/route.h> #include <netinet/in.h> +#include <netinet/if_ether.h> #include <netinet/icmp6.h> #include <netinet6/in6_var.h> @@ -110,6 +111,7 @@ ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) static pid_t pid; +static int eflag; static int nflag; static int tflag; static int32_t thiszone; /* time difference with gmt */ @@ -148,7 +150,7 @@ main(int argc, char *argv[]) pid = getpid(); thiszone = gmt2local(0); rdomain = getrtable(); - while ((ch = getopt(argc, argv, "acd:f:i:nstA:V:")) != -1) { + while ((ch = getopt(argc, argv, "acd:ef:i:nstA:V:")) != -1) { switch (ch) { case 'a': case 'c': @@ -173,6 +175,9 @@ main(int argc, char *argv[]) mode = ch; arg = optarg; break; + case 'e': + eflag = 1; + break; case 'n': nflag = 1; break; @@ -612,6 +617,17 @@ again:; delete(host_buf); continue; } + + if (eflag && sdl->sdl_alen) { + u_char *cp = (u_char *)LLADDR(sdl); + struct ether_addr eaddr; + char nhost[NI_MAXHOST]; + + memcpy(eaddr.ether_addr_octet, cp, ETHER_ADDR_LEN); + if (ether_ntohost(nhost, &eaddr) == 0) + strlcpy(host_buf, nhost, sizeof(host_buf)); + } + gettimeofday(&now, 0); if (tflag) ts_print(&now); @@ -753,7 +769,7 @@ ndp_ether_aton(char *a, u_char *n) void usage(void) { - printf("usage: ndp [-acnt] "); + printf("usage: ndp [-acent] "); printf("[-A wait] [-d hostname] [-f filename] [-i interface]\n"); printf("\t[-s nodename ether_addr [temp] [proxy]] "); printf("[-V rdomain] [hostname]\n");