Doxygen with github
Loading...
Searching...
No Matches
ksDomainQuery.h
1/*
2 * Copyright (c) 2020-2026, Krzysztof Strehlau
3 *
4 * This file is a part of the ksIotFrameworkLib IoT library.
5 * All licensing information can be found inside LICENSE.md file.
6 *
7 * https://github.com/cziter15/ksIotFrameworkLib/blob/master/LICENSE
8 */
9
10#pragma once
11
12#include <IPAddress.h>
13#include <cstdint>
14#include <memory>
15#include <string>
16
17#ifdef ESP32
18 #include <esp_arduino_version.h>
19#endif
20
21#if (defined(ESP32) && ESP_ARDUINO_VERSION_MAJOR >= 3)
22 #define ksUdpClient_t NetworkUDP
23#else
24 #define ksUdpClient_t WiFiUDP
25#endif
26
27class ksUdpClient_t;
28
29namespace ksf::misc
30{
38 {
39 protected:
40 /* DNS server IP address. */
41 IPAddress serverIP;
42 /* UDP client. */
43 std::unique_ptr<ksUdpClient_t> udp;
44
45 /* Domain to resolve IP address for. */
46 std::string domain;
47 /* Resolved IP address. */
48 IPAddress resolvedIP;
49 /* Transaction ID (last). */
50 uint16_t transactionID{0};
51 /* Last query send time. */
52 uint32_t lastQuerySendTimeMs{0};
53
57 void sendQuery();
58
62 void receiveResponse();
63
64 public:
70
74 virtual ~ksDomainQuery();
75
80 ksDomainQuery(IPAddress dnsServer);
84 void invalidate();
85
90 void setDomain(std::string domain);
91
97 bool getResolvedIP(IPAddress& ip) const;
98
102 void process();
103 };
104}
Class for resolving domain names to IP addresses using DNS queries.
Definition ksDomainQuery.h:38
ksDomainQuery()
Default constructor. Uses KSF_DOMAIN_QUERY_DNS_SERVER as the DNS server.
Definition ksDomainQuery.cpp:32
void receiveResponse()
Receives DNS response from the DNS server.
Definition ksDomainQuery.cpp:118
void process()
Handles resolver tasks, such as sending queries and receiving responses.
Definition ksDomainQuery.cpp:184
void setDomain(std::string domain)
Sets the domain to resolve IP address for.
Definition ksDomainQuery.cpp:50
virtual ~ksDomainQuery()
Destructor.
bool getResolvedIP(IPAddress &ip) const
Retrieves the resolved IP address for the domain.
Definition ksDomainQuery.cpp:56
void invalidate()
Invalidates the resolved IP address and the last query send time. It will cause a new query to be sen...
Definition ksDomainQuery.cpp:44
void sendQuery()
Sends DNS query to the DNS server.
Definition ksDomainQuery.cpp:70