1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-12 01:53:07 +03:00

Fix hostname management (#8626)

* manage hostname with sdk string
This commit is contained in:
david gauchard
2022-07-06 22:57:58 +02:00
committed by GitHub
parent 65d30437f0
commit a8e3786d38
3 changed files with 31 additions and 12 deletions

View File

@ -16,6 +16,17 @@ extern "C"
#include "debug.h"
#include "LwipIntf.h"
// wifi_station_hostname is SDK's station(=global) hostname location
// - It is never nullptr but wifi_station_get_hostname()
// can return nullptr when STA is down
// - Because WiFi is started in off mode at boot time,
// wifi_station_set/get_hostname() is now no more used
// because setting hostname firt does not work anymore
// - wifi_station_hostname is overwritten by SDK when wifi is
// woken up in WiFi::mode()
//
extern "C" char* wifi_station_hostname;
// args | esp order arduino order
// ---- + --------- -------------
// local_ip | local_ip local_ip
@ -66,7 +77,7 @@ bool LwipIntf::ipAddressReorder(const IPAddress& local_ip, const IPAddress& arg1
*/
String LwipIntf::hostname(void)
{
return wifi_station_get_hostname();
return wifi_station_hostname;
}
/**
@ -75,7 +86,7 @@ String LwipIntf::hostname(void)
*/
const char* LwipIntf::getHostname(void)
{
return wifi_station_get_hostname();
return wifi_station_hostname;
}
/**
@ -136,12 +147,9 @@ bool LwipIntf::hostname(const char* aHostname)
DEBUGV("hostname '%s' is not compliant with RFC952\n", aHostname);
}
bool ret = wifi_station_set_hostname(aHostname);
if (!ret)
{
DEBUGV("WiFi.hostname(%s): wifi_station_set_hostname() failed\n", aHostname);
return false;
}
bool ret = true;
strcpy(wifi_station_hostname, aHostname);
// now we should inform dhcp server for this change, using lwip_renew()
// looping through all existing interface
@ -149,7 +157,7 @@ bool LwipIntf::hostname(const char* aHostname)
for (netif* intf = netif_list; intf; intf = intf->next)
{
// unconditionally update all known interfaces
intf->hostname = wifi_station_get_hostname();
intf->hostname = wifi_station_hostname;
if (netif_dhcp_data(intf) != nullptr)
{