21#ifndef G_NET_ADDRESS_H
22#define G_NET_ADDRESS_H
38 class AddressStorage ;
39 class AddressStorageImp ;
74 G_EXCEPTION( Error ,
tx(
"address error") )
75 G_EXCEPTION( BadString ,
tx("invalid
address") )
78 static
bool supports( Family ) noexcept ;
82 static
bool supports(
int af ,
int dummy ) noexcept ;
96 Address( const sockaddr * addr , socklen_t len ) ;
100 Address( const sockaddr * addr , socklen_t len ,
bool fixup ) ;
122 operator
G::BasicAddress() const ;
128 static Address parse( std::string_view display_string ) ;
136 static Address parse( std::string_view host_part_string ,
unsigned int port ) ;
140 static Address parse( std::string_view host_part_string , std::string_view
port ) ;
144 static bool isFamilyLocal( std::string_view display_string ) noexcept ;
157 const sockaddr *
address()
const ;
168 std::string
displayString(
bool with_scope_id =
false )
const ;
180 unsigned int port()
const;
183 static int domain( Family ) noexcept ;
187 Family
family() const noexcept ;
190 int af() const noexcept ;
193 static
bool validPort(
unsigned int n ) ;
197 static
bool validString(
std::string_view display_string ,
std::
string * reason =
nullptr ) ;
205 static
bool validStrings(
std::string_view ip ,
std::string_view port_string ,
std::
string * reason =
nullptr ) ;
210 static
bool validData( const sockaddr * , socklen_t len ) ;
233 unsigned long scopeId(
unsigned long default_ = 0UL ) const ;
243 unsigned int bits() const ;
267 bool is4() const noexcept ;
270 bool is6() const noexcept ;
273 bool same( const
Address & ,
bool ipv6_compare_with_scope ) const ;
276 bool operator==( const
Address & ) const ;
279 bool operator!=( const
Address & ) const ;
286 Address( Family ,
unsigned int ,
int ) ;
287 Address(
std::string_view display_string ,
bool with_local ) ;
327 const sockaddr * p()
const ;
330 socklen_t n()
const ;
340 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 & setScopeId(unsigned long)
Sets the scope-id.
bool is6() const noexcept
Returns true if family() is ipv6.
bool isLinkLocal() const
Returns true if this is a link-local address.
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 bool validString(std::string_view display_string, std::string *reason=nullptr)
Returns true if the transport-address display string is valid.
static bool validStrings(std::string_view ip, std::string_view port_string, std::string *reason=nullptr)
Returns true if the combined network-address string and port string is valid.
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.
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 bool isFamilyLocal(std::string_view display_string) noexcept
Returns true if the given address display string looks will parse to Family::local and Family::local ...
static Address parse(std::string_view display_string)
Factory function for any address family.
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) noexcept
A briefer alternative to G::gettext_noop().
Overload discriminator for Address::supports()
Overload discriminator for Address::parse()