21 #ifndef G_NET_ADDRESS__H
22 #define G_NET_ADDRESS__H
36 int inet_pton_imp(
int f ,
const char * p ,
void * result ) ;
37 const char * inet_ntop_imp(
int f ,
void * ap ,
char * buffer ,
size_t n ) ;
62 bool operator==(
const Family & other )
const ;
63 bool operator!=(
const Family & other )
const ;
65 explicit Family(
bool is4_ ) ;
69 G_EXCEPTION( Error ,
"address error" ) ;
70 G_EXCEPTION( BadFamily ,
"unsupported address family" ) ;
71 G_EXCEPTION( BadString ,
"invalid address" ) ;
82 Address(
const sockaddr * addr , socklen_t len ) ;
91 explicit Address(
const std::string & display_string ) ;
95 Address(
const std::string & ip ,
unsigned int port ) ;
112 const sockaddr *
address()
const ;
131 unsigned int port()
const;
137 unsigned long scopeId(
unsigned long default_ = 0UL )
const ;
141 static bool validPort(
unsigned int n ) ;
145 static bool validString(
const std::string & display_string , std::string * reason =
nullptr ) ;
149 static bool validStrings(
const std::string & ip ,
const std::string & port_string , std::string * reason =
nullptr ) ;
154 static bool validData(
const sockaddr * , socklen_t len ) ;
175 bool isLocal( std::string & reason )
const ;
218 const sockaddr *
p()
const ;
221 socklen_t
n()
const ;
234 inline bool GNet::Address::Family::operator==(
const Family & other )
const {
return is4 == other.is4 ; }
235 inline bool GNet::Address::Family::operator!=(
const Family & other )
const {
return is4 != other.is4 ; }
236 inline GNet::Address::Family::Family(
bool is4_ ) : is4(is4_) {}
static Address loopback(Family, unsigned int port=0U)
Returns a loopback address.
Family family() const
Returns the address family.
static bool validData(const sockaddr *, socklen_t len)
Returns true if the sockaddr data is valid.
A helper class for calling accept(), getsockname() and getpeername() and hiding the definition of soc...
The GNet::Address class encapsulates a TCP/UDP transport address.
bool isLoopback() const
Returns true if this is a loopback address.
static bool validStrings(const std::string &ip, const std::string &port_string, std::string *reason=nullptr)
Returns true if the combined network-address string and port string is valid.
std::vector< std::string > StringArray
A std::vector of std::strings.
socklen_t * p2()
Returns the length pointer for accept()/getsockname()/getpeername() to write into.
sockaddr * p1()
Returns the sockaddr pointer for accept()/getsockname()/getpeername() to write into.
A pimple-pattern implementation class used by GNet::AddressStorage.
const sockaddr * address() const
Returns the sockaddr address.
bool sameHostPart(const Address &other) const
Returns true if the two addresses have the same host part (ie.
unsigned int port() const
Returns port part of the address.
bool operator==(const Address &) const
Comparison operator.
const sockaddr * p() const
Returns the pointer.
A 'sockaddr' wrapper class for IPv4 addresses.
AddressStorage()
Default constructor.
static Address defaultAddress()
Returns a default address, being the IPv4 wildcard address with a zero port number.
G::StringArray wildcards() const
Returns an ordered list of wildcard strings that match this address.
socklen_t length() const
Returns the size of the sockaddr address. See address().
std::string hostPartString() const
Returns a string which represents the network address for debugging and diagnostics purposes...
unsigned long scopeId(unsigned long default_=0UL) const
Returns the scope-id.
static bool validString(const std::string &display_string, std::string *reason=nullptr)
Returns true if the transport-address display string is valid.
int domain() const
Returns the address 'domain', eg. PF_INET.
~AddressStorage()
Destructor.
static bool validPort(unsigned int n)
Returns true if the port number is within the valid range.
A type-safe enumerator for IP address family.
bool isLocal(std::string &reason) const
Returns true if this seems to be a local address (for some definition of 'local').
void operator=(const Address &addr)
Assignment operator.
Address(const Address &)
Copy constructor.
void setPort(unsigned int port)
Sets the port number.
socklen_t n() const
Returns the length.
static bool supports(Family)
Returns true if the implementation supports the given address family.
bool operator!=(const Address &) const
Comparison operator.
std::string displayString() const
Returns a string which represents the transport address for debugging and diagnostics purposes...
A 'sockaddr' wrapper class for IPv6 addresses.