21#ifndef G_NET_ADDRESS_H
22#define G_NET_ADDRESS_H
37 class AddressStorage ;
38 class AddressStorageImp ;
73 G_EXCEPTION( Error ,
tx(
"address error") ) ;
74 G_EXCEPTION( BadString ,
tx(
"invalid address") ) ;
75 G_EXCEPTION_CLASS( BadFamily ,
tx(
"unsupported address family") ) ;
77 static bool supports( Family ) noexcept ;
81 static bool supports(
int af ,
int dummy ) noexcept ;
95 Address(
const sockaddr * addr , socklen_t len ) ;
99 Address(
const sockaddr * addr , socklen_t len ,
bool fixup ) ;
121 operator
G::BasicAddress() const ;
127 static Address parse(
const std::string & display_string ) ;
135 static Address parse(
const std::string & host_part_string ,
unsigned int port ) ;
139 static Address parse(
const std::string & host_part_string ,
const std::string &
port ) ;
143 static bool isFamilyLocal(
const std::string & display_string ) noexcept ;
156 const sockaddr *
address()
const ;
167 std::string
displayString(
bool with_scope_id =
false )
const ;
179 unsigned int port()
const;
182 static int domain( Family ) noexcept ;
186 Family
family() const noexcept ;
189 int af() const noexcept ;
192 static
bool validPort(
unsigned int n ) ;
196 static
bool validString( const
std::
string & display_string ,
std::
string * reason =
nullptr ) ;
204 static
bool validStrings( const
std::
string & ip , const
std::
string & port_string ,
std::
string * reason =
nullptr ) ;
209 static
bool validData( const sockaddr * , socklen_t len ) ;
232 unsigned long scopeId(
unsigned long default_ = 0UL ) const ;
242 unsigned int bits() const ;
266 bool is4() const noexcept ;
269 bool is6() const noexcept ;
272 bool same( const
Address & ,
bool ipv6_compare_with_scope ) const ;
275 bool operator==( const
Address & ) const ;
278 bool operator!=( const
Address & ) const ;
285 Address( Family ,
unsigned int ,
int ) ;
286 Address( const
std::
string & display_string ,
bool with_local ) ;
326 const sockaddr * p()
const ;
329 socklen_t n()
const ;
339 std::unique_ptr<AddressStorageImp> m_imp ;
A 'sockaddr' wrapper class for IPv4 addresses.
A 'sockaddr' wrapper class for IPv6 addresses.
A 'sockaddr' wrapper class for local-domain addresses.
A helper class for calling accept(), getsockname() and getpeername() and hiding the definition of soc...
~AddressStorage()
Destructor.
The GNet::Address class encapsulates a TCP/UDP transport address.
bool setZone(const std::string &)
Sets the zone.
Address(Address &&) noexcept
Move constructor.
Address & setScopeId(unsigned long)
Sets the scope-id.
Address(const Address &)
Copy constructor.
bool is6() const noexcept
Returns true if family() is ipv6.
bool isLinkLocal() const
Returns true if this is a link-local address.
static bool isFamilyLocal(const std::string &display_string) noexcept
Returns true if the given address display string looks will parse to Family::local and Family::local ...
int af() const noexcept
Returns the address family number such as AF_INET or AFINET6.
std::string queryString() const
Returns a string that can be used as a prefix for rDNS or DNSBL queries.
G::StringArray wildcards() const
Returns an ordered list of wildcard strings that match this address.
static bool validData(const sockaddr *, socklen_t len)
Returns true if the sockaddr data is valid.
static int domain(Family) noexcept
Returns the address 'domain' for the given family, eg.
static Address loopback(Family, unsigned int port=0U)
Returns a loopback address.
bool is4() const noexcept
Returns true if family() is ipv4.
static bool validPort(unsigned int n)
Returns true if the port number is within the valid range.
bool isUniqueLocal() const
Returns true if this is a locally administered 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.
void swap(Address &other) noexcept
Swaps this with other.
socklen_t length() const
Returns the size of the sockaddr address. See address().
bool isLocal(std::string &reason) const
Returns true if this seems to be a 'local' address, ie.
static Address defaultAddress()
Returns a default address, being the IPv4 wildcard address with a zero port number.
Address & operator=(const Address &)
Assignment operator.
bool isAny() const
Returns true if this is the address family's 'any' address.
static Address parse(const std::string &display_string)
Factory function for any address family.
static bool validString(const std::string &display_string, std::string *reason=nullptr)
Returns true if the transport-address display string is valid.
static bool supports(Family) noexcept
Returns true if the implementation supports the given address family.
bool sameHostPart(const Address &other) const
Returns true if the two addresses have the same host part (ie.
unsigned int bits() const
Returns the number of leading bits set, relevant only to netmask addresses.
std::string displayString(bool with_scope_id=false) const
Returns a printable string that represents the transport address.
unsigned int port() const
Returns port part of the address.
std::string hostPartString() const
Returns a printable string that represents the network address.
bool isMulticast() const
Returns true if this is a multicast address.
bool isLoopback() const
Returns true if this is a loopback address.
const sockaddr * address() const
Returns the sockaddr address.
unsigned long scopeId(unsigned long default_=0UL) const
Returns the scope-id.
Address & setPort(unsigned int port)
Sets the port number.
Family family() const noexcept
Returns the address family enumeration.
bool same(const Address &, bool ipv6_compare_with_scope) const
Comparison function.
std::vector< std::string > StringArray
A std::vector of std::strings.
constexpr const char * tx(const char *p)
A briefer alternative to G::gettext_noop().
Overload discriminator for Address::supports()
Overload discriminator for Address::parse()