The Address class encapsulates an IP transport address. More...
#include <gaddress.h>
Classes | |
class | Broadcast |
An overload discriminator class for GNet::Address. More... | |
class | Localhost |
An overload discriminator class for GNet::Address. More... | |
Public Member Functions | |
Address (const Address &addr) | |
Copy constructor. More... | |
Address (const AddressStorage &) | |
Constructor taking a storage object. More... | |
Address (const sockaddr *addr, socklen_t len) | |
Constructor using a given sockaddr. More... | |
Address (const hostent &h, unsigned int port) | |
Constructor taking the host part from the first address in the given hostent's list of alternatives. More... | |
Address (const hostent &h, const servent &s) | |
Constructor taking the host part from the first address in the given hostent's list of alternatives, and the port number from the given servent structure. More... | |
Address (const servent &s) | |
Constructor for a local INADDR_ANY address, taking the port from the given 'servent' structure. More... | |
Address (unsigned int port) | |
Constructor for a local INADDR_ANY address with the given port number. More... | |
Address (unsigned int port, Localhost) | |
Constructor for a local INADDR_LOOPBACK address with the given port number. More... | |
Address (unsigned int port, Broadcast) | |
Constructor for a local INADDR_BROADCAST 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. More... | |
void | operator= (const Address &addr) |
Assignment operator. More... | |
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. More... | |
std::string | displayString (bool with_port=true, bool with_scope_id=false) const |
Returns a string which represents the address for debugging and diagnostics purposes. More... | |
std::string | hostString () const |
Returns a string which represents the host part of the address for debugging and diagnostics purposes. More... | |
unsigned int | port () const |
Returns port part of address. More... | |
int | domain () const |
Returns the address 'domain', eg. PF_INET. More... | |
unsigned long | scopeId (unsigned long default_=0UL) const |
Returns the scope-id. More... | |
bool | sameHost (const Address &other) const |
Returns true if the two addresses have the same host part (ie. More... | |
bool | isLocal (std::string &reason) const |
Returns true if the address is definitely local. More... | |
bool | isLocal (std::string &reason, const Address &local_hint) const |
An overload with a hint that should be the host's canonical address. More... | |
void | setPort (unsigned int port) |
Sets the port number. More... | |
G::Strings | wildcards () const |
Returns an ordered list of wildcard strings that match this address. More... | |
bool | operator== (const Address &) const |
Comparison operator. More... | |
Static Public Member Functions | |
static int | defaultDomain () |
Returns the default address 'domain', eg. PF_INET. More... | |
static Address | invalidAddress () |
Returns an invalid address. More... | |
static Address | broadcastAddress (unsigned int port) |
Returns a broadcast address. More... | |
static Address | localhost (unsigned int port=0U) |
Returns a localhost ("loopback") address. More... | |
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=NULL) |
Returns true if the display string is valid. More... | |
The Address class encapsulates an IP transport address.
The address is stored internally as a 'sockaddr_in/sockaddr_in6' structure and exposed as a 'sockaddr' structure.
Definition at line 48 of file gaddress.h.
GNet::Address::Address | ( | const Address & | addr | ) |
Copy constructor.
Definition at line 523 of file gaddress_ipv4.cpp.
|
explicit |
Constructor taking a storage object.
Definition at line 503 of file gaddress_ipv4.cpp.
GNet::Address::Address | ( | const sockaddr * | addr, |
socklen_t | len | ||
) |
Constructor using a given sockaddr.
The given sockaddr address must be an Internet address (ie. 'addr->sa_family' must be AF_INET or AF_INET6, and 'len' must be the sizeof sockaddr_in or sockaddr_in6).
Throws an exception if an invalid structure.
Definition at line 508 of file gaddress_ipv4.cpp.
GNet::Address::Address | ( | const hostent & | h, |
unsigned int | port | ||
) |
Constructor taking the host part from the first address in the given hostent's list of alternatives.
Throws an exception if an invalid port number. See also: validPort()
Definition at line 488 of file gaddress_ipv4.cpp.
GNet::Address::Address | ( | const hostent & | h, |
const servent & | s | ||
) |
Constructor taking the host part from the first address in the given hostent's list of alternatives, and the port number from the given servent structure.
Definition at line 493 of file gaddress_ipv4.cpp.
|
explicit |
Constructor for a local INADDR_ANY address, taking the port from the given 'servent' structure.
Definition at line 498 of file gaddress_ipv4.cpp.
|
explicit |
Constructor for a local INADDR_ANY address with the given port number.
Throws an exception if an invalid port number. See also: validPort()
Definition at line 473 of file gaddress_ipv4.cpp.
GNet::Address::Address | ( | unsigned int | port, |
Localhost | dummy | ||
) |
Constructor for a local INADDR_LOOPBACK address with the given port number.
Throws an exception if an invalid port number. See also: validPort()
Definition at line 478 of file gaddress_ipv4.cpp.
GNet::Address::Address | ( | unsigned int | port, |
Broadcast | dummy | ||
) |
Constructor for a local INADDR_BROADCAST address with the given port number.
Throws an exception if an invalid port number. See also: validPort()
Definition at line 483 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 513 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 518 of file gaddress_ipv4.cpp.
GNet::Address::~Address | ( | ) |
Destructor.
Definition at line 534 of file gaddress_ipv4.cpp.
const sockaddr * GNet::Address::address | ( | ) | const |
Returns the sockaddr address.
Typically used when making socket system calls. Never returns NULL.
Definition at line 601 of file gaddress_ipv4.cpp.
Referenced by GNet::Socket::bind(), GNet::Socket::connect(), and GNet::DatagramSocket::write().
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 596 of file gaddress_ipv4.cpp.
|
static |
Returns a broadcast address.
Only useful for datagram sockets.
Definition at line 468 of file gaddress_ipv4.cpp.
|
static |
Returns the default address 'domain', eg. PF_INET.
Definition at line 626 of file gaddress_ipv4.cpp.
std::string GNet::Address::displayString | ( | bool | with_port = true , |
bool | with_scope_id = false |
||
) | const |
Returns a string which represents the address for debugging and diagnostics purposes.
Definition at line 581 of file gaddress_ipv4.cpp.
Referenced by GNet::StreamSocket::accept(), GSmtp::AdminServerPeer::AdminServerPeer(), GNet::Socket::bind(), GNet::Server::canBind(), GNet::Socket::connect(), GNet::Server::init(), isLocal(), GNet::Server::readEvent(), GPop::ServerPeer::ServerPeer(), GSmtp::ServerPeer::ServerPeer(), GAuth::SaslServerBasicImp::trusted(), GAuth::SaslServerBasic::trusted(), GSmtp::ExecutableVerifier::verify(), GSmtp::NetworkVerifier::verify(), and GNet::DatagramSocket::write().
int GNet::Address::domain | ( | ) | const |
Returns the address 'domain', eg. PF_INET.
Definition at line 631 of file gaddress_ipv4.cpp.
std::string GNet::Address::hostString | ( | ) | const |
Returns a string which represents the host part of the address for debugging and diagnostics purposes.
Definition at line 586 of file gaddress_ipv4.cpp.
|
static |
Returns an invalid address.
Should only be needed by socket and resolver classes.
Definition at line 458 of file gaddress_ipv4.cpp.
Referenced by GNet::StreamSocket::accept(), GNet::Server::address(), GNet::MultiServer::firstAddress(), GNet::Socket::getAddress(), GNet::SimpleClient::localAddress(), GNet::ResolverImp::onData(), GNet::ResolverImp::onException(), and GNet::SimpleClient::peerAddress().
bool GNet::Address::isLocal | ( | std::string & | reason | ) | const |
Returns true if the address is definitely local.
Returns false if remote or unknown, with a helpful reason string returned by reference.
Definition at line 549 of file gaddress_ipv4.cpp.
Referenced by GNet::Local::isLocal().
bool GNet::Address::isLocal | ( | std::string & | reason, |
const Address & | local_hint | ||
) | const |
An overload with a hint that should be the host's canonical address.
Definition at line 561 of file gaddress_ipv4.cpp.
References displayString().
socklen_t GNet::Address::length | ( | ) | const |
Returns the size of the sockaddr address.
See address().
Definition at line 606 of file gaddress_ipv4.cpp.
Referenced by GNet::Socket::bind(), GNet::Socket::connect(), and GNet::DatagramSocket::write().
|
static |
Returns a localhost ("loopback") address.
This is a convenience function as an alternative to the Localhost constructor.
Definition at line 463 of file gaddress_ipv4.cpp.
Referenced by GNet::Local::localhostAddress().
void GNet::Address::operator= | ( | const Address & | addr | ) |
Assignment operator.
Definition at line 528 of file gaddress_ipv4.cpp.
bool GNet::Address::operator== | ( | const Address & | other | ) | const |
Comparison operator.
Definition at line 544 of file gaddress_ipv4.cpp.
unsigned int GNet::Address::port | ( | ) | const |
Returns port part of address.
Definition at line 611 of file gaddress_ipv4.cpp.
bool GNet::Address::sameHost | ( | const Address & | other | ) | const |
Returns true if the two addresses have the same host part (ie.
ignoring the port). (But note that a host can have more than one host address.)
Definition at line 576 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 616 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 539 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 621 of file gaddress_ipv4.cpp.
References GNet::AddressImp::validPort().
Referenced by GNet::Resolver::resolve().
|
static |
Returns true if the display string is valid.
This can be used to avoid exceptions from the relevant constructor.
Definition at line 591 of file gaddress_ipv4.cpp.
References GNet::AddressImp::validString().
Referenced by GNet::ResolverImp::onData().
G::Strings 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 (eg. "*.*.*.*") comes last.
Definition at line 636 of file gaddress_ipv4.cpp.
References GNet::AddressImp::wildcards().
Referenced by GAuth::SaslServerBasicImp::trusted().