Skip to content

Commit

Permalink
Request hostname through DHCP
Browse files Browse the repository at this point in the history
If hostname is provided, request it to local DNS through DHCP.
  • Loading branch information
guilhermerc committed Sep 18, 2024
1 parent 2347ded commit b2617d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions connectivity/lwipstack/source/LWIPInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion connectivity/netsocket/include/netsocket/NetworkInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit b2617d1

Please sign in to comment.