listenlocalhost/listenlocalhost.rs
1extern crate pcap;
2
3fn main() {
4 // listen on the device named "any", which is only available on Linux. This is only for
5 // demonstration purposes.
6 let mut cap = pcap::Capture::from_device("any").unwrap().open().unwrap();
7
8 // filter out all packets that don't have 127.0.0.1 as a source or destination.
9 cap.filter("host 127.0.0.1").unwrap();
10
11 while let Ok(packet) = cap.next() {
12 println!("got packet! {:?}", packet);
13 }
14}