summaryrefslogtreecommitdiffstats
path: root/build.rs
diff options
context:
space:
mode:
authorremgodow <remgodow@users.noreply.github.com>2020-09-10 18:52:30 +0200
committerGitHub <noreply@github.com>2020-09-10 18:52:30 +0200
commit075693975376be05d228bc45b321b1f6d08021cd (patch)
tree13a4180f8fc43b690aca4cb038405905761eab81 /build.rs
parent16d9758abfd3a8e48b1666496c9fc4ef2db00c3f (diff)
feat(platform): windows build and run support (#180)
* Remove connections vector from OpenSockets, use common OpenSockets implementation based on sysinfo and netstat2. * Replace termion backend with crossterm, which works on Windows as well. * More fixes for windows build. * Remove tui default-features (termion), update unit tests for crossterm. * Windows compilation fixes. * Remove unused get_open_sockets implementations for linux and mac. Fix formatting. * Add build.rs for windows to download and extract Packet.lib from npcap SDK. * Resolve Cargo.lock after merging main. * fix(tests): adjust snapshots new location of the dns resolution * style(clippy): clippy * style(clippy): remove dead code * style(clippy): use write_all in build.rs * style(clippy): remove unused import added by Intellij * style(review): use String instead of str * fix(build): run build.rs only once * fix(regression): skip iface_is_up() filter only for Windows * fix(review): restore per os implementation of get_open_sockets() * fix(cargo): add missing os specific packages * fix: conditional compilation of windows module * fix: compilation errors * fix: missing Protocol::from_str() implementation * style(clippy): remove unused methods Co-authored-by: Aram Drevekenin <aram@poor.dev>
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/build.rs b/build.rs
new file mode 100644
index 0000000..7f923f9
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,54 @@
+fn main() {
+ #[cfg(target_os = "windows")]
+ download_winpcap_sdk()
+}
+
+#[cfg(target_os = "windows")]
+fn download_winpcap_sdk() {
+ use http_req::request;
+ use std::env;
+ use std::fs::File;
+ use std::io::prelude::*;
+
+ println!("cargo:rerun-if-changed=build.rs");
+
+ let out_dir = env::var("OUT_DIR").unwrap();
+
+ let mut reader = Vec::new();
+ let _res = request::get(
+ "https://nmap.org/npcap/dist/npcap-sdk-1.05.zip",
+ &mut reader,
+ )
+ .unwrap();
+
+ let mut pcapzip = File::create(format!("{}{}", out_dir, "/npcap.zip")).unwrap();
+ pcapzip.write_all(reader.as_slice()).unwrap();
+ pcapzip.flush().unwrap();
+
+ pcapzip = File::open(format!("{}{}", out_dir, "/npcap.zip")).unwrap();
+
+ let lib_name = "Packet.lib";
+ #[cfg(target_arch = "x86_64")]
+ let lib_dir = "Lib/x64";
+ #[cfg(target_arch = "x86")]
+ let lib_dir = "Lib";
+
+ let lib_path = format!("{}/{}", lib_dir, lib_name);
+ let mut zip_archive = zip::ZipArchive::new(pcapzip).unwrap();
+ let mut pcaplib = match zip_archive.by_name(lib_path.as_str()) {
+ Ok(pcaplib) => pcaplib,
+ Err(err) => {
+ panic!(err);
+ }
+ };
+
+ let mut pcaplib_bytes = Vec::new();
+ pcaplib.read_to_end(&mut pcaplib_bytes).unwrap();
+
+ std::fs::create_dir_all(format!("{}/{}", out_dir, lib_dir)).unwrap();
+ let mut pcaplib_file = File::create(format!("{}/{}", out_dir, lib_path)).unwrap();
+ pcaplib_file.write_all(pcaplib_bytes.as_slice()).unwrap();
+ pcaplib_file.flush().unwrap();
+
+ println!("cargo:rustc-link-search=native={}/{}", out_dir, lib_dir);
+}