worms(6) does this more concisely:

        errx(1, "length (2-1024) is %s: %s", errstr,


Index: ping.c
===================================================================
RCS file: /cvs/src/sbin/ping/ping.c,v
retrieving revision 1.142
diff -u -p -r1.142 ping.c
--- ping.c      30 Aug 2016 14:28:31 -0000      1.142
+++ ping.c      2 Sep 2016 16:01:53 -0000
@@ -295,8 +295,9 @@ main(int argc, char *argv[])
                case 's':               /* size of packet to send */
                        datalen = strtonum(optarg, 0, MAXPAYLOAD, &errstr);
                        if (errstr)
-                               errx(1, "packet size is %s: %s", errstr,
-                                   optarg);
+                               errx(1, "packet size is %s: %s; provide a "
+                                   "value between 0 and %d inclusive", errstr,
+                                   optarg, MAXPAYLOAD);
                        break;
 #ifndef SMALL
                case 'T':
@@ -311,20 +312,25 @@ main(int argc, char *argv[])
                        else
                                tos = strtonum(optarg, 0, 255, &errstr);
                        if (tos < 0 || tos > 255 || errstr || errno)
-                               errx(1, "illegal tos value %s", optarg);
+                               errx(1, "illegal tos value %s; provide a "
+                                   "value between 0 and 255 inclusive",
+                                   optarg);
                        break;
 #endif /* SMALL */
                case 't':
                        options |= F_TTL;
                        ttl = strtonum(optarg, 0, MAXTTL, &errstr);
                        if (errstr)
-                               errx(1, "ttl value is %s: %s", errstr, optarg);
+                               errx(1, "ttl value is %s: %s; provide a "
+                                   "value between 0 and %d inclusive",
+                                   errstr, optarg, MAXTTL);
                        break;
                case 'V':
                        rtableid = strtonum(optarg, 0, RT_TABLEID_MAX, &errstr);
                        if (errstr)
-                               errx(1, "rtable value is %s: %s", errstr,
-                                   optarg);
+                               errx(1, "rtable value is %s: %s; provide a "
+                                   "value between 0 and %d inclusive", errstr,
+                                   optarg, RT_TABLEID_MAX);
                        if (setsockopt(s, SOL_SOCKET, SO_RTABLE, &rtableid,
                            sizeof(rtableid)) == -1)
                                err(1, "setsockopt SO_RTABLE");

-- 
Michal Mazurek

Reply via email to