From fa0e7afcae8045c08543f8f85adda9623c1cff25 Mon Sep 17 00:00:00 2001 From: a Date: Thu, 22 Mar 2018 13:57:03 +0100 Subject: [PATCH] Bring back FreeBSD wifi support, dunno why it was deleted --- src/net.c | 48 ++++++++++++++++++++++++++++++++++++++++++------ src/options.c | 11 ++++------- src/pinky.rs | 20 ++++++++++++++++++++ src/prototypes/net.h | 4 ++-- 4 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 src/pinky.rs diff --git a/src/net.c b/src/net.c index de922d2..1f4cf6b 100644 --- a/src/net.c +++ b/src/net.c @@ -65,6 +65,11 @@ #include #include #include +#include +#include +#include +#include +#include #endif /* __FreeBSD__ || __OpenBSD__ */ #endif /* WITH_NET */ @@ -77,11 +82,6 @@ #endif /* __FreeBSD__ */ #if defined(__OpenBSD__) -#include -#include -#include -#include -#include #include "include/openbzd.h" #endif /* __OpenBSD__ */ @@ -208,7 +208,7 @@ get_net(char *str1, char *str2, uint8_t num) { } } #else -#if defined(__OpenBSD__) +#if defined(__OpenBSD__) || defined(__FreeBSD__) } else if (11 == num) { /* wifi name */ get_wifi(str1, str2, (uint8_t)(num - 10)); #endif @@ -780,3 +780,39 @@ get_wifi(char *str1, char *str2, uint8_t num) { #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__ */ diff --git a/src/options.c b/src/options.c index dcb0bc0..2b5f8bb 100644 --- a/src/options.c +++ b/src/options.c @@ -52,7 +52,7 @@ enum { CPP, SLANG, TCL, - OPENBSDWIFI, + WIFINAME, BULLSHIFT }; const char *argp_program_version = PACKAGE_STRING; @@ -175,7 +175,6 @@ static const struct argp_option options[] = { #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__ */ @@ -186,7 +185,7 @@ static const struct argp_option options[] = { { .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__) @@ -195,6 +194,7 @@ static const struct argp_option options[] = { { .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 } @@ -391,10 +391,7 @@ parse_opt(int key, char *arg, struct argp_state *state) { 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__ */ diff --git a/src/pinky.rs b/src/pinky.rs new file mode 100644 index 0000000..7923b29 --- /dev/null +++ b/src/pinky.rs @@ -0,0 +1,20 @@ +#![crate_type = "staticlib"] + +use std::os::raw::c_char; +use std::ffi::CString; + +#[no_mangle] +pub extern fn uzer_func2() -> *mut c_char { + let mut str = String::from("Hello World"); + + let c_str = CString::new(str).unwrap(); + c_str.into_raw() +} + +#[no_mangle] +pub extern fn Rfree(s: *mut c_char) { + unsafe { + if s.is_null() { return } + CString::from_raw(s) + }; +} diff --git a/src/prototypes/net.h b/src/prototypes/net.h index 74d63db..2932d3c 100644 --- a/src/prototypes/net.h +++ b/src/prototypes/net.h @@ -36,8 +36,8 @@ void get_nic_info2(char *, char *, uint8_t num); void get_ip_lookup(char *, char *); void get_nic_info(char *, char *); -#if defined(__linux__) || defined(__OpenBSD__) +#if defined(__linux__) || defined(__OpenBSD__) || defined(__FreeBSD__) void get_wifi(char *, char *, uint8_t num); -#endif /* __linux__ */ +#endif /* __linux__ || __OpenBSD__ || __FreeBSD__ */ #endif /* NET_H_ */ -- 2.11.0