Index: usr.sbin/wlandebug/Makefile =================================================================== --- usr.sbin/wlandebug/Makefile +++ usr.sbin/wlandebug/Makefile @@ -3,6 +3,8 @@ PROG= wlandebug MAN= wlandebug.8 +LIBADD+= 80211 + WARNS?= 2 .include Index: usr.sbin/wlandebug/wlandebug.c =================================================================== --- usr.sbin/wlandebug/wlandebug.c +++ usr.sbin/wlandebug/wlandebug.c @@ -34,15 +34,23 @@ * (default interface is wlan.0). */ #include +#include #include +#include + +#include + #include #include #include #include #include #include +#include +#include + #define N(a) (sizeof(a)/sizeof(a[0])) const char *progname; @@ -147,7 +155,7 @@ snprintf(oid, oidlen, "net.%s.debug", wlan); #elif __FreeBSD__ if (wlan) - snprintf(oid, oidlen, "net.wlan.%s.debug", wlan+4); + snprintf(oid, oidlen, "net.wlan.%s.debug", wlan); else snprintf(oid, oidlen, "net.wlan.debug"); #elif __NetBSD__ @@ -160,6 +168,26 @@ #endif } +static void +change_iface_unit(char *oid, size_t oid_size, char *name) +{ + int s, val; + char *unit_str; + + if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0 || + lib80211_get80211val(s, name, IEEE80211_IOC_UNIT, &val) || + asprintf(&unit_str, "%d", val) < 0) { + /* fall back to the old method */ + if (strncmp(name, "wlan", 4) != 0) + errx(1, "expecting a wlan interface name"); + setoid(oid, oid_size, &name[4]); + } else { + setoid(oid, oid_size, unit_str); + free(unit_str); + } + close(s); +} + int main(int argc, char *argv[]) { @@ -171,7 +199,7 @@ char oid[256]; progname = argv[0]; - setoid(oid, sizeof(oid), "wlan0"); + setoid(oid, sizeof(oid), "0"); if (argc > 1) { if (strcmp(argv[1], "-d") == 0) { setoid(oid, sizeof(oid), NULL); @@ -179,9 +207,7 @@ } 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]); + change_iface_unit(oid, sizeof(oid), argv[2]); argc -= 2, argv += 2; } else if (strcmp(argv[1], "-?") == 0) usage();