Skip to content

Commit 8cd7351

Browse files
committed
Remove ntohs/htons in favor of to_be/from_be
1 parent 2e6256b commit 8cd7351

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

library/std/src/net/addr.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::hash;
77
use crate::io::{self, Write};
88
use crate::iter;
99
use crate::mem;
10-
use crate::net::{htons, ntohs, IpAddr, Ipv4Addr, Ipv6Addr};
10+
use crate::net::{IpAddr, Ipv4Addr, Ipv6Addr};
1111
use crate::option;
1212
use crate::slice;
1313
use crate::sys::net::netc as c;
@@ -528,15 +528,15 @@ impl SocketAddrV6 {
528528

529529
impl FromInner<c::sockaddr_in> for SocketAddrV4 {
530530
fn from_inner(addr: c::sockaddr_in) -> SocketAddrV4 {
531-
SocketAddrV4 { ip: Ipv4Addr::from_inner(addr.sin_addr), port: ntohs(addr.sin_port) }
531+
SocketAddrV4 { ip: Ipv4Addr::from_inner(addr.sin_addr), port: u16::from_be(addr.sin_port) }
532532
}
533533
}
534534

535535
impl FromInner<c::sockaddr_in6> for SocketAddrV6 {
536536
fn from_inner(addr: c::sockaddr_in6) -> SocketAddrV6 {
537537
SocketAddrV6 {
538538
ip: Ipv6Addr::from_inner(addr.sin6_addr),
539-
port: ntohs(addr.sin6_port),
539+
port: u16::from_be(addr.sin6_port),
540540
flowinfo: addr.sin6_flowinfo,
541541
scope_id: addr.sin6_scope_id,
542542
}
@@ -547,7 +547,7 @@ impl IntoInner<c::sockaddr_in> for SocketAddrV4 {
547547
fn into_inner(self) -> c::sockaddr_in {
548548
c::sockaddr_in {
549549
sin_family: c::AF_INET as c::sa_family_t,
550-
sin_port: htons(self.port),
550+
sin_port: self.port.to_be(),
551551
sin_addr: self.ip.into_inner(),
552552
..unsafe { mem::zeroed() }
553553
}
@@ -558,7 +558,7 @@ impl IntoInner<c::sockaddr_in6> for SocketAddrV6 {
558558
fn into_inner(self) -> c::sockaddr_in6 {
559559
c::sockaddr_in6 {
560560
sin6_family: c::AF_INET6 as c::sa_family_t,
561-
sin6_port: htons(self.port),
561+
sin6_port: self.port.to_be(),
562562
sin6_addr: self.ip.into_inner(),
563563
sin6_flowinfo: self.flowinfo,
564564
sin6_scope_id: self.scope_id,

library/std/src/net/mod.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,6 @@ pub enum Shutdown {
6969
Both,
7070
}
7171

72-
#[inline]
73-
const fn htons(i: u16) -> u16 {
74-
i.to_be()
75-
}
76-
#[inline]
77-
const fn ntohs(i: u16) -> u16 {
78-
u16::from_be(i)
79-
}
80-
8172
fn each_addr<A: ToSocketAddrs, F, T>(addr: A, mut f: F) -> io::Result<T>
8273
where
8374
F: FnMut(io::Result<&SocketAddr>) -> io::Result<T>,

0 commit comments

Comments
 (0)