25#ifndef JOIN_CORE_IPADDRESS_HPP
26#define JOIN_CORE_IPADDRESS_HPP
36#include <sys/socket.h>
37#include <netinet/in.h>
174 const void*
addr ()
const;
180 socklen_t
length ()
const;
186 uint32_t
scope ()
const;
317 std::string
toArpa ()
const;
351 const uint8_t&
operator[] (
size_t position)
const;
379 std::unique_ptr<IpAddressImpl> _ip;
474 const uint8_t* bytes =
reinterpret_cast<const uint8_t*
> (ipAddress.addr ());
475 for (socklen_t i = 0; i < ipAddress.length (); ++i)
477 h ^= std::hash<uint8_t>{}(bytes[i] + 0x9e3779b9 + (h << 6) + (h >> 2));
IPv6, IPv4 address class.
Definition ipaddress.hpp:51
bool isIpv4Mapped() const
check if IP address is IPv4 mapped.
Definition ipaddress.cpp:1429
bool isLinkLocal() const
check if IP address is link local.
Definition ipaddress.cpp:1313
IpAddress & operator=(const IpAddress &address)
assign the IpAddress instance by copy.
Definition ipaddress.cpp:1189
bool isIpv4Address() const
check if IP address is an IPv4 address.
Definition ipaddress.cpp:1438
static const IpAddress ipv6Routers
routers multicast IPv6 address.
Definition ipaddress.hpp:363
static const IpAddress ipv6AllNodes
all nodes multicast IPv6 address.
Definition ipaddress.hpp:357
static const IpAddress ipv6SolicitedNodes
solicited nodes multicast IPv6 address.
Definition ipaddress.hpp:360
IpAddress operator~() const
perform NOT operation on IP address.
Definition ipaddress.cpp:1553
bool isSiteLocal() const
check if IP address is site local (deprecated).
Definition ipaddress.cpp:1322
bool isIpv4Compat() const
check if IP address is IPv4 compatible (deprecated).
Definition ipaddress.cpp:1420
std::string toString() const
convert internal address structure to string.
Definition ipaddress.cpp:1499
static constexpr socklen_t ipv6Length
IPv6 length.
Definition ipaddress.hpp:366
bool isLoopBack() const
check if IP address is a loopback address.
Definition ipaddress.cpp:1304
int prefix() const
get prefix length from netmask address.
Definition ipaddress.cpp:1286
uint32_t scope() const
get the scope identifier of the address.
Definition ipaddress.cpp:1277
uint8_t & operator[](size_t position)
returns a reference to the element at the specified location.
Definition ipaddress.cpp:1573
void clear()
clear IP address (wilcard address).
Definition ipaddress.cpp:1517
bool isBroadcast(int prefix=0) const
check if IP address is a broadcast address.
Definition ipaddress.cpp:1349
int family() const
get address family.
Definition ipaddress.cpp:1250
static const IpAddress ipv4Wildcard
wildcard IPv4 address.
Definition ipaddress.hpp:369
~IpAddress()
destroy the IpAddress instance.
Definition ipaddress.cpp:1242
socklen_t length() const
get the size in byte of the internal address structure.
Definition ipaddress.cpp:1268
static const IpAddress ipv4Broadcast
broadcast IPv4 address.
Definition ipaddress.hpp:372
std::string toArpa() const
convert IP address to the in-addr.arpa or ip6.arpa domain name.
Definition ipaddress.cpp:1508
bool isGlobal() const
check if IP address is global.
Definition ipaddress.cpp:1367
bool isUnicast() const
check if IP address is unicast.
Definition ipaddress.cpp:1331
IpAddress toIpv6() const
convert IP address to an IPv6 address.
Definition ipaddress.cpp:1464
static IpAddress ipv4Address(const std::string &interface)
get the specified interface IPv4 address.
Definition ipaddress.cpp:1526
bool isMulticast() const
check if IP address is multicast.
Definition ipaddress.cpp:1358
static constexpr socklen_t ipv4Length
IPv4 length.
Definition ipaddress.hpp:375
bool isWildcard() const
check if IP address is a wildcard address.
Definition ipaddress.cpp:1295
static bool isIpAddress(const std::string &address)
check if the specified string is an IP address.
Definition ipaddress.cpp:1376
const void * addr() const
get the internal address structure.
Definition ipaddress.cpp:1259
static const IpAddress ipv6Wildcard
wildcard IPv6 address.
Definition ipaddress.hpp:354
IpAddress()
create the IpAddress instance (default: IPv6 wildcard address).
Definition ipaddress.cpp:947
IpAddress toIpv4() const
convert IP address to an IPv4 address.
Definition ipaddress.cpp:1483
bool isUniqueLocal() const
check if IP address is unique local.
Definition ipaddress.cpp:1340
bool isIpv6Address() const
check if IP address is an IPv6 address.
Definition ipaddress.cpp:1394
Definition acceptor.hpp:32
bool operator<(const BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoint is lower.
Definition endpoint.hpp:207
IpAddress operator^(const IpAddress &a, const IpAddress &b)
perform XOR operation on IP address.
Definition ipaddress.cpp:1719
bool operator>(const BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoint is greater.
Definition endpoint.hpp:219
IpAddress operator&(const IpAddress &a, const IpAddress &b)
perform AND operation on IP address.
Definition ipaddress.cpp:1665
bool operator!=(const BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoints are not equal.
Definition endpoint.hpp:195
bool operator>=(const BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoint is greater or equal.
Definition endpoint.hpp:243
std::ostream & operator<<(std::ostream &os, const BasicUnixEndpoint< Protocol > &endpoint)
push endpoint representation into a stream.
Definition endpoint.hpp:255
bool operator<=(const BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoint is lower or equal.
Definition endpoint.hpp:231
IpAddress operator|(const IpAddress &a, const IpAddress &b)
perform OR operation on IP address.
Definition ipaddress.cpp:1692
bool operator==(const BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoints are equal.
Definition endpoint.hpp:183
std::vector< IpAddress > IpAddressList
List of IP address.
Definition ipaddress.hpp:45
IpAddress address
Definition tcpacceptor_test.cpp:35