#include <net/if_dl.h>
#include <net/route.h>
#include <netinet/in.h>
+#include <sys/types.h>
+#include <sys/select.h>
+#include <net/if_media.h>
+#include <net80211/ieee80211.h>
+#include <net80211/ieee80211_ioctl.h>
#endif /* __FreeBSD__ || __OpenBSD__ */
#endif /* WITH_NET */
#endif /* __FreeBSD__ */
#if defined(__OpenBSD__)
-#include <sys/types.h>
-#include <sys/select.h>
-#include <net/if_media.h>
-#include <net80211/ieee80211.h>
-#include <net80211/ieee80211_ioctl.h>
#include "include/openbzd.h"
#endif /* __OpenBSD__ */
}
}
#else
-#if defined(__OpenBSD__)
+#if defined(__OpenBSD__) || defined(__FreeBSD__)
} else if (11 == num) { /* wifi name */
get_wifi(str1, str2, (uint8_t)(num - 10));
#endif
#endif /* WITH_NET */
}
#endif /* __OpenBSD__ */
+
+
+/* Based on:
+ https://chromium.googlesource.com/chromiumos/third_party/dhcpcd/+/master/if-bsd.c
+ https://www.freebsd.org/cgi/man.cgi?query=ieee80211&sektion=4&apropos=0&manpath=FreeBSD+5.3-RELEASE+and+Ports
+*/
+#if defined(__FreeBSD__)
+void
+get_wifi(char *str1, char *str2, uint8_t num) {
+#if WITH_NET == 1
+ struct ieee80211req ireq;
+ int fd = 0;
+
+ if (-1 == (fd = socket(AF_INET, SOCK_DGRAM, 0))) {
+ return;
+ }
+
+ memset(&ireq, 0, sizeof(ireq));
+ strlcpy(ireq.i_name, str2, sizeof(ireq.i_name));
+
+ ireq.i_type = IEEE80211_IOC_SSID;
+ ireq.i_val = -1;
+ ireq.i_data = str1;
+
+ (void)ioctl(fd, SIOCG80211, &ireq);
+ CLOSE_FD(fd);
+
+ (void)num;
+#else
+ (void)str1;
+ (void)str2;
+ (void)num;
+ RECOMPILE_WITH("net");
+#endif /* WITH_NET */
+}
+#endif /* __FreeBSD__ */
CPP,
SLANG,
TCL,
- OPENBSDWIFI,
+ WIFINAME,
BULLSHIFT
};
const char *argp_program_version = PACKAGE_STRING;
#if defined(__OpenBSD__)
- { .name = "wifiname", .key = OPENBSDWIFI, .arg = "eth0", .doc = "The name of currently connected wireless/wifi network." },
{ .name = "ramused", .key = 'l', .doc = "The used ram in MB." },
#endif /* __OpenBSD__ */
{ .name = "nicver", .key = 'H', .arg = "eth0", .doc = "The NIC version." },
{ .name = "iplink", .key = 'e', .arg = "eth0", .doc = "The NIC link speed (useful for wireless/wifi)." },
{ .name = "nicinfo", .key = 'G', .arg = "eth0", .doc = "The NIC vendor and model." },
- { .name = "wifiname", .key = 'h', .arg = "eth0", .doc = "The name of currently connected wireless/wifi network." },
+ { .name = "wifiname", .key = 'h', .arg = "wlan0", .doc = "The name of currently connected wireless/wifi network." },
#endif /* __linux__ */
#if defined(__FreeBSD__) || defined(__OpenBSD__)
{ .name = "swaptotal", .key = 'h', .doc = "The total drive swap." },
{ .name = "swapavail", .key = 'H', .doc = "The available drive swap." },
{ .name = "nicgw", .key = 'j', .arg = "re0", .doc = "The NIC gateway address." },
+ { .name = "wifiname", .key = WIFINAME, .arg = "wlan0", .doc = "The name of currently connected wireless/wifi network." },
#endif /* __FreeBSD__ || __OpenBSD__ */
{ .doc = NULL }
NEW_NET_LABEL('j', char nic_info[VLA], nic_info, 7, FMT_KERN);
-#if defined(__OpenBSD__)
- NEW_NET_LABEL(OPENBSDWIFI, char wifiname[VLA], wifiname, 11, FMT_KERN);
-#endif /* __OpenBSD__ */
-
+ NEW_NET_LABEL(WIFINAME, char wifiname[VLA], wifiname, 11, FMT_KERN);
#endif /* __FreeBSD__ || __OpenBSD__ */