Back to Site
Loading...
Searching...
No Matches
librats::Address Struct Reference

#include <address.h>

Public Member Functions

 Address ()=default
 Address (IpAddress ip, uint16_t port)
 Address (std::string_view numeric_ip, uint16_t port)
 Build from a numeric IP literal + port.
std::string to_string () const
 IPv6 endpoints serialise bracketed; everything else plain. "" ip → ":port".
bool is_valid () const noexcept
 A usable dial target: a specified ip and a non-zero port.
bool operator== (const Address &o) const noexcept
bool operator!= (const Address &o) const noexcept
bool operator< (const Address &o) const noexcept

Static Public Member Functions

static std::optional< Address > parse (std::string_view text)
 Parse "host:port" or "[ipv6]:port".

Public Attributes

IpAddress ip
uint16_t port = 0

Detailed Description

Definition at line 34 of file address.h.

Constructor & Destructor Documentation

◆ Address() [1/3]

librats::Address::Address ( )
default

Referenced by operator!=(), operator<(), and operator==().

◆ Address() [2/3]

librats::Address::Address ( IpAddress ip,
uint16_t port )
inline

Definition at line 39 of file address.h.

References ip, and port.

◆ Address() [3/3]

librats::Address::Address ( std::string_view numeric_ip,
uint16_t port )

Build from a numeric IP literal + port.

The literal MUST be a valid IPv4/IPv6 address (hostnames belong in a HostEndpoint); an invalid literal yields an unspecified ip (asserts in debug builds). Kept for the many call sites of the form Address{"1.2.3.4", 80}.

References port.

Member Function Documentation

◆ is_valid()

bool librats::Address::is_valid ( ) const
inlinenoexcept

A usable dial target: a specified ip and a non-zero port.

Definition at line 57 of file address.h.

References ip, and port.

◆ operator!=()

bool librats::Address::operator!= ( const Address & o) const
inlinenoexcept

Definition at line 60 of file address.h.

References Address().

◆ operator<()

bool librats::Address::operator< ( const Address & o) const
inlinenoexcept

Definition at line 61 of file address.h.

References Address(), ip, and port.

◆ operator==()

bool librats::Address::operator== ( const Address & o) const
inlinenoexcept

Definition at line 59 of file address.h.

References Address(), ip, and port.

◆ parse()

std::optional< Address > librats::Address::parse ( std::string_view text)
static

Parse "host:port" or "[ipv6]:port".

Returns nullopt if the port is missing/invalid, if the host is not a numeric IP literal, or for a bare (unbracketed) IPv6 literal whose own colons make the port ambiguous. Exact inverse of to_string().

◆ to_string()

std::string librats::Address::to_string ( ) const

IPv6 endpoints serialise bracketed; everything else plain. "" ip → ":port".

Member Data Documentation

◆ ip

IpAddress librats::Address::ip

Definition at line 35 of file address.h.

Referenced by Address(), is_valid(), operator<(), and operator==().

◆ port

uint16_t librats::Address::port = 0

Definition at line 36 of file address.h.

Referenced by Address(), Address(), is_valid(), operator<(), and operator==().


The documentation for this struct was generated from the following file: