summaryrefslogtreecommitdiffstats
path: root/cpukit/libnetworking/libc
diff options
context:
space:
mode:
authorChristian Mauderer <Christian.Mauderer@embedded-brains.de>2016-05-02 14:49:32 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-06-28 13:01:38 +0200
commit232d6fecb6c699298e21929d3edbf9e8328501d9 (patch)
tree52667d63e33bde26087461a176a476b089edd0c0 /cpukit/libnetworking/libc
parentlibnetworking: Add <rtems/rtems_netdb.h> (diff)
downloadrtems-232d6fecb6c699298e21929d3edbf9e8328501d9.tar.bz2
libnetworking: Import current <netdb.h>
Import the <netdb.h> 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.
Diffstat (limited to 'cpukit/libnetworking/libc')
-rw-r--r--cpukit/libnetworking/libc/gethostbydns.c1
-rw-r--r--cpukit/libnetworking/libc/gethostbyht.c52
-rw-r--r--cpukit/libnetworking/libc/gethostnamadr.c9
-rw-r--r--cpukit/libnetworking/libc/getnetbydns.c2
-rw-r--r--cpukit/libnetworking/libc/herror.c8
5 files changed, 54 insertions, 18 deletions
diff --git a/cpukit/libnetworking/libc/gethostbydns.c b/cpukit/libnetworking/libc/gethostbydns.c
index ba7291f433..7300ef4564 100644
--- a/cpukit/libnetworking/libc/gethostbydns.c
+++ b/cpukit/libnetworking/libc/gethostbydns.c
@@ -118,7 +118,6 @@ typedef union {
char ac;
} align;
-extern int h_errno;
int _dns_ttl_;
#ifdef DEBUG
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)len<sizeof(struct hostent)+11*sizeof(char*)) goto nospace;
- dest=buf+sizeof(struct hostent);
+ dest=buf;
pe->h_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 && !isspace((unsigned char)*cur)) cur++;
- if (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<last && *cur!='\n') cur++;
cur++;
goto again;
nospace:
- errno=ERANGE;
+ rv=ERANGE;
goto __error;
error:
- errno=ENOMEM;
+ rv=ENOMEM;
__error:
if (hostmap!=NULL) free(hostmap);
hostmap=NULL;
- return 0;
+ return rv;
}
#endif
diff --git a/cpukit/libnetworking/libc/gethostnamadr.c b/cpukit/libnetworking/libc/gethostnamadr.c
index ccf2f96164..cf0a12d68f 100644
--- a/cpukit/libnetworking/libc/gethostnamadr.c
+++ b/cpukit/libnetworking/libc/gethostnamadr.c
@@ -371,7 +371,7 @@ nodata:
int gethostbyname_r(const char* name,
struct hostent* result,
char *buf,
- int buflen,
+ size_t buflen,
struct hostent **RESULT,
int *h_errnop)
{
@@ -414,8 +414,13 @@ int gethostbyname_r(const char* name,
{
struct hostent* r;
+ struct hostent* he_buf = (struct hostent *)buf;
+ char *work_buf = buf + sizeof(struct hostent);
+ size_t remain_len = buflen - sizeof(struct hostent);
+ int he_errno;
+
sethostent(0);
- while ((r=gethostent_r(buf,buflen))) {
+ while (gethostent_r(he_buf, work_buf, remain_len, &r, &he_errno) == 0) {
int i;
if (r->h_addrtype==AF_INET && !strcasecmp(r->h_name,name)) { /* found it! */
found:
diff --git a/cpukit/libnetworking/libc/getnetbydns.c b/cpukit/libnetworking/libc/getnetbydns.c
index a92fba62e9..adbd0c9e4c 100644
--- a/cpukit/libnetworking/libc/getnetbydns.c
+++ b/cpukit/libnetworking/libc/getnetbydns.c
@@ -80,8 +80,6 @@
#include "res_config.h"
-extern int h_errno;
-
#define BYADDR 0
#define BYNAME 1
#define MAXALIASES 35
diff --git a/cpukit/libnetworking/libc/herror.c b/cpukit/libnetworking/libc/herror.c
index e7d6ba48cb..bb1112f336 100644
--- a/cpukit/libnetworking/libc/herror.c
+++ b/cpukit/libnetworking/libc/herror.c
@@ -67,7 +67,13 @@ const char *h_errlist[] = {
};
int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
-int h_errno;
+int *
+__h_errno(void)
+{
+ static int the_h_errno;
+
+ return &the_h_errno;
+}
#define HERROR_USE_WRITEV