@@ -1722,6 +1722,18 @@ s_no_extra_traits! {
1722
1722
pub uc_flags: c_int,
1723
1723
__spare__: [ c_int; 4 ] ,
1724
1724
}
1725
+
1726
+ #[ repr( packed) ]
1727
+ pub struct ether_header {
1728
+ pub ether_dhost: [ crate :: u_char; ETHER_ADDR_LEN as usize ] ,
1729
+ pub ether_shost: [ crate :: u_char; ETHER_ADDR_LEN as usize ] ,
1730
+ pub ether_type: crate :: u_short,
1731
+ }
1732
+
1733
+ #[ repr( packed) ]
1734
+ pub struct ether_addr {
1735
+ pub octet: [ crate :: u_char; ETHER_ADDR_LEN as usize ] ,
1736
+ }
1725
1737
}
1726
1738
1727
1739
cfg_if ! {
@@ -2602,6 +2614,65 @@ cfg_if! {
2602
2614
. finish( )
2603
2615
}
2604
2616
}
2617
+
2618
+ // FIXME(msrv): `derive` on packed structs cannot be used below 1.67
2619
+
2620
+ impl PartialEq for ether_header {
2621
+ fn eq( & self , other: & ether_header) -> bool {
2622
+ self . ether_dhost
2623
+ . iter( )
2624
+ . zip( other. ether_dhost. iter( ) )
2625
+ . all( |( a, b) | a == b)
2626
+ && self
2627
+ . ether_dhost
2628
+ . iter( )
2629
+ . zip( other. ether_shost. iter( ) )
2630
+ . all( |( a, b) | a == b)
2631
+ && self . ether_type == other. ether_type
2632
+ }
2633
+ }
2634
+
2635
+ impl Eq for ether_header { }
2636
+ impl fmt:: Debug for ether_header {
2637
+ fn fmt( & self , f: & mut fmt:: Formatter ) -> fmt:: Result {
2638
+ f. debug_struct( "ether_header" )
2639
+ . field( "ether_dhost" , & { self . ether_dhost } )
2640
+ . field( "ether_shost" , & { self . ether_shost } )
2641
+ . field( "ether_type" , & { self . ether_type } )
2642
+ . finish( )
2643
+ }
2644
+ }
2645
+
2646
+ impl hash:: Hash for ether_header {
2647
+ fn hash<H : hash:: Hasher >( & self , state: & mut H ) {
2648
+ { self . ether_dhost } . hash( state) ;
2649
+ { self . ether_shost } . hash( state) ;
2650
+ { self . ether_type } . hash( state) ;
2651
+ }
2652
+ }
2653
+
2654
+ impl PartialEq for ether_addr {
2655
+ fn eq( & self , other: & ether_addr) -> bool {
2656
+ self . octet
2657
+ . iter( )
2658
+ . zip( other. octet. iter( ) )
2659
+ . all( |( a, b) | a == b)
2660
+ }
2661
+ }
2662
+
2663
+ impl Eq for ether_addr { }
2664
+ impl fmt:: Debug for ether_addr {
2665
+ fn fmt( & self , f: & mut fmt:: Formatter ) -> fmt:: Result {
2666
+ f. debug_struct( "ether_addr" )
2667
+ . field( "octet" , & { self . octet } )
2668
+ . finish( )
2669
+ }
2670
+ }
2671
+ impl hash:: Hash for ether_addr {
2672
+ fn hash<H : hash:: Hasher >( & self , state: & mut H ) {
2673
+ { self . octet } . hash( state) ;
2674
+ }
2675
+ }
2605
2676
}
2606
2677
}
2607
2678
@@ -4704,6 +4775,16 @@ pub const RTM_VERSION: c_int = 5;
4704
4775
4705
4776
pub const RTAX_MAX : c_int = 8 ;
4706
4777
4778
+ // net/ethernet.h
4779
+
4780
+ pub const ETHER_ADDR_LEN : c_int = 6 ;
4781
+ pub const ETHER_TYPE_LEN : c_int = 2 ;
4782
+ pub const ETHER_CRC_LEN : c_int = 4 ;
4783
+ pub const ETHER_HDR_LEN : c_int = ETHER_ADDR_LEN * 2 + ETHER_TYPE_LEN ;
4784
+ pub const ETHER_MIN_LEN : c_int = 64 ;
4785
+ pub const ETHER_MAX_LEN : c_int = 1518 ;
4786
+ pub const ETHER_MAX_LEN_JUMBO : c_int = 9018 ;
4787
+
4707
4788
// sys/signal.h
4708
4789
pub const SIGTHR : c_int = 32 ;
4709
4790
pub const SIGLWP : c_int = SIGTHR ;
@@ -5012,6 +5093,34 @@ f! {
5012
5093
pub fn PROT_MAX_EXTRACT ( x: c_int) -> c_int {
5013
5094
( x >> 16 ) & ( crate :: PROT_READ | crate :: PROT_WRITE | crate :: PROT_EXEC )
5014
5095
}
5096
+
5097
+ pub { const } fn ETHER_IS_MULTICAST ( addr: * mut u_char) -> bool {
5098
+ ( * addr. add( 0 ) ) & 0x01 != 0x00
5099
+ }
5100
+
5101
+ pub { const } fn ETHER_IS_IPV6_MULTICAST ( addr: * mut u_char) -> bool {
5102
+ ( * addr. add( 0 ) ) == 0x33 && ( * addr. add( 1 ) ) == 0x33
5103
+ }
5104
+
5105
+ pub { const } fn ETHER_IS_BROADCAST ( addr: * mut u_char) -> bool {
5106
+ ( * addr. add( 0 ) )
5107
+ & ( * addr. add( 1 ) )
5108
+ & ( * addr. add( 2 ) )
5109
+ & ( * addr. add( 3 ) )
5110
+ & ( * addr. add( 4 ) )
5111
+ & ( * addr. add( 5 ) )
5112
+ == 0xff
5113
+ }
5114
+
5115
+ pub { const } fn ETHER_IS_ZERO ( addr: * mut u_char) -> bool {
5116
+ ( * addr. add( 0 ) )
5117
+ | ( * addr. add( 1 ) )
5118
+ | ( * addr. add( 2 ) )
5119
+ | ( * addr. add( 3 ) )
5120
+ | ( * addr. add( 4 ) )
5121
+ | ( * addr. add( 5 ) )
5122
+ == 0x00
5123
+ }
5015
5124
}
5016
5125
5017
5126
safe_f ! {
0 commit comments