SocketAddrV4 in std::net - Rust (original) (raw)

Struct SocketAddrV4

1.0.0 · Source

pub struct SocketAddrV4 { /* private fields */ }

Expand description

An IPv4 socket address.

IPv4 socket addresses consist of an IPv4 address and a 16-bit port number, as stated in IETF RFC 793.

See SocketAddr for a type encompassing both IPv4 and IPv6 socket addresses.

§Portability

SocketAddrV4 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 allrepr(Rust) structs, however, its exact layout remains undefined and should not be relied upon between builds.

§Textual representation

SocketAddrV4 provides a FromStr implementation. It accepts an IPv4 address in its textual representation, followed by a single :, followed by the port encoded as a decimal integer. Other formats are not accepted.

§Examples

use std:🥅:{Ipv4Addr, SocketAddrV4};

let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080);

assert_eq!("127.0.0.1:8080".parse(), Ok(socket));
assert_eq!(socket.ip(), &Ipv4Addr::new(127, 0, 0, 1));
assert_eq!(socket.port(), 8080);

Source§

Source

🔬This is a nightly-only experimental API. (addr_parse_ascii #101035)

Parse an IPv4 socket address from a slice of bytes.

#![feature(addr_parse_ascii)]

use std:🥅:{Ipv4Addr, SocketAddrV4};

let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080);

assert_eq!(SocketAddrV4::parse_ascii(b"127.0.0.1:8080"), Ok(socket));

Source§

1.0.0 (const: 1.69.0) · Source

Creates a new socket address from an IPv4 address and a port number.

§Examples
use std:🥅:{SocketAddrV4, Ipv4Addr};

let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080);

1.0.0 (const: 1.69.0) · Source

Returns the IP address associated with this socket address.

§Examples
use std:🥅:{SocketAddrV4, Ipv4Addr};

let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080);
assert_eq!(socket.ip(), &Ipv4Addr::new(127, 0, 0, 1));

1.9.0 (const: 1.87.0) · Source

Changes the IP address associated with this socket address.

§Examples
use std:🥅:{SocketAddrV4, Ipv4Addr};

let mut socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080);
socket.set_ip(Ipv4Addr::new(192, 168, 0, 1));
assert_eq!(socket.ip(), &Ipv4Addr::new(192, 168, 0, 1));

1.0.0 (const: 1.69.0) · Source

Returns the port number associated with this socket address.

§Examples
use std:🥅:{SocketAddrV4, Ipv4Addr};

let socket = SocketAddrV4::new(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.

§Examples
use std:🥅:{SocketAddrV4, Ipv4Addr};

let mut socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080);
socket.set_port(4242);
assert_eq!(socket.port(), 4242);

1.0.0 · Source§

1.0.0 · Source§

1.0.0 · Source§

1.16.0 · Source§

1.5.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 ==.

1.0.0 · Source§

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

1.0.0 · Source§

Source§

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§

§

§

§

§

§

§