pub struct Device {
pub name: String,
pub desc: Option<String>,
}Expand description
A network device name and (potentially) pcap’s description of it.
Fields§
§name: String§desc: Option<String>Implementations§
Source§impl Device
impl Device
Sourcepub fn open(self) -> Result<Capture<Active>, Error>
pub fn open(self) -> Result<Capture<Active>, Error>
Opens a Capture<Active> on this device.
Examples found in repository?
More examples
examples/getdevices.rs (line 9)
3fn main() {
4 // list all of the devices pcap tells us are available
5 for device in pcap::Device::list().unwrap() {
6 println!("Found device! {:?}", device);
7
8 // now you can create a Capture with this Device if you want.
9 let mut cap = device.open().unwrap();
10
11 // get a packet from this capture
12 let packet = cap.next();
13
14 println!("got a packet! {:?}", packet);
15 }
16}Sourcepub fn lookup() -> Result<Device, Error>
pub fn lookup() -> Result<Device, Error>
Returns the default Device suitable for captures according to pcap_lookupdev, or an error from pcap.
Examples found in repository?
More examples
examples/savefile.rs (line 8)
5fn main() {
6 {
7 // open capture from default device
8 let mut cap = Capture::from_device(Device::lookup().unwrap()).unwrap().open().unwrap();
9
10 // open savefile using the capture
11 let mut savefile = cap.savefile("test.pcap").unwrap();
12
13 // get a packet from the interface
14 let p = cap.next().unwrap();
15
16 // print the packet out
17 println!("packet received on network: {:?}", p);
18
19 // write the packet to the savefile
20 savefile.write(&p);
21 }
22
23 // open a new capture from the test.pcap file we wrote to above
24 let mut cap = Capture::from_file("test.pcap").unwrap();
25
26 // get a packet
27 let p = cap.next().unwrap();
28
29 // print that packet out -- it should be the same as the one we printed above
30 println!("packet obtained from file: {:?}", p);
31}Sourcepub fn list() -> Result<Vec<Device>, Error>
pub fn list() -> Result<Vec<Device>, Error>
Returns a vector of Devices known by pcap via pcap_findalldevs.
Examples found in repository?
examples/getdevices.rs (line 5)
3fn main() {
4 // list all of the devices pcap tells us are available
5 for device in pcap::Device::list().unwrap() {
6 println!("Found device! {:?}", device);
7
8 // now you can create a Capture with this Device if you want.
9 let mut cap = device.open().unwrap();
10
11 // get a packet from this capture
12 let packet = cap.next();
13
14 println!("got a packet! {:?}", packet);
15 }
16}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Device
impl RefUnwindSafe for Device
impl Send for Device
impl Sync for Device
impl Unpin for Device
impl UnwindSafe for Device
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more