xref: /drstd/src/std/net/ip_addr.rs (revision 9670759b785600bf6315e4173e46a602f16add7a)
1 // Tests for this module
2 #[cfg(all(test, not(target_os = "emscripten")))]
3 mod tests;
4 
5 use crate::std::sys_common::{FromInner, IntoInner};
6 use dlibc as c;
7 
8 pub use core::net::IpAddr;
9 
10 pub use core::net::{Ipv4Addr, Ipv6Addr};
11 
12 pub use core::net::Ipv6MulticastScope;
13 
14 impl IntoInner<c::in_addr> for Ipv4Addr {
15     #[inline]
into_inner(self) -> c::in_addr16     fn into_inner(self) -> c::in_addr {
17         // `s_addr` is stored as BE on all machines and the array is in BE order.
18         // So the native endian conversion method is used so that it's never swapped.
19         c::in_addr {
20             s_addr: u32::from_ne_bytes(self.octets()),
21         }
22     }
23 }
24 impl FromInner<c::in_addr> for Ipv4Addr {
from_inner(addr: c::in_addr) -> Ipv4Addr25     fn from_inner(addr: c::in_addr) -> Ipv4Addr {
26         Ipv4Addr::from(addr.s_addr.to_ne_bytes())
27     }
28 }
29 
30 impl IntoInner<c::in6_addr> for Ipv6Addr {
into_inner(self) -> c::in6_addr31     fn into_inner(self) -> c::in6_addr {
32         c::in6_addr {
33             s6_addr: self.octets(),
34         }
35     }
36 }
37 impl FromInner<c::in6_addr> for Ipv6Addr {
38     #[inline]
from_inner(addr: c::in6_addr) -> Ipv6Addr39     fn from_inner(addr: c::in6_addr) -> Ipv6Addr {
40         Ipv6Addr::from(addr.s6_addr)
41     }
42 }
43