-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a binding for pcap_loop * Add a test that covers panic in pcap_loop * Change to mock tests and add a count argument * Check return code from pcap_loop
- Loading branch information
Showing
3 changed files
with
239 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
fn main() { | ||
// get the default Device | ||
let device = pcap::Device::lookup() | ||
.expect("device lookup failed") | ||
.expect("no device available"); | ||
println!("Using device {}", device.name); | ||
|
||
// Setup Capture | ||
let mut cap = pcap::Capture::from_device(device) | ||
.unwrap() | ||
.immediate_mode(true) | ||
.open() | ||
.unwrap(); | ||
|
||
let mut count = 0; | ||
cap.for_each(None, |packet| { | ||
println!("Got {:?}", packet.header); | ||
count += 1; | ||
if count > 100 { | ||
panic!("ow"); | ||
} | ||
}) | ||
.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters