Skip to content
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

Invalid wifi hostname #4415

Closed
leifnel opened this issue Feb 22, 2018 · 9 comments · Fixed by #5873
Closed

Invalid wifi hostname #4415

leifnel opened this issue Feb 22, 2018 · 9 comments · Fixed by #5873
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.

Comments

@leifnel
Copy link

leifnel commented Feb 22, 2018

The hostname sent in the dhcp request contains an underscore; ESP_123456

This causes DDNS updates to fail, as underscore is not legal in hostname (except as first character)

dhcpd[32702]: Unable to add forward map from ESP_123456.lan. to 192.168.1.152: REFUSED

Solution: Just omit the underscore.

@leifnel
Copy link
Author

leifnel commented Feb 23, 2018

This is a workaround:

` String hostname = WiFi.hostname();
  hostname[3]='-';
  WiFi.hostname(hostname);
  WiFi.begin(ssid, password);`

This changes the hostname to ESP-123456, which is a valid hostname.

@devyte
Copy link
Collaborator

devyte commented Feb 27, 2018

@leifnel when you opened the issue, you were presented with a template requesting specific info. You ignored it its entirety. Please edit your post and fill it in.
Are you talking about an example sketch, your own app, or something that is hardcoded in the libs?

@devyte devyte added the waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. label Feb 27, 2018
@devyte
Copy link
Collaborator

devyte commented Mar 2, 2018

@leifnel Will you be providing the info requested in the issue template? At the very least an example sketch is needed.
Also, I can't find anywhere in the core code where the hostname is set to ESP_somenum. The only place I see that does this is the example sketch here:
libraries/ESP8266mDNS/examples/mDNS-SD_Extended/mDNS-SD_Extended.ino
Is that what you are referring to?

@leifnel
Copy link
Author

leifnel commented Mar 2, 2018

The relevant code is simply

#include <ESP8266WiFi.h>
void setup() {
  WiFi.mode(WIFI_STA);
  WiFi.begin("ssid", "password");
}

The hostname is in the format ESP_123456, where 123456 is the last 6 characters of the macaddress.
When the device is connecting to a wifi, where the dhcp-server tries to update the bind9 dns-server with the hostname, the ESP_123456 name is denied, because underscore is not a valid character in hostnames.

@igrr
Copy link
Member

igrr commented Mar 2, 2018

This looks like an SDK bug, but we can work around it somewhere in WiFi.begin.

@Makuna
Copy link
Collaborator

Makuna commented Oct 5, 2018

A better place would be in ESP8266WiFiGenericClass::enableSTA() as it is common to the at least three paths to configure and setup WiFi.

@d-a-v
Copy link
Collaborator

d-a-v commented Dec 30, 2018

This recently came to my attention (I had searched for this before, it was too hidden):

1. A "name" (Net, Host, Gateway, or Domain name) is a text string up
   to 24 characters drawn from the alphabet (A-Z), digits (0-9), minus
   sign (-), and period (.).  Note that periods are only allowed when
   they serve to delimit components of "domain style names". (See
   RFC-921, "Domain Name System Implementation Schedule", for
   background).  No blank or space characters are permitted as part of a
   name. No distinction is made between upper and lower case.  The first
   character must be an alpha character.  The last character must not be
   a minus sign or period.  A host which serves as a GATEWAY should have
   "-GATEWAY" or "-GW" as part of its name.  Hosts which do not serve as
   Internet gateways should not use "-GATEWAY" and "-GW" as part of
   their names. A host which is a TAC should have "-TAC" as the last
   part of its host name, if it is a DoD host.  Single character names
   or nicknames are not allowed.

RFCs:
Internet host table specification (1985)
ref-ed from Requirements for Internet Hosts -- Application and Support (1989, section 2.1 Host Names and Numbers)

Hostnames are set in lwIP interfaces (netif, one for STA, one for AP, at least).
They become visible in the network on a DHCP request (STA as a client). That's why hostname must be set up very early in the sketch (a DHCP request is silently done shortly after reset in persistence mode).

For that reason, a fixing check should be done in lwip2 (when setting up network interfaces), and also in WiFi.hostname(name) by a common function in the core that would replace offending chars / fix hostname validity.

@leifnel
Copy link
Author

leifnel commented Dec 30, 2018

An (unrelated) comment on this: some nameservers (or GUI's) incorrectly prevent entries, which are not hostnames, to have names like _sip.example.org.

@devyte
Copy link
Collaborator

devyte commented Feb 5, 2019

Reference:
espressif/ESP8266_NONOS_SDK#208

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants