diff --git a/examples/bridge/bridge_main.c b/examples/bridge/bridge_main.c index 26b8fcb8b..0f8bce241 100644 --- a/examples/bridge/bridge_main.c +++ b/examples/bridge/bridge_main.c @@ -1,7 +1,7 @@ /**************************************************************************** * examples/bridge/bridge_main.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. * * Authors: Gregory Nutt * @@ -55,7 +55,6 @@ #if defined(CONFIG_EXAMPLES_BRIDGE_NET1_DHCPC) || \ defined(CONFIG_EXAMPLES_BRIDGE_NET2_DHCPC) # include -# include # include #endif @@ -169,7 +168,7 @@ printf("NET1: Configuring %s\n", CONFIG_EXAMPLES_BRIDGE_NET1_IFNAME); if (ds.dnsaddr.s_addr != 0) { - dns_setserver(&ds.dnsaddr); + netlib_set_ipv4dnsaddr(&ds.dnsaddr); } dhcpc_close(handle); @@ -290,7 +289,7 @@ printf("NET2: Configuring %s\n", CONFIG_EXAMPLES_BRIDGE_NET2_IFNAME); if (ds.dnsaddr.s_addr != 0) { - dns_setserver(&ds.dnsaddr); + netlib_set_ipv4dnsaddr(&ds.dnsaddr); } dhcpc_close(handle); diff --git a/examples/discover/discover_main.c b/examples/discover/discover_main.c index 5a32d02fc..1b7e9991a 100644 --- a/examples/discover/discover_main.c +++ b/examples/discover/discover_main.c @@ -2,7 +2,7 @@ * examples/discover/discover_main.c * * Copyright (C) 2012 Max Holtzberg. All rights reserved. - * Copyright (C) 2008, 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2008, 2011-2012, 2015 Gregory Nutt. All rights reserved. * * Authors: Max Holtzberg * Gregory Nutt @@ -65,7 +65,6 @@ /* DHCPC may be used in conjunction with any other feature (or not) */ #ifdef CONFIG_EXAMPLES_DISCOVER_DHCPC -# include # include #endif @@ -167,7 +166,7 @@ int discover_main(int argc, char *argv[]) if (ds.dnsaddr.s_addr != 0) { - dns_setserver(&ds.dnsaddr); + netlib_set_ipv4dnsaddr(&ds.dnsaddr); } dhcpc_close(handle); diff --git a/examples/tcpecho/tcpecho_main.c b/examples/tcpecho/tcpecho_main.c index 7bc6c566f..49f2e2bad 100644 --- a/examples/tcpecho/tcpecho_main.c +++ b/examples/tcpecho/tcpecho_main.c @@ -2,7 +2,7 @@ * examples/tcpecho/tcpecho_main.c * * Copyright (C) 2013 Max Holtzberg. All rights reserved. - * Copyright (C) 2008, 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2008, 2011-2012, 2015 Gregory Nutt. All rights reserved. * * Authors: Max Holtzberg * Gregory Nutt @@ -71,7 +71,6 @@ /* DHCPC may be used in conjunction with any other feature (or not) */ #ifdef CONFIG_EXAMPLES_TCPECHO_DHCPC -# include # include #endif @@ -181,7 +180,7 @@ static int tcpecho_netsetup() if (ds.dnsaddr.s_addr != 0) { - dns_setserver(&ds.dnsaddr); + netlib_set_ipv4dnsaddr(&ds.dnsaddr); } dhcpc_close(handle); diff --git a/examples/webserver/webserver_main.c b/examples/webserver/webserver_main.c index 6fc8e5f47..0e91b9c13 100644 --- a/examples/webserver/webserver_main.c +++ b/examples/webserver/webserver_main.c @@ -1,7 +1,7 @@ /**************************************************************************** * examples/webserver/webserver_main.c * - * Copyright (C) 2007, 2009-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009-2012, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Based on uIP which also has a BSD style license: @@ -70,7 +70,6 @@ /* DHCPC may be used in conjunction with any other feature (or not) */ #ifdef CONFIG_EXAMPLES_WEBSERVER_DHCPC -# include # include #endif @@ -173,7 +172,7 @@ int webserver_main(int argc, char *argv[]) if (ds.dnsaddr.s_addr != 0) { - dns_setserver(&ds.dnsaddr); + netlib_set_ipv4dnsaddr(&ds.dnsaddr); } dhcpc_close(handle); diff --git a/examples/wget/wget_main.c b/examples/wget/wget_main.c index 9993a0786..4d4bf156b 100644 --- a/examples/wget/wget_main.c +++ b/examples/wget/wget_main.c @@ -1,7 +1,7 @@ /**************************************************************************** * examples/wget/wget_main.c * - * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2011, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -47,7 +47,6 @@ #include #include -#include #include /**************************************************************************** diff --git a/examples/xmlrpc/xmlrpc_main.c b/examples/xmlrpc/xmlrpc_main.c index 0cda419d3..5d9d92056 100644 --- a/examples/xmlrpc/xmlrpc_main.c +++ b/examples/xmlrpc/xmlrpc_main.c @@ -2,6 +2,7 @@ * apps/examples/xmlrpc/xmlrpc_main.c * * Copyright (C) 2012 Max Holtzberg. All rights reserved. + * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Max Holtzberg * * Based on the embeddable lightweight XML-RPC server code discussed @@ -80,7 +81,6 @@ /* DHCPC may be used in conjunction with any other feature (or not) */ #ifdef CONFIG_EXAMPLES_XMLRPC_DHCPC -# include # include #endif @@ -341,7 +341,7 @@ static int xmlrpc_netinit(void) if (ds.dnsaddr.s_addr != 0) { - dns_setserver(&ds.dnsaddr); + netlib_set_ipv4dnsaddr(&ds.dnsaddr); } dhcpc_close(handle); diff --git a/include/netutils/netlib.h b/include/netutils/netlib.h index bcdba7938..3926d8ed2 100644 --- a/include/netutils/netlib.h +++ b/include/netutils/netlib.h @@ -3,7 +3,7 @@ * Various non-standard APIs to support netutils. All non-standard and * intended only for internal use. * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011m 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Some of these APIs derive from uIP. uIP also has a BSD style license: @@ -72,7 +72,7 @@ #endif /**************************************************************************** - * Public Function Prototypes + * Public Data ****************************************************************************/ #undef EXTERN @@ -84,6 +84,10 @@ extern "C" #define EXTERN extern #endif +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + /* Convert a textual representation of an IP address to a numerical representation. * * This function takes a textual representation of an IP address in @@ -103,9 +107,9 @@ extern "C" bool netlib_ipaddrconv(FAR const char *addrstr, uint8_t *addr); bool netlib_hwmacconv(FAR const char *hwstr, uint8_t *hw); +#ifdef CONFIG_NET_ETHERNET /* Get and set IP/MAC addresses (Ethernet L2 only) */ -#ifdef CONFIG_NET_ETHERNET int netlib_setmacaddr(FAR const char *ifname, const uint8_t *macaddr); int netlib_getmacaddr(FAR const char *ifname, uint8_t *macaddr); #endif @@ -129,9 +133,9 @@ uint8_t netlib_ipv6netmask2prefix(FAR const uint16_t *mask); void netlib_prefix2ipv6netmask(uint8_t preflen, FAR struct in6_addr *netmask); #endif +#ifdef CONFIG_NET_ICMPv6_AUTOCONF /* ICMPv6 Autoconfiguration */ -#ifdef CONFIG_NET_ICMPv6_AUTOCONF int netlib_icmpv6_autoconfiguration(FAR const char *ifname); #endif @@ -151,6 +155,13 @@ int netlib_getifstatus(FAR const char *ifname, FAR uint8_t *flags); int netlib_ifup(FAR const char *ifname); int netlib_ifdown(FAR const char *ifname); +/* DNS server addressing */ + +#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NETDB_DNSCLIENT) +int netlib_set_ipv4dnsaddr(FAR const struct in_addr *inaddr); +int netlib_get_ipv4addr(FAR struct in_addr *inaddr); +#endif + #undef EXTERN #ifdef __cplusplus } diff --git a/netutils/netlib/Makefile b/netutils/netlib/Makefile index 618c3dc5c..a366a0119 100644 --- a/netutils/netlib/Makefile +++ b/netutils/netlib/Makefile @@ -48,6 +48,9 @@ CSRCS += netlib_setifstatus.c netlib_getifstatus.c ifeq ($(CONFIG_NET_IPv4),y) CSRCS += netlib_setipv4addr.c netlib_getipv4addr.c CSRCS += netlib_setdripv4addr.c netlib_setipv4netmask.c +ifeq ($(CONFIG_NETDB_DNSCLIENT),y) +CSRCS += netlib_setipv4dnsaddr.c netlib_getipv4dnsaddr.c +endif endif ifeq ($(CONFIG_NET_IPv6),y) diff --git a/netutils/netlib/netlib_getipv4dnsaddr.c b/netutils/netlib/netlib_getipv4dnsaddr.c new file mode 100644 index 000000000..4476a8a75 --- /dev/null +++ b/netutils/netlib/netlib_getipv4dnsaddr.c @@ -0,0 +1,98 @@ +/**************************************************************************** + * netutils/netlib/netlib_getipv4addr.c + * + * Copyright (C) 2007-2009, 2011, 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include +#include + +#include + +#include + +#include + +#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NETDB_DNSCLIENT) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: netlib_get_ipv4addr + * + * Description: + * Get the DNS server IPv4address + * + * Parameters: + * ipaddr The location to return the IPv4 address + * + * Return: + * Zero (OK) is returned on success; A negated errno value is returned + * on failure. + * + ****************************************************************************/ + +int netlib_get_ipv4dnsaddr(FAR struct in_addr *inaddr) +{ + struct sockaddr_in addr; + socklen_t addrlen; + int ret = -EINVAL; + + if (inaddr) + { + addrlen = sizeof(struct sockaddr_in); + ret = dns_getserver((FAR struct sockaddr *)&addr, &addrlen); + if (ret >= 0) + { + /* Sanity check */ + + DEBUGASSERT(addr.sin_family == AF_INET && + addrlen == sizeof(sizeof(struct sockaddr_in))); + memcpy(inaddr, &addr.sin_addr, sizeof(struct in_addr)); + } + } + + return ret; +} + +#endif /* CONFIG_NET_IPv4 && CONFIG_NETDB_DNSCLIENT */ diff --git a/netutils/netlib/netlib_setipv4dnsaddr.c b/netutils/netlib/netlib_setipv4dnsaddr.c new file mode 100644 index 000000000..0070a4eaa --- /dev/null +++ b/netutils/netlib/netlib_setipv4dnsaddr.c @@ -0,0 +1,94 @@ +/**************************************************************************** + * netutils/netlib/netlib_setipv4dnsaddr.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include + +#include + +#include + +#include + +#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NETDB_DNSCLIENT) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: netlib_set_ipv4dnsaddr + * + * Description: + * Set the DNS server IPv4 address + * + * Parameters: + * inaddr The address to set + * + * Return: + * Zero (OK) is returned on success; A negated errno value is returned + * on failure. + * + ****************************************************************************/ + +int netlib_set_ipv4dnsaddr(FAR const struct in_addr *inaddr) +{ + struct sockaddr_in addr; + int ret = -EINVAL; + + if (inaddr) + { + /* Set the IPv4 DNS server address */ + + addr.sin_family = AF_INET; + addr.sin_port = 0; + memcpy(&addr.sin_addr, inaddr, sizeof(struct in_addr)); + + ret = dns_setserver((FAR const struct sockaddr *)&addr, + sizeof(struct sockaddr_in)); + } + + return ret; +} + +#endif /* CONFIG_NET_IPv4 && CONFIG_NETDB_DNSCLIENT */ diff --git a/nshlib/nsh_netcmds.c b/nshlib/nsh_netcmds.c index f03fe7556..c241e0b57 100644 --- a/nshlib/nsh_netcmds.c +++ b/nshlib/nsh_netcmds.c @@ -562,7 +562,7 @@ static int ifconfig_callback(FAR struct net_driver_s *dev, void *arg) nsh_output(vtbl, "Mask:%s\n", inet_ntoa(addr)); #if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS) - dns_getserver(&addr); + netlib_get_ipv4dnsaddr(&addr); nsh_output(vtbl, "\tDNSaddr:%s\n", inet_ntoa(addr)); #endif #endif @@ -1216,7 +1216,7 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) addr.s_addr = gip; } - dns_setserver(&addr); + netlib_set_ipv4dnsaddr(&addr); } #endif /* CONFIG_NET_IPv4 */ #endif /* CONFIG_NSH_DHCPC || CONFIG_NSH_DNS */ @@ -1256,7 +1256,7 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) if (ds.dnsaddr.s_addr != 0) { - dns_setserver(&ds.dnsaddr); + netlib_set_ipv4dnsaddr(&ds.dnsaddr); } dhcpc_close(handle); diff --git a/nshlib/nsh_netinit.c b/nshlib/nsh_netinit.c index fee2175d6..393997e33 100644 --- a/nshlib/nsh_netinit.c +++ b/nshlib/nsh_netinit.c @@ -69,7 +69,6 @@ #include #if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS) -# include # include #endif @@ -289,7 +288,7 @@ static void nsh_netinit_configure(void) #if defined(CONFIG_NSH_DNS) addr.s_addr = HTONL(CONFIG_NSH_DNSIPADDR); - dns_setserver(&addr); + netlib_set_ipv4dnsaddr(&addr); #endif #if defined(CONFIG_NSH_DHCPC) @@ -323,7 +322,7 @@ static void nsh_netinit_configure(void) if (ds.dnsaddr.s_addr != 0) { - dns_setserver(&ds.dnsaddr); + netlib_set_ipv4dnsaddr(&ds.dnsaddr); } dhcpc_close(handle);