From 8f447e12cbc20f717879000805dca0eb940e030f Mon Sep 17 00:00:00 2001 From: reticulis Date: Sat, 13 May 2023 16:18:47 +0200 Subject: [PATCH 1/5] fix: link sll --- pnet_packet/src/lib.rs | 1 + pnet_packet/src/sll.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pnet_packet/src/lib.rs b/pnet_packet/src/lib.rs index d87db705..90365991 100644 --- a/pnet_packet/src/lib.rs +++ b/pnet_packet/src/lib.rs @@ -35,5 +35,6 @@ pub mod tcp; pub mod udp; pub mod usbpcap; pub mod vlan; +pub mod sll; pub mod util; diff --git a/pnet_packet/src/sll.rs b/pnet_packet/src/sll.rs index d8d2a9d0..e01030fa 100644 --- a/pnet_packet/src/sll.rs +++ b/pnet_packet/src/sll.rs @@ -2,9 +2,9 @@ use alloc::vec::Vec; -use ethernet::EtherType; +use super::ethernet::EtherType; use pnet_macros::packet; -use pnet_macros_support::types::* +use pnet_macros_support::types::*; // ref: https://wiki.wireshark.org/SLL // ref: https://www.tcpdump.org/linktypes/LINKTYPE_LINUX_SLL.html From b776fb0d56d6c39d2436d566053183f6b7619852 Mon Sep 17 00:00:00 2001 From: reticulis Date: Sat, 13 May 2023 16:48:08 +0200 Subject: [PATCH 2/5] feature: add LINUX_SLL2 --- pnet_packet/src/lib.rs | 1 + pnet_packet/src/sll2.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 pnet_packet/src/sll2.rs diff --git a/pnet_packet/src/lib.rs b/pnet_packet/src/lib.rs index 90365991..eff48b97 100644 --- a/pnet_packet/src/lib.rs +++ b/pnet_packet/src/lib.rs @@ -36,5 +36,6 @@ pub mod udp; pub mod usbpcap; pub mod vlan; pub mod sll; +pub mod sll2; pub mod util; diff --git a/pnet_packet/src/sll2.rs b/pnet_packet/src/sll2.rs new file mode 100644 index 00000000..30855fc7 --- /dev/null +++ b/pnet_packet/src/sll2.rs @@ -0,0 +1,31 @@ +use alloc::vec::Vec; + +use pnet_macros::packet; +use pnet_macros_support::types::*; + +use super::ethernet::EtherType; + +#[packet] +pub struct SSL2 { + #[construct_with(u16)] + protocol: EtherType, + + #[construct_with(u32)] + interface_index: u32be, + + #[construct_with(u16)] + ha_type: u16be, + + #[construct_with(u8)] + packet_type: u8, + + #[construct_with(u8)] + link_layer_address_length: u8, + + #[construct_with(u8, u8, u8, u8, u8, u8, u8, u8)] + #[length = "8"] + pub link_layer_address: Vec, + + #[payload] + pub payload: Vec +} \ No newline at end of file From b60ad541f075ff11f0b3e16315345b4f4903dc61 Mon Sep 17 00:00:00 2001 From: reticulis Date: Sat, 13 May 2023 16:51:20 +0200 Subject: [PATCH 3/5] fix: typo --- pnet_packet/src/sll2.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pnet_packet/src/sll2.rs b/pnet_packet/src/sll2.rs index 30855fc7..8ad59dfc 100644 --- a/pnet_packet/src/sll2.rs +++ b/pnet_packet/src/sll2.rs @@ -6,7 +6,7 @@ use pnet_macros_support::types::*; use super::ethernet::EtherType; #[packet] -pub struct SSL2 { +pub struct SLL2 { #[construct_with(u16)] protocol: EtherType, @@ -28,4 +28,4 @@ pub struct SSL2 { #[payload] pub payload: Vec -} \ No newline at end of file +} From 4e301864eccfdf72cd642a1564b2c15a290356cb Mon Sep 17 00:00:00 2001 From: reticulis Date: Sat, 13 May 2023 19:34:45 +0200 Subject: [PATCH 4/5] fix: add missing field --- pnet_packet/src/sll2.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pnet_packet/src/sll2.rs b/pnet_packet/src/sll2.rs index 8ad59dfc..ffa4a040 100644 --- a/pnet_packet/src/sll2.rs +++ b/pnet_packet/src/sll2.rs @@ -1,3 +1,6 @@ +//! A Linux cooked-mode capture v2 (LINKTYPE_LINUX_SLL2) packet abstraction. +// ref: https://www.tcpdump.org/linktypes/LINKTYPE_LINUX_SLL2.html + use alloc::vec::Vec; use pnet_macros::packet; @@ -5,16 +8,20 @@ use pnet_macros_support::types::*; use super::ethernet::EtherType; +/// Represents an SLL2 packet (LINKTYPE_LINUX_SLL2). #[packet] pub struct SLL2 { #[construct_with(u16)] - protocol: EtherType, + protocol_type: EtherType, + + #[construct_with(u16)] + reserverd: u16be, #[construct_with(u32)] interface_index: u32be, #[construct_with(u16)] - ha_type: u16be, + arphrd_type: u16be, #[construct_with(u8)] packet_type: u8, From 15bc0248c4a646d2b424d861a40bfbbcdb75fc41 Mon Sep 17 00:00:00 2001 From: reticulis Date: Sat, 13 May 2023 19:55:54 +0200 Subject: [PATCH 5/5] chore: modify to public fields --- pnet_packet/src/sll2.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pnet_packet/src/sll2.rs b/pnet_packet/src/sll2.rs index ffa4a040..50a0f487 100644 --- a/pnet_packet/src/sll2.rs +++ b/pnet_packet/src/sll2.rs @@ -12,27 +12,27 @@ use super::ethernet::EtherType; #[packet] pub struct SLL2 { #[construct_with(u16)] - protocol_type: EtherType, + pub protocol_type: EtherType, #[construct_with(u16)] - reserverd: u16be, + pub reserverd: u16be, #[construct_with(u32)] - interface_index: u32be, + pub interface_index: u32be, #[construct_with(u16)] - arphrd_type: u16be, + pub arphrd_type: u16be, #[construct_with(u8)] - packet_type: u8, + pub packet_type: u8, #[construct_with(u8)] - link_layer_address_length: u8, + pub link_layer_address_length: u8, #[construct_with(u8, u8, u8, u8, u8, u8, u8, u8)] - #[length = "8"] + #[length = "8"] pub link_layer_address: Vec, - - #[payload] + + #[payload] pub payload: Vec }