@@ -1677,6 +1677,18 @@ s_no_extra_traits! {
1677
1677
pub uc_flags: c_int,
1678
1678
__spare__: [ c_int; 4 ] ,
1679
1679
}
1680
+
1681
+ #[ repr( packed) ]
1682
+ pub struct ether_header {
1683
+ pub ether_dhost: [ crate :: u_char; ETHER_ADDR_LEN as usize ] ,
1684
+ pub ether_shost: [ crate :: u_char; ETHER_ADDR_LEN as usize ] ,
1685
+ pub ether_type: crate :: u_short,
1686
+ }
1687
+
1688
+ #[ repr( packed) ]
1689
+ pub struct ether_addr {
1690
+ pub octet: [ crate :: u_char; ETHER_ADDR_LEN as usize ] ,
1691
+ }
1680
1692
}
1681
1693
1682
1694
cfg_if ! {
@@ -2557,6 +2569,67 @@ cfg_if! {
2557
2569
. finish( )
2558
2570
}
2559
2571
}
2572
+
2573
+ // FIXME(msrv): `derive` on packed structs cannot be used below 1.67
2574
+
2575
+ impl PartialEq for ether_header {
2576
+ fn eq( & self , other: & ether_header) -> bool {
2577
+ self . ether_dhost
2578
+ . iter( )
2579
+ . zip( other. ether_dhost. iter( ) )
2580
+ . all( |( a, b) | a == b)
2581
+ && self
2582
+ . ether_dhost
2583
+ . iter( )
2584
+ . zip( other. ether_shost
2585
+ . iter( ) )
2586
+ . all( |( a, b) | a == b)
2587
+ && self
2588
+ . ether_type == other. ether_type
2589
+ }
2590
+ }
2591
+
2592
+ impl Eq for ether_header { }
2593
+ impl fmt:: Debug for ether_header {
2594
+ fn fmt( & self , f: & mut fmt:: Formatter ) -> fmt:: Result {
2595
+ f. debug_struct( "ether_header" )
2596
+ . field( "ether_dhost" , & { self . ether_dhost } )
2597
+ . field( "ether_shost" , & { self . ether_shost } )
2598
+ . field( "ether_type" , & { self . ether_type } )
2599
+ . finish( )
2600
+ }
2601
+ }
2602
+
2603
+ impl hash:: Hash for ether_header {
2604
+ fn hash<H : hash:: Hasher >( & self , state: & mut H ) {
2605
+ { self . ether_dhost } . hash( state) ;
2606
+ { self . ether_shost } . hash( state) ;
2607
+ { self . ether_type } . hash( state) ;
2608
+ }
2609
+ }
2610
+
2611
+ impl PartialEq for ether_addr {
2612
+ fn eq( & self , other: & ether_addr) -> bool {
2613
+ self . octet
2614
+ . iter( )
2615
+ . zip( other. octet. iter( ) )
2616
+ . all( |( a, b) | a == b)
2617
+ }
2618
+ }
2619
+
2620
+ impl Eq for ether_addr { }
2621
+ impl fmt:: Debug for ether_addr {
2622
+ fn fmt( & self , f: & mut fmt:: Formatter ) -> fmt:: Result {
2623
+ f. debug_struct( "ether_addr" )
2624
+ . field( "octet" , & { self . octet } )
2625
+ . finish( )
2626
+ }
2627
+ }
2628
+ impl hash:: Hash for ether_addr {
2629
+ fn hash<H : hash:: Hasher >( & self , state: & mut H ) {
2630
+ { self . octet } . hash( state) ;
2631
+ }
2632
+ }
2560
2633
}
2561
2634
}
2562
2635
@@ -4663,6 +4736,16 @@ pub const RTM_VERSION: c_int = 5;
4663
4736
4664
4737
pub const RTAX_MAX : c_int = 8 ;
4665
4738
4739
+ // net/ethernet.h
4740
+
4741
+ pub const ETHER_ADDR_LEN : c_int = 6 ;
4742
+ pub const ETHER_TYPE_LEN : c_int = 2 ;
4743
+ pub const ETHER_CRC_LEN : c_int = 4 ;
4744
+ pub const ETHER_HDR_LEN : c_int = ETHER_ADDR_LEN * 2 + ETHER_TYPE_LEN ;
4745
+ pub const ETHER_MIN_LEN : c_int = 64 ;
4746
+ pub const ETHER_MAX_LEN : c_int = 1518 ;
4747
+ pub const ETHER_MAX_LEN_JUMBO : c_int = 9018 ;
4748
+
4666
4749
// sys/signal.h
4667
4750
pub const SIGTHR : c_int = 32 ;
4668
4751
pub const SIGLWP : c_int = SIGTHR ;
@@ -4973,6 +5056,34 @@ f! {
4973
5056
pub fn PROT_MAX_EXTRACT ( x: c_int) -> c_int {
4974
5057
( x >> 16 ) & ( crate :: PROT_READ | crate :: PROT_WRITE | crate :: PROT_EXEC )
4975
5058
}
5059
+
5060
+ pub { const } fn ETHER_IS_MULTICAST ( addr: * mut u_char) -> bool {
5061
+ ( * addr. add( 0 ) ) & 0x01 != 0x00
5062
+ }
5063
+
5064
+ pub { const } fn ETHER_IS_IPV6_MULTICAST ( addr: * mut u_char) -> bool {
5065
+ ( * addr. add( 0 ) ) == 0x33 && ( * addr. add( 1 ) ) == 0x33
5066
+ }
5067
+
5068
+ pub { const } fn ETHER_IS_BROADCAST ( addr: * mut u_char) -> bool {
5069
+ ( * addr. add( 0 ) )
5070
+ & ( * addr. add( 1 ) )
5071
+ & ( * addr. add( 2 ) )
5072
+ & ( * addr. add( 3 ) )
5073
+ & ( * addr. add( 4 ) )
5074
+ & ( * addr. add( 5 ) )
5075
+ == 0xff
5076
+ }
5077
+
5078
+ pub { const } fn ETHER_IS_ZERO ( addr: * mut u_char) -> bool {
5079
+ ( * addr. add( 0 ) )
5080
+ | ( * addr. add( 1 ) )
5081
+ | ( * addr. add( 2 ) )
5082
+ | ( * addr. add( 3 ) )
5083
+ | ( * addr. add( 4 ) )
5084
+ | ( * addr. add( 5 ) )
5085
+ == 0x00
5086
+ }
4976
5087
}
4977
5088
4978
5089
safe_f ! {
0 commit comments