18#if defined(PROMEKI_PLATFORM_WINDOWS)
21#elif !defined(PROMEKI_PLATFORM_EMSCRIPTEN)
22# include <sys/socket.h>
23# include <netinet/in.h>
86#if !defined(PROMEKI_PLATFORM_EMSCRIPTEN)
127 bool isNull()
const {
return std::holds_alternative<std::monostate>(_data); }
130 bool isIPv4()
const {
return std::holds_alternative<Ipv4Address>(_data); }
133 bool isIPv6()
const {
return std::holds_alternative<Ipv6Address>(_data); }
136 bool isHostname()
const {
return std::holds_alternative<String>(_data); }
191#if !defined(PROMEKI_PLATFORM_EMSCRIPTEN)
213 std::variant<std::monostate, Ipv4Address, Ipv6Address, String> _data;
IPv4 network address.
Definition ipv4address.h:51
IPv6 network address.
Definition ipv6address.h:52
Dynamic array container wrapping std::vector.
Definition list.h:40
High-level network address that can represent IPv4, IPv6, or an unresolved hostname.
Definition networkaddress.h:64
bool isLinkLocal() const
Returns true if the address is link-local.
bool isMulticast() const
Returns true if the address is a multicast address.
bool operator==(const NetworkAddress &other) const
Equality comparison.
Definition networkaddress.h:208
String hostname() const
Returns the stored hostname.
bool isNull() const
Returns true if no address is stored.
Definition networkaddress.h:127
Ipv4Address toIpv4() const
Returns the stored IPv4 address.
String toString() const
Returns a string representation.
Type type() const
Returns the type of address stored.
bool isLoopback() const
Returns true if the address is a loopback address.
NetworkAddress(const Ipv4Address &addr)
Constructs from an IPv4 address.
Definition networkaddress.h:109
static Result< NetworkAddress > fromSockAddr(const struct sockaddr *addr, size_t len)
Constructs from a POSIX/Windows sockaddr structure.
NetworkAddress(const Ipv6Address &addr)
Constructs from an IPv6 address.
Definition networkaddress.h:115
bool isResolved() const
Returns true if this holds a resolved IP address (IPv4 or IPv6).
Definition networkaddress.h:139
bool isIPv4() const
Returns true if this holds an IPv4 address.
Definition networkaddress.h:130
NetworkAddress(const String &hostname)
Constructs from a hostname string (unresolved).
Definition networkaddress.h:121
size_t toSockAddr(struct sockaddr_storage *storage) const
Fills a sockaddr_storage with this address.
static Result< NetworkAddress > fromString(const String &str)
Parses a string into a NetworkAddress.
Ipv6Address toIpv6() const
Returns the stored IPv6 address.
bool isHostname() const
Returns true if this holds an unresolved hostname.
Definition networkaddress.h:136
bool isIPv6() const
Returns true if this holds an IPv6 address.
Definition networkaddress.h:133
bool operator!=(const NetworkAddress &other) const
Inequality comparison.
Definition networkaddress.h:210
NetworkAddress()=default
Default constructor. Creates a null address.
Type
The kind of address stored.
Definition networkaddress.h:67
@ Hostname
Unresolved hostname string.
Definition networkaddress.h:71
@ None
No address set.
Definition networkaddress.h:68
@ IPv4
Resolved IPv4 address.
Definition networkaddress.h:69
@ IPv6
Resolved IPv6 address.
Definition networkaddress.h:70
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35
Formatted text I/O with encoding awareness.
Definition textstream.h:54
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19
TextStream & operator<<(TextStream &stream, const NetworkAddress &addr)
Writes the network address to the stream.