@@ -1661,6 +1661,18 @@ s_no_extra_traits! {
1661
1661
pub uc_flags: c_int,
1662
1662
__spare__: [ c_int; 4 ] ,
1663
1663
}
1664
+
1665
+ #[ repr( packed) ]
1666
+ pub struct ether_header {
1667
+ pub ether_dhost: [ crate :: u_char; ETHER_ADDR_LEN as usize ] ,
1668
+ pub ether_shost: [ crate :: u_char; ETHER_ADDR_LEN as usize ] ,
1669
+ pub ether_type: crate :: u_short,
1670
+ }
1671
+
1672
+ #[ repr( packed) ]
1673
+ pub struct ether_addr {
1674
+ pub octet: [ crate :: u_char; ETHER_ADDR_LEN as usize ] ,
1675
+ }
1664
1676
}
1665
1677
1666
1678
cfg_if ! {
@@ -2541,6 +2553,53 @@ cfg_if! {
2541
2553
. finish( )
2542
2554
}
2543
2555
}
2556
+
2557
+ impl PartialEq for ether_header {
2558
+ fn eq( & self , other: & ether_header) -> bool {
2559
+ self . ether_dhost. iter( ) . zip( other. ether_dhost. iter( ) ) . all( |( a, b) | a == b)
2560
+ && self . ether_dhost. iter( ) . zip( other. ether_shost. iter( ) ) . all( |( a, b) | a == b)
2561
+ && self . ether_type == other. ether_type
2562
+ }
2563
+ }
2564
+
2565
+ impl Eq for ether_header { }
2566
+ impl fmt:: Debug for ether_header {
2567
+ fn fmt( & self , f: & mut fmt:: Formatter ) -> fmt:: Result {
2568
+ f. debug_struct( "ether_header" )
2569
+ . field( "ether_dhost" , & { self . ether_dhost } )
2570
+ . field( "ether_shost" , & { self . ether_shost } )
2571
+ . field( "ether_type" , & { self . ether_type } )
2572
+ . finish( )
2573
+ }
2574
+ }
2575
+
2576
+ impl hash:: Hash for ether_header {
2577
+ fn hash<H : hash:: Hasher >( & self , state: & mut H ) {
2578
+ { self . ether_dhost } . hash( state) ;
2579
+ { self . ether_shost } . hash( state) ;
2580
+ { self . ether_type } . hash( state) ;
2581
+ }
2582
+ }
2583
+
2584
+ impl PartialEq for ether_addr {
2585
+ fn eq( & self , other: & ether_addr) -> bool {
2586
+ self . octet. iter( ) . zip( other. octet. iter( ) ) . all( |( a, b) | a == b)
2587
+ }
2588
+ }
2589
+
2590
+ impl Eq for ether_addr { }
2591
+ impl fmt:: Debug for ether_addr {
2592
+ fn fmt( & self , f: & mut fmt:: Formatter ) -> fmt:: Result {
2593
+ f. debug_struct( "ether_addr" )
2594
+ . field( "octet" , & { self . octet } )
2595
+ . finish( )
2596
+ }
2597
+ }
2598
+ impl hash:: Hash for ether_header {
2599
+ fn hash<H : hash:: Hasher >( & self , state: & mut H ) {
2600
+ { self . octet } . hash( state) ;
2601
+ }
2602
+ }
2544
2603
}
2545
2604
}
2546
2605
@@ -4647,6 +4706,16 @@ pub const RTM_VERSION: c_int = 5;
4647
4706
4648
4707
pub const RTAX_MAX : c_int = 8 ;
4649
4708
4709
+ // net/ethernet.h
4710
+
4711
+ pub const ETHER_ADDR_LEN : c_int = 6 ;
4712
+ pub const ETHER_TYPE_LEN : c_int = 2 ;
4713
+ pub const ETHER_CRC_LEN : c_int = 4 ;
4714
+ pub const ETHER_HDR_LEN : c_int = ETHER_ADDR_LEN * 2 + ETHER_TYPE_LEN ;
4715
+ pub const ETHER_MIN_LEN : c_int = 64 ;
4716
+ pub const ETHER_MAX_LEN : c_int = 1518 ;
4717
+ pub const ETHER_MAX_LEN_JUMBO : c_int = 9018 ;
4718
+
4650
4719
// sys/signal.h
4651
4720
pub const SIGTHR : c_int = 32 ;
4652
4721
pub const SIGLWP : c_int = SIGTHR ;
@@ -4957,6 +5026,24 @@ f! {
4957
5026
pub fn PROT_MAX_EXTRACT ( x: c_int) -> c_int {
4958
5027
( x >> 16 ) & ( crate :: PROT_READ | crate :: PROT_WRITE | crate :: PROT_EXEC )
4959
5028
}
5029
+
5030
+ pub { const } fn ETHER_IS_MULTICAST ( addr: * mut u_char) -> bool {
5031
+ ( * addr. wrapping_add( 0 ) ) & 0x01 != 0x00
5032
+ }
5033
+
5034
+ pub { const } fn ETHER_IS_IPV6_MULTICAST ( addr: * mut u_char) -> bool {
5035
+ ( * addr. wrapping_add( 0 ) ) == 0x33 && ( * addr. wrapping_add( 1 ) ) == 0x33
5036
+ }
5037
+
5038
+ pub { const } fn ETHER_IS_BROADCAST ( addr: * mut u_char) -> bool {
5039
+ ( * addr. wrapping_add( 0 ) ) & ( * addr. wrapping_add( 1 ) ) & ( * addr. wrapping_add( 2 ) )
5040
+ & ( * addr. wrapping_add( 3 ) ) & ( * addr. wrapping_add( 4 ) ) & ( * addr. wrapping_add( 5 ) ) == 0xff
5041
+ }
5042
+
5043
+ pub { const } fn ETHER_IS_ZERO ( addr: * mut u_char) -> bool {
5044
+ ( * addr. wrapping_add( 0 ) ) | ( * addr. wrapping_add( 1 ) ) | ( * addr. wrapping_add( 2 ) )
5045
+ | ( * addr. wrapping_add( 3 ) ) | ( * addr. wrapping_add( 4 ) ) | ( * addr. wrapping_add( 5 ) ) == 0x00
5046
+ }
4960
5047
}
4961
5048
4962
5049
safe_f ! {
0 commit comments