@@ -144,21 +144,21 @@ impl From<Ipv6Address> for core::net::Ipv6Addr {
144
144
///
145
145
/// Corresponds to the `EFI_IP_ADDRESS` type in the UEFI specification. This
146
146
/// type is defined in the same way as edk2 for compatibility with C code. Note
147
- /// that this is an untagged union, so there's no way to tell which type of
147
+ /// that this is an ** untagged union** , so there's no way to tell which type of
148
148
/// address an `IpAddress` value contains without additional context.
149
149
#[ derive( Clone , Copy ) ]
150
150
#[ repr( C ) ]
151
151
pub union IpAddress {
152
- /// This member serves to align the whole type to a 4 bytes as required by
153
- /// the spec. Note that this is slightly different from `repr(align(4))`,
154
- /// which would prevent placing this type in a packed structure.
155
- pub addr : [ u32 ; 4 ] ,
156
-
157
152
/// An IPv4 internet protocol address.
158
153
pub v4 : Ipv4Address ,
159
154
160
155
/// An IPv6 internet protocol address.
161
156
pub v6 : Ipv6Address ,
157
+
158
+ /// This member serves to align the whole type to 4 bytes as required by
159
+ /// the spec. Note that this is slightly different from `repr(align(4))`,
160
+ /// which would prevent placing this type in a packed structure.
161
+ pub _align_helper : [ u32 ; 4 ] ,
162
162
}
163
163
164
164
impl IpAddress {
@@ -190,7 +190,7 @@ impl Debug for IpAddress {
190
190
191
191
impl Default for IpAddress {
192
192
fn default ( ) -> Self {
193
- Self { addr : [ 0u32 ; 4 ] }
193
+ Self { _align_helper : [ 0u32 ; 4 ] }
194
194
}
195
195
}
196
196
@@ -207,20 +207,23 @@ impl From<core::net::IpAddr> for IpAddress {
207
207
}
208
208
}
209
209
210
- /// A Media Access Control (MAC) address.
210
+ /// UEFI Media Access Control (MAC) address.
211
+ ///
212
+ /// UEFI supports multiple network protocols and hardware types, not just
213
+ /// Ethernet. Some of them may use MAC addresses longer than 6 bytes. To be
214
+ /// protocol-agnostic and future-proof, the UEFI spec chooses a maximum size
215
+ /// that can hold any supported media access control address.
216
+ ///
217
+ /// In most cases, this is just a typical `[u8; 6]` Ethernet style MAC
218
+ /// address with the rest of the bytes being zero.
211
219
#[ derive( Clone , Copy , Debug , Default , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
212
220
#[ repr( transparent) ]
213
221
pub struct MacAddress ( pub [ u8 ; 32 ] ) ;
214
222
215
223
impl From < [ u8 ; 6 ] > for MacAddress {
216
224
fn from ( octets : [ u8 ; 6 ] ) -> Self {
217
225
let mut buffer = [ 0 ; 32 ] ;
218
- buffer[ 0 ] = octets[ 0 ] ;
219
- buffer[ 1 ] = octets[ 1 ] ;
220
- buffer[ 2 ] = octets[ 2 ] ;
221
- buffer[ 3 ] = octets[ 3 ] ;
222
- buffer[ 4 ] = octets[ 4 ] ;
223
- buffer[ 5 ] = octets[ 5 ] ;
226
+ buffer. copy_from_slice ( & octets) ;
224
227
Self ( buffer)
225
228
}
226
229
}
0 commit comments