Date: Mon, 11 Apr 2011 16:11:27 +0400 From: Sergey Vinogradov <boogie@lazybytes.org> To: freebsd-current@freebsd.org Subject: [PATCH] ifconfig(8) flag to display IPv4 netmasks in dot-decimal format Message-ID: <4DA2EFEF.3010004@lazybytes.org>
next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format. --------------020809060003010109060206 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, I've written a tiny-tiny patch, which adds the '-t' flag to ifconfig(8). It modifies the output to display IPv4 netmasks in dotted decimal notation: % ifconfig msk0 msk0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 options=c011a<TXCSUM,VLAN_MTU,VLAN_HWTAGGING,TSO4,VLAN_HWTSO,LINKSTATE> ether 00:16:e6:88:0f:89 inet 10.10.0.1 netmask 0xffffff00 broadcast 10.10.0.255 media: Ethernet autoselect (none) status: no carrier % ifconfig -t msk0 msk0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 options=c011a<TXCSUM,VLAN_MTU,VLAN_HWTAGGING,TSO4,VLAN_HWTSO,LINKSTATE> ether 00:16:e6:88:0f:89 inet 10.10.0.1 netmask 255.255.255.0 broadcast 10.10.0.255 media: Ethernet autoselect (none) status: no carrier There was a discussion [1] in freebsd-hackers@ about adding such functionality to ifconfig(8), which urged me write this patch. The default behavior of ifconfig(8) is kept unmodified, so there shouldn't be any compatibility breakages. At least, it works fine for me :) [1] http://lists.freebsd.org/pipermail/freebsd-hackers/2011-April/034997.html -- wbr, Boo --------------020809060003010109060206 Content-Type: text/plain; name="ifconfig.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="ifconfig.patch" Index: sbin/ifconfig/af_inet.c =================================================================== RCS file: /home/ncvs/src/sbin/ifconfig/af_inet.c,v retrieving revision 1.5.2.2.2.1 diff -u -r1.5.2.2.2.1 af_inet.c --- sbin/ifconfig/af_inet.c 21 Dec 2010 17:09:25 -0000 1.5.2.2.2.1 +++ sbin/ifconfig/af_inet.c 11 Apr 2011 12:03:32 -0000 @@ -79,7 +79,10 @@ sin = (struct sockaddr_in *)ifa->ifa_netmask; if (sin == NULL) sin = &null_sin; - printf("netmask 0x%lx ", (unsigned long)ntohl(sin->sin_addr.s_addr)); + if (dotmask) + printf("netmask %s ", inet_ntoa(sin->sin_addr)); + else + printf("netmask 0x%lx ", (unsigned long)ntohl(sin->sin_addr.s_addr)); if (ifa->ifa_flags & IFF_BROADCAST) { sin = (struct sockaddr_in *)ifa->ifa_broadaddr; Index: sbin/ifconfig/ifconfig.8 =================================================================== RCS file: /home/ncvs/src/sbin/ifconfig/ifconfig.8,v retrieving revision 1.159.2.6.4.1 diff -u -r1.159.2.6.4.1 ifconfig.8 --- sbin/ifconfig/ifconfig.8 21 Dec 2010 17:09:25 -0000 1.159.2.6.4.1 +++ sbin/ifconfig/ifconfig.8 11 Apr 2011 12:03:32 -0000 @@ -40,6 +40,7 @@ .Op Fl k .Op Fl m .Op Fl n +.Op Fl t .Ar interface .Op Cm create .Op Ar address_family @@ -56,6 +57,7 @@ .Op Fl L .Op Fl d .Op Fl m +.Op Fl t .Op Fl u .Op Fl v .Op Ar address_family @@ -69,6 +71,7 @@ .Op Fl d .Op Fl k .Op Fl m +.Op Fl t .Op Fl u .Op Fl v .Op Fl C @@ -2400,6 +2403,9 @@ .Fl L flag is supplied, address lifetime is displayed for IPv6 addresses, as time offset string. +The +.Fl t +flag makes IPv4 netmasks being displayed in dotted decimal notation. .Pp Optionally, the .Fl a Index: sbin/ifconfig/ifconfig.c =================================================================== RCS file: /home/ncvs/src/sbin/ifconfig/ifconfig.c,v retrieving revision 1.146.2.5.4.1 diff -u -r1.146.2.5.4.1 ifconfig.c --- sbin/ifconfig/ifconfig.c 21 Dec 2010 17:09:25 -0000 1.146.2.5.4.1 +++ sbin/ifconfig/ifconfig.c 11 Apr 2011 12:03:32 -0000 @@ -90,6 +90,7 @@ int clearaddr; int newaddr = 1; int verbose; +int dotmask; int noload; int supmedia = 0; @@ -132,9 +133,9 @@ "usage: ifconfig %sinterface address_family [address [dest_address]]\n" " [parameters]\n" " ifconfig interface create\n" - " ifconfig -a %s[-d] [-m] [-u] [-v] [address_family]\n" + " ifconfig -a %s[-d] [-m] [-t] [-u] [-v] [address_family]\n" " ifconfig -l [-d] [-u] [address_family]\n" - " ifconfig %s[-d] [-m] [-u] [-v]\n", + " ifconfig %s[-d] [-m] [-t] [-u] [-v]\n", options, options, options); exit(1); } @@ -156,7 +157,7 @@ all = downonly = uponly = namesonly = noload = verbose = 0; /* Parse leading line options */ - strlcpy(options, "adklmnuv", sizeof(options)); + strlcpy(options, "adklmntuv", sizeof(options)); for (p = opts; p != NULL; p = p->next) strlcat(options, p->opt, sizeof(options)); while ((c = getopt(argc, argv, options)) != -1) { @@ -179,6 +180,9 @@ case 'n': /* suppress module loading */ noload++; break; + case 't': /* show IPv4 netmask in dotted decimal notation */ + dotmask++; + break; case 'u': /* restrict scan to "up" interfaces */ uponly++; break; @@ -199,8 +203,8 @@ argc -= optind; argv += optind; - /* -l cannot be used with -a or -m */ - if (namesonly && (all || supmedia)) + /* -l cannot be used with -a, -m or -t */ + if (namesonly && (all || supmedia || dotmask)) usage(); /* nonsense.. */ Index: sbin/ifconfig/ifconfig.h =================================================================== RCS file: /home/ncvs/src/sbin/ifconfig/ifconfig.h,v retrieving revision 1.24.2.1.6.1 diff -u -r1.24.2.1.6.1 ifconfig.h --- sbin/ifconfig/ifconfig.h 21 Dec 2010 17:09:25 -0000 1.24.2.1.6.1 +++ sbin/ifconfig/ifconfig.h 11 Apr 2011 12:03:33 -0000 @@ -132,6 +132,7 @@ extern int printkeys; extern int newaddr; extern int verbose; +extern int dotmask; void setifcap(const char *, int value, int s, const struct afswtch *); --------------020809060003010109060206--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4DA2EFEF.3010004>