Skip to content

Commit

Permalink
Allow configurable max hostname length
Browse files Browse the repository at this point in the history
  • Loading branch information
rechrtb committed Oct 19, 2023
1 parent 9877e1c commit fe2c92b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions components/tcpip_adapter/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@ config TCPIP_ADAPTER_GLOBAL_DATA_LINK_IRAM
help
Link TCPIP adapter global data(.bss .data COMMON) from DRAM to IRAM.

config TCPIP_ADAPTER_HOSTNAME_MAX_LENGTH
int "Max hostname length"
range 1 253
default 32
help
Maximum number of characters in the local hostname

endmenu
1 change: 0 additions & 1 deletion components/tcpip_adapter/include/tcpip_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,6 @@ esp_interface_t tcpip_adapter_get_esp_if(void *dev);
*/
esp_err_t tcpip_adapter_get_sta_list(wifi_sta_list_t *wifi_sta_list, tcpip_adapter_sta_list_t *tcpip_sta_list);

#define TCPIP_HOSTNAME_MAX_SIZE 32
/**
* @brief Set the hostname to the interface
*
Expand Down
6 changes: 4 additions & 2 deletions components/tcpip_adapter/tcpip_adapter_lwip.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
#include "FreeRTOS.h"
#include "timers.h"

#include "sdkconfig.h"

struct tcpip_adapter_pbuf {
struct pbuf_custom pbuf;

Expand Down Expand Up @@ -1217,13 +1219,13 @@ esp_err_t tcpip_adapter_set_hostname(tcpip_adapter_if_t tcpip_if, const char *ho
{
#if LWIP_NETIF_HOSTNAME
struct netif *p_netif;
static char hostinfo[TCPIP_ADAPTER_IF_MAX][TCPIP_HOSTNAME_MAX_SIZE + 1];
static char hostinfo[TCPIP_ADAPTER_IF_MAX][CONFIG_TCPIP_ADAPTER_HOSTNAME_MAX_LENGTH + 1];

if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || hostname == NULL) {
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
}

if (strlen(hostname) > TCPIP_HOSTNAME_MAX_SIZE) {
if (strlen(hostname) > CONFIG_TCPIP_ADAPTER_HOSTNAME_MAX_LENGTH) {
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
}

Expand Down

0 comments on commit fe2c92b

Please sign in to comment.