+
+const byte DNS_PORT = 53;
+
+IPAddress apIP;
+
+AsyncDNSServer dnsServer;
+AsyncWebServer server(80);
+
+String responseHTML = ""
+ ""
+ ""
+ "ESP32_W6100-CaptivePortal"
+ "Hello World from ESP32_W6100!
This is a captive portal example."
+ " All requests will be redirected here.
";
+
+void handleNotFound(AsyncWebServerRequest *request)
+{
+ request->send(200, "text/html", responseHTML);
+}
+
+void setup()
+{
+ Serial.begin(115200);
+
+ while (!Serial && (millis() < 5000));
+
+ Serial.print(F("\nStart AsyncCaptivePortal_ESP32_W6100 on "));
+ Serial.print(ARDUINO_BOARD);
+ Serial.print(F(" with "));
+ Serial.println(SHIELD_TYPE);
+ Serial.println(WEBSERVER_ESP32_W6100_VERSION);
+ Serial.println(ASYNC_UDP_ESP32_W6100_VERSION);
+ Serial.println(ASYNC_DNS_SERVER_ESP32_W6100_VERSION);
+
+ Serial.setDebugOutput(true);
+
+ UDP_LOGWARN(F("Default SPI pinout:"));
+ UDP_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST);
+ UDP_LOGWARN1(F("MOSI:"), MOSI_GPIO);
+ UDP_LOGWARN1(F("MISO:"), MISO_GPIO);
+ UDP_LOGWARN1(F("SCK:"), SCK_GPIO);
+ UDP_LOGWARN1(F("CS:"), CS_GPIO);
+ UDP_LOGWARN1(F("INT:"), INT_GPIO);
+ UDP_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
+ UDP_LOGWARN(F("========================="));
+
+ ///////////////////////////////////
+
+ // To be called before ETH.begin()
+ ESP32_W6100_onEvent();
+
+ // start the ethernet connection and the server:
+ // Use DHCP dynamic IP and random mac
+ //bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
+ // int SPI_HOST, uint8_t *W6100_Mac = W6100_Default_Mac);
+ ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
+ //ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] );
+
+ // Static IP, leave without this line to get IP via DHCP
+ //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
+ //ETH.config(myIP, myGW, mySN, myDNS);
+
+ ESP32_W6100_waitForConnect();
+
+ ///////////////////////////////////
+
+ apIP = ETH.localIP();
+
+ ///////////////////////////////////
+
+ // modify TTL associated with the domain name (in seconds)
+ // default is 60 seconds
+ dnsServer.setTTL(300);
+ // set which return code will be used for all other domains (e.g. sending
+ // ServerFailure instead of NonExistentDomain will reduce number of queries
+ // sent by clients)
+ // default is AsyncDNSReplyCode::NonExistentDomain
+ dnsServer.setErrorReplyCode(AsyncDNSReplyCode::ServerFailure);
+
+ // if DNSServer is started with "*" for domain name, it will reply with
+ // provided IP to all DNS request
+ dnsServer.start(DNS_PORT, "*", apIP);
+
+ server.onNotFound(handleNotFound);
+
+ server.begin();
+
+ Serial.print(F("AsyncDNSServer is @ IP : "));
+ Serial.println(apIP);
+}
+
+void loop()
+{
+}
diff --git a/examples/AsyncDNSServer_ESP32_W6100/AsyncDNSServer_ESP32_W6100.ino b/examples/AsyncDNSServer_ESP32_W6100/AsyncDNSServer_ESP32_W6100.ino
new file mode 100644
index 0000000..4caa9ad
--- /dev/null
+++ b/examples/AsyncDNSServer_ESP32_W6100/AsyncDNSServer_ESP32_W6100.ino
@@ -0,0 +1,168 @@
+/****************************************************************************************************************************
+ AsyncDNSServer_ESP32_W6100.ino
+
+ AFor ESP32_W6100 (ESP32 + W6100)
+
+ AsyncDNSServer_ESP32_W6100 is a Async DNS Server library for the ESP32_W6100
+
+ Based on and modified from ESPAsyncDNSServer Library (https://github.com/devyte/ESPAsyncDNSServer)
+ Built by Khoi Hoang https://github.com/khoih-prog/AsyncDNSServer_ESP32_W6100
+ Licensed under GPLv3 license
+ *****************************************************************************************************************************/
+
+#if !( defined(ESP32) )
+ #error This code is designed for (ESP32 + W6100) to run on ESP32 platform! Please check your Tools->Board setting.
+#endif
+
+#define ASYNC_DNS_ESP32_W6100_DEBUG_PORT Serial
+
+// Use from 0 to 4. Higher number, more debugging messages and memory usage.
+#define _ASYNC_DNS_ESP32_W6100_LOGLEVEL_ 1
+
+/////////////////////////////////////////////
+
+// Enter a MAC address and IP address for your controller below.
+#define NUMBER_OF_MAC 20
+
+byte mac[][NUMBER_OF_MAC] =
+{
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
+};
+
+// Select the IP address according to your local network
+IPAddress myIP(192, 168, 2, 232);
+IPAddress myGW(192, 168, 2, 1);
+IPAddress mySN(255, 255, 255, 0);
+
+// Google DNS Server IP
+IPAddress myDNS(8, 8, 8, 8);
+
+//////////////////////////////////////////////////////////
+
+// Optional values to override default settings
+// Don't change unless you know what you're doing
+//#define ETH_SPI_HOST SPI3_HOST
+//#define SPI_CLOCK_MHZ 25
+
+// Must connect INT to GPIOxx or not working
+//#define INT_GPIO 4
+
+//#define MISO_GPIO 19
+//#define MOSI_GPIO 23
+//#define SCK_GPIO 18
+//#define CS_GPIO 5
+
+//////////////////////////////////////////////////////////
+
+#include
+#include
+
+const byte DNS_PORT = 53;
+
+IPAddress apIP;
+
+AsyncDNSServer dnsServer;
+
+AsyncWebServer server(80);
+
+void handleNotFound(AsyncWebServerRequest *request)
+{
+ String message = "Hello World from " + String(ARDUINO_BOARD);
+ message += "\nURI: ";
+ message += request->url();
+
+ request->send(200, "text/plain", message);
+}
+
+
+void setup()
+{
+ Serial.begin(115200);
+
+ while (!Serial && (millis() < 5000));
+
+ Serial.print(F("\nStart AsyncDNSServer_ESP32_W6100 on "));
+ Serial.print(ARDUINO_BOARD);
+ Serial.print(F(" with "));
+ Serial.println(SHIELD_TYPE);
+ Serial.println(WEBSERVER_ESP32_W6100_VERSION);
+ Serial.println(ASYNC_UDP_ESP32_W6100_VERSION);
+ Serial.println(ASYNC_DNS_SERVER_ESP32_W6100_VERSION);
+
+ Serial.setDebugOutput(true);
+
+ UDP_LOGWARN(F("Default SPI pinout:"));
+ UDP_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST);
+ UDP_LOGWARN1(F("MOSI:"), MOSI_GPIO);
+ UDP_LOGWARN1(F("MISO:"), MISO_GPIO);
+ UDP_LOGWARN1(F("SCK:"), SCK_GPIO);
+ UDP_LOGWARN1(F("CS:"), CS_GPIO);
+ UDP_LOGWARN1(F("INT:"), INT_GPIO);
+ UDP_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
+ UDP_LOGWARN(F("========================="));
+
+ ///////////////////////////////////
+
+ // To be called before ETH.begin()
+ ESP32_W6100_onEvent();
+
+ // start the ethernet connection and the server:
+ // Use DHCP dynamic IP and random mac
+ //bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
+ // int SPI_HOST, uint8_t *W6100_Mac = W6100_Default_Mac);
+ ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
+ //ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] );
+
+ // Static IP, leave without this line to get IP via DHCP
+ //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
+ //ETH.config(myIP, myGW, mySN, myDNS);
+
+ ESP32_W6100_waitForConnect();
+
+ ///////////////////////////////////
+
+ apIP = ETH.localIP();
+
+ ///////////////////////////////////
+
+ // modify TTL associated with the domain name (in seconds)
+ // default is 60 seconds
+ dnsServer.setTTL(300);
+ // set which return code will be used for all other domains
+ // (e.g. sending ServerFailure instead of NonExistentDomain will reduce number of queries
+ // sent by clients). Default is AsyncDNSReplyCode::NonExistentDomain
+ dnsServer.setErrorReplyCode(AsyncDNSReplyCode::ServerFailure);
+
+ // start DNS server for a specific domain name
+ dnsServer.start(DNS_PORT, "*", apIP);
+
+ server.onNotFound(handleNotFound);
+
+ server.begin();
+
+ Serial.print(F("AsyncDNSServer is @ IP : "));
+ Serial.println(apIP);
+}
+
+void loop()
+{
+}
diff --git a/examples/AsyncDNServerFull_ESP32_W6100/AsyncDNServerFull_ESP32_W6100.ino b/examples/AsyncDNServerFull_ESP32_W6100/AsyncDNServerFull_ESP32_W6100.ino
new file mode 100644
index 0000000..49a9ab2
--- /dev/null
+++ b/examples/AsyncDNServerFull_ESP32_W6100/AsyncDNServerFull_ESP32_W6100.ino
@@ -0,0 +1,174 @@
+/****************************************************************************************************************************
+ AsyncDNSServerFull_ESP32_W6100.ino
+
+ For ESP32_W6100 (ESP32 + W6100)
+
+ AsyncDNSServer_ESP32_W6100 is a Async DNS Server library for the ESP32_W6100
+
+ Based on and modified from ESPAsyncDNSServer Library (https://github.com/devyte/ESPAsyncDNSServer)
+ Built by Khoi Hoang https://github.com/khoih-prog/AsyncDNSServer_ESP32_W6100
+ Licensed under GPLv3 license
+ *****************************************************************************************************************************/
+
+#if !( defined(ESP32) )
+ #error This code is designed for (ESP32 + W6100) to run on ESP32 platform! Please check your Tools->Board setting.
+#endif
+
+#define ASYNC_DNS_ESP32_W6100_DEBUG_PORT Serial
+
+// Use from 0 to 4. Higher number, more debugging messages and memory usage.
+#define _ASYNC_DNS_ESP32_W6100_LOGLEVEL_ 1
+
+/////////////////////////////////////////////
+
+// Enter a MAC address and IP address for your controller below.
+#define NUMBER_OF_MAC 20
+
+byte mac[][NUMBER_OF_MAC] =
+{
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
+ { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
+};
+
+// Select the IP address according to your local network
+IPAddress myIP(192, 168, 2, 232);
+IPAddress myGW(192, 168, 2, 1);
+IPAddress mySN(255, 255, 255, 0);
+
+// Google DNS Server IP
+IPAddress myDNS(8, 8, 8, 8);
+
+//////////////////////////////////////////////////////////
+
+// Optional values to override default settings
+// Don't change unless you know what you're doing
+//#define ETH_SPI_HOST SPI3_HOST
+//#define SPI_CLOCK_MHZ 25
+
+// Must connect INT to GPIOxx or not working
+//#define INT_GPIO 4
+
+//#define MISO_GPIO 19
+//#define MOSI_GPIO 23
+//#define SCK_GPIO 18
+//#define CS_GPIO 5
+
+//////////////////////////////////////////////////////////
+
+#include
+#include
+
+const byte DNS_PORT = 53;
+
+IPAddress apIP;
+
+AsyncDNSServer dnsServer;
+
+AsyncWebServer server(80);
+
+void handleNotFound(AsyncWebServerRequest *request)
+{
+ String message = "Hello World from " + String(BOARD_NAME);
+ message += "\nURI: ";
+ message += request->url();
+
+ request->send(200, "text/plain", message);
+}
+
+void setup()
+{
+ Serial.begin(115200);
+
+ while (!Serial && (millis() < 5000));
+
+ Serial.print(F("\nStart AsyncDNSServerFull_ESP32_W6100 on "));
+ Serial.print(ARDUINO_BOARD);
+ Serial.print(F(" with "));
+ Serial.println(SHIELD_TYPE);
+ Serial.println(WEBSERVER_ESP32_W6100_VERSION);
+ Serial.println(ASYNC_UDP_ESP32_W6100_VERSION);
+ Serial.println(ASYNC_DNS_SERVER_ESP32_W6100_VERSION);
+
+ Serial.setDebugOutput(true);
+
+ UDP_LOGWARN(F("Default SPI pinout:"));
+ UDP_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST);
+ UDP_LOGWARN1(F("MOSI:"), MOSI_GPIO);
+ UDP_LOGWARN1(F("MISO:"), MISO_GPIO);
+ UDP_LOGWARN1(F("SCK:"), SCK_GPIO);
+ UDP_LOGWARN1(F("CS:"), CS_GPIO);
+ UDP_LOGWARN1(F("INT:"), INT_GPIO);
+ UDP_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
+ UDP_LOGWARN(F("========================="));
+
+ ///////////////////////////////////
+
+ // To be called before ETH.begin()
+ ESP32_W6100_onEvent();
+
+ // start the ethernet connection and the server:
+ // Use DHCP dynamic IP and random mac
+ //bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
+ // int SPI_HOST, uint8_t *W6100_Mac = W6100_Default_Mac);
+ ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
+ //ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] );
+
+ // Static IP, leave without this line to get IP via DHCP
+ //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
+ //ETH.config(myIP, myGW, mySN, myDNS);
+
+ ESP32_W6100_waitForConnect();
+
+ ///////////////////////////////////
+
+ apIP = ETH.localIP();
+
+ ///////////////////////////////////
+
+ // modify TTL associated with the domain name (in seconds)
+ // default is 60 seconds
+ dnsServer.setTTL(300);
+ // set which return code will be used for all other domains (e.g. sending
+ // ServerFailure instead of NonExistentDomain will reduce number of queries
+ // sent by clients)
+ // default is AsyncDNSReplyCode::NonExistentDomain
+ dnsServer.setErrorReplyCode(AsyncDNSReplyCode::ServerFailure);
+
+ // start DNS server for a specific domain name
+ dnsServer.start(DNS_PORT, "*", apIP);
+
+ // simple HTTP server to see that DNS server is working
+ server.on("/", HTTP_GET, [](AsyncWebServerRequest * request)
+ {
+ request->send(200, "text/plain", "Hello from AsyncDNSServer running on " + String(BOARD_NAME));
+ });
+
+ server.onNotFound(handleNotFound);
+
+ server.begin();
+
+ Serial.print(F("AsyncDNSServer is @ IP : "));
+ Serial.println(apIP);
+}
+
+void loop()
+{
+}
diff --git a/keywords.txt b/keywords.txt
new file mode 100644
index 0000000..8277e68
--- /dev/null
+++ b/keywords.txt
@@ -0,0 +1,36 @@
+#######################################
+# Syntax Coloring Map For Ultrasound
+#######################################
+
+#######################################
+# Datatypes (KEYWORD1)
+#######################################
+
+DNSHeader KEYWORD1
+AsyncDNSServer KEYWORD1
+AsyncDNSReplyCode KEYWORD1
+
+#######################################
+# Methods and Functions (KEYWORD2)
+#######################################
+
+###################
+# General
+###################
+
+requestIncludesOnlyOneQuestion KEYWORD2
+downcaseAndRemoveWwwPrefix KEYWORD2
+getDomainNameWithoutWwwPrefix KEYWORD2
+
+###################
+# AsyncDNSServer
+###################
+
+setErrorReplyCode KEYWORD2
+setTTL KEYWORD2
+start KEYWORD2
+stop KEYWORD2
+
+#######################################
+# Constants (LITERAL1)
+#######################################
diff --git a/library.json b/library.json
new file mode 100644
index 0000000..729b866
--- /dev/null
+++ b/library.json
@@ -0,0 +1,52 @@
+{
+ "name":"AsyncDNSServer_ESP32_W6100",
+ "version": "1.0.0",
+ "description":"Fully Asynchronous DNS Server Library for ESP32 boards using LwIP W6100 Ethernet. This library is one of the current or future and more advanced Async libraries, such as AsyncWebServer_ESP32_W6100, AsyncHTTPRequest_ESP32_W6100, AsyncHTTPSRequest_ESP32_W6100",
+ "keywords":"communication, data, async, udp, ntp, time, time-server, server, client, multicast, broadcast, webserver, esp32, w6100, lwip, lwip-w6100, udp-server, udp-multicast-server, dns-server, captive-portal",
+ "authors":
+ [
+ {
+ "name": "Develo",
+ "url": "https://github.com/devyte"
+ },
+ {
+ "name": "Khoi Hoang",
+ "url": "https://github.com/khoih-prog",
+ "email": "khoih.prog@gmail.com",
+ "maintainer": true
+ }
+ ],
+ "repository":
+ {
+ "type": "git",
+ "url": "https://github.com/khoih-prog/AsyncDNSServer_ESP32_W6100"
+ },
+ "homepage": "https://github.com/khoih-prog/AsyncDNSServer_ESP32_W6100",
+ "export": {
+ "exclude": [
+ "linux",
+ "extras",
+ "tests"
+ ]
+ },
+ "dependencies":
+ [
+ {
+ "owner": "khoih-prog",
+ "name": "WebServer_ESP32_W6100",
+ "version": "^1.5.2",
+ "platforms": "espressif32"
+ },
+ {
+ "owner": "khoih-prog",
+ "name": "AsyncUDP_ESP32_W6100",
+ "version": "^2.0.0",
+ "platforms": "espressif32"
+ }
+ ],
+ "license": "LGPL-3.0",
+ "frameworks": "*",
+ "platforms": ["espressif32"],
+ "examples": "examples/*/*/*.ino",
+ "headers": [ "AsyncDNSServer_ESP32_W6100.h", "AsyncDNSServer_ESP32_W6100.hpp" ]
+}
diff --git a/library.properties b/library.properties
new file mode 100644
index 0000000..a4e9e56
--- /dev/null
+++ b/library.properties
@@ -0,0 +1,13 @@
+name=AsyncDNSServer_ESP32_W6100
+version=1.0.0
+author=Develo,Khoi Hoang
+maintainer=Khoi Hoang
+sentence=Fully Asynchronous DNS Server Library for ESP32 boards using LwIP W6100 Ethernet.
+paragraph=This library is one of the current or future and more advanced Async libraries, such as AsyncWebServer_ESP32_W6100, AsyncHTTPRequest_ESP32_W6100, AsyncHTTPSRequest_ESP32_W6100
+category=Communication
+url=https://github.com/khoih-prog/AsyncDNSServer_ESP32_W6100
+repository=https://github.com/khoih-prog/AsyncDNSServer_ESP32_W6100
+architectures=esp32
+depends=WebServer_ESP32_W6100, AsyncUDP_ESP32_W6100
+license=GPLv3
+includes=AsyncDNSServer_ESP32_W6100.h, AsyncDNSServer_ESP32_W6100.hpp
diff --git a/platformio/platformio.ini b/platformio/platformio.ini
new file mode 100644
index 0000000..32e90e1
--- /dev/null
+++ b/platformio/platformio.ini
@@ -0,0 +1,164 @@
+;PlatformIO Project Configuration File
+;
+; Build options: build flags, source filter
+; Upload options: custom upload port, speed and extra flags
+; Library options: dependencies, extra library storages
+; Advanced options: extra scripting
+;
+; Please visit documentation for the other options and examples
+; https://docs.platformio.org/page/projectconf.html
+
+[platformio]
+; ============================================================
+; chose environment:
+; ESP32
+; esp32s2
+; esp32s3
+; esp32c3
+
+; ============================================================
+default_envs = ESP32
+
+[env]
+; ============================================================
+; Serial configuration
+; choose upload speed, serial-monitor speed
+; ============================================================
+upload_speed = 921600
+;upload_port = COM11
+;monitor_speed = 9600
+;monitor_port = COM11
+
+; ============================================================
+; Checks for the compatibility with frameworks and dev/platforms
+lib_compat_mode = strict
+lib_ldf_mode = chain+
+;lib_ldf_mode = deep+
+
+; ============================================================
+lib_deps =
+; PlatformIO 4.x
+; WebServer_ESP32_W6100@~1.5.2
+; AsyncUdp_ESP32_W6100@~2.0.0
+; PlatformIO 5.x
+ khoih-prog/WebServer_ESP32_W6100@~1.5.2
+ khoih-prog/AsyncUdp_ESP32_W6100@~2.0.0
+
+; ============================================================
+build_flags =
+; set your debug output (default=Serial)
+ -D DEBUG_ESP_PORT=Serial
+; comment the following line to enable WiFi debugging
+ -D NDEBUG
+
+; ============================================================
+[env:ESP32]
+platform = espressif32
+framework = arduino
+
+; ============================================================
+; Board configuration
+; choose your board by uncommenting one of the following lines
+; ============================================================
+;board = esp32cam
+;board = alksesp32
+;board = featheresp32
+;board = espea32
+;board = bpi-bit
+;board = d-duino-32
+board = esp32doit-devkit-v1
+;board = pocket_32
+;board = fm-devkit
+;board = pico32
+;board = esp32-evb
+;board = esp32-gateway
+;board = esp32-pro
+;board = esp32-poe
+;board = oroca_edubot
+;board = onehorse32dev
+;board = lopy
+;board = lopy4
+;board = wesp32
+;board = esp32thing
+;board = sparkfun_lora_gateway_1-channel
+;board = ttgo-lora32-v1
+;board = ttgo-t-beam
+;board = turta_iot_node
+;board = lolin_d32
+;board = lolin_d32_pro
+;board = lolin32
+;board = wemosbat
+;board = widora-air
+;board = xinabox_cw02
+;board = iotbusio
+;board = iotbusproteus
+;board = nina_w10
+
+; ============================================================
+[env:esp32s2]
+platform = espressif32
+framework = arduino
+
+; toolchain download links see
+; refer "name": "xtensa-esp32s2-elf-gcc","version": "gcc8_4_0-esp-2021r1" section of
+; https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json
+; e.g. Windows: https://github.com/espressif/crosstool-NG/releases/download/esp-2021r1/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r1-win32.zip
+platform_packages =
+ toolchain-xtensa32s2@file://C:\Users\Max\Downloads\xtensa-esp32s2-elf
+ framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#a4118ea88987c28aac3a49bcb9cc5d6c0acc6f3f
+ platformio/tool-esptoolpy @ ~1.30100
+framework = arduino
+board = esp32dev
+board_build.mcu = esp32s2
+board_build.partitions = huge_app.csv
+board_build.variant = esp32s2
+board_build.f_cpu = 240000000L
+board_build.f_flash = 80000000L
+board_build.flash_mode = qio
+board_build.arduino.ldscript = esp32s2_out.ld
+build_unflags =
+ -DARDUINO_ESP32_DEV
+ -DARDUINO_VARIANT="esp32"
+build_flags =
+ -DARDUINO_ESP32S2_DEV
+ -DARDUINO_VARIANT="esp32s2"
+
+; ============================================================
+[env:esp32s3]
+platform = espressif32
+framework = arduino
+
+board_build.mcu = esp32s3
+board_build.partitions = huge_app.csv
+board_build.variant = esp32s3
+board_build.f_cpu = 240000000L
+board_build.f_flash = 80000000L
+board_build.flash_mode = qio
+board_build.arduino.ldscript = esp32s3_out.ld
+build_unflags =
+ -DARDUINO_ESP32_DEV
+ -DARDUINO_VARIANT="esp32"
+build_flags =
+ -DARDUINO_ESP32S3_DEV
+ -DARDUINO_VARIANT="esp32s3"
+
+; ============================================================
+[env:esp32sc3]
+platform = espressif32
+framework = arduino
+
+board_build.mcu = esp32c3
+board_build.partitions = huge_app.csv
+board_build.variant = esp32c3
+board_build.f_cpu = 160000000L
+board_build.f_flash = 80000000L
+board_build.flash_mode = qio
+board_build.arduino.ldscript = esp32c3_out.ld
+build_unflags =
+ -DARDUINO_ESP32_DEV
+ -DARDUINO_VARIANT="esp32"
+build_flags =
+ -DARDUINO_ESP32S3_DEV
+ -DARDUINO_VARIANT="esp32c3"
+
+; ============================================================
diff --git a/src/AsyncDNSServer_ESP32_W6100.h b/src/AsyncDNSServer_ESP32_W6100.h
new file mode 100644
index 0000000..3a0d3de
--- /dev/null
+++ b/src/AsyncDNSServer_ESP32_W6100.h
@@ -0,0 +1,84 @@
+/****************************************************************************************************************************
+ AsyncDNSServer_ESP32_W6100.h
+
+ For ESP32_W6100 (ESP32 + W6100)
+
+ AsyncDNSServer_ESP32_W6100 is a Async DNS Server library for the ESP32_W6100
+
+ Based on and modified from ESPAsyncDNSServer Library (https://github.com/devyte/ESPAsyncDNSServer)
+ Built by Khoi Hoang https://github.com/khoih-prog/AsyncDNSServer_ESP32_W6100
+ Licensed under GPLv3 license
+
+ Version: 1.0.0
+
+ Version Modified By Date Comments
+ ------- ----------- ---------- -----------
+ 1.0.0 K Hoang 10/01/2023 Initial coding for ESP32 + LwIP W6100. Sync with AsyncDNSServer_STM32
+ *****************************************************************************************************************************/
+
+#pragma once
+
+#ifndef AsyncDNSServer_ESP32_W6100_h
+#define AsyncDNSServer_ESP32_W6100_h
+
+////////////////////////////////////////////////
+
+#define ASYNC_DNS_SERVER_ESP32_W6100_VERSION "AsyncDNSServer_ESP32_W6100 v1.0.0"
+
+////////////////////////////////////////////////
+
+#include
+#include "AsyncDNSServer_ESP32_W6100_Debug.h"
+
+#define DNS_QR_QUERY 0
+#define DNS_QR_RESPONSE 1
+#define DNS_OPCODE_QUERY 0
+
+////////////////////////////////////////////////
+
+enum class AsyncDNSReplyCode : unsigned char
+{
+ NoError = 0,
+ FormError = 1,
+ ServerFailure = 2,
+ NonExistentDomain = 3,
+ NotImplemented = 4,
+ Refused = 5,
+ YXDomain = 6,
+ YXRRSet = 7,
+ NXRRSet = 8
+};
+
+////////////////////////////////////////////////
+
+class AsyncDNSServer
+{
+ public:
+ AsyncDNSServer();
+ void setErrorReplyCode(const AsyncDNSReplyCode &replyCode);
+ void setTTL(const uint32_t ttl);
+
+ // Returns true if successful, false if there are no sockets available
+ bool start(const uint16_t port, const String &domainName, const IPAddress &resolvedIP);
+
+ // stops the DNS server
+ void stop();
+
+ private:
+ AsyncUDP _udp;
+ uint16_t _port;
+ String _domainName;
+ unsigned char _resolvedIP[4];
+ uint32_t _ttl;
+ AsyncDNSReplyCode _errorReplyCode;
+
+ void processRequest(AsyncUDPPacket &packet);
+ void replyWithIP(AsyncUDPPacket &packet);
+ void replyWithCustomCode(AsyncUDPPacket &packet);
+};
+
+////////////////////////////////////////////////
+
+#include "AsyncDNSServer_ESP32_W6100_Impl.h"
+
+#endif // AsyncDNSServer_ESP32_W6100_h
diff --git a/src/AsyncDNSServer_ESP32_W6100_Debug.h b/src/AsyncDNSServer_ESP32_W6100_Debug.h
new file mode 100644
index 0000000..97d6f0a
--- /dev/null
+++ b/src/AsyncDNSServer_ESP32_W6100_Debug.h
@@ -0,0 +1,95 @@
+/****************************************************************************************************************************
+ AsyncDNSServer_ESP32_W6100_Debug.h
+
+ For ESP32_W6100 (ESP32 + W6100)
+
+ AsyncDNSServer_ESP32_W6100 is a Async DNS Server library for the ESP32_W6100
+
+ Based on and modified from ESPAsyncDNSServer Library (https://github.com/devyte/ESPAsyncDNSServer)
+ Built by Khoi Hoang https://github.com/khoih-prog/AsyncDNSServer_ESP32_W6100
+ Licensed under GPLv3 license
+
+ Version: 1.0.0
+
+ Version Modified By Date Comments
+ ------- ----------- ---------- -----------
+ 1.0.0 K Hoang 10/01/2023 Initial coding for ESP32 + LwIP W6100. Sync with AsyncDNSServer_STM32
+ *****************************************************************************************************************************/
+
+#pragma once
+
+#ifndef AsyncDNSServer_ESP32_W6100_Debug_H
+#define AsyncDNSServer_ESP32_W6100_Debug_H
+
+#ifdef ASYNC_DNS_ESP32_W6100_DEBUG_PORT
+ #define DBG_PORT_ASYNC_DNS ASYNC_DNS_ESP32_W6100_DEBUG_PORT
+#else
+ #define DBG_PORT_ASYNC_DNS Serial
+#endif
+
+/////////////////////////////////////////////////////////
+
+// Change _ASYNC_DNS_ESP32_W6100_LOGLEVEL_ to set tracing and logging verbosity
+// 0: DISABLED: no logging
+// 1: ERROR: errors
+// 2: WARN: errors and warnings
+// 3: INFO: errors, warnings and informational (default)
+// 4: DEBUG: errors, warnings, informational and debug
+
+#ifndef _ASYNC_DNS_ESP32_W6100_LOGLEVEL_
+ #define _ASYNC_DNS_ESP32_W6100_LOGLEVEL_ 0
+#endif
+
+/////////////////////////////////////////////////////////
+
+const char ASYNC_DNS_MARK[] = "[DNS] ";
+
+#define ASYNC_DNS_PRINT DBG_PORT_ASYNC_DNS.print
+#define ASYNC_DNS_PRINTLN DBG_PORT_ASYNC_DNS.println
+
+#define ASYNC_DNS_PRINT_MARK ASYNC_DNS_PRINT(ASYNC_DNS_MARK)
+#define ASYNC_DNS_PRINT_SP DBG_PORT_ASYNC_DNS.print(" ")
+
+///////////////////////////////////////
+
+#define DNS_LOG(x) { ASYNC_DNS_PRINTLN(x); }
+#define DNS_LOG0(x) { ASYNC_DNS_PRINT(x); }
+#define DNS_LOG1(x,y) { ASYNC_DNS_PRINT(x); ASYNC_DNS_PRINTLN(y); }
+#define DNS_LOG2(x,y,z) { ASYNC_DNS_PRINT(x); ASYNC_DNS_PRINT(y); ASYNC_DNS_PRINTLN(z); }
+#define DNS_LOG3(x,y,z,w) { ASYNC_DNS_PRINT(x); ASYNC_DNS_PRINT(y); ASYNC_DNS_PRINT(z); ASYNC_DNS_PRINTLN(w); }
+
+/////////////////////////////////////////////////////////
+
+#define DNS_LOGERROR(x) if(_ASYNC_DNS_ESP32_W6100_LOGLEVEL_>0) { ASYNC_DNS_PRINT_MARK; ASYNC_DNS_PRINTLN(x); }
+#define DNS_LOGERROR0(x) if(_ASYNC_DNS_ESP32_W6100_LOGLEVEL_>0) { ASYNC_DNS_PRINT(x); }
+#define DNS_LOGERROR1(x,y) if(_ASYNC_DNS_ESP32_W6100_LOGLEVEL_>0) { ASYNC_DNS_PRINT_MARK; ASYNC_DNS_PRINT(x); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINTLN(y); }
+#define DNS_LOGERROR2(x,y,z) if(_ASYNC_DNS_ESP32_W6100_LOGLEVEL_>0) { ASYNC_DNS_PRINT_MARK; ASYNC_DNS_PRINT(x); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINT(y); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINTLN(z); }
+#define DNS_LOGERROR3(x,y,z,w) if(_ASYNC_DNS_ESP32_W6100_LOGLEVEL_>0) { ASYNC_DNS_PRINT_MARK; ASYNC_DNS_PRINT(x); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINT(y); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINT(z); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINTLN(w); }
+
+/////////////////////////////////////////////////////////
+
+#define DNS_LOGWARN(x) if(_ASYNC_DNS_ESP32_W6100_LOGLEVEL_>1) { ASYNC_DNS_PRINT_MARK; ASYNC_DNS_PRINTLN(x); }
+#define DNS_LOGWARN0(x) if(_ASYNC_DNS_ESP32_W6100_LOGLEVEL_>1) { ASYNC_DNS_PRINT(x); }
+#define DNS_LOGWARN1(x,y) if(_ASYNC_DNS_ESP32_W6100_LOGLEVEL_>1) { ASYNC_DNS_PRINT_MARK; ASYNC_DNS_PRINT(x); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINTLN(y); }
+#define DNS_LOGWARN2(x,y,z) if(_ASYNC_DNS_ESP32_W6100_LOGLEVEL_>1) { ASYNC_DNS_PRINT_MARK; ASYNC_DNS_PRINT(x); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINT(y); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINTLN(z); }
+#define DNS_LOGWARN3(x,y,z,w) if(_ASYNC_DNS_ESP32_W6100_LOGLEVEL_>1) { ASYNC_DNS_PRINT_MARK; ASYNC_DNS_PRINT(x); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINT(y); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINT(z); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINTLN(w); }
+
+/////////////////////////////////////////////////////////
+
+#define DNS_LOGINFO(x) if(_ASYNC_DNS_ESP32_W6100_LOGLEVEL_>2) { ASYNC_DNS_PRINT_MARK; ASYNC_DNS_PRINTLN(x); }
+#define DNS_LOGINFO0(x) if(_ASYNC_DNS_ESP32_W6100_LOGLEVEL_>2) { ASYNC_DNS_PRINT(x); }
+#define DNS_LOGINFO1(x,y) if(_ASYNC_DNS_ESP32_W6100_LOGLEVEL_>2) { ASYNC_DNS_PRINT_MARK; ASYNC_DNS_PRINT(x); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINTLN(y); }
+#define DNS_LOGINFO2(x,y,z) if(_ASYNC_DNS_ESP32_W6100_LOGLEVEL_>2) { ASYNC_DNS_PRINT_MARK; ASYNC_DNS_PRINT(x); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINT(y); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINTLN(z); }
+#define DNS_LOGINFO3(x,y,z,w) if(_ASYNC_DNS_ESP32_W6100_LOGLEVEL_>2) { ASYNC_DNS_PRINT_MARK; ASYNC_DNS_PRINT(x); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINT(y); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINT(z); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINTLN(w); }
+
+/////////////////////////////////////////////////////////
+
+#define DNS_LOGDEBUG(x) if(_ASYNC_DNS_ESP32_W6100_LOGLEVEL_>3) { ASYNC_DNS_PRINT_MARK; ASYNC_DNS_PRINTLN(x); }
+#define DNS_LOGDEBUG0(x) if(_ASYNC_DNS_ESP32_W6100_LOGLEVEL_>3) { ASYNC_DNS_PRINT(x); }
+#define DNS_LOGDEBUG1(x,y) if(_ASYNC_DNS_ESP32_W6100_LOGLEVEL_>3) { ASYNC_DNS_PRINT_MARK; ASYNC_DNS_PRINT(x); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINTLN(y); }
+#define DNS_LOGDEBUG2(x,y,z) if(_ASYNC_DNS_ESP32_W6100_LOGLEVEL_>3) { ASYNC_DNS_PRINT_MARK; ASYNC_DNS_PRINT(x); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINT(y); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINTLN(z); }
+#define DNS_LOGDEBUG3(x,y,z,w) if(_ASYNC_DNS_ESP32_W6100_LOGLEVEL_>3) { ASYNC_DNS_PRINT_MARK; ASYNC_DNS_PRINT(x); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINT(y); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINT(z); ASYNC_DNS_PRINT_SP; ASYNC_DNS_PRINTLN(w); }
+
+/////////////////////////////////////////////////////////
+
+#endif //AsyncDNSServer_ESP32_W6100_Debug_H
diff --git a/src/AsyncDNSServer_ESP32_W6100_Impl.h b/src/AsyncDNSServer_ESP32_W6100_Impl.h
new file mode 100644
index 0000000..b88248a
--- /dev/null
+++ b/src/AsyncDNSServer_ESP32_W6100_Impl.h
@@ -0,0 +1,248 @@
+/****************************************************************************************************************************
+ AsyncDNSServer_ESP32_W6100_Impl.h
+
+ For ESP32_W6100 (ESP32 + W6100)
+
+ AsyncDNSServer_ESP32_W6100 is a Async DNS Server library for the ESP32_W6100
+
+ Based on and modified from ESPAsyncDNSServer Library (https://github.com/devyte/ESPAsyncDNSServer)
+ Built by Khoi Hoang https://github.com/khoih-prog/AsyncDNSServer_ESP32_W6100
+ Licensed under GPLv3 license
+
+ Version: 1.0.0
+
+ Version Modified By Date Comments
+ ------- ----------- ---------- -----------
+ 1.0.0 K Hoang 10/01/2023 Initial coding for ESP32 + LwIP W6100. Sync with AsyncDNSServer_STM32
+ *****************************************************************************************************************************/
+
+#pragma once
+
+#ifndef AsyncDNSServer_ESP32_W6100_Impl_h
+#define AsyncDNSServer_ESP32_W6100_Impl_h
+
+#include
+
+extern "C"
+{
+ #include
+};
+
+////////////////////////////////////////////////
+
+namespace
+{
+struct DNSHeader
+{
+ uint16_t ID; // identification number
+ unsigned char RD : 1; // recursion desired
+ unsigned char TC : 1; // truncated message
+ unsigned char AA : 1; // authoritive answer
+ unsigned char OPCode : 4; // message_type
+ unsigned char QR : 1; // query/response flag
+ unsigned char RCode : 4; // response code
+ unsigned char Z : 3; // its z! reserved
+ unsigned char RA : 1; // recursion available
+ uint16_t QDCount; // number of question entries
+ uint16_t ANCount; // number of answer entries
+ uint16_t NSCount; // number of authority entries
+ uint16_t ARCount; // number of resource entries
+};
+
+////////////////////////////////////////////////
+
+bool requestIncludesOnlyOneQuestion(DNSHeader * _dnsHeader)
+{
+ return ntohs(_dnsHeader->QDCount) == 1 &&
+ _dnsHeader->ANCount == 0 &&
+ _dnsHeader->NSCount == 0 &&
+ _dnsHeader->ARCount == 0;
+}
+
+////////////////////////////////////////////////
+
+void downcaseAndRemoveWwwPrefix(String &domainName)
+{
+ domainName.toLowerCase();
+ domainName.replace("www.", "");
+}
+
+////////////////////////////////////////////////
+
+String getDomainNameWithoutWwwPrefix(unsigned char *start)
+{
+ String parsedDomainName = "";
+
+ if (start == nullptr || *start == 0)
+ return parsedDomainName;
+
+ int pos = 0;
+
+ while (true)
+ {
+ unsigned char labelLength = *(start + pos);
+
+ for (int i = 0; i < labelLength; i++)
+ {
+ pos++;
+ parsedDomainName += (char) * (start + pos);
+ }
+
+ pos++;
+
+ if (*(start + pos) == 0)
+ {
+ downcaseAndRemoveWwwPrefix(parsedDomainName);
+ return parsedDomainName;
+ }
+ else
+ {
+ parsedDomainName += ".";
+ }
+ }
+}
+}
+
+/////////////////////////////////////////////////////
+
+AsyncDNSServer::AsyncDNSServer()
+{
+ _ttl = htonl(60);
+ _errorReplyCode = AsyncDNSReplyCode::NonExistentDomain;
+}
+
+////////////////////////////////////////////////
+
+bool AsyncDNSServer::start(const uint16_t port, const String &domainName,
+ const IPAddress &resolvedIP)
+{
+ _port = port;
+ _domainName = domainName;
+ _resolvedIP[0] = resolvedIP[0];
+ _resolvedIP[1] = resolvedIP[1];
+ _resolvedIP[2] = resolvedIP[2];
+ _resolvedIP[3] = resolvedIP[3];
+ downcaseAndRemoveWwwPrefix(_domainName);
+
+ if (_udp.listen(_port))
+ {
+ _udp.onPacket(
+ [&](AsyncUDPPacket & packet)
+ {
+ this->processRequest(packet);
+ }
+ );
+
+ return true;
+ }
+
+ return false;
+}
+
+////////////////////////////////////////////////
+
+void AsyncDNSServer::setErrorReplyCode(const AsyncDNSReplyCode &replyCode)
+{
+ _errorReplyCode = replyCode;
+}
+
+////////////////////////////////////////////////
+
+void AsyncDNSServer::setTTL(const uint32_t ttl)
+{
+ _ttl = htonl(ttl);
+}
+
+////////////////////////////////////////////////
+
+void AsyncDNSServer::stop()
+{
+ DNS_LOGDEBUG("Stop");
+
+ _udp.close();
+}
+
+////////////////////////////////////////////////
+
+void AsyncDNSServer::processRequest(AsyncUDPPacket &packet)
+{
+ if (packet.length() >= sizeof(DNSHeader))
+ {
+ unsigned char * _buffer = packet.data();
+ DNSHeader * _dnsHeader = (DNSHeader*) _buffer;
+
+ String domainNameWithoutWwwPrefix = (_buffer == nullptr ? "" : getDomainNameWithoutWwwPrefix(_buffer + sizeof(
+ DNSHeader)));
+
+ DNS_LOGDEBUG1("processRequest: domainNameWithoutWwwPrefix =", domainNameWithoutWwwPrefix);
+
+ if (_dnsHeader->QR == DNS_QR_QUERY && _dnsHeader->OPCode == DNS_OPCODE_QUERY &&
+ requestIncludesOnlyOneQuestion(_dnsHeader) &&
+ (_domainName == "*" || domainNameWithoutWwwPrefix == _domainName)
+ )
+ {
+ replyWithIP(packet);
+ }
+ else if (_dnsHeader->QR == DNS_QR_QUERY)
+ {
+ replyWithCustomCode(packet);
+ }
+ }
+}
+
+////////////////////////////////////////////////
+
+void AsyncDNSServer::replyWithIP(AsyncUDPPacket &packet)
+{
+ //6 bytes below + szeof(ttl) + 2 bytes. Precalculate to avoid using default of 1460, which is way too much
+ AsyncUDPMessage msg(packet.length() + 12 + sizeof(_resolvedIP));
+
+ msg.write(packet.data(), packet.length());
+ DNSHeader * _dnsHeader = (DNSHeader *)msg.data();
+
+ _dnsHeader->QR = DNS_QR_RESPONSE;
+ _dnsHeader->ANCount = _dnsHeader->QDCount;
+ _dnsHeader->QDCount = _dnsHeader->QDCount;
+ //_dnsHeader->RA = 1;
+
+ msg.write((uint8_t)192); // answer name is a pointer
+ msg.write((uint8_t)12); // pointer to offset at 0x00c
+
+ msg.write((uint8_t)0); // 0x0001 answer is type A query (host address)
+ msg.write((uint8_t)1);
+
+ msg.write((uint8_t)0); //0x0001 answer is class IN (internet address)
+ msg.write((uint8_t)1);
+
+ msg.write((uint8_t *)&_ttl, sizeof(_ttl));
+
+ // Length of RData is 4 bytes (because, in this case, RData is IPv4)
+ msg.write((uint8_t)0);
+ msg.write((uint8_t)4);
+ msg.write(_resolvedIP, sizeof(_resolvedIP));
+
+ packet.send(msg);
+
+ DNS_LOGDEBUG1(F("replyWithIP: DNS responds: "), (IPAddress) _resolvedIP);
+}
+
+////////////////////////////////////////////////
+
+void AsyncDNSServer::replyWithCustomCode(AsyncUDPPacket &packet)
+{
+ AsyncUDPMessage msg(packet.length());
+
+ msg.write(packet.data(), packet.length());
+ DNSHeader * _dnsHeader = (DNSHeader *)msg.data();
+
+ _dnsHeader->QR = DNS_QR_RESPONSE;
+ _dnsHeader->RCode = (unsigned char)_errorReplyCode; //default is AsyncDNSReplyCode::NonExistentDomain
+ _dnsHeader->QDCount = 0;
+
+ packet.send(msg);
+}
+
+////////////////////////////////////////////////
+
+
+#endif // AsyncDNSServer_ESP32_W6100_Impl_h
diff --git a/utils/astyle_library.conf b/utils/astyle_library.conf
new file mode 100644
index 0000000..8a73bc2
--- /dev/null
+++ b/utils/astyle_library.conf
@@ -0,0 +1,70 @@
+# Code formatting rules for Arduino libraries, modified from for KH libraries:
+#
+# https://github.com/arduino/Arduino/blob/master/build/shared/examples_formatter.conf
+#
+
+# astyle --style=allman -s2 -t2 -C -S -xW -Y -M120 -f -p -xg -H -xb -c --xC120 -xL *.h *.cpp *.ino
+
+--mode=c
+--lineend=linux
+--style=allman
+
+# -r or -R
+#--recursive
+
+# -c => Converts tabs into spaces
+convert-tabs
+
+# -s2 => 2 spaces indentation
+--indent=spaces=2
+
+# -t2 => tab =2 spaces
+#--indent=tab=2
+
+# -C
+--indent-classes
+
+# -S
+--indent-switches
+
+# -xW
+--indent-preproc-block
+
+# -Y => indent classes, switches (and cases), comments starting at column 1
+--indent-col1-comments
+
+# -M120 => maximum of 120 spaces to indent a continuation line
+--max-continuation-indent=120
+
+# -xC120 => max‑code‑length will break a line if the code exceeds # characters
+--max-code-length=120
+
+# -f =>
+--break-blocks
+
+# -p => put a space around operators
+--pad-oper
+
+# -xg => Insert space padding after commas
+--pad-comma
+
+# -H => put a space after if/for/while
+pad-header
+
+# -xb => Break one line headers (e.g. if/for/while)
+--break-one-line-headers
+
+# -c => Converts tabs into spaces
+#--convert-tabs
+
+# if you like one-liners, keep them
+#keep-one-line-statements
+
+# -xV
+--attach-closing-while
+
+#unpad-paren
+
+# -xp
+remove-comment-prefix
+
diff --git a/utils/restyle.sh b/utils/restyle.sh
new file mode 100644
index 0000000..bcd846f
--- /dev/null
+++ b/utils/restyle.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+for dir in . ; do
+ find $dir -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.ino" \) -exec astyle --suffix=none --options=./utils/astyle_library.conf \{\} \;
+done
+