Skip to content

WiFi.config() can not set DNS. #553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nnnntosh opened this issue Aug 2, 2017 · 2 comments
Closed

WiFi.config() can not set DNS. #553

nnnntosh opened this issue Aug 2, 2017 · 2 comments

Comments

@nnnntosh
Copy link

nnnntosh commented Aug 2, 2017

Hardware:

Board: ESP32 Dev Module
Core Installation/update date: 1/Aug/2017
IDE name: Arduino IDE
Flash Frequency: ?
Upload Speed: 115200

Description:

I am trying to set DNS with WiFi.config(), but DNS lookup ( gethostbyname()) fails.

WiFi.config(ip, gateway, subnet, dns1, dns2);

I tried debugging ESP-IDF. and I have found that DNS response was dropped.
This is the code below.

esp-idf/components/lwip/core/dns.c

        /* Check whether response comes from the same network address to which the
           question was sent. (RFC 5452) */
        if (!ip_addr_cmp(addr, &dns_servers[entry->server_idx])) {
          /* call callback to indicate error, clean up memory and return */
          goto responseerr;
        }

ip_addr_cmp() checks that addr->type matches, but they were not the same.

I checked how to set up DNS with WiFi.config(). Nothing is set to addr->type, it is undefined value.

arduino-esp32/libraries/WiFi/src/WiFiSTA.cpp

    if(dns1 != (uint32_t)0x00000000) {
        // Set DNS1-Server
        d.u_addr.ip4.addr = static_cast<uint32_t>(dns1);
        dns_setserver(0, &d);
    }

I also found that DNS works correctly when I modify the code as follows.

    if(dns1 != (uint32_t)0x00000000) {
        // Set DNS1-Server
        d.u_addr.ip4.addr = static_cast<uint32_t>(dns1);
        IP_SET_TYPE(&d, IPADDR_TYPE_V4);
        dns_setserver(0, &d);
    }

By the way, I think that ip_addr_set_ip4_u32() should be used,
It is not possible because the following build error appears due to gcc option [- Werror = address].

error: the address of 'd' will always evaluate as 'true' [-Werror=address]
@me-no-dev
Copy link
Member

Nice catch!

Raienryu97 pushed a commit to Raienryu97/arduino-esp32 that referenced this issue Aug 2, 2017
@hutje
Copy link

hutje commented Jul 5, 2021

WiFi.setDNS() isn't recognized as function... It is once called in the esp32 WIFI library as keyword but never used.

blue-2357 pushed a commit to blue-2357/arduino-esp32 that referenced this issue Jul 17, 2024
dash0820 added a commit to dash0820/arduino-esp32-stripped that referenced this issue Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants