feat: finished adding pcap-sys
This commit is contained in:
parent
c2b5ea37d0
commit
ad8cad56e7
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -305,7 +305,7 @@ dependencies = [
|
|||||||
name = "sparse-beacon"
|
name = "sparse-beacon"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"nl-sys",
|
"pcap-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
6
build_freebsd.rs
Normal file
6
build_freebsd.rs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "freebsd" {
|
||||||
|
let freebsd_libs = std::env::var("FREEBSD_LIBS").unwrap();
|
||||||
|
println!("cargo:rustc-link-arg=--sysroot={freebsd_libs}");
|
||||||
|
println!("cargo:rustc-link-arg=-L{freebsd_libs}/lib");
|
||||||
|
println!("cargo:rustc-link-arg=-L{freebsd_libs}/usr/lib");
|
||||||
|
}
|
||||||
@ -16,63 +16,20 @@
|
|||||||
use fs_extra::dir::{copy, CopyOptions};
|
use fs_extra::dir::{copy, CopyOptions};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
include!("../build_freebsd.rs");
|
||||||
|
|
||||||
if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" {
|
if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" {
|
||||||
println!("cargo:rustc-link-search=native={}", std::env::var("SPARSE_BUILD_WINPCAP").unwrap());
|
let libdir = std::env::var("SPARSE_BUILD_WINPCAP_LIBS").unwrap();
|
||||||
println!("cargo:rustc-link-search=native={}/x64", std::env::var("SPARSE_BUILD_WINPCAP").unwrap());
|
println!("cargo:rustc-link-search=native={libdir}");
|
||||||
|
println!("cargo:rustc-link-search=native={libdir}/x64");
|
||||||
println!("cargo:rustc-link-lib=wpcap");
|
println!("cargo:rustc-link-lib=wpcap");
|
||||||
} else if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "freebsd" {
|
} else if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "freebsd" {
|
||||||
let libpcap_src = format!("{}/pcap_src", std::env::var("OUT_DIR").unwrap());
|
let libdir = std::env::var("SPARSE_BUILD_LIBPCAP_FREEBSD").unwrap();
|
||||||
|
println!("cargo:rustc-link-search=native={libdir}/lib");
|
||||||
let mut options = CopyOptions::new();
|
|
||||||
options.copy_inside = true;
|
|
||||||
options.skip_exist = true;
|
|
||||||
copy(std::env::var("SPARSE_BUILD_LIBPCAP").unwrap(), &libpcap_src, &options).expect("could not copy libpcap source code to build");
|
|
||||||
|
|
||||||
let dst = cmake::Config::new(&libpcap_src)
|
|
||||||
.profile("MinSizeRel")
|
|
||||||
.define("BUILD_SHARED_LIBS", "OFF")
|
|
||||||
.define("DISABLE_BLUETOOTH", "ON")
|
|
||||||
.define("DISABLE_DAG", "ON")
|
|
||||||
.define("DISABLE_DBUS", "ON")
|
|
||||||
.define("DISABLE_DPDK", "ON")
|
|
||||||
.define("DISABLE_NETMAP", "ON")
|
|
||||||
.define("DISABLE_RDMA", "ON")
|
|
||||||
.define("DISABLE_SEPTEL", "ON")
|
|
||||||
.define("DISABLE_SNF", "ON")
|
|
||||||
.define("DISABLE_TC", "ON")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
println!("cargo:rustc-link-search=native={}/lib", dst.display());
|
|
||||||
println!("cargo:rustc-link-search=native={}/lib64", dst.display());
|
|
||||||
println!("cargo:rustc-link-lib=static=pcap");
|
println!("cargo:rustc-link-lib=static=pcap");
|
||||||
} else {
|
} else {
|
||||||
let libpcap_src = format!("{}/pcap_src", std::env::var("OUT_DIR").unwrap());
|
let libdir = std::env::var("SPARSE_BUILD_LIBPCAP_LINUX").unwrap();
|
||||||
|
println!("cargo:rustc-link-search=native={libdir}/lib");
|
||||||
let mut options = CopyOptions::new();
|
|
||||||
options.copy_inside = true;
|
|
||||||
options.skip_exist = true;
|
|
||||||
copy(std::env::var("SPARSE_BUILD_LIBPCAP").unwrap(), &libpcap_src, &options).expect("could not copy libpcap source code to build");
|
|
||||||
|
|
||||||
let dst = cmake::Config::new(&libpcap_src)
|
|
||||||
.profile("MinSizeRel")
|
|
||||||
.define("BUILD_SHARED_LIBS", "OFF")
|
|
||||||
.define("BUILD_WITH_LIBNL", "OFF")
|
|
||||||
.define("DISABLE_BLUETOOTH", "ON")
|
|
||||||
.define("DISABLE_DAG", "ON")
|
|
||||||
.define("DISABLE_DBUS", "ON")
|
|
||||||
.define("DISABLE_DPDK", "ON")
|
|
||||||
.define("DISABLE_LINUX_USBMON", "ON")
|
|
||||||
.define("DISABLE_NETMAP", "ON")
|
|
||||||
.define("DISABLE_RDMA", "ON")
|
|
||||||
.define("DISABLE_SEPTEL", "ON")
|
|
||||||
.define("DISABLE_SNF", "ON")
|
|
||||||
.define("DISABLE_TC", "ON")
|
|
||||||
.define("PCAP_TYPE", "linux")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
// panic!("hahahahah test {}", dst.display());
|
|
||||||
println!("cargo:rustc-link-search=native={}/lib", dst.display());
|
|
||||||
println!("cargo:rustc-link-search=native={}/lib64", dst.display());
|
|
||||||
println!("cargo:rustc-link-lib=static=pcap");
|
println!("cargo:rustc-link-lib=static=pcap");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,4 +4,4 @@ version = "0.7.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
nl-sys = { path = "../nl-sys" }
|
pcap-sys = { path = "../pcap-sys" }
|
||||||
|
|||||||
@ -1,8 +1,3 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "freebsd" {
|
include!("../build_freebsd.rs");
|
||||||
let freebsd_libs = std::env::var("FREEBSD_LIBS").unwrap();
|
|
||||||
println!("cargo:rustc-link-arg=--sysroot={freebsd_libs}");
|
|
||||||
println!("cargo:rustc-link-arg=-L{freebsd_libs}/lib");
|
|
||||||
println!("cargo:rustc-link-arg=-L{freebsd_libs}/usr/lib");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,6 @@
|
|||||||
use nl_sys::{netlink, route};
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let ip = std::net::Ipv4Addr::new(192, 168, 3, 10);
|
let interfaces = pcap_sys::PcapDevIterator::new().unwrap();
|
||||||
|
for interface in interfaces {
|
||||||
let (ifname, _, srcip, src_mac, dst_mac, _) = {
|
println!("Found interface: {interface}");
|
||||||
let socket = netlink::Socket::new().unwrap();
|
}
|
||||||
|
|
||||||
let routes = socket.get_routes().unwrap();
|
|
||||||
let neighs = socket.get_neigh().unwrap();
|
|
||||||
let links = socket.get_links().unwrap();
|
|
||||||
let addrs = socket.get_addrs().unwrap();
|
|
||||||
|
|
||||||
route::get_macs_and_src_for_ip(&addrs, &routes, &neighs, &links, ip).unwrap()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user