use crate::io;
use crate::iter;
use crate::mem;
-use crate::net::{hton, ntoh, IpAddr, Ipv4Addr, Ipv6Addr};
+use crate::net::{htons, ntohs, IpAddr, Ipv4Addr, Ipv6Addr};
use crate::option;
use crate::slice;
use crate::sys::net::netc as c;
/// ```
#[stable(feature = "sockaddr_checker", since = "1.16.0")]
pub fn is_ipv4(&self) -> bool {
- match *self {
- SocketAddr::V4(_) => true,
- SocketAddr::V6(_) => false,
- }
+ matches!(*self, SocketAddr::V4(_))
}
/// Returns [`true`] if the [IP address] in this `SocketAddr` is an
/// ```
#[stable(feature = "sockaddr_checker", since = "1.16.0")]
pub fn is_ipv6(&self) -> bool {
- match *self {
- SocketAddr::V4(_) => false,
- SocketAddr::V6(_) => true,
- }
+ matches!(*self, SocketAddr::V6(_))
}
}
SocketAddrV4 {
inner: c::sockaddr_in {
sin_family: c::AF_INET as c::sa_family_t,
- sin_port: hton(port),
+ sin_port: htons(port),
sin_addr: *ip.as_inner(),
..unsafe { mem::zeroed() }
},
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn port(&self) -> u16 {
- ntoh(self.inner.sin_port)
+ ntohs(self.inner.sin_port)
}
/// Changes the port number associated with this socket address.
/// ```
#[stable(feature = "sockaddr_setters", since = "1.9.0")]
pub fn set_port(&mut self, new_port: u16) {
- self.inner.sin_port = hton(new_port);
+ self.inner.sin_port = htons(new_port);
}
}
SocketAddrV6 {
inner: c::sockaddr_in6 {
sin6_family: c::AF_INET6 as c::sa_family_t,
- sin6_port: hton(port),
+ sin6_port: htons(port),
sin6_addr: *ip.as_inner(),
sin6_flowinfo: flowinfo,
sin6_scope_id: scope_id,
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn port(&self) -> u16 {
- ntoh(self.inner.sin6_port)
+ ntohs(self.inner.sin6_port)
}
/// Changes the port number associated with this socket address.
/// ```
#[stable(feature = "sockaddr_setters", since = "1.9.0")]
pub fn set_port(&mut self, new_port: u16) {
- self.inner.sin6_port = hton(new_port);
+ self.inner.sin6_port = htons(new_port);
}
/// Returns the flow information associated with this address.