Added hostname.

This commit is contained in:
imi415 2022-05-27 22:21:27 +08:00
parent b5c58fd831
commit 036c6ed031
Signed by: imi415
GPG Key ID: 885EC2B5A8A6F8A7
2 changed files with 8 additions and 3 deletions

View File

@ -61,6 +61,7 @@
#define LWIP_HAVE_LOOPIF 1
#define LWIP_NETIF_LOOPBACK 1
#define LWIP_LOOPBACK_MAX_PBUFS 10
#define LWIP_NETIF_HOSTNAME 1
#define TCP_LISTEN_BACKLOG 1

View File

@ -18,8 +18,10 @@
/* Debug Console */
#include "fsl_debug_console.h"
#define NTP_POOL_ADDR "cn.pool.ntp.org"
#define NTP_POOL_ADDR "cn.pool.ntp.org"
#define NETIF_HOSTNAME "k60_server"
static char *s_netif_hostname = NETIF_HOSTNAME;
static struct netif fsl_netif0;
/* Report state => string */
@ -70,7 +72,7 @@ static void ip_stack_enable_sntp(void) {
sntp_setoperatingmode(SNTP_OPMODE_POLL);
if(dns_gethostbyname(NTP_POOL_ADDR, &ntp_addr, ip_stack_sntp_address_found, NULL) == ERR_OK) {
if (dns_gethostbyname(NTP_POOL_ADDR, &ntp_addr, ip_stack_sntp_address_found, NULL) == ERR_OK) {
/* If ERR_OK is returned, the result is cached in DNS. */
sntp_setserver(0, &ntp_addr);
sntp_init();
@ -91,11 +93,13 @@ void ip_stack_setup(void) {
netif_set_default(&fsl_netif0);
netif_set_up(&fsl_netif0);
netif_set_hostname(&fsl_netif0, s_netif_hostname);
/* Start DHCP, this configures both DNS and IP addresses. */
dhcp_start(&fsl_netif0);
/* Wait for a lease */
while(dhcp_supplied_address(&fsl_netif0) == 0) {
while (dhcp_supplied_address(&fsl_netif0) == 0) {
vTaskDelay(pdMS_TO_TICKS(500));
}