NetAddress

class NetAddress

Represents a network address to which UDP packets may be sent or to which a TCP socket may be bound.

Inheritance diagram

Inheritance diagram of NetAddress

NetAddress(void)
NetAddress(Socket_Address const &addr)
NetAddress(NetAddress const&) = default

Constructs an unspecified address.

Constructs an address from a given Socket_Address. Normally, this constructor should not be used by user code; instead, create a default NetAddress and use one of the set_*() functions to set up an address.

void clear(void)

Resets the NetAddress to its initial state.

Socket_Address const &get_addr(void) const

Returns the Socket_Address for this address.

std::size_t get_hash(void) const
uint32_t get_ip(void) const

Returns the IP address to which this address refers, as a 32-bit integer, in host byte order.

Deprecated: Does not work with IPv6 addresses.

uint8_t get_ip_component(int n) const

Returns the nth 8-bit component of the IP address. An IP address has four components; component 0 is the first (leftmost), and component 3 is the last (rightmost) in the dotted number convention.

std::string get_ip_string(void) const

Returns the IP address to which this address refers, formatted as a string.

int get_port(void) const

Returns the port number to which this address refers.

bool is_any(void) const

Returns true if the IP address has only zeroes.

void output(std::ostream &out) const
bool set_any(int port)

Sets the address up to refer to a particular port, but not to any particular IP. Returns true if successful, false otherwise (currently, this only returns true).

bool set_broadcast(int port)

Sets the address to the broadcast address.

bool set_host(std::string const &hostname, int port)

Sets the address up to refer to a particular port on a particular host. Returns true if the hostname is known, false otherwise.

bool set_localhost(int port)

Sets the address up to refer to a particular port, on this host.

void set_port(int port)

Resets the port number without otherwise changing the address.