33 throw GNet::Address::BadFamily() ;
39 return f == Family::ipv4() ;
44 return Address( Family::ipv4() , 0U ) ;
54 m_4imp( new
Address4(storage.p(),storage.n()) )
74 m_4imp( new
Address4(*other.m_4imp) )
79 m_4imp( new
Address4(port,loopback_overload) )
86 return Address( f , port , 1 ) ;
92 std::swap( m_4imp , temp.m_4imp ) ;
102 m_4imp->setPort( port ) ;
107 return m_4imp->isLoopback() ;
112 return m_4imp->isLocal( reason ) ;
117 return m_4imp->same(*other.m_4imp) ;
122 return !( *
this == other ) ;
127 return m_4imp->sameHostPart(*other.m_4imp) ;
132 return m_4imp->displayString() ;
137 return m_4imp->hostPartString() ;
142 return Address4::validString( s , reason_p ) ;
147 return Address4::validStrings( s1 , s2 , reason_p ) ;
152 return m_4imp->address() ;
157 return m_4imp->address() ;
162 return Address4::length() ;
167 return m_4imp->port() ;
177 return Address4::validPort( port ) ;
182 return Address4::validData( addr , len ) ;
187 return Address4::domain() ;
192 return Family::ipv4() ;
197 return m_4imp->wildcards() ;
227 return &(m_imp->u.general) ;
237 return &m_imp->u.general ;
247 #if ! GCONFIG_HAVE_INET_PTON
249 int GNet::inet_pton_imp(
int f ,
const char * p ,
void * result )
251 if( p ==
nullptr || result ==
nullptr )
255 else if( f == AF_INET )
257 static sockaddr_in sa_zero ;
258 sockaddr_in sa = sa_zero ;
259 sa.sin_family = AF_INET ;
260 sa.sin_addr.s_addr = inet_addr( p ) ;
261 *
reinterpret_cast<struct in_addr*
>(result) = sa.sin_addr ;
271 #if ! GCONFIG_HAVE_INET_NTOP
273 const char * GNet::inet_ntop_imp(
int f ,
void * ap ,
char * buffer ,
size_t n )
277 std::ostringstream ss ;
278 struct in_addr a = *
reinterpret_cast<struct in_addr*
>(ap) ;
279 ss << inet_ntoa( a ) ;
280 if( n <= ss.str().length() )
return nullptr ;
281 std::strncpy( buffer , ss.str().c_str() , n ) ;
static Address loopback(Family, unsigned int port=0U)
Returns a loopback address.
Used by GNet::Address4 to cast between sockaddr and sockaddr_in.
Family family() const
Returns the address family.
static bool validData(const sockaddr *, socklen_t len)
Returns true if the sockaddr data is valid.
and hiding the definition of sockaddr_storage.
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 ip 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 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.
void operator=(const Address &addr)
Assignment operator.
Address(const Address &)
Copy constructor.
This file is formatted for side-by-side comparison with gaddress6.h.
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...