libc/netdb: make getaddrinfo re-entrant also when querying with service name

Signed-off-by: Juha Niskanen <juha.niskanen@haltian.com>
This commit is contained in:
Juha Niskanen 2020-04-24 12:11:03 +03:00 committed by Xiang Xiao
parent e5443a4718
commit ba0a17ca8c
3 changed files with 5 additions and 4 deletions

View File

@ -161,8 +161,9 @@ int getaddrinfo(FAR const char *hostname, FAR const char *servname,
if (servname != NULL)
{
FAR char *endp;
struct servent ent;
FAR struct servent *sp;
FAR char *endp;
port = strtol(servname, &endp, 10);
if (port > 0 && port <= 65535 && *endp == '\0')
@ -175,7 +176,7 @@ int getaddrinfo(FAR const char *hostname, FAR const char *servname,
{
return EAI_NONAME;
}
else if ((sp = getservbyname(servname, NULL)) != NULL)
else if (getservbyname_r(servname, NULL, &ent, NULL, 0, &sp) == OK)
{
/* The s_port field of struct servent is required to
* be in network byte order (per OpenGroup.org)

View File

@ -69,7 +69,7 @@ bool convert_hostent(const FAR struct hostent_s *in,
int i;
int j;
/* Initialize the ouptut of hostent */
/* Initialize the output of hostent */
out->h_name = in->h_name;
out->h_aliases = in->h_aliases;

View File

@ -1,5 +1,5 @@
/****************************************************************************
* libs/libc/netdb/lib_parsehostile.c
* libs/libc/netdb/lib_parsehostfile.c
*
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>