Skip to content

Commit

Permalink
build: try fix win build
Browse files Browse the repository at this point in the history
  • Loading branch information
ttys3 committed Jan 20, 2023
1 parent 7b601dd commit 479e280
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
fn main() {
#[cfg(target_os = "windows")]
download_winpcap_sdk()
download_winpcap_sdk();

#[cfg(target_os = "windows")]
download_winpcap_dll();
}

#[cfg(target_os = "windows")]
Expand Down Expand Up @@ -51,3 +54,46 @@ fn download_winpcap_sdk() {

println!("cargo:rustc-link-search=native={}/{}", out_dir, lib_dir);
}

#[cfg(target_os = "windows")]
fn download_winpcap_dll() {
use http_req::request;
use std::fs::File;
use std::io::prelude::*;
use std::process::Command;

let mut reader = Vec::new();
let res = request::get(
"https://github.com/ttys3/bandwhich/releases/download/0.20.1/npcap.zip",
&mut reader,
)
.unwrap();

if res.status_code().is_redirect() {
reader = Vec::new();
let url = res.headers().get("Location").unwrap();
let _res = request::get(url, &mut reader).unwrap();
}

let zip_path = format!("{}{}", "c:\\", "npcap.zip");
let mut pcapzip = File::create(&zip_path).unwrap();
pcapzip.write_all(reader.as_slice()).unwrap();
pcapzip.flush().unwrap();

let zip_reader = File::open(&zip_path).unwrap();

let mut archive = zip::ZipArchive::new(zip_reader).unwrap();
archive.extract("c:\\").unwrap();

let output = Command::new("cmd")
.env("NPCAP_DIR", "c:\\npcap")
.current_dir("c:\\npcap")
.arg("/C")
.arg("FixInstall.bat")
.output()
.expect("failed to execute process");

if !output.status.success() {
panic!("CFixInstall.bat failing with error: {:?}", output);
}
}

0 comments on commit 479e280

Please sign in to comment.