Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Npcap thread-safe read; &self for send/recv #26

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rscap/src/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ impl SnifferImpl {
}

#[inline]
pub fn send(&self, packet: &[u8]) -> io::Result<usize> {
self.bpf.send(packet)
pub fn send(&self, buf: &[u8]) -> io::Result<usize> {
self.bpf.send(buf)
}

#[inline]
Expand Down
10 changes: 2 additions & 8 deletions rscap/src/bpf/l2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,14 +522,8 @@ impl Bpf {

/// Send a link-layer packet on the interface bound to the given socket.
#[inline]
pub fn send(&self, packet: &[u8]) -> io::Result<usize> {
let res = unsafe {
libc::write(
self.fd,
packet.as_ptr() as *const libc::c_void,
packet.len(),
)
};
pub fn send(&self, buf: &[u8]) -> io::Result<usize> {
let res = unsafe { libc::write(self.fd, buf.as_ptr() as *const libc::c_void, buf.len()) };
match res {
0.. => Ok(res as usize),
_ => Err(io::Error::last_os_error()),
Expand Down
4 changes: 2 additions & 2 deletions rscap/src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ impl SnifferImpl {
}

#[inline]
pub fn send(&self, packet: &[u8]) -> io::Result<usize> {
self.socket.send(packet)
pub fn send(&self, buf: &[u8]) -> io::Result<usize> {
self.socket.send(buf)
}

#[inline]
Expand Down
10 changes: 5 additions & 5 deletions rscap/src/npcap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub(crate) struct SnifferImpl {
impl SnifferImpl {
#[inline]
pub fn new(iface: Interface) -> io::Result<Self> {
let mut adapter = NpcapAdapter::new(iface)?;
let adapter = NpcapAdapter::new(iface)?;
adapter.set_filter(&mut PacketFilter::reject_all())?;

Ok(Self { adapter })
Expand All @@ -71,7 +71,7 @@ impl SnifferImpl {
}

#[inline]
pub fn set_nonblocking(&mut self, nonblocking: bool) -> io::Result<()> {
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
self.adapter.set_nonblocking(nonblocking);
Ok(())
}
Expand All @@ -82,12 +82,12 @@ impl SnifferImpl {
}

#[inline]
pub fn send(&mut self, packet: &[u8]) -> io::Result<usize> {
self.adapter.send(packet)
pub fn send(&self, buf: &[u8]) -> io::Result<usize> {
self.adapter.send(buf)
}

#[inline]
pub fn recv(&mut self, buf: &mut [u8]) -> io::Result<usize> {
pub fn recv(&self, buf: &mut [u8]) -> io::Result<usize> {
self.adapter.recv(buf)
}
}
Loading