GNet::Address Class Reference

The Address class encapsulates an IP transport address. More...

#include <gaddress.h>

List of all members.

Public Member Functions

 Address (const Address &addr)
 Copy constructor.
 Address (const AddressStorage &)
 Constructor taking a storage object.
 Address (const sockaddr *addr, socklen_t len)
 Constructor using a given sockaddr.
 Address (const hostent &h, unsigned int port)
 Constructor taking the host part from the first address in the given hostent's list of alternatives.
 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.
 Address (const servent &s)
 Constructor for a local INADDR_ANY address, taking the port from the given 'servent' structure.
 Address (unsigned int port)
 Constructor for a local INADDR_ANY address with the given port number.
 Address (unsigned int port, Localhost)
 Constructor for a local INADDR_LOOPBACK address with the given port number.
 Address (unsigned int port, Broadcast)
 Constructor for a local INADDR_BROADCAST address with the given port number.
 Address (const std::string &display_string)
 Constructor taking a string originally obtained from displayString().
 Address (const std::string &ip, unsigned int port)
 Constructor taking an ip-address and a port number.
 ~Address ()
 Destructor.
void operator= (const Address &addr)
 Assignment operator.
const sockaddr * address () const
 Returns the sockaddr address.
sockaddr * address ()
 This is a non-const version of address() for compiling on systems which are not properly const-clean.
socklen_t length () const
 Returns the size of the sockaddr address.
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.
std::string hostString () const
 Returns a string which represents the host part of the address for debugging and diagnostics purposes.
unsigned int port () const
 Returns port part of address.
int domain () const
 Returns the address 'domain', eg. PF_INET.
unsigned long scopeId (unsigned long default_=0UL) const
 Returns the scope-id.
