Struct std::net::SocketAddr
Re-export from std::net::address::SocketAddr
Socket address (e.g. IP address and port, or Unix domain socket path)
Fields
-
kind: AddrKind
-
inner: SocketAddrInner
Methods
impl SocketAddr { ... }
-
fn new(addr: IpAddr, port: u16) -> SocketAddr
Create SocketAddr from IP address and port
-
fn with_flowinfo_and_scope(addr: Ipv6Addr, port: u16, flowinfo: u32, scope_id: u32) -> SocketAddr
Create SocketAddr from IPv6 address, port, flow info and scope ID.
-
fn unix(addr: UnixAddr) -> SocketAddr
Create SocketAddr from a Unix domain socket address.
Example
use std::net::{SocketAddr, UnixAddr}; use std::fs::Path; let unix_addr = UnixAddr::from_path(Path::new("/tmp/my.sock")).unwrap(); let addr = SocketAddr::unix(unix_addr);
Run this example -
fn set_port(self: &mut SocketAddr, port: u16)
Sets the port number (only for IP addresses, panics for Unix addresses)
-
fn port(self: &SocketAddr) -> Option<u16>
Returns the port number for IP addresses.
Returns
Option::none()
for Unix socket addresses. -
fn ip(self: &SocketAddr) -> Option<IpAddr>
Returns the IP address for IP socket addresses.
Returns
Option::none()
for Unix socket addresses. -
fn unix_addr(self: &SocketAddr) -> Option<UnixAddr>
Returns the Unix socket address if this is a Unix socket address.
Returns
Option::none()
for IP socket addresses. -
fn parse(s: &[u8]) -> Option<SocketAddr>
Parses a socket address from a string.
-
fn fmt<F>(self: &SocketAddr, f: &mut F) -> Result
F: Formatter<F> -
fn equals(self: &SocketAddr, other: &SocketAddr) -> bool
-
fn hash<H>(self: &SocketAddr, hasher: &mut H)
H: Hasher<H>
Mixins
impl SocketAddr { ... }
-
mixin Equatable<SocketAddr>
-
Returns
false
if arguments are equal,true
otherwise