File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 7
7
- Added ` HiiConfigAccessProtocol ` .
8
8
- Added ` ::octets() ` for ` Ipv4Address ` , ` Ipv6Address ` , and
9
9
` MacAddress ` to streamline the API with ` core::net ` .
10
+ - Added ` ::into_core_addr() ` for ` IpAddress `
11
+ - Added ` ::into_ethernet_addr() ` for ` MacAddress `
10
12
11
13
## Changed
12
14
- ** 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 {
98
98
v6 : Ipv6Address ( ip_addr) ,
99
99
}
100
100
}
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
+ }
101
122
}
102
123
103
124
impl Debug for IpAddress {
@@ -147,6 +168,14 @@ impl MacAddress {
147
168
pub const fn octets ( self ) -> [ u8 ; 32 ] {
148
169
self . 0
149
170
}
171
+
172
+ /// Interpret the MAC address as normal 6-byte MAC address, as used in
173
+ /// Ethernet.
174
+ pub fn into_ethernet_addr ( self ) -> [ u8 ; 6 ] {
175
+ let mut buffer = [ 0 ; 6 ] ;
176
+ buffer. copy_from_slice ( & self . octets ( ) [ 6 ..] ) ;
177
+ buffer
178
+ }
150
179
}
151
180
152
181
// Normal/typical MAC addresses, such as in Ethernet.
You can’t perform that action at this time.
0 commit comments