libc/netdb: Add hostent_s to avoid the change of hostent

and let other function call the new internal function gethostentbyname_r

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Ic6137d6cf03f75d6ed33e23bf04ae74b7264e682
This commit is contained in:
Xiang Xiao
2020-04-01 02:21:04 +08:00
committed by patacongo
parent 99dc8bf4e9
commit 0b662d60fc
16 changed files with 1210 additions and 872 deletions
+13 -8
View File
@@ -184,17 +184,14 @@ struct hostent
FAR char **h_aliases; /* A pointer to an array of pointers to the
* alternative host names, terminated by a
* null pointer. */
FAR int *h_addrtypes; /* A pointer to an array of address type. */
FAR int *h_lengths; /* A pointer to an array of the length, in bytes,
* of the address. */
int h_addrtype; /* Address type. */
int h_length; /* The length, in bytes, of the address. */
FAR char **h_addr_list; /* A pointer to an array of pointers to network
* addresses (in network byte order) for the host,
* terminated by a null pointer. */
};
#define h_addr h_addr_list[0] /* For backward compatibility */
#define h_length h_lengths[0]
#define h_addrtype h_addrtypes[0]
struct netent
{
@@ -291,6 +288,7 @@ int getnameinfo(FAR const struct sockaddr *sa,
FAR struct hostent *gethostbyaddr(FAR const void *addr, socklen_t len,
int type);
FAR struct hostent *gethostbyname(FAR const char *name);
FAR struct hostent *gethostbyname2(FAR const char *name, int type);
FAR struct servent *getservbyport(int port, FAR const char *proto);
FAR struct servent *getservbyname(FAR const char *name,
FAR const char *proto);
@@ -314,9 +312,16 @@ void setservent(int);
int gethostbyaddr_r(FAR const void *addr, socklen_t len, int type,
FAR struct hostent *host, FAR char *buf,
size_t buflen, int *h_errnop);
int gethostbyname_r(FAR const char *name, FAR struct hostent *host,
FAR char *buf, size_t buflen, int *h_errnop);
size_t buflen, FAR struct hostent **result,
FAR int *h_errnop);
int gethostbyname_r(FAR const char *name,
FAR struct hostent *host, FAR char *buf,
size_t buflen, FAR struct hostent **result,
FAR int *h_errnop);
int gethostbyname2_r(FAR const char *name, int type,
FAR struct hostent *host, FAR char *buf,
size_t buflen, FAR struct hostent **result,
FAR int *h_errnop);
int getservbyport_r(int port, FAR const char *proto,
FAR struct servent *result_buf, FAR char *buf,
size_t buflen, FAR struct servent **result);
+2
View File
@@ -38,6 +38,8 @@ ifeq ($(CONFIG_LIBC_NETDB),y)
# Add the netdb C files to the build
CSRCS += lib_netdb.c lib_gethostbyname.c lib_gethostbynamer.c
CSRCS += lib_gethostbyname2.c lib_gethostbyname2r.c
CSRCS += lib_gethostentbynamer.c
CSRCS += lib_gethostbyaddr.c lib_gethostbyaddrr.c
CSRCS += lib_getservbyname.c lib_getservbynamer.c
CSRCS += lib_getservbyport.c lib_getservbyportr.c
+57 -57
View File
@@ -46,6 +46,7 @@
#include <netdb.h>
#include "libc.h"
#include "lib_netdb.h"
/****************************************************************************
* Private Data Types
@@ -123,12 +124,14 @@ int getaddrinfo(FAR const char *hostname, FAR const char *servname,
int flags = 0;
int proto = 0;
int socktype = 0;
FAR struct hostent *hp;
char hostbuffer[CONFIG_NETDB_BUFSIZE];
FAR struct hostent_s host;
FAR struct ai_s *ai;
FAR struct ai_s *prev_ai = NULL;
const int valid_flags = AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST |
AI_NUMERICSERV | AI_V4MAPPED | AI_ALL |
AI_ADDRCONFIG;
int ret = OK;
int i;
if (hostname == NULL && servname == NULL)
@@ -278,63 +281,60 @@ int getaddrinfo(FAR const char *hostname, FAR const char *servname,
/* REVISIT: no check for AI_NUMERICHOST flag. */
/* REVISIT: use gethostbyname_r with own buffer of refactor all
* public APIs to use internal lookup function.
*/
hp = gethostbyname(hostname);
if (hp && hp->h_name && hp->h_name[0] && hp->h_addr_list[0])
gethostentbyname_r(hostname, &host,
hostbuffer, sizeof(hostbuffer), &ret);
if (ret != OK)
{
for (i = 0; hp->h_addr_list[i]; i++)
{
if (family != AF_UNSPEC && hp->h_addrtypes[i] != family)
{
/* Filter by protocol family. */
continue;
}
/* REVISIT: filter by socktype and protocol not implemented. */
ai = alloc_ai(hp->h_addrtypes[i], socktype, proto, port,
hp->h_addr_list[i]);
if (ai == NULL)
{
if (*res)
{
freeaddrinfo(*res);
}
return EAI_MEMORY;
}
/* REVISIT: grok canonical name.
*
* OpenGroup: "if the canonical name is not available, then
* ai_canonname shall refer to the hostname argument or a string
* with the same contents."
*/
ai->ai.ai_canonname = (FAR char *)hostname;
/* Add result to linked list.
* TODO: RFC 3484/6724 destination address sort not implemented.
*/
if (prev_ai != NULL)
{
prev_ai->ai.ai_next = (FAR struct addrinfo *)ai;
}
else
{
*res = (FAR struct addrinfo *)ai;
}
prev_ai = ai;
}
return (*res != NULL) ? OK : EAI_FAMILY;
return ret;
}
return h_errno;
for (i = 0; host.h_addr_list[i]; i++)
{
if (family != AF_UNSPEC && host.h_addrtypes[i] != family)
{
/* Filter by protocol family. */
continue;
}
/* REVISIT: filter by socktype and protocol not implemented. */
ai = alloc_ai(host.h_addrtypes[i], socktype, proto, port,
host.h_addr_list[i]);
if (ai == NULL)
{
if (*res)
{
freeaddrinfo(*res);
}
return EAI_MEMORY;
}
/* REVISIT: grok canonical name.
*
* OpenGroup: "if the canonical name is not available, then
* ai_canonname shall refer to the hostname argument or a string
* with the same contents."
*/
ai->ai.ai_canonname = (FAR char *)hostname;
/* Add result to linked list.
* TODO: RFC 3484/6724 destination address sort not implemented.
*/
if (prev_ai != NULL)
{
prev_ai->ai.ai_next = (FAR struct addrinfo *)ai;
}
else
{
*res = (FAR struct addrinfo *)ai;
}
prev_ai = ai;
}
return (*res != NULL) ? OK : EAI_FAMILY;
}
+3 -7
View File
@@ -40,9 +40,7 @@
#include <nuttx/config.h>
#include <netdb.h>
#include <errno.h>
#include "libc.h"
#include "netdb/lib_netdb.h"
#ifdef CONFIG_LIBC_NETDB
@@ -80,14 +78,12 @@
FAR struct hostent *gethostbyaddr(FAR const void *addr,
socklen_t len, int type)
{
FAR struct hostent *res;
int ret;
DEBUGASSERT(addr != NULL);
DEBUGASSERT(type == AF_INET || type == AF_INET6);
ret = gethostbyaddr_r(addr, len, type, &g_hostent, g_hostbuffer,
CONFIG_NETDB_BUFSIZE, &h_errno);
return ret == 0 ? &g_hostent : NULL;
CONFIG_NETDB_BUFSIZE, &res, &h_errno);
return ret == 0 ? res : NULL;
}
#endif /* CONFIG_LIBC_NETDB */
+39 -21
View File
@@ -48,7 +48,6 @@
#include <arpa/inet.h>
#include <nuttx/net/loopback.h>
#include "libc.h"
#include "netdb/lib_netdb.h"
#ifdef CONFIG_LIBC_NETDB
@@ -61,8 +60,8 @@
struct hostent_info_s
{
int hi_addrtypes[CONFIG_NETDB_MAX_IPADDR + 1];
int hi_lengths[CONFIG_NETDB_MAX_IPADDR + 1];
int hi_addrtypes[CONFIG_NETDB_MAX_IPADDR];
int hi_lengths[CONFIG_NETDB_MAX_IPADDR];
FAR char *hi_addrlist[CONFIG_NETDB_MAX_IPADDR + 1];
char hi_data[1];
};
@@ -162,7 +161,7 @@ static bool lib_lo_ipv6match(FAR const void *addr, socklen_t len, int type)
#ifdef CONFIG_NET_LOOPBACK
static int lib_localhost(FAR const void *addr, socklen_t len, int type,
FAR struct hostent *host, FAR char *buf,
FAR struct hostent_s *host, FAR char *buf,
size_t buflen)
{
FAR struct hostent_info_s *info;
@@ -180,7 +179,7 @@ static int lib_localhost(FAR const void *addr, socklen_t len, int type,
dest = info->hi_data;
buflen -= (sizeof(struct hostent_info_s) - 1);
memset(host, 0, sizeof(struct hostent));
memset(host, 0, sizeof(struct hostent_s));
memset(info, 0, sizeof(struct hostent_info_s));
host->h_addrtypes = info->hi_addrtypes;
@@ -192,9 +191,9 @@ static int lib_localhost(FAR const void *addr, socklen_t len, int type,
{
/* Save the IPv4 address */
host->h_length = sizeof(struct in_addr);
host->h_addr = (FAR char *)&g_lo_ipv4addr;
host->h_addrtype = AF_INET;
host->h_lengths[0] = sizeof(struct in_addr);
host->h_addr_list[0] = (FAR char *)&g_lo_ipv4addr;
host->h_addrtypes[0] = AF_INET;
goto out_copyname;
}
#endif
@@ -204,9 +203,9 @@ static int lib_localhost(FAR const void *addr, socklen_t len, int type,
{
/* Save the IPv6 address */
host->h_length = sizeof(struct in6_addr);
host->h_addr = (FAR char *)&g_lo_ipv6addr;
host->h_addrtype = AF_INET6;
host->h_lengths[0] = sizeof(struct in6_addr);
host->h_addr_list[0] = (FAR char *)&g_lo_ipv6addr;
host->h_addrtypes[0] = AF_INET6;
goto out_copyname;
}
#endif
@@ -256,8 +255,8 @@ out_copyname:
#ifdef CONFIG_NETDB_HOSTFILE
int lib_hostfile_lookup(FAR const void *addr, socklen_t len, int type,
FAR struct hostent *host, FAR char *buf,
size_t buflen, int *h_errnop)
FAR struct hostent_s *host, FAR char *buf,
size_t buflen, FAR int *h_errnop)
{
FAR FILE *stream;
int herrnocode;
@@ -286,7 +285,7 @@ int lib_hostfile_lookup(FAR const void *addr, socklen_t len, int type,
{
/* Read the next entry from the hosts file */
nread = lib_parse_hostfile(stream, host, buf, buflen);
nread = parse_hostfile(stream, host, buf, buflen);
if (nread < 0)
{
/* Possible errors:
@@ -305,13 +304,13 @@ int lib_hostfile_lookup(FAR const void *addr, socklen_t len, int type,
goto errorout_with_stream;
}
}
else if (len == host->h_length && type == host->h_addrtype)
else if (len == host->h_lengths[0] && type == host->h_addrtypes[0])
{
/* We successfully read the entry and the type and size of the
* address is good. Now compare the addresses:
*/
FAR char *hostaddr = host->h_addr;
FAR char *hostaddr = host->h_addr_list[0];
if (hostaddr != NULL)
{
ninfo("Comparing addresses...\n");
@@ -371,6 +370,7 @@ errorout_with_herrnocode:
* buf - Caller provided buffer to hold string data associated with the
* host data.
* buflen - The size of the caller-provided buffer
* result - There host entry returned in the event of a success.
* h_errnop - There h_errno value returned in the event of a failure.
*
* Returned Value:
@@ -381,11 +381,19 @@ errorout_with_herrnocode:
int gethostbyaddr_r(FAR const void *addr, socklen_t len, int type,
FAR struct hostent *host, FAR char *buf,
size_t buflen, int *h_errnop)
size_t buflen, FAR struct hostent **result,
FAR int *h_errnop)
{
struct hostent_s tmp;
int ret;
DEBUGASSERT(addr != NULL && host != NULL && buf != NULL);
DEBUGASSERT(type == AF_INET || type == AF_INET6);
/* Linux man page says result must be NULL in case of failure. */
*result = NULL;
/* Make sure that the h_errno has a non-error code */
if (h_errnop)
@@ -396,10 +404,13 @@ int gethostbyaddr_r(FAR const void *addr, socklen_t len, int type,
#ifdef CONFIG_NET_LOOPBACK
/* Check for the local loopback address */
if (lib_localhost(addr, len, type, host, buf, buflen) == 0)
ret = lib_localhost(addr, len, type, &tmp, buf, buflen);
if (ret == OK)
{
/* Yes.. we are done */
convert_hostent(&tmp, AF_UNSPEC, host);
*result = host;
return OK;
}
#endif
@@ -416,8 +427,13 @@ int gethostbyaddr_r(FAR const void *addr, socklen_t len, int type,
#ifdef CONFIG_NETDB_HOSTFILE
/* Search the hosts file for a match */
return lib_hostfile_lookup(addr, len, type, host, buf, buflen, h_errnop);
ret = lib_hostfile_lookup(addr, len, type, &tmp, buf, buflen, h_errnop);
if (ret == OK)
{
convert_hostent(&tmp, AF_UNSPEC, host);
*result = host;
return OK;
}
#else
/* The host file file is not supported. The host address mapping was not
* found from any lookup heuristic
@@ -428,8 +444,10 @@ int gethostbyaddr_r(FAR const void *addr, socklen_t len, int type,
*h_errnop = HOST_NOT_FOUND;
}
return ERROR;
ret = ERROR;
#endif
return ret;
}
#endif /* CONFIG_LIBC_NETDB */
+1 -10
View File
@@ -40,10 +40,6 @@
#include <nuttx/config.h>
#include <netdb.h>
#include <errno.h>
#include "libc.h"
#include "netdb/lib_netdb.h"
#ifdef CONFIG_LIBC_NETDB
@@ -81,12 +77,7 @@
FAR struct hostent *gethostbyname(FAR const char *name)
{
int ret;
DEBUGASSERT(name != NULL);
ret = gethostbyname_r(name, &g_hostent, g_hostbuffer, CONFIG_NETDB_BUFSIZE,
&h_errno);
return ret == 0 ? &g_hostent : NULL;
return gethostbyname2(name, AF_UNSPEC);
}
#endif /* CONFIG_LIBC_NETDB */
+76
View File
@@ -0,0 +1,76 @@
/****************************************************************************
* libs/libc/netdb/lib_gethostbyname2.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <netdb.h>
#include "netdb/lib_netdb.h"
#ifdef CONFIG_LIBC_NETDB
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: gethostbyname2
*
* Description:
* The gethostbyname2() function returns a structure of type hostent for
* the given host name. Here name is either a hostname, or an IPv4 address
* in standard dot notation (as for inet_addr(3)), or an IPv6 address in
* colon (and possibly dot) notation.
*
* If name is an IPv4 or IPv6 address, no lookup is performed and
* gethostbyname2_r() simply copies name into the h_name field
* and its struct in_addr equivalent into the h_addr_list[0] field of the
* returned hostent structure.
*
* Input Parameters:
* name - The name of the host to find.
* type - The type of the address to find.
*
* Returned Value:
* Upon successful completion, this function will return a pointer to a
* hostent structure if the requested entry was found, and a null pointer
* if the end of the database was reached or the requested entry was not
* found.
*
* Upon unsuccessful completion, gethostbyname2() will set h_errno to
* indicate the error
*
****************************************************************************/
FAR struct hostent *gethostbyname2(FAR const char *name, int type)
{
FAR struct hostent *res;
int ret;
ret = gethostbyname2_r(name, type, &g_hostent, g_hostbuffer,
CONFIG_NETDB_BUFSIZE, &res, &h_errno);
return ret == 0 ? res : NULL;
}
#endif /* CONFIG_LIBC_NETDB */
+107
View File
@@ -0,0 +1,107 @@
/****************************************************************************
* libs/libc/netdb/lib_gethostbyname2r.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <netdb.h>
#include "netdb/lib_netdb.h"
#ifdef CONFIG_LIBC_NETDB
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: gethostbyname2_r
*
* Description:
* The gethostbyname2_r() function returns a structure of type hostent for
* the given host name. Here name is either a hostname, or an IPv4 address
* in standard dot notation (as for inet_addr(3)), or an IPv6 address in
* colon (and possibly dot) notation.
*
* If name is an IPv4 or IPv6 address, no lookup is performed and
* gethostbyname2_r() simply copies name into the h_name field
* and its struct in_addr equivalent into the h_addr_list[0] field of the
* returned hostent structure.
*
* gethostname2_r() is *not* POSIX but is similar to a Glibc extension and
* is used internally by NuttX to implement the POSIX gethostname().
*
* Input Parameters:
* name - The name of the host to find.
* type - The type of the address to find.
* host - Caller provided location to return the host data.
* buf - Caller provided buffer to hold string data associated with the
* host data.
* buflen - The size of the caller-provided buffer
* result - There host entry returned in the event of a success.
* h_errnop - There h_errno value returned in the event of a failure.
*
* Returned Value:
* Zero (OK) is returned on success, -1 (ERROR) is returned on a failure
* with the returned h_errno value provided the reason for the failure.
*
****************************************************************************/
int gethostbyname2_r(FAR const char *name, int type,
FAR struct hostent *host, FAR char *buf,
size_t buflen, FAR struct hostent **result,
FAR int *h_errnop)
{
struct hostent_s tmp;
int ret;
/* Linux man page says result must be NULL in case of failure. */
*result = NULL;
ret = gethostentbyname_r(name, &tmp, buf, buflen, h_errnop);
if (ret == OK)
{
if (convert_hostent(&tmp, type, host))
{
*result = host;
}
else
{
if (h_errnop)
{
*h_errnop = HOST_NOT_FOUND;
}
ret = ERROR;
}
}
return ret;
}
#endif /* CONFIG_LIBC_NETDB */
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+5 -5
View File
@@ -46,7 +46,6 @@
#include <arpa/inet.h>
#include <assert.h>
#include "libc.h"
#include "netdb/lib_netdb.h"
#ifdef CONFIG_LIBC_NETDB
@@ -98,22 +97,23 @@ int getnameinfo(FAR const struct sockaddr *addr, socklen_t addrlen,
if (host && !(flags & NI_NUMERICHOST))
{
struct hostent hostent;
FAR struct hostent *res;
int h_errno;
ret = gethostbyaddr_r(saddr, saddr_len, addr->sa_family, &hostent,
host, hostlen, &h_errno);
host, hostlen, &res, &h_errno);
if (ret == OK)
{
size_t sz = strlen(hostent.h_name) + 1;
size_t sz = strlen(res->h_name) + 1;
if (sz <= hostlen)
{
memmove(host, hostent.h_name, sz);
memmove(host, res->h_name, sz);
}
else
{
memmove(host, hostent.h_name, hostlen);
memmove(host, res->h_name, hostlen);
host[hostlen - 1] = '\0';
}
}
+1 -1
View File
@@ -55,7 +55,7 @@ FAR struct servent *getservbyname(FAR const char *name,
FAR const char *proto)
{
static struct servent ent;
struct servent *res;
FAR struct servent *res;
int ret;
ret = getservbyname_r(name, proto, &ent, NULL, 0, &res);
+1 -1
View File
@@ -58,7 +58,7 @@
FAR struct servent *getservbyport(int port, FAR const char *proto)
{
static struct servent ent;
struct servent *res;
FAR struct servent *res;
int ret;
ret = getservbyport_r(port, proto, &ent, NULL, 0, &res);
+45
View File
@@ -63,4 +63,49 @@ int h_errno;
* Public Functions
****************************************************************************/
bool convert_hostent(const FAR struct hostent_s *in,
int type, FAR struct hostent *out)
{
int i;
int j;
/* Initialize the ouptut of hostent */
out->h_name = in->h_name;
out->h_aliases = in->h_aliases;
if (type != AF_UNSPEC)
{
out->h_addrtype = type;
if (type == AF_INET)
{
out->h_length = sizeof(struct in_addr);
}
else
{
out->h_length = sizeof(struct in6_addr);
}
}
else
{
type = in->h_addrtypes[0];
out->h_addrtype = in->h_addrtypes[0];
out->h_length = in->h_lengths[0];
}
out->h_addr_list = in->h_addr_list;
/* Remove different type from list */
for (i = j = 0; in->h_addr_list[i]; i++)
{
if (type == in->h_addrtypes[i])
{
in->h_addr_list[j++] = in->h_addr_list[i];
}
}
in->h_addr_list[j] = NULL;
return j != 0;
}
#endif /* CONFIG_LIBC_NETDB */
+25
View File
@@ -43,6 +43,7 @@
#include <nuttx/config.h>
#include <netdb.h>
#include <stdio.h>
#ifdef CONFIG_LIBC_NETDB
@@ -78,6 +79,20 @@
* Public Types
****************************************************************************/
struct hostent_s
{
FAR char *h_name; /* Official name of the host. */
FAR char **h_aliases; /* A pointer to an array of pointers to the
* alternative host names, terminated by a
* null pointer. */
FAR int *h_addrtypes; /* A pointer to an array of address type. */
FAR int *h_lengths; /* A pointer to an array of the length, in bytes,
* of the address. */
FAR char **h_addr_list; /* A pointer to an array of pointers to network
* addresses (in network byte order) for the host,
* terminated by a null pointer. */
};
struct services_db_s
{
FAR const char *s_name;
@@ -105,6 +120,16 @@ EXTERN const struct services_db_s g_services_db[];
* Public Function Prototypes
****************************************************************************/
bool convert_hostent(const FAR struct hostent_s *in,
int type, FAR struct hostent *out);
ssize_t parse_hostfile(FAR FILE *stream, FAR struct hostent_s *host,
FAR char *buf, size_t buflen);
int gethostentbyname_r(FAR const char *name,
FAR struct hostent_s *host, FAR char *buf,
size_t buflen, FAR int *h_errnop);
#undef EXTERN
#ifdef __cplusplus
}
+13 -13
View File
@@ -50,7 +50,7 @@
#include <arpa/inet.h>
#include "libc.h"
#include "lib_netdb.h"
#ifdef CONFIG_NETDB_HOSTFILE
@@ -72,8 +72,8 @@
struct hostent_info_s
{
FAR char *hi_aliases[CONFIG_NETDB_MAX_ALTNAMES + 1];
int hi_addrtypes[2];
int hi_lengths[2];
int hi_addrtypes[1];
int hi_lengths[1];
FAR char *hi_addrlist[2];
char hi_data[1];
};
@@ -239,7 +239,7 @@ static ssize_t lib_copystring(FAR FILE *stream, FAR char *ptr,
****************************************************************************/
/****************************************************************************
* Name: lib_parse_hostfile
* Name: parse_hostfile
*
* Description:
* Parse the next line from the hosts file.
@@ -264,8 +264,8 @@ static ssize_t lib_copystring(FAR FILE *stream, FAR char *ptr,
*
****************************************************************************/
ssize_t lib_parse_hostfile(FAR FILE *stream, FAR struct hostent *host,
FAR char *buf, size_t buflen)
ssize_t parse_hostfile(FAR FILE *stream, FAR struct hostent_s *host,
FAR char *buf, size_t buflen)
{
FAR struct hostent_info_s *info;
FAR char addrstring[48];
@@ -291,7 +291,7 @@ ssize_t lib_parse_hostfile(FAR FILE *stream, FAR struct hostent *host,
ptr = info->hi_data;
buflen -= (sizeof(struct hostent_info_s) - 1);
memset(host, 0, sizeof(struct hostent));
memset(host, 0, sizeof(struct hostent_s));
memset(info, 0, sizeof(struct hostent_info_s));
host->h_addrtypes = info->hi_addrtypes;
@@ -361,7 +361,7 @@ ssize_t lib_parse_hostfile(FAR FILE *stream, FAR struct hostent *host,
return -EAGAIN;
}
host->h_addrtype = AF_INET6;
host->h_addrtypes[0] = AF_INET6;
}
else
{
@@ -382,14 +382,14 @@ ssize_t lib_parse_hostfile(FAR FILE *stream, FAR struct hostent *host,
return -EAGAIN;
}
host->h_addrtype = AF_INET;
host->h_addrtypes[0] = AF_INET;
}
host->h_addr = ptr;
host->h_length = addrlen;
host->h_addr_list[0] = ptr;
host->h_lengths[0] = addrlen;
ptr += addrlen;
buflen -= addrlen;
ptr += addrlen;
buflen -= addrlen;
/* Skip over any additional whitespace */