File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -145,6 +145,27 @@ impl IpAddress {
145
145
v6 : Ipv6Address ( octets) ,
146
146
}
147
147
}
148
+
149
+ /// Transforms this EFI type to the Rust standard library's type
150
+ /// [`StdIpAddr`].
151
+ ///
152
+ /// # Arguments
153
+ /// - `is_ipv6`: Whether the internal data should be interpreted as IPv6 or
154
+ /// IPv4 address.
155
+ ///
156
+ /// # Safety
157
+ /// Callers must ensure that the `v4` field is valid if `is_ipv6` is false,
158
+ /// and that the `v6` field is valid if `is_ipv6` is true
159
+ #[ must_use]
160
+ pub unsafe fn into_core_ip_addr ( self , is_ipv6 : bool ) -> StdIpAddr {
161
+ if is_ipv6 {
162
+ // SAFETY: Caller assumes that the underlying data is initialized.
163
+ StdIpAddr :: V6 ( StdIpv6Addr :: from ( unsafe { self . v6 . octets ( ) } ) )
164
+ } else {
165
+ // SAFETY: Caller assumes that the underlying data is initialized.
166
+ StdIpAddr :: V4 ( StdIpv4Addr :: from ( unsafe { self . v4 . octets ( ) } ) )
167
+ }
168
+ }
148
169
}
149
170
150
171
impl Debug for IpAddress {
@@ -221,6 +242,17 @@ impl MacAddress {
221
242
pub const fn octets ( self ) -> [ u8 ; 32 ] {
222
243
self . 0
223
244
}
245
+
246
+ /// Tries to interpret the MAC address as normal 6-byte MAC address, as used
247
+ /// in ethernet.
248
+ pub fn try_into_ethernet_mac_addr ( self ) -> Result < [ u8 ; 6 ] , [ u8 ; 32 ] > {
249
+ let extra = self . octets ( ) [ 4 ..] . iter ( ) . any ( |& x| x != 0 ) ;
250
+ if extra {
251
+ Err ( self . 0 )
252
+ } else {
253
+ Ok ( self . octets ( ) [ ..4 ] . try_into ( ) . unwrap ( ) )
254
+ }
255
+ }
224
256
}
225
257
226
258
// Normal/typical MAC addresses, such as in Ethernet.
You can’t perform that action at this time.
0 commit comments