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