summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Trawick <trawick@apache.org>2001-08-29 15:20:24 +0000
committerJeff Trawick <trawick@apache.org>2001-08-29 15:20:24 +0000
commit9c84a09d2b65c273d03520134ba9a15e0515ca8a (patch)
treea54d9e4a23c045a295698aa4bec0016f728572f8
parentd8126851ace8e5e87416a28a81a0667b7fc13bfb (diff)
downloadapr-9c84a09d2b65c273d03520134ba9a15e0515ca8a.tar.gz
Error codes from getaddrinfo() need their own range within the
apr_status_t layout. This is used to fix the bungling of these error codes. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@62243 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--CHANGES2
-rw-r--r--build/apr_network.m428
-rw-r--r--configure.in1
-rw-r--r--include/apr_errno.h7
-rw-r--r--misc/unix/errorcodes.c11
-rw-r--r--network_io/unix/sa_common.c15
6 files changed, 56 insertions, 8 deletions
diff --git a/CHANGES b/CHANGES
index d6879e543..4fca7a695 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,7 @@
Changes with APR b1
+ *) Fix the bungling of getaddrinfo() error codes. [Jeff Trawick]
+
*) Add an apr_thread_once function to APR. This allows a
program to ensure that a function is only called once.
[Ryan Bloom]
diff --git a/build/apr_network.m4 b/build/apr_network.m4
index 2da1daf44..af3531fcd 100644
--- a/build/apr_network.m4
+++ b/build/apr_network.m4
@@ -104,6 +104,34 @@ fi
])
dnl
+dnl check for negative error codes for getaddrinfo()
+dnl
+AC_DEFUN(APR_CHECK_NEGATIVE_EAI,[
+ AC_CACHE_CHECK(for negative error codes for getaddrinfo, ac_cv_negative_eai,[
+ AC_TRY_RUN( [
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+
+void main(void) {
+ if (EAI_ADDRFAMILY < 0) {
+ exit(0);
+ }
+ exit(1);
+}
+],[
+ ac_cv_negative_eai="yes"
+],[
+ ac_cv_negative_eai="no"
+],[
+ ac_cv_negative_eai="no"
+])])
+if test "$ac_cv_negative_eai" = "yes"; then
+ AC_DEFINE(NEGATIVE_EAI, 1, [Define if EAI_ error codes from getaddrinfo are negative])
+fi
+])
+
+dnl
dnl check for gethostbyname() which handles numeric address strings
dnl
AC_DEFUN(APR_CHECK_GETHOSTBYNAME_NAS,[
diff --git a/configure.in b/configure.in
index 91412b405..24cff3877 100644
--- a/configure.in
+++ b/configure.in
@@ -1327,6 +1327,7 @@ AC_ARG_ENABLE(ipv6,
AC_SEARCH_LIBS(getaddrinfo, inet6)
AC_SEARCH_LIBS(getnameinfo, inet6)
APR_CHECK_WORKING_GETADDRINFO
+APR_CHECK_NEGATIVE_EAI
APR_CHECK_WORKING_GETNAMEINFO
APR_CHECK_SOCKADDR_IN6
AC_MSG_CHECKING(if APR supports IPv6)
diff --git a/include/apr_errno.h b/include/apr_errno.h
index eccbf5ad3..75e3b7bc7 100644
--- a/include/apr_errno.h
+++ b/include/apr_errno.h
@@ -153,6 +153,10 @@ APR_DECLARE(char *) apr_strerror(apr_status_t statcode, char *buf,
* on systems which don't have the corresponding errno.
*/
/**
+ * APR_OS_START_EAIERR folds EAI_ error codes from getaddrinfo() into
+ * apr_status_t values.
+ */
+/**
* APR_OS_START_SYSERR folds platform-specific system error values into
* apr_status_t values.
*/
@@ -160,7 +164,8 @@ APR_DECLARE(char *) apr_strerror(apr_status_t statcode, char *buf,
#define APR_OS_START_STATUS (APR_OS_START_ERROR + 500)
#define APR_OS_START_USEERR (APR_OS_START_STATUS + 500)
#define APR_OS_START_CANONERR (APR_OS_START_USEERR + 500)
-#define APR_OS_START_SYSERR (APR_OS_START_CANONERR + 500)
+#define APR_OS_START_EAIERR (APR_OS_START_CANONERR + 500)
+#define APR_OS_START_SYSERR (APR_OS_START_EAIERR + 500)
#define APR_SUCCESS 0
diff --git a/misc/unix/errorcodes.c b/misc/unix/errorcodes.c
index caea40ca6..b33a0835a 100644
--- a/misc/unix/errorcodes.c
+++ b/misc/unix/errorcodes.c
@@ -365,8 +365,19 @@ APR_DECLARE(char *) apr_strerror(apr_status_t statcode, char *buf,
else if (statcode < APR_OS_START_USEERR) {
return stuffbuffer(buf, bufsize, apr_error_string(statcode));
}
+ else if (statcode < APR_OS_START_EAIERR) {
+ return stuffbuffer(buf, bufsize, "APR does not understand this error code");
+ }
else if (statcode < APR_OS_START_SYSERR) {
+#if defined(HAVE_GETADDRINFO)
+ statcode -= APR_OS_START_EAIERR;
+#if defined(NEGATIVE_EAI)
+ statcode = -statcode;
+#endif
+ return stuffbuffer(buf, bufsize, gai_strerror(statcode));
+#else
return stuffbuffer(buf, bufsize, "APR does not understand this error code");
+#endif
}
else {
return apr_os_strerror(buf, bufsize, statcode - APR_OS_START_SYSERR);
diff --git a/network_io/unix/sa_common.c b/network_io/unix/sa_common.c
index 1290b7983..c03706e9b 100644
--- a/network_io/unix/sa_common.c
+++ b/network_io/unix/sa_common.c
@@ -355,14 +355,15 @@ APR_DECLARE(apr_status_t) apr_sockaddr_info_get(apr_sockaddr_t **sa,
return errno;
}
else {
- /* XXX fixme!
- * no current way to represent this with APR's error
- * scheme... note that glibc uses negative values for these
- * numbers, perhaps so they don't conflict with h_errno
- * values... Tru64 uses positive values which conflict
- * with h_errno values
+ /* issues with representing this with APR's error scheme:
+ * glibc uses negative values for these numbers, perhaps so
+ * they don't conflict with h_errno values... Tru64 uses
+ * positive values which conflict with h_errno values
*/
- return error + APR_OS_START_SYSERR;
+#if defined(NEGATIVE_EAI)
+ error = -error;
+#endif
+ return error + APR_OS_START_EAIERR;
}
}
cursa = *sa;