Skip to content

Commit cc48a0a

Browse files
committed
uefi-raw: improve documentation of IpAddress and MacAddress
1 parent e3d5afb commit cc48a0a

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

uefi-raw/src/lib.rs

+17-14
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,21 @@ impl From<Ipv6Address> for core::net::Ipv6Addr {
144144
///
145145
/// Corresponds to the `EFI_IP_ADDRESS` type in the UEFI specification. This
146146
/// 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
148148
/// address an `IpAddress` value contains without additional context.
149149
#[derive(Clone, Copy)]
150150
#[repr(C)]
151151
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-
157152
/// An IPv4 internet protocol address.
158153
pub v4: Ipv4Address,
159154

160155
/// An IPv6 internet protocol address.
161156
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],
162162
}
163163

164164
impl IpAddress {
@@ -190,7 +190,7 @@ impl Debug for IpAddress {
190190

191191
impl Default for IpAddress {
192192
fn default() -> Self {
193-
Self { addr: [0u32; 4] }
193+
Self { _align_helper: [0u32; 4] }
194194
}
195195
}
196196

@@ -207,20 +207,23 @@ impl From<core::net::IpAddr> for IpAddress {
207207
}
208208
}
209209

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.
211219
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
212220
#[repr(transparent)]
213221
pub struct MacAddress(pub [u8; 32]);
214222

215223
impl From<[u8; 6]> for MacAddress {
216224
fn from(octets: [u8; 6]) -> Self {
217225
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);
224227
Self(buffer)
225228
}
226229
}

0 commit comments

Comments
 (0)