File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 77- Added ` HiiConfigAccessProtocol ` .
88- Added ` ::octets() ` for ` Ipv4Address ` , ` Ipv6Address ` , and
99 ` MacAddress ` to streamline the API with ` core::net ` .
10+ - Added ` ::into_core_addr() ` for ` IpAddress `
11+ - Added ` ::into_ethernet_addr() ` for ` MacAddress `
1012
1113## Changed
1214- ** Breaking:** The MSRV is now 1.85.1 and the crate uses the Rust 2024 edition.
Original file line number Diff line number Diff line change @@ -98,6 +98,27 @@ impl IpAddress {
9898 v6 : Ipv6Address ( ip_addr) ,
9999 }
100100 }
101+
102+ /// Transforms this EFI type to the Rust standard library's type
103+ /// [`core::net::IpAddr`].
104+ ///
105+ /// # Arguments
106+ /// - `is_ipv6`: Whether the internal data should be interpreted as IPv6 or
107+ /// IPv4 address.
108+ ///
109+ /// # Safety
110+ /// Callers must ensure that the `v4` field is valid if `is_ipv6` is false,
111+ /// and that the `v6` field is valid if `is_ipv6` is true
112+ #[ must_use]
113+ pub unsafe fn into_core_addr ( self , is_ipv6 : bool ) -> core:: net:: IpAddr {
114+ if is_ipv6 {
115+ // SAFETY: Caller assumes that the underlying data is initialized.
116+ core:: net:: IpAddr :: V6 ( core:: net:: Ipv6Addr :: from ( unsafe { self . v6 . octets ( ) } ) )
117+ } else {
118+ // SAFETY: Caller assumes that the underlying data is initialized.
119+ core:: net:: IpAddr :: V4 ( core:: net:: Ipv4Addr :: from ( unsafe { self . v4 . octets ( ) } ) )
120+ }
121+ }
101122}
102123
103124impl Debug for IpAddress {
@@ -147,6 +168,15 @@ impl MacAddress {
147168 pub const fn octets ( self ) -> [ u8 ; 32 ] {
148169 self . 0
149170 }
171+
172+ /// Interpret the MAC address as normal 6-byte MAC address, as used in
173+ /// Ethernet.
174+ #[ must_use]
175+ pub fn into_ethernet_addr ( self ) -> [ u8 ; 6 ] {
176+ let mut buffer = [ 0 ; 6 ] ;
177+ buffer. copy_from_slice ( & self . octets ( ) [ 6 ..] ) ;
178+ buffer
179+ }
150180}
151181
152182// Normal/typical MAC addresses, such as in Ethernet.
You can’t perform that action at this time.
0 commit comments