wrowe 2002/10/13 16:28:22
Modified: network_io/unix sa_common.c
Log:
First, revert my changes from yesterday to make Jeff Trawick's suggestions
simpler to follow.
Revision Changes Path
1.62 +44 -36 apr/network_io/unix/sa_common.c
Index: sa_common.c
===================================================================
RCS file: /home/cvs/apr/network_io/unix/sa_common.c,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -r1.61 -r1.62
--- sa_common.c 13 Oct 2002 04:10:21 -0000 1.61
+++ sa_common.c 13 Oct 2002 23:28:22 -0000 1.62
@@ -85,6 +85,16 @@
#endif
};
+#ifndef NETWARE
+#ifdef HAVE_SET_H_ERRNO
+#define SET_H_ERRNO(newval) set_h_errno(newval)
+#else
+#define SET_H_ERRNO(newval) h_errno = (newval)
+#endif
+#else
+#define SET_H_ERRNO(newval)
+#endif
+
#if APR_HAS_THREADS && !defined(GETHOSTBYNAME_IS_THREAD_SAFE) && \
defined(HAVE_GETHOSTBYNAME_R)
/* This is the maximum size that may be returned from the reentrant
@@ -326,12 +336,8 @@
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(hostname, NULL, &hints, &ai_list);
if (error) {
-#ifdef WIN32
- /* XXX Netware also??? */
- return apr_get_netos_error();
-#else
if (error == EAI_SYSTEM) {
- return apr_get_os_error();
+ return errno;
}
else {
/* issues with representing this with APR's error scheme:
@@ -344,7 +350,6 @@
#endif
return error + APR_OS_START_EAIERR;
}
-#endif
}
prev_sa = NULL;
@@ -418,8 +423,6 @@
#ifdef GETHOSTBYNAME_R_HOSTENT_DATA
struct hostent_data hd;
#else
- /* If you see ERANGE, that means GETHOSBYNAME_BUFLEN needs to be
- * bumped. */
char tmp[GETHOSTBYNAME_BUFLEN];
#endif
int hosterror;
@@ -448,23 +451,30 @@
/* Linux glibc2+ */
gethostbyname_r(hostname, &hs, tmp, GETHOSTBYNAME_BUFLEN - 1,
&hp, &hosterror);
- if (!hp) {
- return (hosterror + APR_OS_START_SYSERR);
- }
#else
/* Solaris, Irix et alia */
hp = gethostbyname_r(hostname, &hs, tmp, GETHOSTBYNAME_BUFLEN - 1,
&hosterror);
- if (!hp) {
- return (hosterror + APR_OS_START_SYSERR);
- }
#endif
#else
hp = gethostbyname(hostname);
#endif
if (!hp) {
+#ifdef WIN32
return apr_get_netos_error();
+#elif APR_HAS_THREADS && !defined(GETHOSTBYNAME_IS_THREAD_SAFE) && \
+ defined(HAVE_GETHOSTBYNAME_R) && !defined(BEOS)
+#ifdef GETHOSTBYNAME_R_HOSTENT_DATA
+ return (h_errno + APR_OS_START_SYSERR);
+#else
+ /* If you see ERANGE, that means GETHOSBYNAME_BUFLEN needs to be
+ * bumped. */
+ return (hosterror + APR_OS_START_SYSERR);
+#endif
+#else
+ return (h_errno + APR_OS_START_SYSERR);
+#endif
}
}
@@ -546,7 +556,7 @@
/* don't know if it is portable for getnameinfo() to set h_errno;
* clear it then see if it was set */
- apr_set_netos_error(0);
+ SET_H_ERRNO(0);
/* default flags are NI_NAMREQD; otherwise, getnameinfo() will return
* a numeric address string if it fails to resolve the host name;
* that is *not* what we want here
@@ -556,10 +566,7 @@
flags != 0 ? flags : NI_NAMEREQD);
if (rc != 0) {
*hostname = NULL;
-#ifdef WIN32
- /* XXX and Netware? */
- return apr_get_netos_error();
-#else
+
/* something went wrong. Look at the EAI_ error code */
if (rc != EAI_SYSTEM) {
#if defined(NEGATIVE_EAI)
@@ -570,14 +577,13 @@
else {
/* EAI_SYSTEM System error returned in errno. */
/* IMHO, Implementations that set h_errno a simply broken. */
- if (apr_get_netos_error()) { /* for broken implementations which
set h_errno */
- return apr_get_netos_error();
+ if (h_errno) { /* for broken implementations which set h_errno */
+ return h_errno + APR_OS_START_SYSERR;
}
else { /* "normal" case */
- return apr_get_os_error();
+ return errno + APR_OS_START_SYSERR;
}
}
-#endif
}
*hostname = sockaddr->hostname = apr_pstrdup(sockaddr->pool,
tmphostname);
@@ -603,19 +609,11 @@
gethostbyaddr_r((char *)&sockaddr->sa.sin.sin_addr,
sizeof(struct in_addr), AF_INET,
&hs, tmp, GETHOSTBYNAME_BUFLEN - 1, &hptr, &hosterror);
- if (!hptr) {
- *hostname = NULL;
- return hosterror + APR_OS_START_SYSERR;
- }
#else
/* Solaris, Irix et alia */
hptr = gethostbyaddr_r((char *)&sockaddr->sa.sin.sin_addr,
sizeof(struct in_addr), AF_INET,
&hs, tmp, GETHOSTBYNAME_BUFLEN, &hosterror);
- if (!hptr) {
- *hostname = NULL;
- return hosterror + APR_OS_START_SYSERR;
- }
#endif
#else
struct hostent *hptr;
@@ -623,12 +621,22 @@
sizeof(struct in_addr), AF_INET);
#endif
- if (!hptr) {
- *hostname = NULL;
- return apr_get_netos_error();
+ if (hptr) {
+ *hostname = sockaddr->hostname = apr_pstrdup(sockaddr->pool,
hptr->h_name);
+ return APR_SUCCESS;
}
- *hostname = sockaddr->hostname = apr_pstrdup(sockaddr->pool,
hptr->h_name);
- return APR_SUCCESS;
+ *hostname = NULL;
+#if APR_HAS_THREADS && !defined(GETHOSTBYADDR_IS_THREAD_SAFE) && \
+ defined(HAVE_GETHOSTBYADDR_R) && !defined(BEOS) && \
+ !defined(GETHOSTBYNAME_R_HOSTENT_DATA)
+ return hosterror + APR_OS_START_SYSERR;
+#elif defined(WIN32)
+ return apr_get_netos_error();
+#elif defined(OS2)
+ return h_errno;
+#else
+ return h_errno + APR_OS_START_SYSERR;
+#endif
#endif
}