forked from smoltcp-rs/smoltcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtcpdump.rs
More file actions
21 lines (20 loc) · 682 Bytes
/
Copy pathtcpdump.rs
File metadata and controls
21 lines (20 loc) · 682 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use smoltcp::phy::wait as phy_wait;
use smoltcp::phy::{Device, RawSocket, RxToken};
use smoltcp::time::Instant;
use smoltcp::wire::{EthernetFrame, PrettyPrinter};
use std::env;
use std::os::unix::io::AsRawFd;
fn main() {
let ifname = env::args().nth(1).unwrap();
let mut socket = RawSocket::new(ifname.as_ref(), smoltcp::phy::Medium::Ethernet).unwrap();
loop {
phy_wait(socket.as_raw_fd(), None).unwrap();
let (rx_token, _) = socket.receive(Instant::now()).unwrap();
rx_token.consume(|buffer| {
println!(
"{}",
PrettyPrinter::<EthernetFrame<&[u8]>>::new("", &buffer)
);
})
}
}