@@ -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,55 @@ 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. iter( ) . zip( other. ether_dhost. iter( ) ) . all( |( a, b) | a == b)
2578
+ && self . ether_dhost. iter( ) . zip( other. ether_shost. iter( ) ) . all( |( a, b) | a == b)
2579
+ && self . ether_type == other. ether_type
2580
+ }
2581
+ }
2582
+
2583
+ impl Eq for ether_header { }
2584
+ impl fmt:: Debug for ether_header {
2585
+ fn fmt( & self , f: & mut fmt:: Formatter ) -> fmt:: Result {
2586
+ f. debug_struct( "ether_header" )
2587
+ . field( "ether_dhost" , & { self . ether_dhost } )
2588
+ . field( "ether_shost" , & { self . ether_shost } )
2589
+ . field( "ether_type" , & { self . ether_type } )
2590
+ . finish( )
2591
+ }
2592
+ }
2593
+
2594
+ impl hash:: Hash for ether_header {
2595
+ fn hash<H : hash:: Hasher >( & self , state: & mut H ) {
2596
+ { self . ether_dhost } . hash( state) ;
2597
+ { self . ether_shost } . hash( state) ;
2598
+ { self . ether_type } . hash( state) ;
2599
+ }
2600
+ }
2601
+
2602
+ impl PartialEq for ether_addr {
2603
+ fn eq( & self , other: & ether_addr) -> bool {
2604
+ self . octet. iter( ) . zip( other. octet. iter( ) ) . all( |( a, b) | a == b)
2605
+ }
2606
+ }
2607
+
2608
+ impl Eq for ether_addr { }
2609
+ impl fmt:: Debug for ether_addr {
2610
+ fn fmt( & self , f: & mut fmt:: Formatter ) -> fmt:: Result {
2611
+ f. debug_struct( "ether_addr" )
2612
+ . field( "octet" , & { self . octet } )
2613
+ . finish( )
2614
+ }
2615
+ }
2616
+ impl hash:: Hash for ether_addr {
2617
+ fn hash<H : hash:: Hasher >( & self , state: & mut H ) {
2618
+ { self . octet } . hash( state) ;
2619
+ }
2620
+ }
2560
2621
}
2561
2622
}
2562
2623
@@ -4663,6 +4724,16 @@ pub const RTM_VERSION: c_int = 5;
4663
4724
4664
4725
pub const RTAX_MAX : c_int = 8 ;
4665
4726
4727
+ // net/ethernet.h
4728
+
4729
+ pub const ETHER_ADDR_LEN : c_int = 6 ;
4730
+ pub const ETHER_TYPE_LEN : c_int = 2 ;
4731
+ pub const ETHER_CRC_LEN : c_int = 4 ;
4732
+ pub const ETHER_HDR_LEN : c_int = ETHER_ADDR_LEN * 2 + ETHER_TYPE_LEN ;
4733
+ pub const ETHER_MIN_LEN : c_int = 64 ;
4734
+ pub const ETHER_MAX_LEN : c_int = 1518 ;
4735
+ pub const ETHER_MAX_LEN_JUMBO : c_int = 9018 ;
4736
+
4666
4737
// sys/signal.h
4667
4738
pub const SIGTHR : c_int = 32 ;
4668
4739
pub const SIGLWP : c_int = SIGTHR ;
@@ -4973,6 +5044,24 @@ f! {
4973
5044
pub fn PROT_MAX_EXTRACT ( x: c_int) -> c_int {
4974
5045
( x >> 16 ) & ( crate :: PROT_READ | crate :: PROT_WRITE | crate :: PROT_EXEC )
4975
5046
}
5047
+
5048
+ pub { const } fn ETHER_IS_MULTICAST ( addr: * mut u_char) -> bool {
5049
+ ( * addr. add( 0 ) ) & 0x01 != 0x00
5050
+ }
5051
+
5052
+ pub { const } fn ETHER_IS_IPV6_MULTICAST ( addr: * mut u_char) -> bool {
5053
+ ( * addr. add( 0 ) ) == 0x33 && ( * addr. add( 1 ) ) == 0x33
5054
+ }
5055
+
5056
+ pub { const } fn ETHER_IS_BROADCAST ( addr: * mut u_char) -> bool {
5057
+ ( * addr. add( 0 ) ) & ( * addr. add( 1 ) ) & ( * addr. add( 2 ) )
5058
+ & ( * addr. add( 3 ) ) & ( * addr. add( 4 ) ) & ( * addr. add( 5 ) ) == 0xff
5059
+ }
5060
+
5061
+ pub { const } fn ETHER_IS_ZERO ( addr: * mut u_char) -> bool {
5062
+ ( * addr. add( 0 ) ) | ( * addr. add( 1 ) ) | ( * addr. add( 2 ) )
5063
+ | ( * addr. add( 3 ) ) | ( * addr. add( 4 ) ) | ( * addr. add( 5 ) ) == 0x00
5064
+ }
4976
5065
}
4977
5066
4978
5067
safe_f ! {
0 commit comments