1// Tests for this module
2#[cfg(all(test, not(target_os = "emscripten")))]
3mod tests;
4
5use crate::sys::net::netc as c;
6use crate::sys_common::{FromInner, IntoInner};
7
8#[stable(feature = "ip_addr", since = "1.7.0")]
9pub use core::net::IpAddr;
10
11#[stable(feature = "rust1", since = "1.0.0")]
12pub use core::net::{Ipv4Addr, Ipv6Addr};
13
14#[unstable(feature = "ip", issue = "27709")]
15pub use core::net::Ipv6MulticastScope;
16
17impl IntoInner<c::in_addr> for Ipv4Addr {
18 #[inline]
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()) }
23 }
24}
25impl FromInner<c::in_addr> for Ipv4Addr {
26 fn from_inner(addr: c::in_addr) -> Ipv4Addr {
27 Ipv4Addr::from(addr.s_addr.to_ne_bytes())
28 }
29}
30
31impl IntoInner<c::in6_addr> for Ipv6Addr {
32 fn into_inner(self) -> c::in6_addr {
33 c::in6_addr { s6_addr: self.octets() }
34 }
35}
36impl FromInner<c::in6_addr> for Ipv6Addr {
37 #[inline]
38 fn from_inner(addr: c::in6_addr) -> Ipv6Addr {
39 Ipv6Addr::from(addr.s6_addr)
40 }
41}
42