From 238c9eb65af22393584c3569f654015d31f4b9cf Mon Sep 17 00:00:00 2001 From: Andriy Voskoboinyk Date: Mon, 16 Oct 2017 07:01:27 +0000 Subject: [PATCH] wlandebug(8): obtain original interface name via ifconfig_get_orig_name() --- usr.sbin/wlandebug/Makefile | 2 ++ usr.sbin/wlandebug/wlandebug.c | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/usr.sbin/wlandebug/Makefile b/usr.sbin/wlandebug/Makefile index e916c23e7512..7ac993319947 100644 --- a/usr.sbin/wlandebug/Makefile +++ b/usr.sbin/wlandebug/Makefile @@ -3,6 +3,8 @@ PROG= wlandebug MAN= wlandebug.8 +LIBADD+= ifconfig + WARNS?= 2 .include diff --git a/usr.sbin/wlandebug/wlandebug.c b/usr.sbin/wlandebug/wlandebug.c index 9bec123b5f63..f7227eb8be96 100644 --- a/usr.sbin/wlandebug/wlandebug.c +++ b/usr.sbin/wlandebug/wlandebug.c @@ -43,6 +43,8 @@ #include #include +#include + #define N(a) (sizeof(a)/sizeof(a[0])) const char *progname; @@ -160,6 +162,21 @@ setoid(char oid[], size_t oidlen, const char *wlan) #endif } +static void +get_orig_iface_name(char *oid, size_t oid_size, char *name) +{ + struct ifconfig_handle *h; + char *orig_name; + + h = ifconfig_open(); + if (ifconfig_get_orig_name(h, name, &orig_name) < 0) + errc(1, ifconfig_err_errno(h), "cannot get interface name"); + + ifconfig_close(h); + setoid(oid, oid_size, orig_name); + free(orig_name); +} + int main(int argc, char *argv[]) { @@ -179,9 +196,7 @@ main(int argc, char *argv[]) } else if (strcmp(argv[1], "-i") == 0) { if (argc <= 2) errx(1, "missing interface name for -i option"); - if (strncmp(argv[2], "wlan", 4) != 0) - errx(1, "expecting a wlan interface name"); - setoid(oid, sizeof(oid), argv[2]); + get_orig_iface_name(oid, sizeof(oid), argv[2]); argc -= 2, argv += 2; } else if (strcmp(argv[1], "-?") == 0) usage();