dns: move dns_add_nameserver() to dhcpc
authorJin-Seong Kim <jseong82.kim@samsung.com>
Mon, 10 Apr 2017 06:10:30 +0000 (15:10 +0900)
committerHeesub Shin <heesub.shin@samsung.com>
Tue, 18 Apr 2017 03:02:14 +0000 (12:02 +0900)
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 <jseong82.kim@samsung.com>
apps/netutils/dhcpc/dhcpc.c
apps/system/utils/netcmd.c

index ccdc86e..51333d7 100644 (file)
@@ -74,6 +74,9 @@
 #include <apps/netutils/dhcpc.h>
 #include <apps/netutils/netlib.h>
 
+#if defined (CONFIG_NETDB_DNSCLIENT) && defined (CONFIG_NETDB_DNSSERVER_BY_DHCP)
+#include <tinyara/net/dns.h>
+#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;
 }
index f63827b..6eef5f2 100644 (file)
@@ -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);