1 // Tests for this module
2 #[cfg(all(test, not(target_os = "emscripten")))]
5 use crate::sys
::net
::netc
as c
;
6 use crate::sys_common
::{FromInner, IntoInner}
;
8 #[stable(feature = "ip_addr", since = "1.7.0")]
9 pub use core
::net
::IpAddr
;
11 #[stable(feature = "rust1", since = "1.0.0")]
12 pub use core
::net
::{Ipv4Addr, Ipv6Addr}
;
14 #[unstable(feature = "ip", issue = "27709")]
15 pub use core
::net
::Ipv6MulticastScope
;
17 impl IntoInner
<c
::in_addr
> for Ipv4Addr
{
19 fn into_inner(self) -> c
::in_addr
{
20 // `s_addr` is stored as BE on all machines and the array is in BE order.
21 // So the native endian conversion method is used so that it's never swapped.
22 c
::in_addr { s_addr: u32::from_ne_bytes(self.octets()) }
25 impl FromInner
<c
::in_addr
> for Ipv4Addr
{
26 fn from_inner(addr
: c
::in_addr
) -> Ipv4Addr
{
27 Ipv4Addr
::from(addr
.s_addr
.to_ne_bytes())
31 impl IntoInner
<c
::in6_addr
> for Ipv6Addr
{
32 fn into_inner(self) -> c
::in6_addr
{
33 c
::in6_addr { s6_addr: self.octets() }
36 impl FromInner
<c
::in6_addr
> for Ipv6Addr
{
38 fn from_inner(addr
: c
::in6_addr
) -> Ipv6Addr
{
39 Ipv6Addr
::from(addr
.s6_addr
)