VideoTools
|
The GNet::Address class encapsulates a TCP/UDP transport address. More...
#include <gaddress.h>
Classes | |
class | Family |
A type-safe enumerator for IP address family. More... | |
Public Member Functions | |
Address (const Address &) | |
Copy constructor. | |
Address (const AddressStorage &) | |
Constructor taking a storage object. | |
Address (const sockaddr *addr, socklen_t len) | |
Constructor using a given sockaddr. More... | |
Address (Family, unsigned int port) | |
Constructor for a wildcard INADDR_ANY address with the given port number. More... | |
Address (const std::string &display_string) | |
Constructor taking a string originally obtained from displayString(). More... | |
Address (const std::string &ip, unsigned int port) | |
Constructor taking an ip-address and a port number. More... | |
~Address () | |
Destructor. | |
void | operator= (const Address &addr) |
Assignment operator. | |
const sockaddr * | address () const |
Returns the sockaddr address. More... | |
sockaddr * | address () |
This is a non-const version of address() for compiling on systems which are not properly const-clean. More... | |
socklen_t | length () const |
Returns the size of the sockaddr address. See address(). | |
std::string | displayString () const |
Returns a string which represents the transport address for debugging and diagnostics purposes. More... | |
std::string | hostPartString () const |
Returns a string which represents the network address for debugging and diagnostics purposes. More... | |
unsigned int | port () const |
Returns port part of the address. | |
int | domain () const |
Returns the address 'domain', eg. PF_INET. | |
unsigned long | scopeId (unsigned long default_=0UL) const |
Returns the scope-id. More... | |
bool | sameHostPart (const Address &other) const |
Returns true if the two addresses have the same host part (ie. More... | |
void | setPort (unsigned int port) |
Sets the port number. More... | |
G::StringArray | wildcards () const |
Returns an ordered list of wildcard strings that match this address. More... | |
bool | isLoopback () const |
Returns true if this is a loopback address. | |
bool | isLocal (std::string &reason) const |
Returns true if this seems to be a local address. More... | |
Family | family () const |
Returns the address family. | |
bool | operator== (const Address &) const |
Comparison operator. | |
bool | operator!= (const Address &) const |
Comparison operator. | |
Static Public Member Functions | |
static bool | supports (Family) |
Returns true if the implementation supports the given address family. | |
static Address | defaultAddress () |
Returns a default address, being the IPv4 wildcard address with a zero port number. More... | |
static Address | loopback (Family, unsigned int port=0U) |
Returns a loopback address. | |
static bool | validPort (unsigned int n) |
Returns true if the port number is within the valid range. More... | |
static bool | validString (const std::string &display_string, std::string *reason=nullptr) |
Returns true if the display string is valid. More... | |
static bool | validStrings (const std::string &ip, const std::string &port_string, std::string *reason=nullptr) |
Returns true if the combined ip address string and port string is valid. More... | |
static bool | validData (const sockaddr *, socklen_t len) |
Returns true if the sockaddr data is valid. More... | |
The GNet::Address class encapsulates a TCP/UDP transport address.
The address is exposed as a 'sockaddr' structure for low-level socket operations.
A double pimple pattern is used for the implementation; this class instantiates either a GNet::Address4 implementation sub-object or a GNet::Address6 sub-object depending on the address family, and forwards its method calls directly to the one instantiated sub-object. In an IPv4-only build the GNet::Address6 is forward-declared but not defined and all methods are forwarded to the GNet::Address4 sub-object.
Definition at line 55 of file gaddress.h.
GNet::Address::Address | ( | const sockaddr * | addr, |
socklen_t | len | ||
) |
Constructor using a given sockaddr.
Throws an exception if an invalid structure. See also: validData()
Definition at line 58 of file gaddress_ipv4.cpp.
GNet::Address::Address | ( | Family | f, |
unsigned int | port | ||
) |
Constructor for a wildcard INADDR_ANY address with the given port number.
Throws an exception if an invalid port number.
Definition at line 47 of file gaddress_ipv4.cpp.
|
explicit |
Constructor taking a string originally obtained from displayString().
Throws an exception if an invalid string. See also validString().
Definition at line 63 of file gaddress_ipv4.cpp.
GNet::Address::Address | ( | const std::string & | ip, |
unsigned int | port | ||
) |
Constructor taking an ip-address and a port number.
Throws an exception if an invalid string.
Definition at line 68 of file gaddress_ipv4.cpp.
const sockaddr * GNet::Address::address | ( | ) | const |
Returns the sockaddr address.
Typically used when making socket system calls. Never returns nullptr.
Definition at line 155 of file gaddress_ipv4.cpp.
sockaddr * GNet::Address::address | ( | ) |
This is a non-const version of address() for compiling on systems which are not properly const-clean.
Definition at line 150 of file gaddress_ipv4.cpp.
|
static |
Returns a default address, being the IPv4 wildcard address with a zero port number.
Definition at line 42 of file gaddress_ipv4.cpp.
std::string GNet::Address::displayString | ( | ) | const |
Returns a string which represents the transport address for debugging and diagnostics purposes.
Definition at line 130 of file gaddress_ipv4.cpp.
std::string GNet::Address::hostPartString | ( | ) | const |
Returns a string which represents the network address for debugging and diagnostics purposes.
Definition at line 135 of file gaddress_ipv4.cpp.
bool GNet::Address::isLocal | ( | std::string & | reason | ) | const |
Returns true if this seems to be a local address.
Returns an explanation by reference otherwise.
Definition at line 110 of file gaddress_ipv4.cpp.
bool GNet::Address::sameHostPart | ( | const Address & | other | ) | const |
Returns true if the two addresses have the same host part (ie.
the network address, ignoring the port number).
Definition at line 125 of file gaddress_ipv4.cpp.
unsigned long GNet::Address::scopeId | ( | unsigned long | default_ = 0UL | ) | const |
Returns the scope-id.
Returns the default if scope-ids are not supported by the underlying address type.
Definition at line 170 of file gaddress_ipv4.cpp.
void GNet::Address::setPort | ( | unsigned int | port | ) |
Sets the port number.
Throws an exception if an invalid port number (ie. too big).
Definition at line 100 of file gaddress_ipv4.cpp.
|
static |
Returns true if the sockaddr data is valid.
This can be used to avoid exceptions from the relevant constructor.
Definition at line 180 of file gaddress_ipv4.cpp.
|
static |
Returns true if the port number is within the valid range.
This can be used to avoid exceptions from the relevant constructors.
Definition at line 175 of file gaddress_ipv4.cpp.
|
static |
Returns true if the display string is valid.
This can be used to avoid exceptions from the relevant constructor.
Definition at line 140 of file gaddress_ipv4.cpp.
|
static |
Returns true if the combined ip address string and port string is valid.
This can be used to avoid exceptions from the relevant constructor.
Definition at line 145 of file gaddress_ipv4.cpp.
G::StringArray GNet::Address::wildcards | ( | ) | const |
Returns an ordered list of wildcard strings that match this address.
The fully-address-specific string (eg. "192.168.0.1") comes first, and the most general match-all wildcard like "*.*.*.*" or "128.0.0.0/1" comes last.
Definition at line 195 of file gaddress_ipv4.cpp.