resolv.conf: Fix some basic compilation issues. Logic still not complete.
This commit is contained in:
parent
a7acb45ca6
commit
0889963b50
@ -164,6 +164,12 @@ struct dns_answer_s
|
||||
} u;
|
||||
};
|
||||
|
||||
/* The type of the callback from dns_foreach_nameserver() */
|
||||
|
||||
typedef CODE int (*dns_callback_t)(FAR void *arg,
|
||||
FAR struct sockaddr *addr,
|
||||
FAR socklen_t addrlen);
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
33
libc/Kconfig
33
libc/Kconfig
@ -533,23 +533,7 @@ config NETDB_BUFSIZE
|
||||
|
||||
endif # NETDB_HOSTFILE
|
||||
|
||||
menuconfig NETDB_RESOLVCONF
|
||||
bool "DNS server file support"
|
||||
default n
|
||||
depends on FS_READABLE
|
||||
select LIBC_NETDB
|
||||
---help---
|
||||
Enable DNS server look ups in resolver file.
|
||||
|
||||
if NETDB_RESOLVCONF
|
||||
|
||||
config NETDB_RESOLVCONF_PATH
|
||||
string "Path to host configuration file"
|
||||
default "/etc/resolv.conf"
|
||||
|
||||
endif # NETDB_RESOLVCONF
|
||||
|
||||
config NETDB_DNSCLIENT
|
||||
menuconfig NETDB_DNSCLIENT
|
||||
bool "DNS Name resolution"
|
||||
default n
|
||||
depends on NET && NET_UDP
|
||||
@ -716,6 +700,21 @@ config NETDB_DNSSERVER_IPv6ADDR_8
|
||||
of the 8-values. The default for all eight values is fc00::1.
|
||||
|
||||
endif # NETDB_DNSSERVER_IPv6
|
||||
|
||||
config NETDB_RESOLVCONF
|
||||
bool "DNS server file support"
|
||||
default n
|
||||
depends on FS_READABLE
|
||||
---help---
|
||||
Enable DNS server look ups in resolver file.
|
||||
|
||||
if NETDB_RESOLVCONF
|
||||
|
||||
config NETDB_RESOLVCONF_PATH
|
||||
string "Path to host configuration file"
|
||||
default "/etc/resolv.conf"
|
||||
|
||||
endif # NETDB_RESOLVCONF
|
||||
endif # NETDB_DNSCLIENT
|
||||
|
||||
comment "Non-standard Library Support"
|
||||
|
@ -45,6 +45,8 @@
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
@ -99,12 +101,6 @@ union dns_server_u
|
||||
#endif
|
||||
};
|
||||
|
||||
/* The type of the callback from dns_foreach_nameserver() */
|
||||
|
||||
typedef CODE int (*dns_callback_t)(FAR void *arg,
|
||||
FAR struct sockaddr *addr,
|
||||
FAR socklen_t *addrlen);
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
@ -198,7 +194,7 @@ int dns_find_answer(FAR const char *hostname, FAR struct sockaddr *addr,
|
||||
FAR socklen_t *addrlen);
|
||||
#endif
|
||||
|
||||
o#undef EXTERN
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
@ -39,6 +39,14 @@
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/net/ip.h>
|
||||
#include <nuttx/net/dns.h>
|
||||
|
||||
#include "netdb/lib_dns.h"
|
||||
@ -75,12 +83,12 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
|
||||
char line[DNS_MAX_LINE];
|
||||
int ret;
|
||||
|
||||
stream = fopen(CONFIG_NETDB_RESOLVCONF, "at");
|
||||
stream = fopen(CONFIG_NETDB_RESOLVCONF_PATH, "at");
|
||||
if (stream == NULL)
|
||||
{
|
||||
int errcode = errno;
|
||||
ndbg("ERROR: Failed to open %s: %d\n",
|
||||
CONFIG_NETDB_RESOLVCONF, errcode);
|
||||
CONFIG_NETDB_RESOLVCONF_PATH, errcode);
|
||||
DEBUGASSERT(errcode > 0);
|
||||
return -errcode;
|
||||
}
|
||||
@ -90,7 +98,7 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
|
||||
|
||||
if (addr->sa_family == AF_INET)
|
||||
{
|
||||
if (socklen < sizeof(struct sockaddr_in))
|
||||
if (addrlen < sizeof(struct sockaddr_in))
|
||||
{
|
||||
ret = -EINVAL;
|
||||
goto errout;
|
||||
@ -116,7 +124,7 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
|
||||
|
||||
if (addr->sa_family == AF_INET6)
|
||||
{
|
||||
if (socklen < sizeof(struct sockaddr_in6))
|
||||
if (addrlen < sizeof(struct sockaddr_in6))
|
||||
{
|
||||
ret = -EINVAL;
|
||||
goto errout;
|
||||
@ -223,7 +231,7 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
|
||||
|
||||
g_dns_address = true;
|
||||
return OK;
|
||||
#endif /* CONFIG_NETDB_RESOLVCONF */
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NETDB_RESOLVCONF */
|
||||
#endif /* CONFIG_NETDB_DNSCLIENT */
|
||||
|
@ -194,6 +194,7 @@ static bool dns_initialize(void)
|
||||
g_dns_initialized = true;
|
||||
}
|
||||
|
||||
#ifndef CONFIG_NETDB_RESOLVCONF
|
||||
/* Has the DNS server IP address been assigned? */
|
||||
|
||||
if (!g_dns_address)
|
||||
@ -205,7 +206,7 @@ static bool dns_initialize(void)
|
||||
/* No, configure the default IPv4 DNS server address */
|
||||
|
||||
addr4.sin_family = AF_INET;
|
||||
addr4.sin_port = DNS_DEFAULT_PORT;
|
||||
addr4.sin_port = HTONS(DNS_DEFAULT_PORT);
|
||||
addr4.sin_addr.s_addr = HTONL(CONFIG_NETDB_DNSSERVER_IPv4ADDR);
|
||||
|
||||
ret = dns_add_nameserver((FAR struct sockaddr *)&addr4,
|
||||
@ -222,7 +223,7 @@ static bool dns_initialize(void)
|
||||
/* No, configure the default IPv6 DNS server address */
|
||||
|
||||
addr6.sin6_family = AF_INET6;
|
||||
addr6.sin6_port = DNS_DEFAULT_PORT;
|
||||
addr6.sin6_port = HTONS(DNS_DEFAULT_PORT);
|
||||
memcpy(addr6.sin6_addr.s6_addr, g_ipv6_hostaddr, 16);
|
||||
|
||||
ret = dns_add_nameserver((FAR struct sockaddr *)&addr6,
|
||||
@ -233,11 +234,12 @@ static bool dns_initialize(void)
|
||||
}
|
||||
|
||||
#else
|
||||
/* No, then we are not ready to perform DNS queries */
|
||||
/* Then we are not ready to perform DNS queries */
|
||||
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
#endif /* !ONFIG_NETDB_RESOLVCONF */
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -39,6 +39,15 @@
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <nuttx/net/dns.h>
|
||||
|
||||
#include "netdb/lib_dns.h"
|
||||
@ -49,6 +58,7 @@
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NETDB_RESOLVCONF
|
||||
static FAR char *skip_spaces(FAR char *ptr)
|
||||
{
|
||||
while (isspace(*ptr)) ptr++;
|
||||
@ -57,9 +67,10 @@ static FAR char *skip_spaces(FAR char *ptr)
|
||||
|
||||
static FAR char *find_spaces(FAR char *ptr)
|
||||
{
|
||||
while (isspace(*ptr)) ptr++;
|
||||
while (*ptr && !isspace(*ptr)) ptr++;
|
||||
return ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
@ -87,12 +98,12 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg)
|
||||
|
||||
/* Open the resolver configuration file */
|
||||
|
||||
stream = fopen(CONFIG_NETDB_RESOLVCONF, "rb");
|
||||
stream = fopen(CONFIG_NETDB_RESOLVCONF_PATH, "rb");
|
||||
if (stream == NULL)
|
||||
{
|
||||
int errcode = errno;
|
||||
ndbg("ERROR: Failed to open %s: %d\n",
|
||||
CONFIG_NETDB_RESOLVCONF, errcode);
|
||||
CONFIG_NETDB_RESOLVCONF_PATH, errcode);
|
||||
DEBUGASSERT(errcode > 0);
|
||||
return -errcode;
|
||||
}
|
||||
@ -103,8 +114,18 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg)
|
||||
ptr = skip_spaces(line);
|
||||
if (strncmp(ptr, NETDB_DNS_KEYWORD, keylen) == 0)
|
||||
{
|
||||
socklen_t copylen;
|
||||
/* Skip over the 'nameserver' keyword */
|
||||
|
||||
ptr = find_spaces(ptr);
|
||||
ptr = skip_spaces(ptr);
|
||||
if (*ptr == '\0')
|
||||
{
|
||||
ndbg("ERROR: Missing address in %s record\n",
|
||||
CONFIG_NETDB_RESOLVCONF_PATH);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Convert the address string to a binary representation */
|
||||
/* REVISIT: We really need a customizable port number. The
|
||||
* OpenBSD version supports a [host]:port syntax. When a
|
||||
* non-standard port is specified the host address must be
|
||||
@ -126,8 +147,9 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg)
|
||||
/* REVISIT: We really need a customizable port number */
|
||||
|
||||
u.ipv4.sin_family = AF_INET;
|
||||
u.ipv4.sin_port = DNS_DEFAULT_PORT;
|
||||
ret = callback(arg, AF_INET, &u.ipv4, sizeof(struct sockaddr_in));
|
||||
u.ipv4.sin_port = HTONS(DNS_DEFAULT_PORT);
|
||||
ret = callback(arg, (FAR struct sockaddr *)&u.ipv4,
|
||||
sizeof(struct sockaddr_in));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@ -146,8 +168,9 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg)
|
||||
/* REVISIT: We really need a customizable port number */
|
||||
|
||||
u.ipv6.sin6_family = AF_INET6;
|
||||
u.ipv6.sin6_port = DNS_DEFAULT_PORT;
|
||||
ret = callback(arg, &u.ipv6, sizeof(struct sockaddr_in6));
|
||||
u.ipv6.sin6_port = HTONS(DNS_DEFAULT_PORT);
|
||||
ret = callback(arg, (FAR struct sockaddr *)&u.ipv6,
|
||||
sizeof(struct sockaddr_in6));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@ -185,7 +208,8 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg)
|
||||
{
|
||||
/* Perform the callback */
|
||||
|
||||
ret = callback(arg, &g_dns_server.ipv4, sizeof(struct sockaddr_in);
|
||||
ret = callback(arg, (FAR struct sockaddr *)&g_dns_server.ipv4,
|
||||
sizeof(struct sockaddr_in));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@ -197,7 +221,8 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg)
|
||||
{
|
||||
/* Perform the callback */
|
||||
|
||||
ret = callback(arg, &g_dns_server.ipv6, sizeof(struct sockaddr_in6);
|
||||
ret = callback(arg, (FAR struct sockaddr *)&g_dns_server.ipv6,
|
||||
sizeof(struct sockaddr_in6));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user