[components/net] add dns server ip address config, may custom in menuconfig

Signed-off-by: MurphyZhao <d2014zjt@163.com>
This commit is contained in:
MurphyZhao 2018-05-28 17:13:41 +08:00
parent f29cc0dba4
commit c0587d0407
2 changed files with 29 additions and 4 deletions

View File

@ -217,8 +217,18 @@ config LWIP_USING_DHCPD
config DHCPD_USING_ROUTER
bool "alloc gateway ip for router"
default y
config LWIP_USING_CUSTOMER_DNS_SERVER
bool "Enable customer DNS server config"
default n
if LWIP_USING_CUSTOMER_DNS_SERVER
config DHCP_DNS_SERVER_IP
string "Custom DNS server IP address"
default 1.1.1.1
endif
endif
endif
endmenu

View File

@ -434,10 +434,25 @@ static void dhcpd_thread_entry(void *parameter)
// DHCP_OPTION_DNS_SERVER, use the default DNS server address in lwIP
*dhcp_opt++ = DHCP_OPTION_DNS_SERVER;
*dhcp_opt++ = 4;
*dhcp_opt++ = 208;
*dhcp_opt++ = 67;
*dhcp_opt++ = 222;
*dhcp_opt++ = 222;
#ifndef DHCP_DNS_SERVER_IP
*dhcp_opt++ = DHCPD_SERVER_IPADDR0;
*dhcp_opt++ = DHCPD_SERVER_IPADDR1;
*dhcp_opt++ = DHCPD_SERVER_IPADDR2;
*dhcp_opt++ = 1;
#else
struct ip_addr dns_addr;
ip4addr_aton(DHCP_DNS_SERVER_IP, &dns_addr);
DNS_SERVER_IPADDR0 = (ntohl(dns_addr.addr) >> 24) & 0xFF;
DNS_SERVER_IPADDR1 = (ntohl(dns_addr.addr) >> 16) & 0xFF;
DNS_SERVER_IPADDR2 = (ntohl(dns_addr.addr) >> 8) & 0xFF;
DNS_SERVER_IPADDR3 = (ntohl(dns_addr.addr) >> 0) & 0xFF;
*dhcp_opt++ = DNS_SERVER_IPADDR0;
*dhcp_opt++ = DNS_SERVER_IPADDR1;
*dhcp_opt++ = DNS_SERVER_IPADDR2;
*dhcp_opt++ = DNS_SERVER_IPADDR3;
#endif
// DHCP_OPTION_LEASE_TIME
*dhcp_opt++ = DHCP_OPTION_LEASE_TIME;