Hi,

i'm slowly working towards removing support for the networks(5)
database because networks(5) is broken by design.  Nowadays, the
only meaningful way to translate names to numbers and vice versa
is via DNS.  However, the networks(5) database isn't integrated
with DNS in any way, even less so than the hosts(5) database, which
at least maintains some relationship to the resolver(3) and
getaddrinfo(3) families of functions.  Besides, even historically,
the networks(5) database was only used by a handful of programs and
never worked in the same comprehensive sense as DNS for host names.

While here, the gethostent(3) library interface should go away,
too, because enumerating hosts just isn't meaningful.  There is no
reasonable way to implement this function, it has been broken since
the switch to libc/asr, and i remember only one complaint which
didn't sound very urgent.  sethostent(3) and endhostent(3) can be
kept as stubs for now to prevent disruption to ports land.

As a first step, i propose to remove support from the relatively
few programs in the base system still using this.  In the second
step, about a dozen ports would need looking into; i already have
a list.  Some are likely to magically fix themselves when their
configure script doesn't find the functions.  In the third step,
the interfaces would be removed as part of a libc major bump.

To show a specific example, here is the first part of the first
step: Remove networks(5) support from netstat(1).

OK?
  Ingo

P.S.
I'm running a system with all this (except sethostent(3) and
endhostent(3)) removed right now, so some more patches are being
tested and can be sent out soon.  The following programs require
minor tweaks: getent(1) systat(1) amd(8) ifconfig(8) mountd(8)
pppd(8) route(8) tcpdump(8) ypbind(8) ypinit(8) ypserv(8) ypxfr(8).


Index: inet.c
===================================================================
RCS file: /cvs/src/usr.bin/netstat/inet.c,v
retrieving revision 1.134
diff -u -p -r1.134 inet.c
--- inet.c      14 Aug 2014 12:55:50 -0000      1.134
+++ inet.c      21 Oct 2014 17:05:30 -0000
@@ -801,7 +801,6 @@ inetname(struct in_addr *inp)
        char *cp;
        static char line[50];
        struct hostent *hp;
-       struct netent *np;
        static char domain[MAXHOSTNAMELEN];
        static int first = 1;
 
@@ -818,12 +817,6 @@ inetname(struct in_addr *inp)
                int net = inet_netof(*inp);
                int lna = inet_lnaof(*inp);
 
-               if (lna == INADDR_ANY) {
-                       np = getnetbyaddr(net, AF_INET);
-                       if (np)
-                               cp = np->n_name;
-               }
-               if (cp == NULL) {
                        hp = gethostbyaddr((char *)inp, sizeof (*inp), AF_INET);
                        if (hp) {
                                if ((cp = strchr(hp->h_name, '.')) &&
@@ -831,7 +824,6 @@ inetname(struct in_addr *inp)
                                        *cp = '\0';
                                cp = hp->h_name;
                        }
-               }
        }
        if (inp->s_addr == INADDR_ANY)
                snprintf(line, sizeof line, "*");
Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/netstat/main.c,v
retrieving revision 1.101
diff -u -p -r1.101 main.c
--- main.c      23 Jun 2014 03:46:17 -0000      1.101
+++ main.c      21 Oct 2014 17:05:31 -0000
@@ -372,13 +372,6 @@ main(int argc, char *argv[])
                printproto(tp, tp->pr_name, af, tableid, pcbaddr);
                exit(0);
        }
-       /*
-        * Keep file descriptors open to avoid overhead
-        * of open/close on each call to get* routines.
-        */
-       sethostent(1);
-       setnetent(1);
-
        if (iflag) {
                intpr(interval, repeatcount);
                exit(0);
Index: netstat.1
===================================================================
RCS file: /cvs/src/usr.bin/netstat/netstat.1,v
retrieving revision 1.71
diff -u -p -r1.71 netstat.1
--- netstat.1   10 May 2014 23:31:40 -0000      1.71
+++ netstat.1   21 Oct 2014 17:05:31 -0000
@@ -312,12 +312,10 @@ Address formats are of the form
 or
 .Dq network.port
 if a socket's address specifies a network but no specific host address.
-When known, the host and network addresses are displayed symbolically
-according to the databases
-.Pa /etc/hosts
-and
-.Pa /etc/networks ,
-respectively.
+When known, the host addresses are displayed symbolically
+according to the
+.Xr hosts 5
+database.
 If a symbolic name for an address is unknown, or if the
 .Fl n
 option is specified, the address is printed numerically, according
@@ -427,7 +425,6 @@ Subsequent lines of output show values a
 .Xr netintro 4 ,
 .Xr route 4 ,
 .Xr hosts 5 ,
-.Xr networks 5 ,
 .Xr protocols 5 ,
 .Xr services 5 ,
 .Xr iostat 8 ,
Index: show.c
===================================================================
RCS file: /cvs/src/usr.bin/netstat/show.c,v
retrieving revision 1.42
diff -u -p -r1.42 show.c
--- show.c      8 May 2014 09:28:08 -0000       1.42
+++ show.c      21 Oct 2014 17:05:31 -0000
@@ -713,21 +713,13 @@ routename6(struct sockaddr_in6 *sin6)
 char *
 netname4(in_addr_t in, in_addr_t mask)
 {
-       char *cp = NULL;
-       struct netent *np = NULL;
        int mbits;
 
        in = ntohl(in);
        mask = ntohl(mask);
-       if (!nflag && in != INADDR_ANY) {
-               if ((np = getnetbyaddr(in, AF_INET)) != NULL)
-                       cp = np->n_name;
-       }
-       if (in == INADDR_ANY && mask == INADDR_ANY)
-               cp = "default";
        mbits = mask ? 33 - ffs(mask) : 0;
-       if (cp)
-               strlcpy(line, cp, sizeof(line));
+       if (in == INADDR_ANY && mask == INADDR_ANY)
+               strlcpy(line, "default", sizeof(line));
 #define C(x)   ((x) & 0xff)
        else if (mbits < 9)
                snprintf(line, sizeof(line), "%u/%d", C(in >> 24), mbits);

Reply via email to