feat: fixed pcap linking and added nix packages

This commit is contained in:
Andrew Rioux
2025-01-20 20:39:26 -05:00
parent ad8cad56e7
commit af2e832762
23 changed files with 1220 additions and 81 deletions

View File

@@ -17,15 +17,18 @@
name = "pcap-sys"
version = "0.1.0"
edition = "2021"
license = "AGPL-3.0-only"
publish = false
[dependencies]
errno = "0.3.10"
futures = "0.3.25"
libc = "0.2.169"
tokio = { version = "1.21.2", features = ["net", "rt", "macros", "rt-multi-thread" ] }
tokio = { version = "1.21.2", features = [
"net",
"rt",
"macros",
"rt-multi-thread",
] }
tokio-stream = "0.1.14"
packets = { path = "../packets" }
[build-dependencies]
cmake = "0.1"
fs_extra = "1.3.0"

View File

@@ -13,10 +13,8 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
use fs_extra::dir::{copy, CopyOptions};
fn main() {
include!("../build_freebsd.rs");
include!("../build_common.rs");
if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" {
let libdir = std::env::var("SPARSE_BUILD_WINPCAP_LIBS").unwrap();
@@ -27,8 +25,12 @@ fn main() {
let libdir = std::env::var("SPARSE_BUILD_LIBPCAP_FREEBSD").unwrap();
println!("cargo:rustc-link-search=native={libdir}/lib");
println!("cargo:rustc-link-lib=static=pcap");
} else {
let libdir = std::env::var("SPARSE_BUILD_LIBPCAP_LINUX").unwrap();
} else if std::env::var("CARGO_CFG_TARGET_ENV").unwrap() == "musl" {
let libdir = std::env::var("SPARSE_BUILD_LIBPCAP_LINUX_MUSL").unwrap();
println!("cargo:rustc-link-search=native={libdir}/lib");
println!("cargo:rustc-link-lib=static=pcap");
} else if std::env::var("CARGO_CFG_TARGET_ENV").unwrap() == "gnu" {
let libdir = std::env::var("SPARSE_BUILD_LIBPCAP_LINUX_GNU").unwrap();
println!("cargo:rustc-link-search=native={libdir}/lib");
println!("cargo:rustc-link-lib=static=pcap");
}

View File

@@ -15,7 +15,7 @@
use std::{
ffi::{CStr, CString},
ptr, slice
ptr, slice,
};
pub mod error;
@@ -410,7 +410,9 @@ impl<T: NotListening> Interface<T> {
Ok(stream::InterfaceStream {
inner: tokio::io::unix::AsyncFd::with_interest(
stream::InternalInterfaceStream::<DevActivated>::new(unsafe { std::mem::transmute(self) })?,
stream::InternalInterfaceStream::<DevActivated>::new(unsafe {
std::mem::transmute(self)
})?,
tokio::io::Interest::READABLE,
)?,
})

View File

@@ -24,7 +24,10 @@ use futures::{ready, StreamExt};
use tokio::io::unix::AsyncFd;
use tokio_stream::StreamMap;
use super::{error, ffi, packets, Activated, NotListening, Disabled, State, Interface, DevActivated, DevDisabled, PcapDevIterator};
use super::{
error, ffi, packets, Activated, DevActivated, DevDisabled, Disabled, Interface, NotListening,
PcapDevIterator, State,
};
pub(crate) struct InternalInterfaceStream<T: Activated> {
interface: Interface<T>,