pub enum SocketAddr {
V4(SocketAddrV4),
V6(SocketAddrV6),
}
Available on non-WASI only.
Expand descriptionAn internet socket address, either IPv4 or IPv6.
Internet socket addresses consist of an IP address, a 16-bit port number, as well as possibly some version-dependent additional information. See SocketAddrV4
’s and SocketAddrV6
’s respective documentation for more details.
SocketAddr
is intended to be a portable representation of socket addresses and is likely not the same as the internal socket address type used by the target operating system’s API. Like all repr(Rust)
structs, however, its exact layout remains undefined and should not be relied upon between builds.
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
assert_eq!("127.0.0.1:8080".parse(), Ok(socket));
assert_eq!(socket.port(), 8080);
assert_eq!(socket.is_ipv4(), true);
§1.0.0
An IPv4 socket address.
§1.0.0An IPv6 socket address.
Source§ Source🔬This is a nightly-only experimental API. (addr_parse_ascii
)
Parse a socket address from a slice of bytes.
#![feature(addr_parse_ascii)]
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
let socket_v4 = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
let socket_v6 = SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), 8080);
assert_eq!(SocketAddr::parse_ascii(b"127.0.0.1:8080"), Ok(socket_v4));
assert_eq!(SocketAddr::parse_ascii(b"[::1]:8080"), Ok(socket_v6));
Source§ 1.7.0 (const: 1.69.0) · Source
Creates a new socket address from an IP address and a port number.
§Examplesuse std::net::{IpAddr, Ipv4Addr, SocketAddr};
let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
assert_eq!(socket.ip(), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)));
assert_eq!(socket.port(), 8080);
1.7.0 (const: 1.69.0) · Source
Returns the IP address associated with this socket address.
§Examplesuse std::net::{IpAddr, Ipv4Addr, SocketAddr};
let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
assert_eq!(socket.ip(), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)));
1.9.0 (const: 1.87.0) · Source
Changes the IP address associated with this socket address.
§Examplesuse std::net::{IpAddr, Ipv4Addr, SocketAddr};
let mut socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
socket.set_ip(IpAddr::V4(Ipv4Addr::new(10, 10, 0, 1)));
assert_eq!(socket.ip(), IpAddr::V4(Ipv4Addr::new(10, 10, 0, 1)));
1.0.0 (const: 1.69.0) · Source
Returns the port number associated with this socket address.
§Examplesuse std::net::{IpAddr, Ipv4Addr, SocketAddr};
let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
assert_eq!(socket.port(), 8080);
1.9.0 (const: 1.87.0) · Source
Changes the port number associated with this socket address.
§Examplesuse std::net::{IpAddr, Ipv4Addr, SocketAddr};
let mut socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
socket.set_port(1025);
assert_eq!(socket.port(), 1025);
1.16.0 (const: 1.69.0) · Source
Returns true
if the IP address in this SocketAddr
is an IPv4
address, and false
otherwise.
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
assert_eq!(socket.is_ipv4(), true);
assert_eq!(socket.is_ipv6(), false);
1.16.0 (const: 1.69.0) · Source
Returns true
if the IP address in this SocketAddr
is an IPv6
address, and false
otherwise.
use std::net::{IpAddr, Ipv6Addr, SocketAddr};
let socket = SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 65535, 0, 1)), 8080);
assert_eq!(socket.is_ipv4(), false);
assert_eq!(socket.is_ipv6(), true);
1.0.0 · Source§ 1.0.0 · Source§ 1.0.0 · Source§ 1.17.0 · Source§ 1.16.0 · Source§ 1.16.0 · Source§ 1.0.0 · Source§ Source§
The associated error which can be returned from parsing.
Source§Parses a string
s
to return a value of this type.
Read more 1.0.0 · Source§ 1.0.0 · Source§ 1.0.0 · Source§ Source§Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between
self
and
other
values if one exists.
Read more 1.0.0 · Source§Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more 1.0.0 · Source§Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more 1.0.0 · Source§Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more 1.0.0 · Source§Tests greater than or equal to (for
self
and
other
) and is used by the
>=
operator.
Read more 1.0.0 · Source§ Source§Returned iterator over socket addresses which this type may correspond to.
Source§ 1.0.0 · Source§ 1.0.0 · Source§ 1.0.0 · Source§RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4