Skip to content

Commit b2617d1

Browse files
committed
Request hostname through DHCP
If hostname is provided, request it to local DNS through DHCP.
1 parent 2347ded commit b2617d1

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

connectivity/lwipstack/source/LWIPInterface.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ LWIP::Interface::Interface() :
433433
nsapi_error_t LWIP::add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out, NetworkInterface *user_network_interface)
434434
{
435435
#if LWIP_ETHERNET
436+
const char *hostname;
436437
Interface *interface = new (std::nothrow) Interface();
437438
if (!interface) {
438439
return NSAPI_ERROR_NO_MEMORY;
@@ -441,6 +442,11 @@ nsapi_error_t LWIP::add_ethernet_interface(EMAC &emac, bool default_if, OnboardN
441442
interface->memory_manager = &memory_manager;
442443
interface->ppp_enabled = false;
443444

445+
hostname = user_network_interface->get_hostname();
446+
if (hostname) {
447+
netif_set_hostname(&interface->netif, hostname);
448+
}
449+
444450
#if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
445451
netif->interface.hwaddr[0] = MBED_MAC_ADDR_0;
446452
netif->interface.hwaddr[1] = MBED_MAC_ADDR_1;

connectivity/netsocket/include/netsocket/NetworkInterface.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ class NetworkInterface: public DNS {
102102
* @retval NSAPI_ERROR_OK on success
103103
* @retval NSAPI_ERROR_UNSUPPORTED if this feature is not supported
104104
* @retval NSAPI_ERROR_PARAMETER if hostname is not valid
105-
* @retval NSAPI_ERROR_BUSY if hostname couldn't be set
105+
* @retval NSAPI_ERROR_BUSY if hostname couldn't be set (e.g. for
106+
* LwIP stack, hostname can only be set before calling
107+
* \c EthernetInterface::connect method)
106108
*/
107109
virtual nsapi_error_t set_hostname(const char *hostname);
108110

0 commit comments

Comments
 (0)