So, who knows what the -n flag is doing in ping(8)?
The man page has this to say:

     -n      Numeric output only.  No attempt will be made to look up symbolic
                  names for host addresses.

$ ping -c1 amd64.openbsd.adns.de
PING amd64.openbsd.adns.de (217.31.84.226): 56 data bytes
64 bytes from 217.31.84.226: icmp_seq=0 ttl=247 time=17.972 ms
--- amd64.openbsd.adns.de ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/std-dev = 17.972/17.972/17.972/0.000 ms

$ ping -nc1 amd64.openbsd.adns.de
PING amd64.openbsd.adns.de (217.31.84.226): 56 data bytes
64 bytes from 217.31.84.226: icmp_seq=0 ttl=247 time=28.371 ms
--- amd64.openbsd.adns.de ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/std-dev = 28.371/28.371/28.371/0.000 ms

Hm, no difference, so what is it used for?

Turns out it's used in pr_addr which in turn gets called for "special"
responses.

1) Something that's not an echo reply
2) LSRR or RR IP options

2) isn't relevant in this day and age. I would argue that for 1) ping
has it arse backwards. For debugging purposes the IP address is
relevant. DNS can lie.

Also this gets in the way of a merge with ping6(8) which uses pr_addr
for all printing purposes. It either always does reverse DNS lookups
(-H) or never (the default). ping(8)'s sometimes do DNS lookups
behavior could be somehow shoved into this put it will be complicated
for no good reason.

This changes the default to never do reverse lookups. A second diff
then implements ping6(8)'s -H option in ping(8).

Comments / OK?

diff --git ping/ping.8 ping/ping.8
index dd39e66..e3d3d0b 100644
--- ping/ping.8
+++ ping/ping.8
@@ -39,7 +39,7 @@
 .Sh SYNOPSIS
 .Nm ping
 .Bk -words
-.Op Fl DdEefLnqRv
+.Op Fl DdEefLqRv
 .Op Fl c Ar count
 .Op Fl I Ar ifaddr
 .Op Fl i Ar wait
@@ -142,9 +142,6 @@ is specified,
 sends that many packets as fast as possible before falling into its normal
 mode of behavior.
 Only root may set a preload value.
-.It Fl n
-Numeric output only.
-No attempt will be made to look up symbolic names for host addresses.
 .It Fl p Ar pattern
 You may specify up to 16
 .Dq pad
diff --git ping/ping.c ping/ping.c
index 11003e9..ac7d947 100644
--- ping/ping.c
+++ ping/ping.c
@@ -103,7 +103,7 @@ struct payload {
 int options;
 #define        F_FLOOD         0x0001
 #define        F_INTERVAL      0x0002
-#define        F_NUMERIC       0x0004
+/*                     0x0004 */
 #define        F_PINGFILLED    0x0008
 #define        F_QUIET         0x0010
 #define        F_RROUTE        0x0020
@@ -279,7 +279,7 @@ main(int argc, char *argv[])
                                    optarg);
                        break;
                case 'n':
-                       options |= F_NUMERIC;
+                       /* ignore for backward compatibility */
                        break;
                case 'p':               /* fill buffer with user pattern */
                        options |= F_PINGFILLED;
@@ -503,14 +503,9 @@ main(int argc, char *argv[])
        else
                (void)printf("PING %s: %d data bytes\n", hostname, datalen);
 
-       if (options & F_NUMERIC) {
-               if (pledge("stdio inet", NULL) == -1)
-                       err(1, "pledge");
-       } else {
-               if (pledge("stdio inet dns", NULL) == -1)
-                       err(1, "pledge");
-       }
-
+       if (pledge("stdio inet", NULL) == -1)
+               err(1, "pledge");
+       
        while (preload--)               /* fire off them quickies */
                pinger();
 
@@ -1290,23 +1285,16 @@ pr_iph(struct ip *ip)
 
 /*
  * pr_addr --
- *     Return an ascii host address as a dotted quad and optionally with
- * a hostname.
+ *     Return an ascii host address as a dotted quad.
  */
 char *
 pr_addr(in_addr_t a)
 {
-       struct hostent *hp;
        struct in_addr in;
-       static char buf[16+3+HOST_NAME_MAX+1];
+       static char buf[16];
 
        in.s_addr = a;
-       if ((options & F_NUMERIC) ||
-           !(hp = gethostbyaddr((char *)&in.s_addr, sizeof(in.s_addr), 
AF_INET)))
-               (void)snprintf(buf, sizeof buf, "%s", inet_ntoa(in));
-       else
-               (void)snprintf(buf, sizeof buf, "%s (%s)", hp->h_name,
-                   inet_ntoa(in));
+       (void)snprintf(buf, sizeof buf, "%s", inet_ntoa(in));
        return(buf);
 }
 
@@ -1447,7 +1435,7 @@ void
 usage(void)
 {
        (void)fprintf(stderr,
-           "usage: ping [-DdEefLnqRv] [-c count] [-I ifaddr] [-i wait]\n"
+           "usage: ping [-DdEefLqRv] [-c count] [-I ifaddr] [-i wait]\n"
            "\t[-l preload] [-p pattern] [-s packetsize]"
 #ifndef        SMALL
            " [-T toskeyword]"


-- 
I'm not entirely sure you are real.

Reply via email to