Remove ntohs/htons in favor of to_be/from_be

This commit is contained in:
Linus Färnstrand 2020-11-03 01:08:31 +01:00
parent 2e6256b243
commit 8cd7351962
2 changed files with 5 additions and 14 deletions

View File

@ -7,7 +7,7 @@ use crate::hash;
use crate::io::{self, Write};
use crate::iter;
use crate::mem;
use crate::net::{htons, ntohs, IpAddr, Ipv4Addr, Ipv6Addr};
use crate::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use crate::option;
use crate::slice;
use crate::sys::net::netc as c;
@ -528,7 +528,7 @@ impl SocketAddrV6 {
impl FromInner<c::sockaddr_in> for SocketAddrV4 {
fn from_inner(addr: c::sockaddr_in) -> SocketAddrV4 {
SocketAddrV4 { ip: Ipv4Addr::from_inner(addr.sin_addr), port: ntohs(addr.sin_port) }
SocketAddrV4 { ip: Ipv4Addr::from_inner(addr.sin_addr), port: u16::from_be(addr.sin_port) }
}
}
@ -536,7 +536,7 @@ impl FromInner<c::sockaddr_in6> for SocketAddrV6 {
fn from_inner(addr: c::sockaddr_in6) -> SocketAddrV6 {
SocketAddrV6 {
ip: Ipv6Addr::from_inner(addr.sin6_addr),
port: ntohs(addr.sin6_port),
port: u16::from_be(addr.sin6_port),
flowinfo: addr.sin6_flowinfo,
scope_id: addr.sin6_scope_id,
}
@ -547,7 +547,7 @@ impl IntoInner<c::sockaddr_in> for SocketAddrV4 {
fn into_inner(self) -> c::sockaddr_in {
c::sockaddr_in {
sin_family: c::AF_INET as c::sa_family_t,
sin_port: htons(self.port),
sin_port: self.port.to_be(),
sin_addr: self.ip.into_inner(),
..unsafe { mem::zeroed() }
}
@ -558,7 +558,7 @@ impl IntoInner<c::sockaddr_in6> for SocketAddrV6 {
fn into_inner(self) -> c::sockaddr_in6 {
c::sockaddr_in6 {
sin6_family: c::AF_INET6 as c::sa_family_t,
sin6_port: htons(self.port),
sin6_port: self.port.to_be(),
sin6_addr: self.ip.into_inner(),
sin6_flowinfo: self.flowinfo,
sin6_scope_id: self.scope_id,

View File

@ -69,15 +69,6 @@ pub enum Shutdown {
Both,
}
#[inline]
const fn htons(i: u16) -> u16 {
i.to_be()
}
#[inline]
const fn ntohs(i: u16) -> u16 {
u16::from_be(i)
}
fn each_addr<A: ToSocketAddrs, F, T>(addr: A, mut f: F) -> io::Result<T>
where
F: FnMut(io::Result<&SocketAddr>) -> io::Result<T>,