martin 02/01/31 05:21:32
Modified: network_io/unix sa_common.c
Log:
Be a bit more conservative regarding all those broken implementations out
there. Not everyone has FreeBSD or Linux.
getnameinfo() should return a rc containing 0 (success) or some EAI_ value.
This rc can be used as a mapped APR_ error (+APR_OS_START_EAIERR).
Only if the rc == EAI_SYSTEM, errno should be inspected (I see no reason
whatsoever to look at h_errno, as (like for apr_sockaddr_info_get()'s call
of getaddrinfo()) the error is supposed to be in errno.
However, and because h_errno has been zeroed out before the call,
I added another test for nonzero h_errno. Everone happy?
Revision Changes Path
1.49 +15 -17 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.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- sa_common.c 29 Jan 2002 08:37:45 -0000 1.48
+++ sa_common.c 31 Jan 2002 13:21:32 -0000 1.49
@@ -524,26 +524,24 @@
flags != 0 ? flags : NI_NAMEREQD);
if (rc != 0) {
*hostname = NULL;
-#if 1
- /* De facto implementations return the error code in their
- * return value. See isc.org's bind9, or
- * FreeBSD's lib/libc/net/getnameinfo.c
- * Implementations that set h_errno a simply broken.
- * @@ if you encounter one, replace the #if 1 by an
- * @@ appropriate #ifdef and delete these lines.
- */
- return rc + APR_OS_START_SYSERR;
-#else
- /* XXX I have no idea if this is okay. I don't see any info
- * about getnameinfo() returning anything other than good or bad.
- */
- if (h_errno) {
- return h_errno + APR_OS_START_SYSERR;
+
+ /* something went wrong. Look at the EAI_ error code */
+ if (rc != EAI_SYSTEM) {
+#if defined(NEGATIVE_EAI)
+ if (rc < 0) rc = -rc;
+#endif
+ return rc + APR_OS_START_EAIERR; /* return the EAI_ error */
}
else {
- return APR_NOTFOUND;
+ /* EAI_SYSTEM System error returned in errno. */
+ /* IMHO, Implementations that set h_errno a simply broken. */
+ if (h_errno) { /* for broken implementations which set h_errno */
+ return h_errno + APR_OS_START_SYSERR;
+ }
+ else { /* "normal" case */
+ return errno + APR_OS_START_SYSERR;
+ }
}
-#endif
}
*hostname = sockaddr->hostname = apr_pstrdup(sockaddr->pool,
tmphostname);