trawick 00/12/14 08:04:11
Modified: network_io/unix sa_common.c
Log:
tweak some comments, restore some commented-out logic in
the call to getnameinfo(), free the storage returned by
getaddrinfo()
Revision Changes Path
1.20 +13 -4 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.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- sa_common.c 2000/12/13 22:30:22 1.19
+++ sa_common.c 2000/12/14 16:04:08 1.20
@@ -239,7 +239,11 @@
/* now handle the hostname */
addrlen = lastchar - str + 1;
-#if APR_HAVE_IPV6 /* XXX don't require this; would need to pass char[] for
ipaddr and always define APR_INET6 */
+/* XXX we don't really have to require APR_HAVE_IPV6 for this;
+ * just pass char[] for ipaddr (so we don't depend on struct in6_addr)
+ * and always define APR_INET6
+ */
+#if APR_HAVE_IPV6
if (*str == '[') {
const char *end_bracket = memchr(str, ']', addrlen);
struct in6_addr ipaddr;
@@ -253,7 +257,7 @@
/* handle scope id; this is the only context where it is allowed */
scope_delim = memchr(str, '%', addrlen);
if (scope_delim) {
- if (scope_delim == end_bracket - 1) { /* '%' without scope
identifier */
+ if (scope_delim == end_bracket - 1) { /* '%' without scope id */
*port = 0;
return APR_EINVAL;
}
@@ -331,6 +335,7 @@
}
(*sa)->sa.sin.sin_family = ai->ai_family;
memcpy(&(*sa)->sa, ai->ai_addr, ai->ai_addrlen);
+ freeaddrinfo(ai);
}
else {
if (family == APR_UNSPEC) {
@@ -343,7 +348,7 @@
set_sockaddr_vars(*sa, (*sa)->sa.sin.sin_family);
#else
if (family == APR_UNSPEC) {
- (*sa)->sa.sin.sin_family = APR_INET; /* we don't yet support IPv6
here */
+ (*sa)->sa.sin.sin_family = APR_INET; /* we don't support IPv6 here */
}
else {
(*sa)->sa.sin.sin_family = family;
@@ -397,9 +402,13 @@
#endif
h_errno = 0; /* don't know if it is portable for getnameinfo() to set
h_errno */
+ /* 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
+ */
rc = getnameinfo((const struct sockaddr *)&sockaddr->sa, sockaddr->salen,
tmphostname, sizeof(tmphostname), NULL, 0,
- /* flags != 0 ? flags : */ NI_NAMEREQD);
+ flags != 0 ? flags : NI_NAMEREQD);
if (rc != 0) {
*hostname = NULL;
/* XXX I have no idea if this is okay. I don't see any info