]>
Commit | Line | Data |
---|---|---|
49aad941 FG |
1 | impl ::core::convert::From<::std::net::Ipv4Addr> for IN_ADDR { |
2 | fn from(addr: ::std::net::Ipv4Addr) -> Self { | |
3 | // u32::from(addr) is in host byte order | |
4 | // S_addr must be big-endian, network byte order | |
5 | Self { S_un: IN_ADDR_0 { S_addr: u32::from(addr).to_be() } } | |
6 | } | |
7 | } | |
8 | impl ::core::convert::From<IN_ADDR> for ::std::net::Ipv4Addr { | |
9 | fn from(in_addr: IN_ADDR) -> Self { | |
10 | // SAFETY: this is safe because the union variants are just views of the same exact data | |
11 | // in_addr.S_un.S_addr is big-endian, network byte order | |
12 | // Ipv4Addr::new() expects the parameter in host byte order | |
13 | Self::from(u32::from_be(unsafe { in_addr.S_un.S_addr })) | |
14 | } | |
15 | } |