DeterministicESPAsyncWebServer v6.28.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
dns_resolver.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file dns_resolver.h
6 * @brief DNS resolver with answer verification (DETWS_ENABLE_DNS_RESOLVER).
7 *
8 * Resolves a hostname to an IPv4 address via lwIP (dns_gethostbyname, marshalled
9 * to tcpip_thread like the http_client), and classifies / verifies the answer:
10 * a remote name resolving to 0.0.0.0, the broadcast address, loopback, or a
11 * multicast address is rejected as a spoof / DNS-rebinding indicator. The
12 * classifier + verifier are pure and host-tested; the resolve is ESP32-only and
13 * blocking (call it off the request hot path).
14 *
15 * @author Douglas Quigg (dstroy0)
16 * @date 2026
17 */
18
19#ifndef DETERMINISTICESPASYNCWEBSERVER_DNS_RESOLVER_H
20#define DETERMINISTICESPASYNCWEBSERVER_DNS_RESOLVER_H
21
22#include "ServerConfig.h"
23#include <stddef.h>
24#include <stdint.h>
25
26#if DETWS_ENABLE_DNS_RESOLVER
27
28/** @brief IPv4 address category (RFC special-purpose ranges). */
29enum class DetwsIpClass : uint8_t
30{
31 DETWS_IP_UNSPECIFIED = 0, ///< 0.0.0.0
32 DETWS_IP_LOOPBACK, ///< 127.0.0.0/8
33 DETWS_IP_PRIVATE, ///< 10/8, 172.16/12, 192.168/16
34 DETWS_IP_LINKLOCAL, ///< 169.254.0.0/16
35 DETWS_IP_MULTICAST, ///< 224.0.0.0/4
36 DETWS_IP_BROADCAST, ///< 255.255.255.255
37 DETWS_IP_PUBLIC, ///< globally-routable unicast
38};
39
40// ---------------------------------------------------------------------------
41// Host-testable core
42// ---------------------------------------------------------------------------
43
44/** @brief Classify a host-order IPv4 word (e.g. (10u << 24) | (0u << 16) | (0u << 8) | 1u). */
45DetwsIpClass detws_dns_classify(uint32_t ip);
46
47/**
48 * @brief Is @p ip a plausible A-record answer for a remote host?
49 *
50 * Rejects unspecified / broadcast / loopback / multicast (spoof / rebinding
51 * indicators); accepts private / link-local / public. Host order.
52 */
53bool detws_dns_verify(uint32_t ip);
54
55// ---------------------------------------------------------------------------
56// Resolve (ESP32; returns false on host)
57// ---------------------------------------------------------------------------
58
59/**
60 * @brief Resolve @p host to an IPv4 address (host order) into @p out_ip.
61 *
62 * Accepts a dotted-quad directly; otherwise queries DNS with a
63 * DETWS_DNS_TIMEOUT_MS deadline. Blocking. @return true on success.
64 */
65bool detws_dns_resolve(const char *host, uint32_t *out_ip);
66
67/**
68 * @brief Resolve @p host and require the answer to pass detws_dns_verify().
69 * @return true only if it resolved AND the address is a plausible answer.
70 */
71bool detws_dns_resolve_verified(const char *host, uint32_t *out_ip);
72
73#if !defined(ARDUINO)
74/** @brief Host test hook: make detws_dns_resolve() return @p ip (host order) when @p ok, else fail. */
75void detws_dns_test_set_resolve(bool ok, uint32_t ip);
76#endif
77
78#endif // DETWS_ENABLE_DNS_RESOLVER
79#endif // DETERMINISTICESPASYNCWEBSERVER_DNS_RESOLVER_H
User-facing configuration for DeterministicESPAsyncWebServer.