OSDN Git Service

Bring back FreeBSD wifi support, dunno why it was deleted
authora <a@b.c>
Thu, 22 Mar 2018 12:57:03 +0000 (13:57 +0100)
committera <a@b.c>
Thu, 22 Mar 2018 12:57:03 +0000 (13:57 +0100)
src/net.c
src/options.c
src/pinky.rs [new file with mode: 0644]
src/prototypes/net.h

index de922d2..1f4cf6b 100644 (file)
--- a/src/net.c
+++ b/src/net.c
 #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__ */
 
@@ -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__ */
index dcb0bc0..2b5f8bb 100644 (file)
@@ -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 (file)
index 0000000..7923b29
--- /dev/null
@@ -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)
+  };
+}
index 74d63db..2932d3c 100644 (file)
@@ -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_ */