@@ -16,6 +16,14 @@ use core::fmt::{Debug, Formatter};
1616#[ repr( transparent) ]
1717pub struct Ipv4Address ( pub [ u8 ; 4 ] ) ;
1818
19+ impl Ipv4Address {
20+ /// Returns the octets of the IP address.
21+ #[ must_use]
22+ pub const fn octets ( self ) -> [ u8 ; 4 ] {
23+ self . 0
24+ }
25+ }
26+
1927impl From < core:: net:: Ipv4Addr > for Ipv4Address {
2028 fn from ( ip : core:: net:: Ipv4Addr ) -> Self {
2129 Self ( ip. octets ( ) )
@@ -33,6 +41,14 @@ impl From<Ipv4Address> for core::net::Ipv4Addr {
3341#[ repr( transparent) ]
3442pub struct Ipv6Address ( pub [ u8 ; 16 ] ) ;
3543
44+ impl Ipv6Address {
45+ /// Returns the octets of the IP address.
46+ #[ must_use]
47+ pub const fn octets ( self ) -> [ u8 ; 16 ] {
48+ self . 0
49+ }
50+ }
51+
3652impl From < core:: net:: Ipv6Addr > for Ipv6Address {
3753 fn from ( ip : core:: net:: Ipv6Addr ) -> Self {
3854 Self ( ip. octets ( ) )
@@ -82,6 +98,16 @@ impl IpAddress {
8298 v6 : Ipv6Address ( ip_addr) ,
8399 }
84100 }
101+
102+ /// Returns the octets of the union. Without additional context, it is not
103+ /// clear whether the octets represent an IPv4 or IPv6 address.
104+ ///
105+ /// # Safety
106+ /// Callers must be sure that all underlying bytes were initialized.
107+ #[ must_use]
108+ pub const unsafe fn octets ( & self ) -> [ u8 ; 16 ] {
109+ unsafe { self . v6 . octets ( ) }
110+ }
85111}
86112
87113impl Debug for IpAddress {
@@ -125,6 +151,15 @@ impl From<core::net::IpAddr> for IpAddress {
125151#[ repr( transparent) ]
126152pub struct MacAddress ( pub [ u8 ; 32 ] ) ;
127153
154+ impl MacAddress {
155+ /// Returns the octets of the MAC address.
156+ #[ must_use]
157+ pub const fn octets ( self ) -> [ u8 ; 32 ] {
158+ self . 0
159+ }
160+ }
161+
162+ // Normal/typical MAC addresses, such as in Ethernet.
128163impl From < [ u8 ; 6 ] > for MacAddress {
129164 fn from ( octets : [ u8 ; 6 ] ) -> Self {
130165 let mut buffer = [ 0 ; 32 ] ;
0 commit comments