Represents a network address to which UDP packets may be sent or to which a TCP socket may be bound. More...
#include "netAddress.h"
Public Member Functions | |
NetAddress () | |
Constructs an unspecified address. More... | |
NetAddress (const Socket_Address &addr) | |
Constructs an address from a given Socket_Address. More... | |
void | clear () |
Resets the NetAddress to its initial state. More... | |
const Socket_Address & | get_addr () const |
Returns the Socket_Address for this address. More... | |
size_t | get_hash () const |
uint32_t | get_ip () const |
Returns the IP address to which this address refers, as a 32-bit integer, in host byte order. More... | |
uint8_t | get_ip_component (int n) const |
Returns the nth 8-bit component of the IP address. More... | |
std::string | get_ip_string () const |
Returns the IP address to which this address refers, formatted as a string. More... | |
int | get_port () const |
Returns the port number to which this address refers. More... | |
bool | is_any () const |
Returns true if the IP address has only zeroes. More... | |
bool | operator != (const NetAddress &other) const |
bool | operator== (const NetAddress &other) const |
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. More... | |
bool | set_broadcast (int port) |
Sets the address to the broadcast address. More... | |
bool | set_host (const std::string &hostname, int port) |
Sets the address up to refer to a particular port on a particular host. More... | |
bool | set_localhost (int port) |
Sets the address up to refer to a particular port, on this host. More... | |
void | set_port (int port) |
Resets the port number without otherwise changing the address. More... | |
Represents a network address to which UDP packets may be sent or to which a TCP socket may be bound.
Definition at line 25 of file netAddress.h.
NetAddress::NetAddress | ( | ) |
Constructs an unspecified address.
Definition at line 22 of file netAddress.cxx.
NetAddress::NetAddress | ( | const Socket_Address & | addr | ) |
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.
Definition at line 31 of file netAddress.cxx.
void NetAddress::clear | ( | ) |
Resets the NetAddress to its initial state.
Definition at line 74 of file netAddress.cxx.
References Socket_Address::clear().
Referenced by NetDatagram::clear().
const Socket_Address & NetAddress::get_addr | ( | ) | const |
Returns the Socket_Address for this address.
Definition at line 138 of file netAddress.cxx.
uint32_t NetAddress::get_ip | ( | ) | const |
Returns the IP address to which this address refers, as a 32-bit integer, in host byte order.
Definition at line 116 of file netAddress.cxx.
References Socket_Address::GetIPAddressRaw().
uint8_t NetAddress::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.
Definition at line 126 of file netAddress.cxx.
std::string NetAddress::get_ip_string | ( | ) | const |
Returns the IP address to which this address refers, formatted as a string.
Definition at line 106 of file netAddress.cxx.
References Socket_Address::get_ip().
int NetAddress::get_port | ( | ) | const |
Returns the port number to which this address refers.
Definition at line 82 of file netAddress.cxx.
References Socket_Address::get_port().
bool NetAddress::is_any | ( | ) | const |
Returns true if the IP address has only zeroes.
Definition at line 98 of file netAddress.cxx.
References Socket_Address::is_any().
bool NetAddress::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).
Definition at line 41 of file netAddress.cxx.
References Socket_Address::set_any_IP().
bool NetAddress::set_broadcast | ( | int | port | ) |
Sets the address to the broadcast address.
Definition at line 57 of file netAddress.cxx.
References Socket_Address::set_broadcast().
bool NetAddress::set_host | ( | const std::string & | 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.
Definition at line 66 of file netAddress.cxx.
References Socket_Address::set_host().
Referenced by DirectD::connect_to().
bool NetAddress::set_localhost | ( | int | port | ) |
Sets the address up to refer to a particular port, on this host.
Definition at line 49 of file netAddress.cxx.
References Socket_Address::set_host().
void NetAddress::set_port | ( | int | port | ) |
Resets the port number without otherwise changing the address.
Definition at line 90 of file netAddress.cxx.
References Socket_Address::set_port().