From 232d6fecb6c699298e21929d3edbf9e8328501d9 Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Mon, 2 May 2016 14:49:32 +0200 Subject: libnetworking: Import current Import the from current FreeBSD. This allows to build some current software (e.g. libressl). Add __h_errno(). Update gethostent_r() API. Linux and FreeBSD use a common API now. Adapt the RTEMS one to provide the same one. Match gethostbyname_r() with prototype. --- cpukit/libnetworking/libc/gethostbyht.c | 52 +++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 12 deletions(-) (limited to 'cpukit/libnetworking/libc/gethostbyht.c') diff --git a/cpukit/libnetworking/libc/gethostbyht.c b/cpukit/libnetworking/libc/gethostbyht.c index 2278e7092b..279514ea89 100644 --- a/cpukit/libnetworking/libc/gethostbyht.c +++ b/cpukit/libnetworking/libc/gethostbyht.c @@ -214,17 +214,36 @@ _gethostbyhtaddr( #ifdef _THREAD_SAFE -struct hostent* gethostent_r(char* buf, int len) +int +gethostent_r( + struct hostent *pe, + char *buf, + size_t len, + struct hostent **result, + int *h_errnop) { char *dest; - struct hostent* pe=(struct hostent*)buf; char* last; char* max=buf+len; int aliasidx; int curlen; - - - if (!hostf) return 0; + int rv; + + if (pe == NULL || buf == NULL || result == NULL || h_errnop == NULL) { + if (h_errnop != NULL) { + *h_errnop = NETDB_INTERNAL; + } + return EINVAL; + } + + *result = NULL; + *h_errnop = NETDB_INTERNAL; + rv = -1; + + if (!hostf) { + rv = ENOENT; + return rv; + } fseek(hostf,0,SEEK_END); curlen=ftell(hostf); fseek(hostf,0,SEEK_SET); @@ -248,16 +267,22 @@ struct hostent* gethostent_r(char* buf, int len) last=hostmap+hostlen; again: if ((size_t)lenh_name=0; pe->h_aliases=(char**)dest; pe->h_aliases[0]=0; dest+=10*sizeof(char*); pe->h_addr_list=(char**)dest; dest+=2*sizeof(char**); - if (cur>=last) return 0; + if (cur>=last) { + rv = ERANGE; + return rv; + } if (*cur=='#' || *cur=='\n') goto parseerror; /* first, the ip number */ pe->h_name=cur; while (cur=last) return 0; + if (cur>=last) { + rv = ERANGE; + return rv; + } if (*cur=='\n') goto parseerror; { char save=*cur; @@ -301,19 +326,22 @@ again: pe->h_aliases[aliasidx]=0; pe->h_name=pe->h_aliases[0]; pe->h_aliases++; - return pe; + *result = pe; + *h_errnop = 0; + rv = 0; + return rv; parseerror: while (cur