tcpdump.rs 634 B

1234567891011121314151617181920
  1. extern crate smoltcp;
  2. use std::env;
  3. use std::os::unix::io::AsRawFd;
  4. use smoltcp::phy::wait as phy_wait;
  5. use smoltcp::phy::{Device, RxToken, RawSocket};
  6. use smoltcp::wire::{PrettyPrinter, EthernetFrame};
  7. fn main() {
  8. let ifname = env::args().nth(1).unwrap();
  9. let mut socket = RawSocket::new(ifname.as_ref()).unwrap();
  10. loop {
  11. phy_wait(socket.as_raw_fd(), None).unwrap();
  12. let (rx_token, _) = socket.receive().unwrap();
  13. rx_token.consume(/*timestamp = */ 0, |buffer| {
  14. println!("{}", PrettyPrinter::<EthernetFrame<&[u8]>>::new("", &buffer));
  15. Ok(())
  16. }).unwrap();
  17. }
  18. }