netdb: Separate lib_dnsclient.c into lib_dnsbind.c and lib_dnsquery.c
This commit is contained in:
parent
62f04d98c1
commit
9097425203
@ -48,7 +48,8 @@ endif
|
||||
# Add DNS lookup support
|
||||
|
||||
ifeq ($(CONFIG_NETDB_DNSCLIENT),y)
|
||||
CSRCS += lib_dnsinit.c lib_dnsclient.c lib_dnsaddserver.c lib_dnsforeach.c
|
||||
CSRCS += lib_dnsinit.c lib_dnsbind.c lib_dnsquery.c lib_dnsaddserver.c
|
||||
CSRCS += lib_dnsforeach.c
|
||||
|
||||
ifneq ($(CONFIG_NETDB_DNSCLIENT_ENTRIES),0)
|
||||
CSRCS += lib_dnscache.c
|
||||
|
@ -46,19 +46,12 @@
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#if 0
|
||||
#include <time.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include <nuttx/net/dns.h>
|
||||
|
||||
#include "netdb/lib_dns.h"
|
||||
@ -409,64 +402,6 @@ static int dns_recv_response(int sd, FAR struct sockaddr *addr,
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dns_bind
|
||||
*
|
||||
* Description:
|
||||
* Initialize the DNS resolver and return a socket bound to the DNS name
|
||||
* server. The name server was previously selected via dns_server().
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, the bound, non-negative socket descriptor is returned. A
|
||||
* negated errno value is returned on any failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int dns_bind(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
int errcode;
|
||||
int sd;
|
||||
int ret;
|
||||
|
||||
/* Has the DNS client been properly initialized? */
|
||||
|
||||
if (!dns_initialize())
|
||||
{
|
||||
ndbg("ERROR: DNS client has not been initialized\n");
|
||||
return -EDESTADDRREQ;
|
||||
}
|
||||
|
||||
/* Create a new socket */
|
||||
|
||||
sd = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
if (sd < 0)
|
||||
{
|
||||
errcode = get_errno();
|
||||
ndbg("ERROR: socket() failed: %d\n", errcode);
|
||||
return -errcode;
|
||||
}
|
||||
|
||||
/* Set up a receive timeout */
|
||||
|
||||
tv.tv_sec = 30;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
ret = setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval));
|
||||
if (ret < 0)
|
||||
{
|
||||
errcode = get_errno();
|
||||
ndbg("ERROR: setsockopt() failed: %d\n", errcode);
|
||||
close(sd);
|
||||
return -errcode;
|
||||
}
|
||||
|
||||
return sd;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dns_query
|
||||
*
|
Loading…
Reference in New Issue
Block a user