#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
****************************************************************************/
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;
}
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);