From b2617d15e27a4cdd064d1de591bc4816c28d332e Mon Sep 17 00:00:00 2001 From: Guilherme Ricioli Date: Tue, 16 Apr 2024 10:50:48 -0300 Subject: [PATCH] Request hostname through DHCP If hostname is provided, request it to local DNS through DHCP. --- connectivity/lwipstack/source/LWIPInterface.cpp | 6 ++++++ connectivity/netsocket/include/netsocket/NetworkInterface.h | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/connectivity/lwipstack/source/LWIPInterface.cpp b/connectivity/lwipstack/source/LWIPInterface.cpp index a1cfcf31c41..35b4cfeb48a 100644 --- a/connectivity/lwipstack/source/LWIPInterface.cpp +++ b/connectivity/lwipstack/source/LWIPInterface.cpp @@ -433,6 +433,7 @@ LWIP::Interface::Interface() : nsapi_error_t LWIP::add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out, NetworkInterface *user_network_interface) { #if LWIP_ETHERNET + const char *hostname; Interface *interface = new (std::nothrow) Interface(); if (!interface) { return NSAPI_ERROR_NO_MEMORY; @@ -441,6 +442,11 @@ nsapi_error_t LWIP::add_ethernet_interface(EMAC &emac, bool default_if, OnboardN interface->memory_manager = &memory_manager; interface->ppp_enabled = false; + hostname = user_network_interface->get_hostname(); + if (hostname) { + netif_set_hostname(&interface->netif, hostname); + } + #if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE) netif->interface.hwaddr[0] = MBED_MAC_ADDR_0; netif->interface.hwaddr[1] = MBED_MAC_ADDR_1; diff --git a/connectivity/netsocket/include/netsocket/NetworkInterface.h b/connectivity/netsocket/include/netsocket/NetworkInterface.h index 37213330050..74057c81bf4 100644 --- a/connectivity/netsocket/include/netsocket/NetworkInterface.h +++ b/connectivity/netsocket/include/netsocket/NetworkInterface.h @@ -102,7 +102,9 @@ class NetworkInterface: public DNS { * @retval NSAPI_ERROR_OK on success * @retval NSAPI_ERROR_UNSUPPORTED if this feature is not supported * @retval NSAPI_ERROR_PARAMETER if hostname is not valid - * @retval NSAPI_ERROR_BUSY if hostname couldn't be set + * @retval NSAPI_ERROR_BUSY if hostname couldn't be set (e.g. for + * LwIP stack, hostname can only be set before calling + * \c EthernetInterface::connect method) */ virtual nsapi_error_t set_hostname(const char *hostname);