|
DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
|
Authoritative DNS server (UDP/53) - resolve local names on an offline LAN. More...
#include <stddef.h>#include <stdint.h>Go to the source code of this file.
Typedefs | |
| typedef uint32_t(* | DnsResolveFn) (const char *name) |
| Resolve a queried name to an IPv4 address. | |
Functions | |
| size_t | dns_server_build_response (const uint8_t *query, size_t qlen, uint32_t ttl, DnsResolveFn resolve, uint8_t *out, size_t out_cap) |
Build a DNS reply to query. Pure - no clock, no I/O. | |
| bool | dns_server_add (const char *name, uint8_t a, uint8_t b, uint8_t c, uint8_t d) |
| Add an A record to the built-in table (case-insensitive name). | |
| uint32_t | dns_server_lookup (const char *name) |
Look name up in the built-in table. | |
| void | dns_server_clear () |
| Remove every record from the built-in table. | |
| bool | dns_server_begin () |
| Start answering DNS queries on UDP/53 from the built-in table. | |
Authoritative DNS server (UDP/53) - resolve local names on an offline LAN.
A tiny name server for a network with no path to a real DNS: register name -> IPv4 A records with dns_server_add() and the device answers matching A/IN queries from that fixed table (NXDOMAIN for anything else). Devices can then use printer.lan instead of 192.168.1.5, a companion to the NTP server for self-hosted, offline infrastructure. Zero heap; gated by DETWS_ENABLE_DNS_SERVER.
The response builder (dns_server_build_response) is pure - it parses the query and, via a resolver callback, writes the reply - so the wire format is host-tested with no lwIP. dns_server_begin() binds UDP/53 through the transport UDP service and serves the built-in table (dns_server_lookup). It is a general resolver, distinct from the provisioning captive-portal DNS (which points every name at the softAP); do not enable both.
Definition in file dns_server.h.
| typedef uint32_t(* DnsResolveFn) (const char *name) |
Resolve a queried name to an IPv4 address.
| name | the queried name, lower/upper case as sent (match case-insensitively). |
Definition at line 35 of file dns_server.h.
| size_t dns_server_build_response | ( | const uint8_t * | query, |
| size_t | qlen, | ||
| uint32_t | ttl, | ||
| DnsResolveFn | resolve, | ||
| uint8_t * | out, | ||
| size_t | out_cap | ||
| ) |
Build a DNS reply to query. Pure - no clock, no I/O.
Parses the first question; for an A/IN query it looks the name up via resolve and, on a hit, appends a single A answer (compressed name pointer, ttl, the address). A miss on an A query returns NXDOMAIN; a non-A query returns no answer with RCODE 0. The query id and the recursion-desired bit are preserved and AA (authoritative) is set.
| query | the received query bytes. |
| qlen | length of query (must be >= 12, the DNS header). |
| ttl | TTL (seconds) to advertise on the answer. |
| resolve | the name -> IPv4 resolver. |
| out | output buffer. |
| out_cap | capacity of out. |
| bool dns_server_add | ( | const char * | name, |
| uint8_t | a, | ||
| uint8_t | b, | ||
| uint8_t | c, | ||
| uint8_t | d | ||
| ) |
Add an A record to the built-in table (case-insensitive name).
| uint32_t dns_server_lookup | ( | const char * | name | ) |
Look name up in the built-in table.
| void dns_server_clear | ( | ) |
Remove every record from the built-in table.
| bool dns_server_begin | ( | ) |
Start answering DNS queries on UDP/53 from the built-in table.