meh / rust-packet

Network packet handling for Rust.
92 stars 28 forks source link

Panic creating TCP packet #17

Open jkcoxson opened 2 years ago

jkcoxson commented 2 years ago

Hello, I'm trying to create TCP packets using this library, but the internal library is panicking. Here is my code:

let pkt = packet::tcp::Builder::default()
            .acknowledgment(0)
            .unwrap()
            .sequence(0)
            .unwrap()
            .destination(12345)
            .unwrap()
            .source(12345)
            .unwrap()
            .flags(Flags::empty())
            .unwrap()
            .pointer(0)
            .unwrap()
            .window(0xffff)
            .unwrap()
            .payload::<Vec<&u8>>(vec![&0x00])
            .unwrap()
            .build()
            .unwrap();

        println!("{:02X?}", pkt);

and the error message

thread 'tests::packet' panicked at 'range start index 18 out of range for slice of length 0', library/core/src/slice/index.rs:52:5
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/panicking.rs:142:14
   2: core::slice::index::slice_start_index_len_fail_rt
             at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/slice/index.rs:52:5
   3: core::ops::function::FnOnce::call_once
             at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/ops/function.rs:248:5
   4: core::intrinsics::const_eval_select
             at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/intrinsics.rs:2372:5
   5: core::slice::index::slice_start_index_len_fail
             at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/slice/index.rs:42:9
   6: <core::ops::range::RangeFrom<usize> as core::slice::index::SliceIndex<[T]>>::index_mut
             at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/slice/index.rs:399:13
   7: core::slice::index::<impl core::ops::index::IndexMut<I> for [T]>::index_mut
             at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/slice/index.rs:30:9
   8: packet::tcp::packet::Packet<B>::set_pointer
             at /Users/jacksoncoxson/.cargo/registry/src/github.com-1ecc6299db9ec823/packet-0.1.4/src/tcp/packet.rs:253:20
   9: packet::tcp::builder::Builder<B>::pointer
             at /Users/jacksoncoxson/.cargo/registry/src/github.com-1ecc6299db9ec823/packet-0.1.4/src/tcp/builder.rs:133:3
  10: secret_tunnel::tests::packet
             at ./src/lib.rs:82:19
  11: secret_tunnel::tests::packet::{{closure}}
             at ./src/lib.rs:81:5
  12: core::ops::function::FnOnce::call_once
             at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/ops/function.rs:248:5
  13: core::ops::function::FnOnce::call_once
             at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/ops/function.rs:248:5