From b8471cb0f379d431088336d4f0bb67376cde8439 Mon Sep 17 00:00:00 2001 From: chenyong <1521761801@qq.com> Date: Mon, 2 Sep 2019 10:51:21 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91esp8266=20?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=9B=BA=E4=BB=B6=E8=8E=B7=E5=8F=96=20DNS=20?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E5=A4=B1=E8=B4=A5=EF=BC=8C=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=BB=98=E8=AE=A4=20DNS=20=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenyong <1521761801@qq.com> --- class/esp8266/at_device_esp8266.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/class/esp8266/at_device_esp8266.c b/class/esp8266/at_device_esp8266.c index a2fec72..352c4ee 100644 --- a/class/esp8266/at_device_esp8266.c +++ b/class/esp8266/at_device_esp8266.c @@ -40,9 +40,14 @@ /* ============================= esp8266 network interface operations ============================= */ +static int esp8266_netdev_set_dns_server(struct netdev *netdev, uint8_t dns_num, ip_addr_t *dns_server); + static void esp8266_get_netdev_info(struct rt_work *work, void *work_data) { -#define AT_ADDR_LEN 32 +#define AT_ADDR_LEN 32 +#define AT_ERR_DNS_SERVER "255.255.255.255" +#define AT_DEF_DNS_SERVER "114.114.114.114" + at_response_t resp = RT_NULL; char ip[AT_ADDR_LEN] = {0}, mac[AT_ADDR_LEN] = {0}; char gateway[AT_ADDR_LEN] = {0}, netmask[AT_ADDR_LEN] = {0}; @@ -125,13 +130,21 @@ static void esp8266_get_netdev_info(struct rt_work *work, void *work_data) goto __exit; } - if (rt_strlen(dns_server1) > 0) + /* set primary DNS server address */ + if (rt_strlen(dns_server1) > 0 && + rt_strncmp(dns_server1, AT_ERR_DNS_SERVER, rt_strlen(AT_ERR_DNS_SERVER)) != 0) { inet_aton(dns_server1, &ip_addr); netdev_low_level_set_dns_server(netdev, 0, &ip_addr); } + else + { + inet_aton(AT_DEF_DNS_SERVER, &ip_addr); + esp8266_netdev_set_dns_server(netdev, 0, &ip_addr); + } - if (rt_strlen(dns_server2) > 0) + /* set secondary DNS server address */ + if (rt_strlen(dns_server2) > 0 ) { inet_aton(dns_server2, &ip_addr); netdev_low_level_set_dns_server(netdev, 1, &ip_addr);