1- use crate :: if_packet;
21use std:: fmt;
32use std:: time:: { Duration , SystemTime , UNIX_EPOCH } ;
43
54/// Descriptor for single packet within a block in mmapped ringbuffer
65pub struct PacketDescriptor < ' a > {
76 ptr : * mut u8 ,
8- hdr : & ' a if_packet :: tpacket3_hdr ,
7+ hdr : & ' a libc :: tpacket3_hdr ,
98}
109
1110impl < ' a > PacketDescriptor < ' a > {
1211 #[ allow( clippy:: cast_ptr_alignment) ]
1312 pub fn get_next ( self ) -> PacketDescriptor < ' a > {
1413 let next_offset = isize:: try_from ( self . hdr . tp_next_offset ) . unwrap_or ( isize:: MAX ) ;
1514 let next_ptr = unsafe { self . ptr . offset ( next_offset) } ;
16- let next_hdr_ptr = next_ptr as * const if_packet :: tpacket3_hdr ;
15+ let next_hdr_ptr = next_ptr as * const libc :: tpacket3_hdr ;
1716 PacketDescriptor {
1817 ptr : next_ptr,
1918 hdr : unsafe { next_hdr_ptr. as_ref ( ) . unwrap ( ) } ,
@@ -32,11 +31,11 @@ impl<'a> PacketDescriptor<'a> {
3231 }
3332
3433 pub fn has_vlan_tci ( & self ) -> bool {
35- ( self . hdr . tp_status & if_packet :: TP_STATUS_VLAN_VALID ) == if_packet :: TP_STATUS_VLAN_VALID
34+ ( self . hdr . tp_status & libc :: TP_STATUS_VLAN_VALID ) == libc :: TP_STATUS_VLAN_VALID
3635 }
3736
3837 pub fn has_vlan_tpid ( & self ) -> bool {
39- ( self . hdr . tp_status & if_packet :: TP_STATUS_VLAN_TPID_VALID ) == if_packet :: TP_STATUS_VLAN_TPID_VALID
38+ ( self . hdr . tp_status & libc :: TP_STATUS_VLAN_TPID_VALID ) == libc :: TP_STATUS_VLAN_TPID_VALID
4039 }
4140
4241 pub fn get_vlan_tci ( & self ) -> u32 {
@@ -51,7 +50,7 @@ impl<'a> PacketDescriptor<'a> {
5150impl From < * mut u8 > for PacketDescriptor < ' _ > {
5251 #[ allow( clippy:: cast_ptr_alignment) ]
5352 fn from ( ptr : * mut u8 ) -> Self {
54- let hdr_ptr = ptr as * const if_packet :: tpacket3_hdr ;
53+ let hdr_ptr = ptr as * const libc :: tpacket3_hdr ;
5554 let hdr = unsafe { hdr_ptr. as_ref ( ) . unwrap ( ) } ;
5655 PacketDescriptor { ptr, hdr }
5756 }
@@ -64,35 +63,40 @@ impl From<*mut u8> for PacketDescriptor<'_> {
6463/// needs to be called to indicate kernel that it free to use this block again
6564#[ derive( Debug ) ]
6665pub struct BlockDescriptor < ' a > {
67- ptr : * mut u8 , // pointer to the start of the data
68- desc : & ' a mut if_packet :: tpacket_block_desc , // the actual block descriptor
66+ ptr : * mut u8 , // pointer to the start of the data
67+ desc : & ' a mut libc :: tpacket_block_desc , // the actual block descriptor
6968}
7069
7170unsafe impl Send for BlockDescriptor < ' _ > { }
7271
7372impl < ' a > BlockDescriptor < ' a > {
73+ // Returns reference to block header
74+ fn block_header ( & self ) -> & libc:: tpacket_hdr_v1 {
75+ unsafe { & self . desc . hdr . bh1 }
76+ }
77+
7478 pub fn flush ( & mut self ) {
75- self . desc . hdr . block_status = if_packet :: TP_STATUS_KERNEL ;
79+ self . desc . hdr . bh1 . block_status = libc :: TP_STATUS_KERNEL ;
7680 }
7781
7882 pub fn is_ready ( & self ) -> bool {
79- self . desc . hdr . block_status & if_packet :: TP_STATUS_USER != 0
83+ self . block_header ( ) . block_status & libc :: TP_STATUS_USER != 0
8084 }
8185
8286 pub fn get_number_of_packets ( & self ) -> u32 {
83- self . desc . hdr . num_packets
87+ self . block_header ( ) . num_pkts
8488 }
8589
8690 pub fn get_first_packet ( & self ) -> PacketDescriptor < ' a > {
87- let offset = isize:: try_from ( self . desc . hdr . offset_to_first_pkt ) . unwrap_or ( isize:: MAX ) ;
91+ let offset = isize:: try_from ( self . block_header ( ) . offset_to_first_pkt ) . unwrap_or ( isize:: MAX ) ;
8892 unsafe { self . ptr . offset ( offset) } . into ( )
8993 }
9094}
9195
9296impl From < * mut u8 > for BlockDescriptor < ' _ > {
9397 #[ allow( clippy:: cast_ptr_alignment) ]
9498 fn from ( ptr : * mut u8 ) -> Self {
95- let desc_ptr = ptr. cast :: < if_packet :: tpacket_block_desc > ( ) ;
99+ let desc_ptr = ptr. cast :: < libc :: tpacket_block_desc > ( ) ;
96100
97101 BlockDescriptor {
98102 ptr,
0 commit comments