-
Notifications
You must be signed in to change notification settings - Fork 4
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
Ability to set datalink type #24
Comments
Add support for setting and getting linktype. Closes #24
@rossmacarthur Are you able to check the branch in #27 to see if it does what you need? I don't have a great way to test this functionality. |
@dbcfd Thanks! I tested this out and for some reason when I run this it doesn't work. I modified it to set the datalink after opening the capture and that works. diff --git a/src/stream.rs b/src/stream.rs
index 18d7a40..7545333 100644
--- a/src/stream.rs
+++ b/src/stream.rs
@@ -32,10 +32,10 @@ impl PacketStream {
.set_snaplen(config.snaplen())?
.set_promiscuous()?
.set_buffer_size(config.buffer_size())?;
+ handle.activate()?;
if let Some(datalink) = config.datalink() {
handle.set_datalink(*datalink)?;
}
- handle.activate()?;
if !config.blocking() {
handle.set_non_block()?;
} Additionally, I also need to set rfmon to make it work but I think this is macOS specific thing that is required. diff --git a/src/handle.rs b/src/handle.rs
index de45f2f..e426ae6 100644
--- a/src/handle.rs
+++ b/src/handle.rs
@@ -133,6 +133,14 @@ impl Handle {
}
}
+ pub fn set_rfmon(&self) -> Result<&Self, Error> {
+ if 0 != unsafe { pcap_sys::pcap_set_rfmon(self.handle, 1) } {
+ Err(pcap_util::convert_libpcap_error(self.handle))
+ } else {
+ Ok(self)
+ }
+ }
+
pub fn set_snaplen(&self, snaplen: u32) -> Result<&Self, Error> {
if 0 != unsafe { pcap_sys::pcap_set_snaplen(self.handle, snaplen as _) } {
Err(pcap_util::convert_libpcap_error(self.handle))
diff --git a/src/stream.rs b/src/stream.rs
index 18d7a40..df9555c 100644
--- a/src/stream.rs
+++ b/src/stream.rs
@@ -30,6 +30,7 @@ impl PacketStream {
if live_capture {
handle
.set_snaplen(config.snaplen())?
+ .set_rfmon()?
.set_promiscuous()?
.set_buffer_size(config.buffer_size())?;
if let Some(datalink) = config.datalink() { It would be nice if these were more tweakable when creating the packet stream. I am imagining more of an API like the following, and not have the Handle::live_capture("en0")?
.set_rfmon()?
.set_promiscuous()?
.activate()?
.set_data_link(127)?
.into_packet_stream(); // consumes `Handle` and returns a `PacketStream`. |
@rossmacarthur Adjusted the api for creating handles and streams in #28 Still need to add rfmon support, but let me know if that is a little more usable for you. |
No description provided.
The text was updated successfully, but these errors were encountered: