3 /// The windows `sockaddr_in6` type is a union with accessor functions which
4 /// are not `const fn`. Define our own layout-compatible version so that we
5 /// can transmute in and out of it.
12 sin6_addr
: c
::in6_addr
,
18 pub(crate) const fn in_addr_s_addr(addr
: c
::in_addr
) -> u32 {
22 #[cfg(not(feature = "std"))]
25 pub(crate) const fn in_addr_s_addr(addr
: c
::in_addr
) -> u32 {
26 // This should be `*addr.S_un.S_addr()`, except that isn't a `const fn`.
27 unsafe { core::mem::transmute(addr) }
30 // TODO: With Rust 1.55, we can use the above `in_addr_s_addr` definition that
31 // uses a const-fn transmute.
32 #[cfg(feature = "std")]
35 pub(crate) fn in_addr_s_addr(addr
: c
::in_addr
) -> u32 {
36 // This should be `*addr.S_un.S_addr()`, except that isn't a `const fn`.
37 unsafe { core::mem::transmute(addr) }
42 pub(crate) const fn in_addr_new(s_addr
: u32) -> c
::in_addr
{
46 #[cfg(not(feature = "std"))]
49 pub(crate) const fn in_addr_new(s_addr
: u32) -> c
::in_addr
{
50 unsafe { core::mem::transmute(s_addr) }
53 // TODO: With Rust 1.55, we can use the above `in_addr_new` definition that
54 // uses a const-fn transmute.
55 #[cfg(feature = "std")]
58 pub(crate) fn in_addr_new(s_addr
: u32) -> c
::in_addr
{
59 unsafe { core::mem::transmute(s_addr) }
64 pub(crate) const fn in6_addr_s6_addr(addr
: c
::in6_addr
) -> [u8; 16] {
68 #[cfg(not(feature = "std"))]
71 pub(crate) const fn in6_addr_s6_addr(addr
: c
::in6_addr
) -> [u8; 16] {
72 unsafe { core::mem::transmute(addr) }
75 // TODO: With Rust 1.55, we can use the above `in6_addr_s6_addr` definition
76 // that uses a const-fn transmute.
77 #[cfg(feature = "std")]
80 pub(crate) fn in6_addr_s6_addr(addr
: c
::in6_addr
) -> [u8; 16] {
81 unsafe { core::mem::transmute(addr) }
86 pub(crate) const fn in6_addr_new(s6_addr
: [u8; 16]) -> c
::in6_addr
{
87 c
::in6_addr { s6_addr }
90 #[cfg(not(feature = "std"))]
93 pub(crate) const fn in6_addr_new(s6_addr
: [u8; 16]) -> c
::in6_addr
{
94 unsafe { core::mem::transmute(s6_addr) }
97 // TODO: With Rust 1.55, we can use the above `in6_addr_new` definition that
98 // uses a const-fn transmute.
99 #[cfg(feature = "std")]
102 pub(crate) fn in6_addr_new(s6_addr
: [u8; 16]) -> c
::in6_addr
{
103 unsafe { core::mem::transmute(s6_addr) }
108 pub(crate) const fn sockaddr_in6_sin6_scope_id(addr
: c
::sockaddr_in6
) -> u32 {
112 #[cfg(not(feature = "std"))]
115 pub(crate) const fn sockaddr_in6_sin6_scope_id(addr
: c
::sockaddr_in6
) -> u32 {
116 let addr
: sockaddr_in6
= unsafe { core::mem::transmute(addr) }
;
120 // TODO: With Rust 1.55, we can use the above `sockaddr_in6_sin6_scope_id`
121 // definition that uses a const-fn transmute.
122 #[cfg(feature = "std")]
125 pub(crate) fn sockaddr_in6_sin6_scope_id(addr
: c
::sockaddr_in6
) -> u32 {
126 let addr
: sockaddr_in6
= unsafe { core::mem::transmute(addr) }
;
130 #[cfg(not(feature = "std"))]
133 pub(crate) fn sockaddr_in6_sin6_scope_id_mut(addr
: &mut c
::sockaddr_in6
) -> &mut u32 {
134 &mut addr
.sin6_scope_id
137 #[cfg(not(feature = "std"))]
140 pub(crate) fn sockaddr_in6_sin6_scope_id_mut(addr
: &mut c
::sockaddr_in6
) -> &mut u32 {
141 let addr
: &mut sockaddr_in6
= unsafe { core::mem::transmute(addr) }
;
142 &mut addr
.sin6_scope_id
147 pub(crate) const fn sockaddr_in6_new(
149 target_os
= "dragonfly",
150 target_os
= "freebsd",
153 target_os
= "netbsd",
154 target_os
= "openbsd",
157 sin6_family
: c
::sa_family_t
,
160 sin6_addr
: c
::in6_addr
,
162 ) -> c
::sockaddr_in6
{
165 target_os
= "dragonfly",
166 target_os
= "freebsd",
169 target_os
= "netbsd",
170 target_os
= "openbsd",
178 #[cfg(target_os = "illumos")]
183 #[cfg(not(feature = "std"))]
186 pub(crate) const fn sockaddr_in6_new(
190 sin6_addr
: c
::in6_addr
,
192 ) -> c
::sockaddr_in6
{
193 let addr
= sockaddr_in6
{
200 unsafe { core::mem::transmute(addr) }
203 // TODO: With Rust 1.55, we can use the above `sockaddr_in6_new` definition
204 // that uses a const-fn transmute.
205 #[cfg(feature = "std")]
208 pub(crate) fn sockaddr_in6_new(
212 sin6_addr
: c
::in6_addr
,
214 ) -> c
::sockaddr_in6
{
215 let addr
= sockaddr_in6
{
222 unsafe { core::mem::transmute(addr) }