pub enum TargetAddr {
Ip(SocketAddr),
Domain(String, u16),
}Expand description
Where to connect: an IP socket address or a domain name plus port.
Variants§
Ip(SocketAddr)
An IP address and port.
Domain(String, u16)
A domain name and port. Through a proxy the name is resolved by the proxy.
Values built with TargetAddr::new or str::parse are validated (non-empty, at most
MAX_DOMAIN_LEN bytes, only A-Z a-z 0-9 - . _). A hand-built variant is validated
again before it is sent to a proxy.
Implementations§
Source§impl TargetAddr
impl TargetAddr
Sourcepub fn new(host: &str, port: u16) -> Result<TargetAddr, AddrError>
pub fn new(host: &str, port: u16) -> Result<TargetAddr, AddrError>
Builds a target from a host (IP literal or domain name) and a port.
IP literals (including IPv6 without brackets) become TargetAddr::Ip; everything else is
validated as a domain name.
Sourcepub fn parse_with_default_port(
s: &str,
default_port: u16,
) -> Result<TargetAddr, AddrError>
pub fn parse_with_default_port( s: &str, default_port: u16, ) -> Result<TargetAddr, AddrError>
Parses host, host:port, [v6], [v6]:port or a bare IPv6 literal, using
default_port when the string has no port.
use ghast_auth::connect::{DEFAULT_MINECRAFT_PORT, TargetAddr};
let t = TargetAddr::parse_with_default_port("mc.example.net", DEFAULT_MINECRAFT_PORT).unwrap();
assert_eq!(t, TargetAddr::Domain("mc.example.net".into(), 25565));Sourcepub fn is_local(&self) -> bool
pub fn is_local(&self) -> bool
Returns true if the target is on this machine or on the local network: loopback,
private IPv4 ranges (RFC 1918), link-local, IPv6 unique-local, or the localhost name
(RFC 6761).
Other domain names are not considered local, because deciding that would require a
local DNS lookup. CGNAT (100.64.0.0/10) is not considered local either.
Trait Implementations§
Source§impl Clone for TargetAddr
impl Clone for TargetAddr
Source§fn clone(&self) -> TargetAddr
fn clone(&self) -> TargetAddr
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TargetAddr
impl Debug for TargetAddr
Source§impl Display for TargetAddr
impl Display for TargetAddr
impl Eq for TargetAddr
Source§impl From<SocketAddr> for TargetAddr
impl From<SocketAddr> for TargetAddr
Source§fn from(addr: SocketAddr) -> TargetAddr
fn from(addr: SocketAddr) -> TargetAddr
Source§impl FromStr for TargetAddr
impl FromStr for TargetAddr
Source§fn from_str(s: &str) -> Result<TargetAddr, <TargetAddr as FromStr>::Err>
fn from_str(s: &str) -> Result<TargetAddr, <TargetAddr as FromStr>::Err>
Parses host:port or [v6]:port. The port is required; see
TargetAddr::parse_with_default_port for a default.