Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F150989126
D2856.id8343.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D2856.id8343.diff
View Options
Index: sbin/ifconfig/af_inet.c
===================================================================
--- sbin/ifconfig/af_inet.c
+++ sbin/ifconfig/af_inet.c
@@ -54,6 +54,7 @@
static struct in_aliasreq in_addreq;
static struct ifreq in_ridreq;
+extern char *f_subnet;
static void
in_status(int s __unused, const struct ifaddrs *ifa)
@@ -66,19 +67,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 (f_subnet != NULL && strcmp(f_subnet, "cidr") == 0) {
+ 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 (f_subnet != NULL && strcmp(f_subnet, "dotted") == 0)
+ 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/af_link.c
===================================================================
--- sbin/ifconfig/af_link.c
+++ sbin/ifconfig/af_link.c
@@ -51,19 +51,31 @@
static struct ifreq link_ridreq;
+extern char *f_ether;
+
static void
link_status(int s __unused, const struct ifaddrs *ifa)
{
/* XXX no const 'cuz LLADDR is defined wrong */
struct sockaddr_dl *sdl = (struct sockaddr_dl *) ifa->ifa_addr;
+ char *ether_format;
+ int i;
if (sdl != NULL && sdl->sdl_alen > 0) {
if ((sdl->sdl_type == IFT_ETHER ||
sdl->sdl_type == IFT_L2VLAN ||
sdl->sdl_type == IFT_BRIDGE) &&
sdl->sdl_alen == ETHER_ADDR_LEN)
- printf("\tether %s\n",
- ether_ntoa((struct ether_addr *)LLADDR(sdl)));
+ if (f_ether != NULL && strcmp(f_ether, "dash") == 0) {
+ ether_format = ether_ntoa((struct ether_addr *)LLADDR(sdl));
+ for (i = 0; i < strlen(ether_format); i++) {
+ if (ether_format[i] == ':')
+ ether_format[i] = '-';
+ }
+ printf("\tether %s\n", ether_format);
+ } else
+ printf("\tether %s\n",
+ ether_ntoa((struct ether_addr *)LLADDR(sdl)));
else {
int n = sdl->sdl_nlen > 0 ? sdl->sdl_nlen + 1 : 0;
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
Index: sbin/ifconfig/ifconfig.c
===================================================================
--- sbin/ifconfig/ifconfig.c
+++ sbin/ifconfig/ifconfig.c
@@ -97,6 +97,10 @@
int supmedia = 0;
int printkeys = 0; /* Print keying material for interfaces. */
+/* Formatter Strings */
+char *f_subnet, *f_ether;
+char *f_input, *f_format, *f_class, *f_modifier;
+
static int ifconfig(int argc, char *const *argv, int iscreate,
const struct afswtch *afp);
static void status(const struct afswtch *afp, const struct sockaddr_dl *sdl,
@@ -140,8 +144,8 @@
}
fprintf(stderr,
- "usage: ifconfig %sinterface address_family [address [dest_address]]\n"
- " [parameters]\n"
+ "usage: ifconfig [-f type:format] %sinterface address_family\n"
+ " [address [dest_address]] [parameters]\n"
" ifconfig interface create\n"
" ifconfig -a %s[-d] [-m] [-u] [-v] [address_family]\n"
" ifconfig -l [-d] [-u] [address_family]\n"
@@ -316,7 +320,7 @@
all = downonly = uponly = namesonly = noload = verbose = 0;
/* Parse leading line options */
- strlcpy(options, "adklmnuv", sizeof(options));
+ strlcpy(options, "f:adklmnuv", sizeof(options));
for (p = opts; p != NULL; p = p->next)
strlcat(options, p->opt, sizeof(options));
while ((c = getopt(argc, argv, options)) != -1) {
@@ -327,6 +331,34 @@
case 'd': /* restrict scan to "down" interfaces */
downonly++;
break;
+ case 'f':
+ if (optarg == NULL)
+ usage();
+ f_input = strdup(optarg);
+ if (f_input == NULL)
+ errx(1, "Failed to allocate memory");
+
+ while ((f_format = strsep(&f_input, ",")) != NULL) {
+printf("Format: %s\n", f_format);
+ f_class = f_format;
+ f_modifier = strchr(f_format, ':');
+ if (f_modifier[0] == '\0') {
+ printf("Skipping %s\n", f_class);
+ continue;
+ }
+ f_modifier[0] = '\0';
+ f_modifier++;
+printf("Class: %s, modifier: %s\n", f_class, f_modifier);
+ if (strcmp(f_class, "subnet") == 0) {
+printf("setting subnet to %s\n", f_modifier);
+ f_subnet = f_modifier;
+ }
+ else if (strcmp(f_class, "ether") == 0) {
+printf("setting ether to %s\n", f_modifier);
+ f_ether = f_modifier;
+ }
+ }
+ break;
case 'k':
printkeys++;
break;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Apr 6, 8:14 AM (6 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
30950496
Default Alt Text
D2856.id8343.diff (5 KB)
Attached To
Mode
D2856: make ifconfig print ipv4 netmasks in dotted-quad notation, rather than hex
Attached
Detach File
Event Timeline
Log In to Comment