libc/netdb: Replace get_errno with errno

and fix the typo error

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I51e2e4dbdb46fea89f4e18a41d99b943b03cedab
This commit is contained in:
Xiang Xiao 2020-03-29 01:08:10 +08:00 committed by patacongo
parent 910ebbf5b0
commit 07c3b16462
8 changed files with 36 additions and 40 deletions

View File

@ -204,7 +204,7 @@ int dns_query(int sd, FAR const char *hostname, FAR union dns_addr_u *addr,
* Name: dns_save_answer
*
* Description:
* Same the last resolved hostname in the DNS cache
* Save the last resolved hostname in the DNS cache
*
* Input Parameters:
* hostname - The hostname string to be cached.

View File

@ -69,17 +69,16 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
#ifdef CONFIG_NETDB_RESOLVCONF_NONSTDPORT
uint16_t port;
#endif
int status;
int ret;
stream = fopen(CONFIG_NETDB_RESOLVCONF_PATH, "a+");
if (stream == NULL)
{
int errcode = get_errno();
ret = -errno;
nerr("ERROR: Failed to open %s: %d\n",
CONFIG_NETDB_RESOLVCONF_PATH, errcode);
DEBUGASSERT(errcode > 0);
return -errcode;
CONFIG_NETDB_RESOLVCONF_PATH, ret);
DEBUGASSERT(ret < 0);
return ret;
}
#ifdef CONFIG_NET_IPv4
@ -100,8 +99,8 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
DNS_MAX_ADDRSTR) == NULL)
{
ret = -errno;
nerr("ERROR: inet_ntop failed: %d\n", errcode);
DEBUGASSERT(errcode < 0);
nerr("ERROR: inet_ntop failed: %d\n", ret);
DEBUGASSERT(ret < 0);
goto errout;
}
@ -133,8 +132,8 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
DNS_MAX_ADDRSTR) == NULL)
{
ret = -errno;
nerr("ERROR: inet_ntop failed: %d\n", errcode);
DEBUGASSERT(errcode < 0);
nerr("ERROR: inet_ntop failed: %d\n", ret);
DEBUGASSERT(ret < 0);
goto errout;
}
@ -167,21 +166,21 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
if (port != 0 && port != DNS_DEFAULT_PORT)
{
status = fprintf(stream, "%s [%s]:%u\n",
NETDB_DNS_KEYWORD, addrstr, port);
ret = fprintf(stream, "%s [%s]:%u\n",
NETDB_DNS_KEYWORD, addrstr, port);
}
else
#endif
{
status = fprintf(stream, "%s %s\n",
NETDB_DNS_KEYWORD, addrstr);
ret = fprintf(stream, "%s %s\n",
NETDB_DNS_KEYWORD, addrstr);
}
if (status < 0)
if (ret < 0)
{
ret = -errno;
nerr("ERROR: fprintf failed: %d\n", errcode);
DEBUGASSERT(errcode < 0);
nerr("ERROR: fprintf failed: %d\n", ret);
DEBUGASSERT(ret < 0);
goto errout;
}

View File

@ -52,7 +52,7 @@
* Pre-processor Definitions
****************************************************************************/
#if CONFIG_NET_SOCKOPTS < 1
#ifndef CONFIG_NET_SOCKOPTS
# error CONFIG_NET_SOCKOPTS required by this logic
#endif
@ -79,7 +79,6 @@
int dns_bind(void)
{
struct timeval tv;
int errcode;
int sd;
int ret;
@ -96,9 +95,9 @@ int dns_bind(void)
sd = socket(PF_INET, SOCK_DGRAM, 0);
if (sd < 0)
{
errcode = get_errno();
nerr("ERROR: socket() failed: %d\n", errcode);
return -errcode;
ret = -errno;
nerr("ERROR: socket() failed: %d\n", ret);
return ret;
}
/* Set up a receive timeout */
@ -109,10 +108,10 @@ int dns_bind(void)
ret = setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval));
if (ret < 0)
{
errcode = get_errno();
nerr("ERROR: setsockopt() failed: %d\n", errcode);
ret = -errno;
nerr("ERROR: setsockopt() failed: %d\n", ret);
close(sd);
return -errcode;
return ret;
}
return sd;

View File

@ -105,7 +105,7 @@ static struct dns_cache_s g_dns_cache[CONFIG_NETDB_DNSCLIENT_ENTRIES];
* Name: dns_save_answer
*
* Description:
* Same the last resolved hostname in the DNS cache
* Save the last resolved hostname in the DNS cache
*
* Input Parameters:
* hostname - The hostname string to be cached.

View File

@ -104,11 +104,11 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg)
stream = fopen(CONFIG_NETDB_RESOLVCONF_PATH, "rb");
if (stream == NULL)
{
int errcode = get_errno();
ret = -errno;
nerr("ERROR: Failed to open %s: %d\n",
CONFIG_NETDB_RESOLVCONF_PATH, errcode);
DEBUGASSERT(errcode > 0);
return -errcode;
CONFIG_NETDB_RESOLVCONF_PATH, ret);
DEBUGASSERT(ret < 0);
return ret;
}
keylen = strlen(NETDB_DNS_KEYWORD);

View File

@ -217,7 +217,6 @@ static int dns_send_query(int sd, FAR const char *name,
uint8_t buffer[SEND_BUFFER_SIZE];
uint16_t id;
socklen_t addrlen;
int errcode;
int ret;
int len;
int n;
@ -323,9 +322,9 @@ static int dns_send_query(int sd, FAR const char *name,
if (ret < 0)
{
errcode = get_errno();
nerr("ERROR: sendto failed: %d\n", errcode);
return -errcode;
ret = -errno;
nerr("ERROR: sendto failed: %d\n", ret);
return ret;
}
return OK;
@ -358,7 +357,6 @@ static int dns_recv_response(int sd, FAR union dns_addr_u *addr, int *naddr,
union dns_addr_u recvaddr;
socklen_t raddrlen;
int naddr_read;
int errcode;
int ret;
/* Receive the response */
@ -368,9 +366,9 @@ static int dns_recv_response(int sd, FAR union dns_addr_u *addr, int *naddr,
&recvaddr.addr, &raddrlen);
if (ret < 0)
{
errcode = -_NX_GETERRNO(ret);
nerr("ERROR: recv failed: %d\n", errcode);
return errcode;
ret = -_NX_GETERRNO(ret);
nerr("ERROR: recv failed: %d\n", ret);
return ret;
}
#ifdef CONFIG_NET_IPv4

View File

@ -280,7 +280,7 @@ int lib_hostfile_lookup(FAR const void *addr, socklen_t len, int type,
stream = fopen(CONFIG_NETDB_HOSTCONF_PATH, "r");
if (stream == NULL)
{
int errcode = get_errno();
int errcode = -errno;
nerr("ERROR: Failed to open the hosts file %s: %d\n",
CONFIG_NETDB_HOSTCONF_PATH, errcode);

View File

@ -651,7 +651,7 @@ static int lib_hostfile_lookup(FAR const char *name, FAR struct hostent *host,
stream = fopen(CONFIG_NETDB_HOSTCONF_PATH, "r");
if (stream == NULL)
{
int errcode = get_errno();
int errcode = -errno;
nerr("ERROR: Failed to open the hosts file %s: %d\n",
CONFIG_NETDB_HOSTCONF_PATH, errcode);