|
DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
|
Layer 3 (Network) - a family-tagged IP address (IPv4 or IPv6) with RFC-faithful text parsing, canonical formatting, and scope classification. More...
#include <stddef.h>#include <stdint.h>Go to the source code of this file.
Classes | |
| struct | DetIp |
| A v4 or v6 address in network (big-endian) byte order. More... | |
Macros | |
| #define | DET_IP_STR_MAX 46 |
| Longest text an det_ip_format can produce, including the NUL (RFC 5952 v4-mapped). | |
Enumerations | |
| enum class | DetIpFamily : uint8_t { DET_IP_NONE = 0 , DET_IP_V4 = 4 , DET_IP_V6 = 6 } |
| Address family tag. More... | |
| enum class | DetIpScope : uint8_t { DET_IP_SCOPE_UNSPECIFIED = 0 , DET_IP_SCOPE_LOOPBACK , DET_IP_SCOPE_LINK_LOCAL , DET_IP_SCOPE_PRIVATE , DET_IP_SCOPE_MULTICAST , DET_IP_SCOPE_GLOBAL } |
| Address scope, in rough order of reachability (used for allow/deny policy + logging). More... | |
Functions | |
| bool | det_ip_parse (const char *s, DetIp *out) |
Parse an IPv4 or IPv6 textual address (RFC 4291 §2.2) into out. | |
| size_t | det_ip_format (const DetIp *ip, char *out, size_t cap) |
Format ip into out as its RFC 5952 canonical text. | |
| DetIpScope | det_ip_classify (const DetIp *ip) |
Classify ip into a DetIpScope. | |
| bool | det_ip_equal (const DetIp *a, const DetIp *b) |
True if a and b are the same family and address. | |
| bool | det_ip_is_v4_mapped (const DetIp *ip) |
True if ip is an IPv4-mapped IPv6 address (::ffff:a.b.c.d, RFC 4291 §2.5.5.2). | |
| DetIp | det_ip_from_v4_octets (uint8_t a, uint8_t b, uint8_t c, uint8_t d) |
| Build a v4 DetIp from four octets (a.b.c.d). | |
| DetIp | det_ip_from_v6_bytes (const uint8_t bytes[16]) |
| Build a v6 DetIp from 16 address bytes in network (big-endian) order. | |
| uint32_t | det_ip_to_v4_be (const DetIp *ip) |
| The v4 address as a big-endian (network-order) uint32 (a<<24 | b<<16 | c<<8 | d). | |
| bool | det_ip_is_unspecified (const DetIp *ip) |
True if ip is empty (DetIpFamily::DET_IP_NONE) or the all-zero unspecified address (0.0.0.0 / ::). | |
| bool | det_ip_prefix_match (const DetIp *addr, const DetIp *net, uint8_t prefix_len) |
CIDR containment: is addr inside the net / prefix_len block? | |
Layer 3 (Network) - a family-tagged IP address (IPv4 or IPv6) with RFC-faithful text parsing, canonical formatting, and scope classification.
One representation for both address families so the rest of the stack can carry a peer address without caring whether it is v4 or v6. The address bytes are stored in network (big-endian, left-to-right) order: a v4 address uses bytes[0..3], a v6 address bytes[0..15].
Pure and host-testable - no lwIP, no Arduino, no heap, no stdlib parsing. The parser implements RFC 4291 §2.2 text forms (dotted-quad v4; v6 with :: zero-compression and the embedded-v4 ::ffff:a.b.c.d tail); the formatter emits the RFC 5952 canonical form (lower-case, no leading zeros, the longest zero run compressed to ::, v4-mapped shown as dotted). ESP32 dual-stack bring-up (enabling IPv6 on the netif) lives in the physical layer behind DETWS_ENABLE_IPV6; the TCP/UDP listeners already bind IPADDR_TYPE_ANY, so the server accepts v6 connections the moment the interface has a v6 address.
Definition in file ip.h.
| #define DET_IP_STR_MAX 46 |
Longest text an det_ip_format can produce, including the NUL (RFC 5952 v4-mapped).
|
strong |
|
strong |
Address scope, in rough order of reachability (used for allow/deny policy + logging).
| bool det_ip_parse | ( | const char * | s, |
| DetIp * | out | ||
| ) |
Parse an IPv4 or IPv6 textual address (RFC 4291 §2.2) into out.
out->family set to DetIpFamily::DET_IP_V4/V6), false if s is malformed. Definition at line 350 of file ip.cpp.
References DetIp::bytes, DET_IP_V4, DET_IP_V6, and DetIp::family.
Referenced by listener_ip_allow_add_cidr().
| size_t det_ip_format | ( | const DetIp * | ip, |
| char * | out, | ||
| size_t | cap | ||
| ) |
Format ip into out as its RFC 5952 canonical text.
ip is empty or cap is too small (need up to DET_IP_STR_MAX). Definition at line 388 of file ip.cpp.
References DetIp::bytes, det_ip_is_v4_mapped(), DET_IP_STR_MAX, DET_IP_V4, DET_IP_V6, and DetIp::family.
| DetIpScope det_ip_classify | ( | const DetIp * | ip | ) |
Classify ip into a DetIpScope.
Definition at line 448 of file ip.cpp.
References DetIp::bytes, DET_IP_SCOPE_UNSPECIFIED, DET_IP_V4, DET_IP_V6, and DetIp::family.
True if a and b are the same family and address.
Definition at line 459 of file ip.cpp.
References DetIp::bytes, DET_IP_V4, DET_IP_V6, and DetIp::family.
Referenced by listener_accept_allowed_ip().
| bool det_ip_is_v4_mapped | ( | const DetIp * | ip | ) |
True if ip is an IPv4-mapped IPv6 address (::ffff:a.b.c.d, RFC 4291 §2.5.5.2).
Definition at line 443 of file ip.cpp.
References DetIp::bytes, DET_IP_V6, and DetIp::family.
Referenced by det_ip_format(), and det_ip_to_v4_be().
| DetIp det_ip_from_v4_octets | ( | uint8_t | a, |
| uint8_t | b, | ||
| uint8_t | c, | ||
| uint8_t | d | ||
| ) |
Build a v4 DetIp from four octets (a.b.c.d).
Definition at line 473 of file ip.cpp.
References DetIp::bytes, DET_IP_V4, and DetIp::family.
Referenced by det_lwip_to_detip().
| DetIp det_ip_from_v6_bytes | ( | const uint8_t | bytes[16] | ) |
Build a v6 DetIp from 16 address bytes in network (big-endian) order.
Definition at line 485 of file ip.cpp.
References DetIp::bytes, DET_IP_V6, and DetIp::family.
Referenced by det_lwip_to_detip().
| uint32_t det_ip_to_v4_be | ( | const DetIp * | ip | ) |
The v4 address as a big-endian (network-order) uint32 (a<<24 | b<<16 | c<<8 | d).
ip is not a v4 (or v4-mapped) address. Definition at line 493 of file ip.cpp.
References DetIp::bytes, det_ip_is_v4_mapped(), DET_IP_V4, and DetIp::family.
| bool det_ip_is_unspecified | ( | const DetIp * | ip | ) |
True if ip is empty (DetIpFamily::DET_IP_NONE) or the all-zero unspecified address (0.0.0.0 / ::).
Definition at line 505 of file ip.cpp.
References DetIp::bytes, DET_IP_NONE, DET_IP_V4, and DetIp::family.
Referenced by listener_accept_allowed_ip().
CIDR containment: is addr inside the net / prefix_len block?
The two must be the same family. prefix_len is 0..32 for v4, 0..128 for v6; the top prefix_len bits of the address bytes must match net (a prefix of 0 matches everything). This is the standard v4/v6 allowlist match.
addr is covered; false on a family mismatch or an out-of-range prefix. Definition at line 516 of file ip.cpp.
References DetIp::bytes, DET_IP_V4, DET_IP_V6, and DetIp::family.
Referenced by listener_ip_allowed().