|
3 | 3 | //! Network access protocols.
|
4 | 4 | //!
|
5 | 5 | //! These protocols can be used to interact with network resources.
|
| 6 | +//! |
| 7 | +//! To work with Mac and IP addresses, `uefi` uses with the types: |
| 8 | +//! - [`EfiIpAddr`] that is tightly integrated with the [`core::net::IpAddr`] |
| 9 | +//! type, |
| 10 | +//! - [`EfiMacAddr`] |
6 | 11 |
|
7 | 12 | pub mod http;
|
8 | 13 | pub mod ip4config2;
|
9 | 14 | pub mod pxe;
|
10 | 15 | pub mod snp;
|
11 | 16 |
|
12 |
| -pub use uefi_raw::MacAddress; |
13 |
| - |
14 |
| -/// Represents an IPv4/v6 address. |
15 |
| -/// |
16 |
| -/// Corresponds to the `EFI_IP_ADDRESS` type in the C API. |
17 |
| -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
18 |
| -#[repr(C, align(4))] |
19 |
| -pub struct IpAddress(pub [u8; 16]); |
20 |
| - |
21 |
| -impl IpAddress { |
22 |
| - /// Construct a new IPv4 address. |
23 |
| - #[must_use] |
24 |
| - pub const fn new_v4(ip_addr: [u8; 4]) -> Self { |
25 |
| - let mut buffer = [0; 16]; |
26 |
| - buffer[0] = ip_addr[0]; |
27 |
| - buffer[1] = ip_addr[1]; |
28 |
| - buffer[2] = ip_addr[2]; |
29 |
| - buffer[3] = ip_addr[3]; |
30 |
| - Self(buffer) |
31 |
| - } |
32 |
| - |
33 |
| - /// Construct a new IPv6 address. |
34 |
| - #[must_use] |
35 |
| - pub const fn new_v6(ip_addr: [u8; 16]) -> Self { |
36 |
| - Self(ip_addr) |
37 |
| - } |
38 |
| - |
39 |
| - /// Construct from a `uefi_raw::IpAddress` union. |
40 |
| - /// |
41 |
| - /// # Safety |
42 |
| - /// |
43 |
| - /// `is_ipv6` must accurately reflect how the union was initialized. |
44 |
| - #[must_use] |
45 |
| - const unsafe fn from_raw(ip_addr: uefi_raw::IpAddress, is_ipv6: bool) -> Self { |
46 |
| - if is_ipv6 { |
47 |
| - Self::new_v6(unsafe { ip_addr.v6.0 }) |
48 |
| - } else { |
49 |
| - Self::new_v4(unsafe { ip_addr.v4.0 }) |
50 |
| - } |
51 |
| - } |
52 |
| - |
53 |
| - #[must_use] |
54 |
| - const fn as_raw_ptr(&self) -> *const uefi_raw::IpAddress { |
55 |
| - // The uefi-raw type is defined differently, but the layout is |
56 |
| - // compatible. |
57 |
| - self.0.as_ptr().cast() |
58 |
| - } |
59 |
| - |
60 |
| - #[must_use] |
61 |
| - fn as_raw_ptr_mut(&mut self) -> *mut uefi_raw::IpAddress { |
62 |
| - // The uefi-raw type is defined differently, but the layout is |
63 |
| - // compatible. |
64 |
| - self.0.as_mut_ptr().cast() |
65 |
| - } |
66 |
| -} |
67 |
| - |
68 |
| -impl From<core::net::Ipv4Addr> for IpAddress { |
69 |
| - fn from(t: core::net::Ipv4Addr) -> Self { |
70 |
| - Self::new_v4(t.octets()) |
71 |
| - } |
72 |
| -} |
73 |
| - |
74 |
| -impl From<IpAddress> for core::net::Ipv4Addr { |
75 |
| - fn from(IpAddress(o): IpAddress) -> Self { |
76 |
| - Self::from([o[0], o[1], o[2], o[3]]) |
77 |
| - } |
78 |
| -} |
79 |
| - |
80 |
| -impl From<core::net::Ipv6Addr> for IpAddress { |
81 |
| - fn from(t: core::net::Ipv6Addr) -> Self { |
82 |
| - Self::new_v6(t.octets()) |
83 |
| - } |
84 |
| -} |
85 |
| - |
86 |
| -impl From<IpAddress> for core::net::Ipv6Addr { |
87 |
| - fn from(value: IpAddress) -> Self { |
88 |
| - Self::from(value.0) |
89 |
| - } |
90 |
| -} |
91 |
| - |
92 |
| -impl From<core::net::IpAddr> for IpAddress { |
93 |
| - fn from(t: core::net::IpAddr) -> Self { |
94 |
| - match t { |
95 |
| - core::net::IpAddr::V4(a) => a.into(), |
96 |
| - core::net::IpAddr::V6(a) => a.into(), |
97 |
| - } |
98 |
| - } |
99 |
| -} |
100 |
| - |
101 |
| -// NOTE: We cannot impl From<IpAddress> for core::net::IpAddr |
102 |
| -// because IpAddress is a raw union, with nothing indicating |
103 |
| -// whether it should be considered v4 or v6. |
| 17 | +pub use uefi_raw::{IpAddress as EfiIpAddr, MacAddress as EfiMacAddr}; |
0 commit comments