bool sameHost (const Address &other) const
 Returns true if the two addresses have the same host part (ie.
bool isLocal (std::string &reason) const
 Returns true if the address is definitely local.
bool isLocal (std::string &reason, const Address &local_hint) const
 An overload with a hint that should be the host's canonical address.
void setPort (unsigned int port)
 Sets the port number.
G::Strings wildcards () const
 Returns an ordered list of wildcard strings that match this address.
bool operator== (const Address &other) const
 Comparison operator.

Static Public Member Functions

static int defaultDomain ()
 Returns the default address 'domain', eg. PF_INET.
static Address invalidAddress ()
 Returns an invalid address.
static Address broadcastAddress (unsigned int port)
 Returns a broadcast address.
static Address localhost (unsigned int port=0U)
 Returns a localhost ("loopback") address.
static bool validPort (unsigned int n)
 Returns true if the port number is within the valid range.
static bool validString (const std::string &display_string, std::string *reason=NULL)
 Returns true if the display string is valid.

Classes

class  Broadcast
 An overload discriminator class for GNet::Address. More...
class  Localhost
 An overload discriminator class for GNet::Address. More...


Detailed Description

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.

See also:
GNet::Resolver

Definition at line 48 of file gaddress.h.


Constructor & Destructor Documentation

GNet::Address::Address ( const Address addr  ) 

Copy constructor.

Definition at line 425 of file gaddress_ipv4.cpp.

Referenced by broadcastAddress(), invalidAddress(), and localhost().

GNet::Address::Address ( const AddressStorage storage  )  [explicit]

Constructor taking a storage object.

Definition at line 405 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 410 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 390 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 395 of file gaddress_ipv4.cpp.

GNet::Address::Address ( const servent &  s  )  [explicit]

Constructor for a local INADDR_ANY address, taking the port from the given 'servent' structure.

Definition at line 400 of file gaddress_ipv4.cpp.

GNet::Address::Address ( unsigned int  port  )  [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 375 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 380 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 385 of file gaddress_ipv4.cpp.

GNet::Address::Address ( const std::string &  display_string  )  [explicit]

Constructor taking a string originally obtained from displayString().

Throws an exception if an invalid string.

See also validString().

Definition at line 415 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 420 of file gaddress_ipv4.cpp.

GNet::Address::~Address (  ) 

Destructor.

Definition at line 436 of file gaddress_ipv4.cpp.


Member Function Documentation

int GNet::Address::defaultDomain (  )  [static]

Returns the default address 'domain', eg. PF_INET.

Definition at line 528 of file gaddress_ipv4.cpp.

Referenced by domain().

GNet::Address GNet::Address::invalidAddress (  )  [static]

GNet::Address GNet::Address::broadcastAddress ( unsigned int  port  )  [static]

Returns a broadcast address.

Only useful for datagram sockets.

Definition at line 370 of file gaddress_ipv4.cpp.

References Address().

GNet::Address GNet::Address::localhost ( unsigned int  port = 0U  )  [static]

Returns a localhost ("loopback") address.

This is a convenience function as an alternative to the Localhost constructor.

Definition at line 365 of file gaddress_ipv4.cpp.

References Address().

Referenced by isLocal(), and GNet::Local::localhostAddress().

void GNet::Address::operator= ( const Address addr  ) 

Assignment operator.

Definition at line 430 of file gaddress_ipv4.cpp.

References m_imp.

const sockaddr * GNet::Address::address (  )  const

Returns the sockaddr address.

Typically used when making socket system calls. Never returns NULL.

Definition at line 503 of file gaddress_ipv4.cpp.

References GNet::AddressImp::raw().

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 498 of file gaddress_ipv4.cpp.

References GNet::AddressImp::raw().

socklen_t GNet::Address::length (  )  const

Returns the size of the sockaddr address.

See address().

Definition at line 508 of file gaddress_ipv4.cpp.

Referenced by GNet::Socket::bind(), GNet::Socket::connect(), and GNet::DatagramSocket::write().

std::string GNet::Address::displayString ( bool  with_port = true,
bool  with_scope_id = false 
) const

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 488 of file gaddress_ipv4.cpp.

References GNet::AddressImp::hostString().

unsigned int GNet::Address::port (  )  const

Returns port part of address.

Definition at line 513 of file gaddress_ipv4.cpp.

References GNet::AddressImp::port().

Referenced by GNet::Local::canonicalAddress().

int GNet::Address::domain (  )  const

Returns the address 'domain', eg. PF_INET.

Definition at line 533 of file gaddress_ipv4.cpp.

References defaultDomain().

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 518 of file gaddress_ipv4.cpp.

bool GNet::Address::validPort ( unsigned int  n  )  [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 523 of file gaddress_ipv4.cpp.

References GNet::AddressImp::validPort().

Referenced by GNet::Resolver::resolve().

bool GNet::Address::validString ( const std::string &  display_string,
std::string *  reason = NULL 
) [static]

Returns true if the display string is valid.

This can be used to avoid exceptions from the relevant constructor.

Definition at line 493 of file gaddress_ipv4.cpp.

References GNet::AddressImp::validString().

Referenced by GNet::ResolverImp::onData().

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 478 of file gaddress_ipv4.cpp.

References m_imp, and GNet::AddressImp::sameHost().

Referenced by isLocal().

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 451 of file gaddress_ipv4.cpp.

References displayString(), localhost(), and sameHost().

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 463 of file gaddress_ipv4.cpp.

References displayString(), localhost(), and sameHost().

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 441 of file gaddress_ipv4.cpp.

References GNet::AddressImp::setPort().

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 538 of file gaddress_ipv4.cpp.

References displayString(), G::Str::fromUInt(), G_ASSERT, G::Str::isUInt(), result, G::Str::splitIntoFields(), and G::Str::toUInt().

Referenced by GSmtp::SaslServerImp::trusted().

bool GNet::Address::operator== ( const Address other  )  const

Comparison operator.

Definition at line 446 of file gaddress_ipv4.cpp.

References m_imp, and GNet::AddressImp::same().


The documentation for this class was generated from the following files:

Generated on Fri Apr 18 15:56:13 2008 for E-MailRelay by  doxygen 1.5.5