tcpdump.rs 511 B

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