Bug 169072 - [patch] A little change to ifconfig(8) to display CIDR prefixes instead of hex masks
Summary: [patch] A little change to ifconfig(8) to display CIDR prefixes instead of he...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-14 16:50 UTC by Vitaliy Turovets
Modified: 2016-05-31 17:35 UTC (History)
1 user (show)

See Also:


Attachments
file.txt (2.02 KB, text/plain)
2012-06-14 16:50 UTC, Vitaliy Turovets
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vitaliy Turovets 2012-06-14 16:50:01 UTC
I as network administrator very much dislike how network masks (hexadecimal format) are show for IPv4 by ifconfig.
Since this i added the '-D' switch and some code allowing ifconfig to print IPv4 netmasks in CIDR format. As an example:

Original behaviour:
[18:25][db][~corebug/ifconfig_my] # ./ifconfig LAN
LAN: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=3<RXCSUM,TXCSUM>
        ether 00:12:79:d2:e4:7d
        inet 192.168.0.4 netmask 0xffffff00 broadcast 192.168.0.255
        inet6 fe80::212:79ff:fed2:e47d%LAN prefixlen 64 scopeid 0x9
        nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
        media: Ethernet autoselect (100baseTX <full-duplex>)
        status: active
        vlan: 10 parent interface: bge0

Behaviour with '-D' switch:
[18:25][db][~corebug/ifconfig_my] # ./ifconfig -D LAN
LAN: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=3<RXCSUM,TXCSUM>
        ether 00:12:79:d2:e4:7d
        inet 192.168.0.4/24
        inet6 fe80::212:79ff:fed2:e47d%LAN prefixlen 64 scopeid 0x9
        nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
        media: Ethernet autoselect (100baseTX <full-duplex>)
        status: active
        vlan: 10 parent interface: bge0

Note the difference between 
        inet 192.168.0.4 netmask 0xffffff00 broadcast 192.168.0.255
and
       inet 192.168.0.4/24
I think that such a switch must be present and i suppose that lot of ISP and/or enterprise network admins would agree with me.
Files affected are: ifconfig.c, ifconfig.h, af_inet.c.
The diff between original version and my one is included

Fix: Patch attached with submission follows:
How-To-Repeat: Just build the ifconfig:)
Comment 1 commit-hook freebsd_committer freebsd_triage 2016-05-31 17:31:08 UTC
A commit references this bug:

Author: allanjude
Date: Tue May 31 17:30:08 UTC 2016
New revision: 301059
URL: https://svnweb.freebsd.org/changeset/base/301059

Log:
  ifconfig(8) now supports some output formatting options

  specified by the -f flag or IFCONFIG_FORMAT environment variable, the user
  can request that inet4 subnet masks be printed in CIDR or dotted-quad
  notation, in addition to the traditional hex output.
  inet6 prefixes can be printed in CIDR as well.

  For more documentation see the ifconfig(8) man page.

  PR:		169072
  Requested by:	seanc, marcel, brd, many others
  Reviewed by:	gnn, jhb (earlier version)
  Relnotes:	yes
  Sponsored by:	ScaleEngine Inc.
  Differential Revision:	https://reviews.freebsd.org/D2856

Changes:
  head/sbin/ifconfig/af_inet.c
  head/sbin/ifconfig/af_inet6.c
  head/sbin/ifconfig/af_link.c
  head/sbin/ifconfig/ifconfig.8
  head/sbin/ifconfig/ifconfig.c
Comment 2 Allan Jude freebsd_committer freebsd_triage 2016-05-31 17:35:59 UTC
You can now select between hex, dotted (255.255.255.0), and CIDR (/24) like so:

ifconfig -f inet:dotted

or set IFCONFIG_FORMAT=inet:cidr