mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 11:56:10 +08:00
Move the DNS server from apps/netutils/dnsclient to nuttx/libc/netdb. Move netdb functions from libc/net to libc/netdb. Fix up naming to reflect the repartitioning
This commit is contained in:
+1
-1
Submodule configs updated: 8e27cf333e...0e83a96479
+2
-2
@@ -263,7 +263,7 @@ EXTERN int h_errno;
|
|||||||
* Public Function Prototypes
|
* Public Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_LIB_NETDB
|
#ifdef CONFIG_LIBC_NETDB
|
||||||
#if 0 /* None of these are yet supported */
|
#if 0 /* None of these are yet supported */
|
||||||
|
|
||||||
void endhostent(void);
|
void endhostent(void);
|
||||||
@@ -311,7 +311,7 @@ int gethostbyaddr_r(FAR const void *addr, socklen_t len, int type,
|
|||||||
int gethostbyname_r(FAR const char *name, FAR struct hostent *host,
|
int gethostbyname_r(FAR const char *name, FAR struct hostent *host,
|
||||||
FAR char *buf, size_t buflen, int *h_errnop);
|
FAR char *buf, size_t buflen, int *h_errnop);
|
||||||
|
|
||||||
#endif /* CONFIG_LIB_NETDB */
|
#endif /* CONFIG_LIBC_NETDB */
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -0,0 +1,216 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* include/nuttx/net/dnsclient.h
|
||||||
|
* DNS resolver code header file.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007-2009, 2011-2012, 2014 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* Inspired by/based on uIP logic by Adam Dunkels:
|
||||||
|
*
|
||||||
|
* Copyright (c) 2002-2003, Adam Dunkels. All rights reserved.
|
||||||
|
* Author Adam Dunkels <adam@dunkels.com>
|
||||||
|
*
|
||||||
|
* 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. The name of the author may not be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior
|
||||||
|
* written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __INCLUDE_NUTTX_NET_DNSCLIENT_H
|
||||||
|
#define __INCLUDE_NUTTX_NET_DNSCLIENT_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
|
||||||
|
#include <nuttx/net/netconfig.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* If both IPv4 and IPv6 are enabled, the DNS client can support only one or
|
||||||
|
* the other.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if !defined(CONFIG_NETDB_DNSCLIENT_IPv4) && \
|
||||||
|
!defined(CONFIG_NETDB_DNSCLIENT_IPv6)
|
||||||
|
# ifdef CONFIG_NET_IPv6
|
||||||
|
# define CONFIG_NETDB_DNSCLIENT_IPv6 1
|
||||||
|
# else
|
||||||
|
# define CONFIG_NETDB_DNSCLIENT_IPv4 1
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dns_bind_sock
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the DNS resolver using the caller provided socket.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int dns_bind_sock(FAR int *sockfd);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dns_bind
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the DNS resolver using an internal, share-able socket.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int dns_bind(void);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dns_free_sock
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Release the DNS resolver by closing the socket.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int dns_free_sock(FAR int *sockfd);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dns_query_sock
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Using the DNS resolver socket (sockfd), look up the the 'hostname', and
|
||||||
|
* return its IP address in 'ipaddr'
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Returns zero (OK) if the query was successful.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int dns_query_sock(int sockfd, FAR const char *hostname, FAR in_addr_t *ipaddr);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dns_query
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Using the internal DNS resolver socket, look up the the 'hostname', and
|
||||||
|
* return its IP address in 'ipaddr'
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Returns zero (OK) if the query was successful.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int dns_query(FAR const char *hostname, FAR in_addr_t *ipaddr);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dns_setserver
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Configure which DNS server to use for queries
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_NETDB_DNSCLIENT_IPv6
|
||||||
|
void dns_setserver(FAR const struct in6_addr *dnsserver);
|
||||||
|
#else
|
||||||
|
void dns_setserver(FAR const struct in_addr *dnsserver);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dns_getserver
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Obtain the currently configured DNS server.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_NETDB_DNSCLIENT_IPv6
|
||||||
|
void dns_getserver(FAR struct in6_addr *dnsserver);
|
||||||
|
#else
|
||||||
|
void dns_getserver(FAR struct in_addr *dnsserver);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dns_whois_socket
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Get the binding for 'name' using the DNS server accessed via 'sockfd'
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_NETDB_DNSCLIENT_IPv6
|
||||||
|
int dns_whois_socket(int sockfd, FAR const char *name,
|
||||||
|
FAR struct sockaddr_in6 *addr);
|
||||||
|
#else
|
||||||
|
int dns_whois_socket(int sockfd, FAR const char *name,
|
||||||
|
FAR struct sockaddr_in *addr);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dns_whois
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Get the binding for 'name' using the DNS server accessed via the DNS
|
||||||
|
* resolvers internal socket.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_NETDB_DNSCLIENT_IPv6
|
||||||
|
int dns_whois(FAR const char *name, FAR struct sockaddr_in6 *addr);
|
||||||
|
#else
|
||||||
|
int dns_whois(FAR const char *name, FAR struct sockaddr_in *addr);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dns_gethostip
|
||||||
|
*
|
||||||
|
* Descriptions:
|
||||||
|
* Combines the operations of dns_bind_sock(), dns_query_sock(), and
|
||||||
|
* dns_free_sock() to obtain the the IP address ('ipaddr') associated with
|
||||||
|
* the 'hostname' in one operation.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int dns_gethostip(FAR const char *hostname, FAR in_addr_t *ipaddr);
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __INCLUDE_NUTTX_NET_DNSCLIENT_H */
|
||||||
+51
-4
@@ -504,12 +504,17 @@ config ARCH_BZERO
|
|||||||
|
|
||||||
endif # ARCH_OPTIMIZED_FUNCTIONS
|
endif # ARCH_OPTIMIZED_FUNCTIONS
|
||||||
|
|
||||||
menuconfig LIB_NETDB
|
config LIBC_NETDB
|
||||||
bool "Network database support"
|
bool
|
||||||
|
default n
|
||||||
|
|
||||||
|
menuconfig NETDB_HOSTFILE
|
||||||
|
bool "Network host file support"
|
||||||
default n
|
default n
|
||||||
depends on FS_READABLE
|
depends on FS_READABLE
|
||||||
|
select LIBC_NETDB
|
||||||
|
|
||||||
if LIB_NETDB
|
if NETDB_HOSTFILE
|
||||||
|
|
||||||
config NETDB_HOSTCONF_PATH
|
config NETDB_HOSTCONF_PATH
|
||||||
string "Path to host configuration file"
|
string "Path to host configuration file"
|
||||||
@@ -523,7 +528,49 @@ config NETDB_BUFSIZE
|
|||||||
int "gethostname() buffer size"
|
int "gethostname() buffer size"
|
||||||
default 128
|
default 128
|
||||||
|
|
||||||
endif # LIB_NETDB
|
endif # NETDB_HOSTFILE
|
||||||
|
|
||||||
|
config NETDB_DNSCLIENT
|
||||||
|
bool "DNS Name resolution"
|
||||||
|
default n
|
||||||
|
depends on NET && NET_UDP
|
||||||
|
select LIBC_NETDB
|
||||||
|
---help---
|
||||||
|
Enable support for the name resolution.
|
||||||
|
|
||||||
|
if NETDB_DNSCLIENT
|
||||||
|
|
||||||
|
choice
|
||||||
|
prompt "Internet Protocol"
|
||||||
|
default NETDB_DNSCLIENT_IPv4 if NET_IPv4
|
||||||
|
default NETDB_DNSCLIENT_IPv6 if NET_IPv6 && !NET_IPv4
|
||||||
|
|
||||||
|
config NETDB_DNSCLIENT_IPv4
|
||||||
|
bool "IPv4"
|
||||||
|
depends on NET_IPv4
|
||||||
|
|
||||||
|
config NETDB_DNSCLIENT_IPv6
|
||||||
|
bool "IPv6"
|
||||||
|
depends on NET_IPv6
|
||||||
|
|
||||||
|
endchoice # Internet Protocol
|
||||||
|
|
||||||
|
config NETDB_DNSCLIENT_ENTRIES
|
||||||
|
int "Number of DNS resolver entries"
|
||||||
|
default 8
|
||||||
|
---help---
|
||||||
|
Number of DNS resolver entries. Default: 8
|
||||||
|
|
||||||
|
config NETDB_DNSCLIENT_MAXRESPONSE
|
||||||
|
int "Max response size"
|
||||||
|
default 96
|
||||||
|
---help---
|
||||||
|
This setting determines the maximum size of response message that
|
||||||
|
can be received by the DNS resolver. The default is 96 but may
|
||||||
|
need to be larger on enterprise networks (perhaps 176).
|
||||||
|
|
||||||
|
endif # NETDB_DNSCLIENT
|
||||||
|
|
||||||
|
|
||||||
comment "Non-standard Library Support"
|
comment "Non-standard Library Support"
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ include signal/Make.defs
|
|||||||
include math/Make.defs
|
include math/Make.defs
|
||||||
include fixedmath/Make.defs
|
include fixedmath/Make.defs
|
||||||
include net/Make.defs
|
include net/Make.defs
|
||||||
|
include netdb/Make.defs
|
||||||
include time/Make.defs
|
include time/Make.defs
|
||||||
include libgen/Make.defs
|
include libgen/Make.defs
|
||||||
include dirent/Make.defs
|
include dirent/Make.defs
|
||||||
|
|||||||
+1
-1
@@ -218,7 +218,7 @@ float lib_sqrtapprox(float x);
|
|||||||
|
|
||||||
/* Defined in lib_parsehostfile.c */
|
/* Defined in lib_parsehostfile.c */
|
||||||
|
|
||||||
#ifdef CONFIG_LIB_NETDB
|
#ifdef CONFIG_NETDB_HOSTFILE
|
||||||
ssize_t lib_parse_hostfile(FAR FILE *stream, FAR struct hostent *host,
|
ssize_t lib_parse_hostfile(FAR FILE *stream, FAR struct hostent *host,
|
||||||
FAR char *buf, size_t buflen);
|
FAR char *buf, size_t buflen);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+1
-1
@@ -46,7 +46,7 @@ endif
|
|||||||
|
|
||||||
# netdb support
|
# netdb support
|
||||||
|
|
||||||
ifeq ($(CONFIG_LIB_NETDB),y)
|
ifeq ($(CONFIG_NETDB_HOSTFILE),y)
|
||||||
CSRCS += lib_netdb.c lib_gethostbyname.c lib_gethostbynamer.c
|
CSRCS += lib_netdb.c lib_gethostbyname.c lib_gethostbynamer.c
|
||||||
CSRCS += lib_gethostbyaddr.c lib_gethostbyaddrr.c lib_parsehostfile.c
|
CSRCS += lib_gethostbyaddr.c lib_gethostbyaddrr.c lib_parsehostfile.c
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -61,7 +61,7 @@
|
|||||||
* IPv6 addresses, regardless of networking support.
|
* IPv6 addresses, regardless of networking support.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef CONFIG_LIB_NETDB
|
#ifdef CONFIG_NETDB_HOSTFILE
|
||||||
# undef CONFIG_NET_IPv4
|
# undef CONFIG_NET_IPv4
|
||||||
# undef CONFIG_NET_IPv6
|
# undef CONFIG_NET_IPv6
|
||||||
# define CONFIG_NET_IPv4 1
|
# define CONFIG_NET_IPv4 1
|
||||||
|
|||||||
@@ -63,7 +63,7 @@
|
|||||||
* IPv6 addresses, regardless of networking support.
|
* IPv6 addresses, regardless of networking support.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef CONFIG_LIB_NETDB
|
#ifdef CONFIG_NETDB_HOSTFILE
|
||||||
# undef CONFIG_NET_IPv4
|
# undef CONFIG_NET_IPv4
|
||||||
# undef CONFIG_NET_IPv6
|
# undef CONFIG_NET_IPv6
|
||||||
# define CONFIG_NET_IPv4 1
|
# define CONFIG_NET_IPv4 1
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
############################################################################
|
||||||
|
# libc/netdb/Make.defs
|
||||||
|
#
|
||||||
|
# Copyright (C) 2011-2013 Gregory Nutt. All rights reserved.
|
||||||
|
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_LIBC_NETDB),y)
|
||||||
|
|
||||||
|
# Add the netdb C files to the build
|
||||||
|
|
||||||
|
# Add host file support
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_NETDB_HOSTFILE),y)
|
||||||
|
CSRCS += lib_netdb.c lib_gethostbyname.c lib_gethostbynamer.c
|
||||||
|
CSRCS += lib_gethostbyaddr.c lib_gethostbyaddrr.c lib_parsehostfile.c
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Add DNS support
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_NETDB_DNSCLIENT),y)
|
||||||
|
CSRCS = dns_resolver.c dns_socket.c dns_gethostip.c
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Add the net directory to the build
|
||||||
|
|
||||||
|
DEPPATH += --dep-path netdb
|
||||||
|
VPATH += :netdb
|
||||||
|
|
||||||
|
endif
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* libc/netdb/dns_gethostip.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007, 2009, 2012, 2014 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* Based heavily on portions of uIP:
|
||||||
|
*
|
||||||
|
* Author: Adam Dunkels <adam@dunkels.com>
|
||||||
|
* Copyright (c) 2002-2003, Adam Dunkels.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* 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. The name of the author may not be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior
|
||||||
|
* written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <nuttx/net/dnsclient.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dns_gethostip
|
||||||
|
*
|
||||||
|
* Descriptions:
|
||||||
|
* Combines the operations of dns_bind_sock(), dns_query_sock(), and
|
||||||
|
* dns_free_sock() to obtain the the IP address ('ipaddr') associated with
|
||||||
|
* the 'hostname' in one operation.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int dns_gethostip(FAR const char *hostname, FAR in_addr_t *ipaddr)
|
||||||
|
{
|
||||||
|
int sockfd = -1;
|
||||||
|
int ret=ERROR;
|
||||||
|
|
||||||
|
dns_bind_sock(&sockfd);
|
||||||
|
if (sockfd >= 0)
|
||||||
|
{
|
||||||
|
ret = dns_query_sock(sockfd, hostname, ipaddr);
|
||||||
|
dns_free_sock(&sockfd);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* libc/netdb/dns_resolver.c
|
||||||
|
* DNS host name to IP address resolver.
|
||||||
|
*
|
||||||
|
* The uIP DNS resolver functions are used to lookup a hostname and
|
||||||
|
* map it to a numerical IP address. It maintains a list of resolved
|
||||||
|
* hostnames that can be queried. New hostnames can be resolved using the
|
||||||
|
* dns_whois() function.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007, 2009, 2012, 2014 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* Based heavily on portions of uIP:
|
||||||
|
*
|
||||||
|
* Author: Adam Dunkels <adam@dunkels.com>
|
||||||
|
* Copyright (c) 2002-2003, Adam Dunkels.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* 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. The name of the author may not be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior
|
||||||
|
* written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
|
||||||
|
#include <nuttx/net/dnsclient.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int g_sockfd = -1;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dns_bind
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the DNS resolver using an internal, share-able socket.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int dns_bind(void)
|
||||||
|
{
|
||||||
|
return dns_bind_sock(&g_sockfd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dns_query
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Using the internal DNS resolver socket, look up the the 'hostname', and
|
||||||
|
* return its IP address in 'ipaddr'
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Returns zero (OK) if the query was successful.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int dns_query(FAR const char *hostname, FAR in_addr_t *ipaddr)
|
||||||
|
{
|
||||||
|
return dns_query_sock(g_sockfd, hostname, ipaddr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dns_whois
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Get the binding for 'name' using the DNS server accessed via the DNS
|
||||||
|
* resolvers internal socket.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_NETDB_DNSCLIENT_IPv6
|
||||||
|
int dns_whois(FAR const char *name, FAR struct sockaddr_in6 *addr)
|
||||||
|
#else
|
||||||
|
int dns_whois(FAR const char *name, FAR struct sockaddr_in *addr)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
return dns_whois_socket(g_sockfd, name, addr);
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* libc/net/lib_gethostbyaddr.c
|
* libc/netdb/lib_gethostbyaddr.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@@ -43,9 +43,9 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "lib_internal.h"
|
#include "lib_internal.h"
|
||||||
#include "net/lib_netdb.h"
|
#include "netdb/lib_netdb.h"
|
||||||
|
|
||||||
#ifdef CONFIG_LIB_NETDB
|
#ifdef CONFIG_NETDB_HOSTFILE
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
@@ -89,4 +89,4 @@ FAR struct hostent *gethostbyaddr(FAR const void *addr, socklen_t len, int type)
|
|||||||
return ret == 0 ? &g_hostent : NULL;
|
return ret == 0 ? &g_hostent : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_LIB_NETDB */
|
#endif /* CONFIG_NETDB_HOSTFILE */
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* libc/net/lib_gethostbyaddrr.c
|
* libc/netdb/lib_gethostbyaddrr.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@@ -48,9 +48,9 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
#include "lib_internal.h"
|
#include "lib_internal.h"
|
||||||
#include "net/lib_netdb.h"
|
#include "netdb/lib_netdb.h"
|
||||||
|
|
||||||
#ifdef CONFIG_LIB_NETDB
|
#ifdef CONFIG_NETDB_HOSTFILE
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
@@ -185,4 +185,4 @@ errorout_with_herrnocode:
|
|||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_LIB_NETDB */
|
#endif /* CONFIG_NETDB_HOSTFILE */
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* libc/net/lib_gethostbyname.c
|
* libc/netdb/lib_gethostbyname.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@@ -43,9 +43,9 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "lib_internal.h"
|
#include "lib_internal.h"
|
||||||
#include "net/lib_netdb.h"
|
#include "netdb/lib_netdb.h"
|
||||||
|
|
||||||
#ifdef CONFIG_LIB_NETDB
|
#ifdef CONFIG_NETDB_HOSTFILE
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
@@ -89,4 +89,4 @@ FAR struct hostent *gethostbyname(FAR const char *name)
|
|||||||
return ret == 0 ? &g_hostent : NULL;
|
return ret == 0 ? &g_hostent : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_LIB_NETDB */
|
#endif /* CONFIG_NETDB_HOSTFILE */
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* libc/net/lib_gethostbynamer.c
|
* libc/netdb/lib_gethostbynamer.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
|
|
||||||
#include "lib_internal.h"
|
#include "lib_internal.h"
|
||||||
|
|
||||||
#ifdef CONFIG_LIB_NETDB
|
#ifdef CONFIG_NETDB_HOSTFILE
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
@@ -353,4 +353,4 @@ errorout_with_herrnocode:
|
|||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_LIB_NETDB */
|
#endif /* CONFIG_NETDB_HOSTFILE */
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* libc/net/lib_netdb.c
|
* libc/netdb/lib_netdb.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@@ -41,9 +41,9 @@
|
|||||||
|
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
|
||||||
#include "net/lib_netdb.h"
|
#include "netdb/lib_netdb.h"
|
||||||
|
|
||||||
#ifdef CONFIG_LIB_NETDB
|
#ifdef CONFIG_NETDB_HOSTFILE
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Data
|
* Public Data
|
||||||
@@ -56,4 +56,4 @@ char g_hostbuffer[CONFIG_NETDB_BUFSIZE];
|
|||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#endif /* CONFIG_LIB_NETDB */
|
#endif /* CONFIG_NETDB_HOSTFILE */
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* libc/net/lib_netdb.h
|
* libc/netdb/lib_netdb.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
|
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
|
||||||
#ifdef CONFIG_LIB_NETDB
|
#ifdef CONFIG_NETDB_HOSTFILE
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* libc/net/lib_parsehostile.c
|
* libc/netdb/lib_parsehostile.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
|
|
||||||
#include "lib_internal.h"
|
#include "lib_internal.h"
|
||||||
|
|
||||||
#ifdef CONFIG_LIB_NETDB
|
#ifdef CONFIG_NETDB_HOSTFILE
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
@@ -446,4 +446,4 @@ ssize_t lib_parse_hostfile(FAR FILE *stream, FAR struct hostent *host,
|
|||||||
return nread;
|
return nread;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_LIB_NETDB */
|
#endif /* CONFIG_NETDB_HOSTFILE */
|
||||||
Reference in New Issue
Block a user