diff --git a/libs/libc/netdb/lib_dns.h b/libs/libc/netdb/lib_dns.h index 3caba915190..e712a667b1b 100644 --- a/libs/libc/netdb/lib_dns.h +++ b/libs/libc/netdb/lib_dns.h @@ -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. diff --git a/libs/libc/netdb/lib_dnsaddserver.c b/libs/libc/netdb/lib_dnsaddserver.c index d87e7addc4d..65fedbdd07f 100644 --- a/libs/libc/netdb/lib_dnsaddserver.c +++ b/libs/libc/netdb/lib_dnsaddserver.c @@ -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; } diff --git a/libs/libc/netdb/lib_dnsbind.c b/libs/libc/netdb/lib_dnsbind.c index 3a873021deb..8d941affceb 100644 --- a/libs/libc/netdb/lib_dnsbind.c +++ b/libs/libc/netdb/lib_dnsbind.c @@ -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; diff --git a/libs/libc/netdb/lib_dnscache.c b/libs/libc/netdb/lib_dnscache.c index 6623d6e23a6..0f4963e7ef6 100644 --- a/libs/libc/netdb/lib_dnscache.c +++ b/libs/libc/netdb/lib_dnscache.c @@ -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. diff --git a/libs/libc/netdb/lib_dnsforeach.c b/libs/libc/netdb/lib_dnsforeach.c index 1105a03ca0f..3ec7e333d52 100644 --- a/libs/libc/netdb/lib_dnsforeach.c +++ b/libs/libc/netdb/lib_dnsforeach.c @@ -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); diff --git a/libs/libc/netdb/lib_dnsquery.c b/libs/libc/netdb/lib_dnsquery.c index c23009f24cb..36800ae06b0 100644 --- a/libs/libc/netdb/lib_dnsquery.c +++ b/libs/libc/netdb/lib_dnsquery.c @@ -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 diff --git a/libs/libc/netdb/lib_gethostbyaddrr.c b/libs/libc/netdb/lib_gethostbyaddrr.c index e4ff8abb88d..49fd791878f 100644 --- a/libs/libc/netdb/lib_gethostbyaddrr.c +++ b/libs/libc/netdb/lib_gethostbyaddrr.c @@ -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); diff --git a/libs/libc/netdb/lib_gethostbynamer.c b/libs/libc/netdb/lib_gethostbynamer.c index 4852a927f6e..cf82b5891cd 100644 --- a/libs/libc/netdb/lib_gethostbynamer.c +++ b/libs/libc/netdb/lib_gethostbynamer.c @@ -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);