17#if defined(PROMEKI_PLATFORM_WINDOWS)
20#elif !defined(PROMEKI_PLATFORM_EMSCRIPTEN)
21# include <netinet/in.h>
104 bool isNull()
const {
return _addr == 0; }
123 if(a == 10)
return true;
124 if(a == 172 && (b & 0xF0) == 16)
return true;
125 if(a == 192 && b == 168)
return true;
139 return (_addr &
mask._addr) == (network._addr &
mask._addr);
163 return static_cast<uint8_t>((_addr >> (24 - index * 8)) & 0xFF);
194#if !defined(PROMEKI_PLATFORM_EMSCRIPTEN)
Lightweight error code wrapper for the promeki library.
Definition error.h:39
IPv4 network address.
Definition ipv4address.h:51
bool isInSubnet(Ipv4Address network, int prefixLen) const
Returns true if this address is within the given subnet.
static Ipv4Address loopback()
Returns the loopback address (127.0.0.1).
Definition ipv4address.h:74
static Result< Ipv4Address > fromSockAddr(const struct sockaddr_in *sa)
Constructs from a sockaddr_in structure.
bool isPrivate() const
Returns true if the address is in a private range.
Definition ipv4address.h:120
uint32_t toUint32() const
Returns the address as a 32-bit integer in network byte order.
Definition ipv4address.h:154
static Ipv4Address any()
Returns the INADDR_ANY address (0.0.0.0).
Definition ipv4address.h:71
uint8_t octet(int index) const
Returns a single octet of the address.
Definition ipv4address.h:161
bool isMulticast() const
Returns true if the address is in the 224.0.0.0/4 multicast range.
Definition ipv4address.h:110
bool isNull() const
Returns true if the address is 0.0.0.0.
Definition ipv4address.h:104
static Ipv4Address fromUint32(uint32_t networkOrder)
Creates an address from a 32-bit integer in network byte order.
Definition ipv4address.h:66
bool operator<(const Ipv4Address &other) const
Less-than comparison for ordering.
Definition ipv4address.h:220
Ipv6Address toIpv6Mapped() const
Converts to an IPv4-mapped IPv6 address (::%ffff:a.b.c.d).
Ipv4Address()
Default constructor. Creates a null (0.0.0.0) address.
Definition ipv4address.h:80
String toString() const
Returns a dotted-quad string representation.
Error toSockAddr(struct sockaddr_in *sa) const
Fills a sockaddr_in with this address.
bool isLinkLocal() const
Returns true if the address is in the 169.254.0.0/16 link-local range.
Definition ipv4address.h:113
bool isBroadcast() const
Returns true if the address is 255.255.255.255.
Definition ipv4address.h:130
Ipv4Address(uint8_t a, uint8_t b, uint8_t c, uint8_t d)
Constructs from four octets.
Definition ipv4address.h:95
bool operator!=(const Ipv4Address &other) const
Returns true if the addresses are not equal.
Definition ipv4address.h:218
static Result< Ipv4Address > fromString(const String &str)
Parses an IPv4 address from dotted-quad notation.
bool operator==(const Ipv4Address &other) const
Returns true if both addresses are equal.
Definition ipv4address.h:216
bool isInSubnet(Ipv4Address network, Ipv4Address mask) const
Returns true if this address is within the given subnet.
Definition ipv4address.h:138
MacAddress multicastMac() const
Returns the Ethernet multicast MAC address for this IPv4 multicast address.
Ipv4Address(uint32_t networkOrder)
Constructs from a 32-bit integer in network byte order.
Definition ipv4address.h:86
static Ipv4Address broadcast()
Returns the broadcast address (255.255.255.255).
Definition ipv4address.h:77
bool isLoopback() const
Returns true if the address is in the 127.0.0.0/8 range.
Definition ipv4address.h:107
IPv6 network address.
Definition ipv6address.h:52
Dynamic array container wrapping std::vector.
Definition list.h:40
IEEE 802 MAC (Ethernet hardware) address.
Definition macaddress.h:44
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35
Formatted text I/O with encoding awareness.
Definition textstream.h:54
TextStream & operator<<(TextStream &stream, const Ipv4Address &addr)
Writes a dotted-quad IPv4 address to the stream.
#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