mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 10:47:19 +02:00
ESP-NETIF: fix get/set hostname API to reflect user settings
On startup of the common interface (ethernet, wifi), the lwip netif hostname was assigned to confg value . Fixed to assign to esp-netif hostname if it exists Closes https://github.com/espressif/esp-idf/issues/4737
This commit is contained in:
@ -262,6 +262,10 @@ esp_err_t esp_netif_set_mac(esp_netif_t *esp_netif, uint8_t mac[]);
|
|||||||
/**
|
/**
|
||||||
* @brief Set the hostname of an interface
|
* @brief Set the hostname of an interface
|
||||||
*
|
*
|
||||||
|
* The configured hostname overrides the default configuration value CONFIG_LWIP_LOCAL_HOSTNAME.
|
||||||
|
* Please note that when the hostname is altered after interface started/connected the changes
|
||||||
|
* would only be reflected once the interface restarts/reconnects
|
||||||
|
*
|
||||||
* @param[in] esp_netif Handle to esp-netif instance
|
* @param[in] esp_netif Handle to esp-netif instance
|
||||||
* @param[in] hostname New hostname for the interface. Maximum length 32 bytes.
|
* @param[in] hostname New hostname for the interface. Maximum length 32 bytes.
|
||||||
*
|
*
|
||||||
|
@ -1110,11 +1110,11 @@ esp_err_t esp_netif_get_hostname(esp_netif_t *esp_netif, const char **hostname)
|
|||||||
#if LWIP_NETIF_HOSTNAME
|
#if LWIP_NETIF_HOSTNAME
|
||||||
struct netif *p_netif = esp_netif->lwip_netif;
|
struct netif *p_netif = esp_netif->lwip_netif;
|
||||||
|
|
||||||
if (p_netif != NULL) {
|
if (p_netif != NULL && p_netif->hostname != NULL) {
|
||||||
*hostname = p_netif->hostname;
|
*hostname = p_netif->hostname;
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
} else {
|
} else {
|
||||||
return ESP_ERR_ESP_NETIF_INVALID_PARAMS;
|
return ESP_ERR_ESP_NETIF_IF_NOT_READY;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
return ESP_ERR_ESP_NETIF_IF_NOT_READY;
|
return ESP_ERR_ESP_NETIF_IF_NOT_READY;
|
||||||
|
@ -4,7 +4,8 @@ menu "LWIP"
|
|||||||
string "Local netif hostname"
|
string "Local netif hostname"
|
||||||
default 'espressif'
|
default 'espressif'
|
||||||
help
|
help
|
||||||
The name this device will report to other devices on the network
|
The default name this device will report to other devices on the network.
|
||||||
|
Could be updated at runtime with esp_netif_set_hostname()
|
||||||
|
|
||||||
config LWIP_DNS_SUPPORT_MDNS_QUERIES
|
config LWIP_DNS_SUPPORT_MDNS_QUERIES
|
||||||
bool "Enable mDNS queries in resolving host name"
|
bool "Enable mDNS queries in resolving host name"
|
||||||
|
@ -196,11 +196,14 @@ err_t ethernetif_init(struct netif *netif)
|
|||||||
{
|
{
|
||||||
LWIP_ASSERT("netif != NULL", (netif != NULL));
|
LWIP_ASSERT("netif != NULL", (netif != NULL));
|
||||||
/* Have to get the esp-netif handle from netif first and then driver==ethernet handle from there */
|
/* Have to get the esp-netif handle from netif first and then driver==ethernet handle from there */
|
||||||
esp_eth_handle_t eth_handle = esp_netif_get_io_driver(esp_netif_get_handle_from_netif_impl(netif));
|
esp_netif_t *esp_netif = esp_netif_get_handle_from_netif_impl(netif);
|
||||||
|
esp_eth_handle_t eth_handle = esp_netif_get_io_driver(esp_netif);
|
||||||
/* Initialize interface hostname */
|
/* Initialize interface hostname */
|
||||||
#if LWIP_NETIF_HOSTNAME
|
#if LWIP_NETIF_HOSTNAME
|
||||||
#if ESP_LWIP
|
#if ESP_LWIP
|
||||||
netif->hostname = CONFIG_LWIP_LOCAL_HOSTNAME;
|
if (esp_netif_get_hostname(esp_netif, &netif->hostname) != ESP_OK) {
|
||||||
|
netif->hostname = CONFIG_LWIP_LOCAL_HOSTNAME;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
netif->hostname = "lwip";
|
netif->hostname = "lwip";
|
||||||
#endif
|
#endif
|
||||||
|
@ -233,7 +233,9 @@ wlanif_init(struct netif *netif)
|
|||||||
/* Initialize interface hostname */
|
/* Initialize interface hostname */
|
||||||
|
|
||||||
#if ESP_LWIP
|
#if ESP_LWIP
|
||||||
netif->hostname = CONFIG_LWIP_LOCAL_HOSTNAME;
|
if (esp_netif_get_hostname(esp_netif_get_handle_from_netif_impl(netif), &netif->hostname) != ESP_OK) {
|
||||||
|
netif->hostname = CONFIG_LWIP_LOCAL_HOSTNAME;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
netif->hostname = "lwip";
|
netif->hostname = "lwip";
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user