From db891df81abc0dfe512f501f193f6ad3ffa470da Mon Sep 17 00:00:00 2001 From: Jin-Seong Kim Date: Mon, 10 Apr 2017 15:10:30 +0900 Subject: [PATCH] dns: move dns_add_nameserver() to dhcpc This commit is to change the place dns_add_nameserver function when CONFIG_NETDB_DNSSERVER_BY_DHCP enabled, dns server IP address is configured by using received dhcp message without using ifconfig command, dns server can not be configured so that to prevent the dns server configuration problem we've changed the place of dns_add_nameserver to dhcpc Change-Id: Iccf8be5aa601d87fecf42e0f0662c09779312342 Signed-off-by: Jin-Seong Kim --- apps/netutils/dhcpc/dhcpc.c | 14 ++++++++++++++ apps/system/utils/netcmd.c | 11 ++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/apps/netutils/dhcpc/dhcpc.c b/apps/netutils/dhcpc/dhcpc.c index ccdc86e..51333d7 100644 --- a/apps/netutils/dhcpc/dhcpc.c +++ b/apps/netutils/dhcpc/dhcpc.c @@ -74,6 +74,9 @@ #include #include +#if defined (CONFIG_NETDB_DNSCLIENT) && defined (CONFIG_NETDB_DNSSERVER_BY_DHCP) +#include +#endif /**************************************************************************** * Definitions ****************************************************************************/ @@ -600,5 +603,16 @@ int dhcpc_request(void *handle, struct dhcpc_state *presult) ndbg("Got default router %d.%d.%d.%d\n", (presult->default_router.s_addr) & 0xff, (presult->default_router.s_addr >> 8) & 0xff, (presult->default_router.s_addr >> 16) & 0xff, (presult->default_router.s_addr >> 24) & 0xff); ndbg("Lease expires in %d seconds\n", presult->lease_time); +#if defined (CONFIG_NETDB_DNSCLIENT) && defined (CONFIG_NETDB_DNSSERVER_BY_DHCP) + struct sockaddr_in dns; + if (presult->dnsaddr.s_addr != 0) { + ndbg("Set DNS IP address via dns_add_nameserver\n"); + dns.sin_addr.s_addr = presult->dnsaddr.s_addr; + dns.sin_family = AF_INET; + dns.sin_port = htons(DNS_DEFAULT_PORT); + dns_add_nameserver((FAR struct sockaddr *)&dns, sizeof(struct sockaddr_in)); + } +#endif + return OK; } diff --git a/apps/system/utils/netcmd.c b/apps/system/utils/netcmd.c index f63827b..6eef5f2 100644 --- a/apps/system/utils/netcmd.c +++ b/apps/system/utils/netcmd.c @@ -623,15 +623,8 @@ int cmd_ifconfig(int argc, char **argv) printf("IP address %s\n", inet_ntoa(ds.ipaddr)); printf("Netmask %s\n", inet_ntoa(ds.netmask)); printf("Gateway %s\n", inet_ntoa(ds.default_router)); - -#ifdef CONFIG_NETDB_DNSCLIENT - if (ds.dnsaddr.s_addr != 0) { - struct sockaddr_in sock_dns; - sock_dns.sin_family = AF_INET; - sock_dns.sin_port = htons(DNS_DEFAULT_PORT); - sock_dns.sin_addr.s_addr = htonl(ds.dnsaddr.s_addr); - dns_add_nameserver((FAR struct sockaddr *)&sock_dns, sizeof(struct sockaddr_in)); - } +#if defined (CONFIG_NETDB_DNSCLIENT) && defined (CONFIG_NETDB_DNSSERVER_BY_DHCP) + printf("Default DNS %s\n", inet_ntoa(ds.dnsaddr)); #endif dhcpc_close(handle); -- 2.7.4