IPv4 network address. More...
#include <ipv4address.h>
Public Member Functions | |
| Ipv4Address () | |
| Default constructor. Creates a null (0.0.0.0) address. | |
| Ipv4Address (uint32_t networkOrder) | |
| Constructs from a 32-bit integer in network byte order. | |
| Ipv4Address (uint8_t a, uint8_t b, uint8_t c, uint8_t d) | |
| Constructs from four octets. | |
| bool | isNull () const |
| Returns true if the address is 0.0.0.0. | |
| bool | isLoopback () const |
| Returns true if the address is in the 127.0.0.0/8 range. | |
| bool | isMulticast () const |
| Returns true if the address is in the 224.0.0.0/4 multicast range. | |
| bool | isLinkLocal () const |
| Returns true if the address is in the 169.254.0.0/16 link-local range. | |
| bool | isPrivate () const |
| Returns true if the address is in a private range. | |
| bool | isBroadcast () const |
| Returns true if the address is 255.255.255.255. | |
| bool | isInSubnet (Ipv4Address network, Ipv4Address mask) const |
| Returns true if this address is within the given subnet. | |
| bool | isInSubnet (Ipv4Address network, int prefixLen) const |
| Returns true if this address is within the given subnet. | |
| uint32_t | toUint32 () const |
| Returns the address as a 32-bit integer in network byte order. | |
| uint8_t | octet (int index) const |
| Returns a single octet of the address. | |
| String | toString () const |
| Returns a dotted-quad string representation. | |
| Ipv6Address | toIpv6Mapped () const |
| Converts to an IPv4-mapped IPv6 address (::%ffff:a.b.c.d). | |
| MacAddress | multicastMac () const |
| Returns the Ethernet multicast MAC address for this IPv4 multicast address. | |
| Error | toSockAddr (struct sockaddr_in *sa) const |
| Fills a sockaddr_in with this address. | |
| bool | operator== (const Ipv4Address &other) const |
| Returns true if both addresses are equal. | |
| bool | operator!= (const Ipv4Address &other) const |
| Returns true if the addresses are not equal. | |
| bool | operator< (const Ipv4Address &other) const |
| Less-than comparison for ordering. | |
Static Public Member Functions | |
| static Result< Ipv4Address > | fromString (const String &str) |
| Parses an IPv4 address from dotted-quad notation. | |
| static Ipv4Address | fromUint32 (uint32_t networkOrder) |
| Creates an address from a 32-bit integer in network byte order. | |
| static Ipv4Address | any () |
| Returns the INADDR_ANY address (0.0.0.0). | |
| static Ipv4Address | loopback () |
| Returns the loopback address (127.0.0.1). | |
| static Ipv4Address | broadcast () |
| Returns the broadcast address (255.255.255.255). | |
| static Result< Ipv4Address > | fromSockAddr (const struct sockaddr_in *sa) |
| Constructs from a sockaddr_in structure. | |
IPv4 network address.
Simple value type representing a 32-bit IPv4 address stored in network byte order (big-endian). Provides parsing, formatting, subnet checks, and classification (loopback, multicast, private, etc.).
This class is purely computational and requires no platform-specific headers or system calls.
This class is not thread-safe. Concurrent access to a single instance requires external synchronization.
|
inlineexplicit |
Constructs from a 32-bit integer in network byte order.
| networkOrder | The address in network byte order (big-endian). |
Constructs from four octets.
| a | First octet (most significant). |
| b | Second octet. |
| c | Third octet. |
| d | Fourth octet (least significant). |
|
static |
Constructs from a sockaddr_in structure.
| sa | Pointer to a sockaddr_in. Must have sin_family == AF_INET. |
|
static |
Parses an IPv4 address from dotted-quad notation.
| str | The string to parse (e.g. "192.168.1.1"). |
|
inlinestatic |
Creates an address from a 32-bit integer in network byte order.
| networkOrder | The address in network byte order. |
| bool Ipv4Address::isInSubnet | ( | Ipv4Address | network, |
| int | prefixLen | ||
| ) | const |
Returns true if this address is within the given subnet.
| network | The network address. |
| prefixLen | The prefix length (0-32). |
|
inline |
Returns true if this address is within the given subnet.
| network | The network address. |
| mask | The subnet mask. |
|
inline |
Returns true if the address is in a private range.
Checks for 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16.
| MacAddress Ipv4Address::multicastMac | ( | ) | const |
Returns the Ethernet multicast MAC address for this IPv4 multicast address.
Maps this address to its IANA multicast MAC (01:00:5e + low 23 bits) per RFC 1112. Only 23 of the 28 multicast group bits are used, so 32 different multicast IPs share each MAC address. Use this to check for multicast MAC collisions:
|
inline |
Returns a single octet of the address.
| index | Octet index (0 = most significant, 3 = least significant). |
| Ipv6Address Ipv4Address::toIpv6Mapped | ( | ) | const |
Converts to an IPv4-mapped IPv6 address (::%ffff:a.b.c.d).
| Error Ipv4Address::toSockAddr | ( | struct sockaddr_in * | sa | ) | const |
Fills a sockaddr_in with this address.
Sets sin_family to AF_INET and sin_addr. The port field (sin_port) is set to zero; callers should set it separately.
| [out] | sa | The structure to fill. |
| String Ipv4Address::toString | ( | ) | const |
Returns a dotted-quad string representation.
|
inline |
Returns the address as a 32-bit integer in network byte order.