smoltcp-rs / smoltcp

a smol tcp/ip stack
BSD Zero Clause License
3.64k stars 404 forks source link

panic running tcpdump example: thread 'main' panicked at 'Invalid argument (os error 22)', src/phy/raw_socket.rs:85:25 #794

Open jeremyandrews opened 1 year ago

jeremyandrews commented 1 year ago

When trying to run the tcpdump example on an Apple M2 MacBook running macOS 13.4 I get the following error:

% cargo run --release --example tcpdump en0         
    Finished release [optimized + debuginfo] target(s) in 0.03s
     Running `target/release/examples/tcpdump en0`
thread 'main' panicked at 'Invalid argument (os error 22)', src/phy/raw_socket.rs:85:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

(The same thing happens on lo0 if I generate traffic on the loopback.) I also tried running with sudo but that doesn't change anything.

% sudo ./target/release/examples/tcpdump en0
Password:
thread 'main' panicked at 'Invalid argument (os error 22)', src/phy/raw_socket.rs:85:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Here's a full backtrace if it's useful:

% RUST_BACKTRACE=full cargo run --release --example tcpdump en0
    Finished release [optimized + debuginfo] target(s) in 0.03s
     Running `target/release/examples/tcpdump en0`
thread 'main' panicked at 'Invalid argument (os error 22)', src/phy/raw_socket.rs:85:25
stack backtrace:
   0:        0x100581054 - std::backtrace_rs::backtrace::libunwind::trace::h0a647ce7e8dc2fab
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:        0x100581054 - std::backtrace_rs::backtrace::trace_unsynchronized::hea920694a2a8ac80
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:        0x100581054 - std::sys_common::backtrace::_print_fmt::h7b4e20c1da2ebb61
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:65:5
   3:        0x100581054 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h819e9cbdf1a9e730
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:44:22
   4:        0x100592e78 - core::fmt::write::ha5e9bf3131ecb7c0
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/fmt/mod.rs:1254:17
   5:        0x10057ee34 - std::io::Write::write_fmt::h414ce9994bf17404
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/io/mod.rs:1698:15
   6:        0x100580e68 - std::sys_common::backtrace::_print::h28d98f2094da6d1d
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:47:5
   7:        0x100580e68 - std::sys_common::backtrace::print::h8072db0bbd5bcc3d
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:34:9
   8:        0x100582388 - std::panicking::default_hook::{{closure}}::h2c85c5b0c2ede151
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:269:22
   9:        0x100582148 - std::panicking::default_hook::hcf2f70992d02f6fe
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:288:9
  10:        0x100582860 - std::panicking::rust_panic_with_hook::h023af7f90b47eb8b
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:691:13
  11:        0x100582794 - std::panicking::begin_panic_handler::{{closure}}::h14283519edc1d634
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:582:13
  12:        0x100581474 - std::sys_common::backtrace::__rust_end_short_backtrace::hc366c0b0cef5b747
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:150:18
  13:        0x100582528 - rust_begin_unwind
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
  14:        0x10059b158 - core::panicking::panic_fmt::h324f50b29db90195
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
  15:        0x100566a78 - core::panicking::panic_display::hb2ed48e4abfece70
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:150:5
  16:        0x100566a78 - <smoltcp::phy::raw_socket::RawSocket as smoltcp::phy::Device>::receive::h618231980dd660d7
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panic.rs:54:9
  17:        0x100563d74 - tcpdump::main::ha5ed1d995545d88d
                               at ~/smoltcp/examples/tcpdump.rs:13:29
  18:        0x100563f38 - core::ops::function::FnOnce::call_once::ha83551be70b1affb
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:250:5
  19:        0x100563f38 - std::sys_common::backtrace::__rust_begin_short_backtrace::h4565efca4eb3ecfa
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:134:18
  20:        0x100563f50 - std::rt::lang_start::{{closure}}::hfbf75f877353f311
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/rt.rs:166:18
  21:        0x10057c928 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h6f7eb9f266759f90
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:287:13
  22:        0x10057c928 - std::panicking::try::do_call::h54b2febb9ea02379
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:485:40
  23:        0x10057c928 - std::panicking::try::h95a2f9f45aeb75ea
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:449:19
  24:        0x10057c928 - std::panic::catch_unwind::h9686256fa0fc97a1
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panic.rs:140:14
  25:        0x10057c928 - std::rt::lang_start_internal::{{closure}}::h227e8b10bc4e486b
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/rt.rs:148:48
  26:        0x10057c928 - std::panicking::try::do_call::h414d500a3ee5fa44
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:485:40
  27:        0x10057c928 - std::panicking::try::h4f025820961f1c3f
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:449:19
  28:        0x10057c928 - std::panic::catch_unwind::h0b71dfe3538d125d
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panic.rs:140:14
  29:        0x10057c928 - std::rt::lang_start_internal::h8ee16b8f6c950a26
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/rt.rs:148:20
  30:        0x100563f20 - _main
kurkpitaine commented 8 months ago

Got the same issue, I commented line 39 in raw_socket.rs and it works. I did not dig for a proper fix.