aboutsummaryrefslogtreecommitdiff
path: root/sbin/ifconfig/ifconfig.c
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/ifconfig/ifconfig.c')
-rw-r--r--sbin/ifconfig/ifconfig.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index 2cbe7a881bd0..a8bd5a0c89db 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -313,14 +313,10 @@ cmpifaddrs(struct ifaddrs *a, struct ifaddrs *b, struct ifa_queue *q)
static void freeformat(void)
{
- if (f_inet != NULL)
- free(f_inet);
- if (f_inet6 != NULL)
- free(f_inet6);
- if (f_ether != NULL)
- free(f_ether);
- if (f_addr != NULL)
- free(f_addr);
+ free(f_inet);
+ free(f_inet6);
+ free(f_ether);
+ free(f_addr);
}
static void setformat(char *input)
@@ -330,9 +326,18 @@ static void setformat(char *input)
formatstr = strdup(input);
while ((category = strsep(&formatstr, ",")) != NULL) {
modifier = strchr(category, ':');
- if (modifier == NULL || modifier[1] == '\0') {
- warnx("Skipping invalid format specification: %s\n",
- category);
+ if (modifier == NULL) {
+ if (strcmp(category, "default") == 0) {
+ freeformat();
+ } else if (strcmp(category, "cidr") == 0) {
+ free(f_inet);
+ f_inet = strdup(category);
+ free(f_inet6);
+ f_inet6 = strdup(category);
+ } else {
+ warnx("Skipping invalid format: %s\n",
+ category);
+ }
continue;
}
@@ -340,14 +345,19 @@ static void setformat(char *input)
modifier[0] = '\0';
modifier++;
- if (strcmp(category, "addr") == 0)
+ if (strcmp(category, "addr") == 0) {
+ free(f_addr);
f_addr = strdup(modifier);
- else if (strcmp(category, "ether") == 0)
+ } else if (strcmp(category, "ether") == 0) {
+ free(f_ether);
f_ether = strdup(modifier);
- else if (strcmp(category, "inet") == 0)
+ } else if (strcmp(category, "inet") == 0) {
+ free(f_inet);
f_inet = strdup(modifier);
- else if (strcmp(category, "inet6") == 0)
+ } else if (strcmp(category, "inet6") == 0) {
+ free(f_inet6);
f_inet6 = strdup(modifier);
+ }
}
free(formatstr);
}
@@ -612,8 +622,6 @@ main(int ac, char *av[])
.io_s = -1,
};
- f_inet = f_inet6 = f_ether = f_addr = NULL;
-
lifh = ifconfig_open();
if (lifh == NULL)
err(EXIT_FAILURE, "ifconfig_open");