Page MenuHomeFreeBSD

D2856.id8320.diff
No OneTemporary

D2856.id8320.diff

Index: sbin/ifconfig/af_inet.c
===================================================================
--- sbin/ifconfig/af_inet.c
+++ sbin/ifconfig/af_inet.c
@@ -54,6 +54,8 @@
static struct in_aliasreq in_addreq;
static struct ifreq in_ridreq;
+static int in_cidr;
+static int in_dotquad;
static void
in_status(int s __unused, const struct ifaddrs *ifa)
@@ -66,19 +68,34 @@
if (sin == NULL)
return;
- printf("\tinet %s ", inet_ntoa(sin->sin_addr));
+ printf("\tinet %s", inet_ntoa(sin->sin_addr));
if (ifa->ifa_flags & IFF_POINTOPOINT) {
sin = (struct sockaddr_in *)ifa->ifa_dstaddr;
if (sin == NULL)
sin = &null_sin;
- printf("--> %s ", inet_ntoa(sin->sin_addr));
+ printf(" --> %s ", inet_ntoa(sin->sin_addr));
}
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 (in_cidr) {
+ int cidr = 32;
+ unsigned long smask;
+
+ smask = ntohl(sin->sin_addr.s_addr);
+ while ((smask & 1) == 0) {
+ smask = smask >> 1;
+ cidr--;
+ if (cidr == 0)
+ break;
+ }
+ printf("/%d ", cidr);
+ } else if (in_dotquad)
+ 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;
@@ -197,6 +214,28 @@
.af_addreq = &in_addreq,
};
+static void
+in_copt_cb(const char *optarg __unused)
+{
+ in_cidr++; /* print IPv4 subnet mask in CIDR notation */
+}
+static struct option in_copt = {
+ .opt = "c",
+ .opt_usage = "[-c]",
+ .cb = in_copt_cb
+};
+
+static void
+in_sopt_cb(const char *optarg __unused)
+{
+ in_dotquad++; /* print IPv4 subnet mask in dotted quad notation */
+}
+static struct option in_sopt = {
+ .opt = "s",
+ .opt_usage = "[-s]",
+ .cb = in_sopt_cb
+};
+
static __constructor void
inet_ctor(void)
{
@@ -206,4 +245,6 @@
return;
#endif
af_register(&af_inet);
+ opt_register(&in_copt);
+ opt_register(&in_sopt);
}
Index: sbin/ifconfig/ifconfig.8
===================================================================
--- sbin/ifconfig/ifconfig.8
+++ sbin/ifconfig/ifconfig.8
@@ -28,7 +28,7 @@
.\" From: @(#)ifconfig.8 8.3 (Berkeley) 1/5/94
.\" $FreeBSD$
.\"
-.Dd Aug 12, 2015
+.Dd August 29, 2015
.Dt IFCONFIG 8
.Os
.Sh NAME
@@ -36,6 +36,8 @@
.Nd configure network interface parameters
.Sh SYNOPSIS
.Nm
+.Op Fl c
+.Op Fl s
.Op Fl L
.Op Fl k
.Op Fl m
@@ -194,6 +196,17 @@
List the interfaces in the given group.
.El
.Pp
+The following flags can be used to modify the output format of
+.Nm :
+.Bl -tag -width indent
+.It Fl c
+Display subnet masks in CIDR notation.
+For example 10.0.0.0/8 or 203.0.113.224/29
+.It Fl s
+Display subnet masks in dotted quad notation.
+For example 255.255.0.0 or 255.255.255.192
+.El
+.Pp
The following parameters may be set with
.Nm :
.Bl -tag -width indent

File Metadata

Mime Type
text/plain
Expires
Thu, Feb 26, 11:35 AM (6 m, 22 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29004081
Default Alt Text
D2856.id8320.diff (2 KB)

Event Timeline