[PATCH] ifconfig: Support prefix length.

Samuel Thibault <[email protected]>
Newsgroups gmane.os.hurd.bugs,gmane.comp.gnu.inetutils.bugs
Message-ID <20220927004905.xvivrtudyiob5m2j@begin>
Prefix lengths are much more convenient, support them as an alternative
to passing -m separately from -A.

* ifconfig/options.c (parse_opt): Detect prefix length, and in such a
case, call parse_opt_set_netmask.

Index: inetutils-2.3/ifconfig/options.c
===================================================================
--- inetutils-2.3.orig/ifconfig/options.c
+++ inetutils-2.3/ifconfig/options.c
@@ -547,8 +547,29 @@ parse_opt (int key, char *arg, struct ar
       break;
 
     case 'A':		/* Interface address.  */
-      parse_opt_set_address (ifp, arg);
-      break;
+      {
+	char *netlen = strchr (arg, '/');
+
+	if (netlen)
+	  {
+	    char *end, *str;
+	    unsigned n;
+	    struct in_addr addr;
+
+	    *netlen++ = 0;
+
+	    n = strtol (netlen, &end, 10);
+	    if (end == netlen)
+	      error (EXIT_FAILURE, 0, "Wrong netmask length %s", netlen);
+
+	    addr.s_addr = htonl (INADDR_BROADCAST << (32-n));
+	    str = strdup (inet_ntoa (addr));
+	    parse_opt_set_netmask (ifp, str);
+	  }
+
+	parse_opt_set_address (ifp, arg);
+	break;
+      }
 
     case 'm':		/* Interface netmask.  */
       parse_opt_set_netmask (ifp, arg);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.