Skip to content

Commit

Permalink
wlandebug(8): obtain original interface name via ifconfig_get_orig_na…
Browse files Browse the repository at this point in the history
…me()
  • Loading branch information
Andriy Voskoboinyk authored and Andriy Voskoboinyk committed Oct 16, 2017
1 parent c2803f1 commit 238c9eb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions usr.sbin/wlandebug/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
PROG= wlandebug
MAN= wlandebug.8

LIBADD+= ifconfig

WARNS?= 2

.include <bsd.prog.mk>
21 changes: 18 additions & 3 deletions usr.sbin/wlandebug/wlandebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#include <string.h>
#include <err.h>

#include <libifconfig.h>

#define N(a) (sizeof(a)/sizeof(a[0]))

const char *progname;
Expand Down Expand Up @@ -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[])
{
Expand All @@ -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();
Expand Down

0 comments on commit 238c9eb

Please sign in to comment.