]> git.proxmox.com Git - rustc.git/blame - library/std/src/net/ip_addr.rs
New upstream version 1.69.0+dfsg1
[rustc.git] / library / std / src / net / ip_addr.rs
CommitLineData
1b1a35ee
XL
1// Tests for this module
2#[cfg(all(test, not(target_os = "emscripten")))]
3mod tests;
4
532ac7d7 5use crate::sys::net::netc as c;
064997fb 6use crate::sys_common::{FromInner, IntoInner};
85aaf69f 7
9cc50fc6 8#[stable(feature = "ip_addr", since = "1.7.0")]
9ffffee4 9pub use core::net::IpAddr;
c34b1796 10
c34b1796 11#[stable(feature = "rust1", since = "1.0.0")]
9ffffee4 12pub use core::net::{Ipv4Addr, Ipv6Addr};
85aaf69f 13
17df50a5 14#[unstable(feature = "ip", issue = "27709")]
9ffffee4 15pub use core::net::Ipv6MulticastScope;
85aaf69f 16
3dfed10e 17impl IntoInner<c::in_addr> for Ipv4Addr {
cdc7bbd5 18 #[inline]
3dfed10e 19 fn into_inner(self) -> c::in_addr {
064997fb
FG
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.
9ffffee4 22 c::in_addr { s_addr: u32::from_ne_bytes(self.octets()) }
064997fb
FG
23 }
24}
25impl FromInner<c::in_addr> for Ipv4Addr {
26 fn from_inner(addr: c::in_addr) -> Ipv4Addr {
9ffffee4 27 Ipv4Addr::from(addr.s_addr.to_ne_bytes())
85aaf69f
SL
28 }
29}
30
064997fb
FG
31impl IntoInner<c::in6_addr> for Ipv6Addr {
32 fn into_inner(self) -> c::in6_addr {
9ffffee4 33 c::in6_addr { s6_addr: self.octets() }
dfeec247 34 }
85aaf69f 35}
92a42be0 36impl FromInner<c::in6_addr> for Ipv6Addr {
cdc7bbd5 37 #[inline]
92a42be0 38 fn from_inner(addr: c::in6_addr) -> Ipv6Addr {
9ffffee4 39 Ipv6Addr::from(addr.s6_addr)
8bb4bdeb
XL
40 }
41}