libc/netdb: Fix typo error in the implementation of gethostbyname_r

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I6675e800ad5627881ca904e80317df94f5973eb7
This commit is contained in:
Xiang Xiao 2020-03-30 11:28:13 +08:00 committed by patacongo
parent dd0aca6822
commit d8b5362380

View File

@ -83,8 +83,7 @@ struct hostent_info_s
* h_addr_list[0] field of the returned hostent structure. * h_addr_list[0] field of the returned hostent structure.
* *
* Input Parameters: * Input Parameters:
* stream - File stream of the opened hosts file with the file pointer * name - The name of the host to find.
* positioned at the beginning of the next host entry.
* host - Caller provided location to return the host data. * host - Caller provided location to return the host data.
* buf - Caller provided buffer to hold string data associated with the * buf - Caller provided buffer to hold string data associated with the
* host data. * host data.
@ -219,15 +218,14 @@ static int lib_numeric_address(FAR const char *name, FAR struct hostent *host,
* Check if the name is the reserved name for the local loopback device. * Check if the name is the reserved name for the local loopback device.
* *
* Input Parameters: * Input Parameters:
* stream - File stream of the opened hosts file with the file pointer * name - The name of the host to find.
* positioned at the beginning of the next host entry.
* host - Caller provided location to return the host data. * host - Caller provided location to return the host data.
* buf - Caller provided buffer to hold string data associated with the * buf - Caller provided buffer to hold string data associated with the
* host data. * host data.
* buflen - The size of the caller-provided buffer * buflen - The size of the caller-provided buffer
* *
* Returned Value: * Returned Value:
* Zero (0) is returned if the name is an numeric IP address. * Zero (0) is returned if the name is the loopback device.
* *
****************************************************************************/ ****************************************************************************/
@ -385,7 +383,7 @@ static int lib_find_answer(FAR const char *name, FAR struct hostent *host,
if (((FAR struct sockaddr_in *)ptr)->sin_family == AF_INET) if (((FAR struct sockaddr_in *)ptr)->sin_family == AF_INET)
#endif #endif
{ {
addrlen = sizeof(struct sockaddr_in); addrlen = sizeof(struct in_addr);
addrtype = AF_INET; addrtype = AF_INET;
addrdata = &((FAR struct sockaddr_in *)ptr)->sin_addr; addrdata = &((FAR struct sockaddr_in *)ptr)->sin_addr;
} }
@ -396,7 +394,7 @@ static int lib_find_answer(FAR const char *name, FAR struct hostent *host,
else else
#endif #endif
{ {
addrlen = sizeof(struct sockaddr_in6); addrlen = sizeof(struct in6_addr);
addrtype = AF_INET6; addrtype = AF_INET6;
addrdata = &((FAR struct sockaddr_in6 *)ptr)->sin6_addr; addrdata = &((FAR struct sockaddr_in6 *)ptr)->sin6_addr;
} }
@ -545,7 +543,7 @@ static int lib_dns_lookup(FAR const char *name, FAR struct hostent *host,
if (((FAR struct sockaddr_in *)ptr)->sin_family == AF_INET) if (((FAR struct sockaddr_in *)ptr)->sin_family == AF_INET)
#endif #endif
{ {
addrlen = sizeof(struct sockaddr_in); addrlen = sizeof(struct in_addr);
addrtype = AF_INET; addrtype = AF_INET;
addrdata = &((FAR struct sockaddr_in *)ptr)->sin_addr; addrdata = &((FAR struct sockaddr_in *)ptr)->sin_addr;
} }
@ -556,7 +554,7 @@ static int lib_dns_lookup(FAR const char *name, FAR struct hostent *host,
else else
#endif #endif
{ {
addrlen = sizeof(struct sockaddr_in6); addrlen = sizeof(struct in6_addr);
addrtype = AF_INET6; addrtype = AF_INET6;
addrdata = &((FAR struct sockaddr_in6 *)ptr)->sin6_addr; addrdata = &((FAR struct sockaddr_in6 *)ptr)->sin6_addr;
} }
@ -606,7 +604,7 @@ static int lib_dns_lookup(FAR const char *name, FAR struct hostent *host,
* buflen - The size of the caller-provided buffer * buflen - The size of the caller-provided buffer
* *
* Returned Value: * Returned Value:
* Zero (0) is returned if the DNS lookup was successful. * Zero (0) is returned if the host file lookup was successful.
* *
****************************************************************************/ ****************************************************************************/
@ -756,10 +754,6 @@ errorout_with_herrnocode:
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)
{ {
#ifdef CONFIG_NETDB_DNSCLIENT
int ret;
#endif
DEBUGASSERT(name != NULL && host != NULL && buf != NULL); DEBUGASSERT(name != NULL && host != NULL && buf != NULL);
/* Make sure that the h_errno has a non-error code */ /* Make sure that the h_errno has a non-error code */
@ -796,8 +790,7 @@ int gethostbyname_r(FAR const char *name, FAR struct hostent *host,
#if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0 #if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0
/* Check if we already have this hostname mapping cached */ /* Check if we already have this hostname mapping cached */
ret = lib_find_answer(name, host, buf, buflen); if (lib_find_answer(name, host, buf, buflen) >= 0)
if (ret >= 0)
{ {
/* Found the address mapping in the cache */ /* Found the address mapping in the cache */
@ -807,8 +800,7 @@ int gethostbyname_r(FAR const char *name, FAR struct hostent *host,
/* Try to get the host address using the DNS name server */ /* Try to get the host address using the DNS name server */
ret = lib_dns_lookup(name, host, buf, buflen); if (lib_dns_lookup(name, host, buf, buflen) >= 0)
if (ret >= 0)
{ {
/* Successful DNS lookup! */ /* Successful DNS lookup! */