1 --- apache_1.3.41/conf/httpd.conf-dist 2004-11-24 21:10:19.000000000 +0200
2 +++ apache_1.3.41-ipv6/conf/httpd.conf-dist 2009-02-16 19:29:36.596835634 +0200
7 +# Listen can take two arguments.
8 +# (this is an extension for supporting IPv6 addresses)
13 # BindAddress: You can support virtual hosts with this option. This directive
14 # is used to tell the server which IP address to listen to. It can either
15 --- apache_1.3.41/configure.v6 1970-01-01 03:00:00.000000000 +0300
16 +++ apache_1.3.41-ipv6/configure.v6 2009-02-16 19:29:36.600169885 +0200
20 +./configure --enable-rule=INET6 --enable-module=proxy $*
21 --- apache_1.3.41/README.v6 1970-01-01 03:00:00.000000000 +0300
22 +++ apache_1.3.41-ipv6/README.v6 2009-02-16 19:29:36.590170307 +0200
24 +IPv6-ready apache 1.3.x
28 +This patchkit enables apache 1.3.x to perform HTTP connection over IPv6.
29 +Most of optional modules are left unchanged, i.e. it won't support IPv6,
30 +and it may not compile.
32 +Basically you can write IPv6 address where IPv4 address fits.
34 +extra command-line argument:
35 + -4 Assume IPv4 address on ambiguous directives
36 + -6 Assume IPv6 address on ambiguous directives (default)
38 + The above two can be used, for example, to disambiguate
43 + Listen is expanded to take one or two arguments.
47 + This is to let you specify "Listen :: 80", since "Listen :::80"
53 + "deny from" and "allow from" supports IPv6 addresses, under the
55 + {deny,allow} from v6addr
56 + {deny,allow} from v6addr/v6mask
57 + {deny,allow} from v6addr/prefixlen
58 + Also, wildcard ("*") and string hostname matches IPv6 hosts as well.
62 + http/ftp proxying for both IPv4 and IPv6 is possible.
63 + Access control functions (NoProxy) are not updated yet.
65 + NOTE: for security reasons, we recommend you to filter out
66 + outsider's access to your proxy, by directives like below:
70 + allow from 10.0.0.0/8
71 + allow from 3ffe:9999:8888:7777::/64
75 + If you would like to this feature, you must describe 'Listen'
76 + part on configuration file explicitly. like below:
81 + NameVirtualHost is expanded to take one more two arguments.
82 + NameVirtualHost address
83 + NameVirtualHost address:port
84 + NameVirtualHost address port
85 + This is to let you specify IPv6 address into address part.
87 + Note that, if colon is found in the specified address string,
88 + the code will to resolve the address in the following way:
89 + 1. try to resolve as address:port (most of IPv6 address fails)
90 + 2. if (1) is failed, try to resolve as address only
91 + If there's ambiguity, i.e. 3ffe:0501::1:2, the address may not be
92 + parsed as you expect (3ffe:0501::1 with port 2, or 3ffe:0501::1:2
93 + with default port). To get the right effect you are encouraged
94 + to specify it without ambiguity. In IPv6 case "address port"
95 + (specify address and port separated by a space) is the safest way.
97 + <VirtualHost host:port [host:port ...]>
98 + If you would like to specify IPv6 numeric address in host part,
99 + use bracketed format like below:
100 + <VirtualHost [::1]:80>
101 + Note: Now we DO NOT handle old non-bracketed format,
102 + <VirtualHost 0:0:0:0:0:0:0:1:80>
103 + so configuration file must be updated.
104 + Note: The following is bad example to specify host ::1 port 80.
105 + This will treated as host ::1:80.
106 + <VirtualHost ::1:80>
108 +logresolve (src/support)
109 + error statistics in nameserver cache code is omitted.
112 + Originally mod_unique_id used IPv4 address as a seed for UNIQUE_ID,
113 + and took IPv4 address registered onto DNS for the hostname (UNIX
114 + hostname taken by gethostname(3)). Therefore, this does not work
115 + for IPv6-only hosts as they do not have IPv4 address for them.
117 + Now, UNIQUE_ID can be generated using IPv6 address. IPv6 address can
118 + be used as the seed for UNIQUE_ID.
119 + Because of this, UNIQUE_ID will be longer than normal apache. This
120 + may cause problem with some of the CGI scripts.
121 + The preference of the addresses is based on the order returned
122 + by getaddrinfo(). If your getaddrinfo() returns IPv4 address, IPv4
123 + adderss will be used as a seed.
124 + Note that some of IPv6 addresses are "scoped"; If you happened to use
125 + link-local or site-local address as a seed, the UNIQUE_ID may not be
128 + If longer UNIQUE_ID causes a problem, define SHORT_UNIQUE_ID in
129 + mod_unique_id.c. In this case, length of UNIQUE_ID will be kept the
130 + same. However, for IPv6 addresses mod_unique_id.c will use the last
131 + 32bit (not the whole 128bit) as the seed. Therefore, there can be
132 + collision in UNIQUE_ID.
134 + The behavior should be improved in the near future; we welcome your
137 +Modules known to be incompatible with IPv6
141 + Configure has extra option, --enable-rule=INET6. if the option
142 + is specified, IPv6 code will be enabled.
145 + We do not support IPv4 mapped address (IPv6 address format like
146 + ::ffff:10.1.1.1) in configuration file.
148 +This kit assumes that you have working(*) getaddrinfo() and getnameinfo()
149 +library functions. Even if you don't have one, don't panic. We have
150 +included last-resort version (which support IPv4 only) into the kit.
151 +For more complete implementation you might want to check BIND 8.2.
152 +(*) NOTE: we have noticed that some of IPv6 stack is shipped with broken
153 +getaddrinfo(). In such cases, you should get and install BIND 8.2.
155 +When compiling this kit onto IPv6, you may need to specify some additional
156 +library paths or cpp defs (like -linet6 or -DINET6).
157 +Now you don't have to specify --enable-rule=INET6. The "configure" script
158 +will give you some warnings if the IPv6 stack is not known to the
159 +"configure" script. Currently, the following IPv6 stacks are supported:
160 +- KAME IPv6 stack, http://www.kame.net/
161 + use configure.v6 for convenience,
162 +- Linux IPv6 stack, http://www.linux.org/
163 + use configure.v6 for convenience.
164 +- Solaris 8 IPv6 stack, http://www.sun.com/
165 + use configure.v6 for convenience.
166 +To disable IPv6 support, specify --disable-rule=INET6 to the "configure"
169 +CAVEAT: This patchkit may change some of apache module API, to avoid
170 +IPv4-dependent structure member variable. Please let us know if there's
171 +any troubles as we know very little about the apache module API.
174 + Thanks to all people submitted patches/fixes for this patch kit,
176 + "Chris P. Ross" <cross@eng.us.uu.net>
179 + Jun-ichiro itojun Hagino, KAME project
180 + http://www.kame.net/
181 + mailto:core@kame.net
183 + Arkadiusz Miskiewicz, Polish Linux Distribution project (IPv6)
184 + http://www.pld.org.pl/
185 + mailto:feedback@pld.org.pl
186 + Satoshi SHIDA, Linux IPv6 Users Group JP
187 + http://www.v6.linux.or.jp/
188 + YOSHIFUJI Hideaki, USAGI Project
189 + http://www.linux-ipv6.org/
190 --- apache_1.3.41/src/ap/ap_snprintf.c 2006-07-12 11:16:05.000000000 +0300
191 +++ apache_1.3.41-ipv6/src/ap/ap_snprintf.c 2009-02-16 19:29:36.603503089 +0200
205 +static char *conv_sockaddr(struct sockaddr *sa, char *buf_end, int *len)
208 + char hostnamebuf[MAXHOSTNAMELEN];
209 + char portnamebuf[MAXHOSTNAMELEN];
214 + salen = SA_LEN(sa);
216 + salen = sa->sa_len;
218 + if (getnameinfo(sa, salen, hostnamebuf, sizeof(hostnamebuf),
219 + portnamebuf, sizeof(portnamebuf), NI_NUMERICHOST | NI_NUMERICSERV)) {
220 + strcpy(hostnamebuf, "???");
221 + strcpy(portnamebuf, "???");
223 + if (strcmp(portnamebuf,"0") == 0)
224 + strcpy(portnamebuf, "*");
225 + q = portnamebuf + strlen(portnamebuf);
226 + while (portnamebuf < q)
229 + q = hostnamebuf + strlen(hostnamebuf);
230 + while (hostnamebuf < q)
233 + *len = buf_end - p;
241 * Convert a floating point number to a string formats 'f', 'e' or 'E'.
242 * The result is placed in buf, and len denotes the length of the string
243 @@ -1015,6 +1052,7 @@
244 /* print a struct sockaddr_in as a.b.c.d:port */
248 struct sockaddr_in *si;
250 si = va_arg(ap, struct sockaddr_in *);
251 @@ -1023,6 +1061,16 @@
252 if (adjust_precision && precision < s_len)
256 + struct sockaddr *sa;
258 + sa = va_arg(ap, struct sockaddr *);
260 + s = conv_sockaddr(sa, &num_buf[NUM_BUF_SIZE], &s_len);
261 + if (adjust_precision && precision < s_len)
268 --- apache_1.3.41/src/Configuration.tmpl 2009-02-16 19:29:13.454337891 +0200
269 +++ apache_1.3.41-ipv6/src/Configuration.tmpl 2009-02-16 19:29:36.600169885 +0200
271 # Rule EXPAT=default : If Expat can be found at the system or
272 # in lib/expat-lite, use it; otherwise
279 # Use Win32 API system calls for socket communication instead
285 Rule CYGWIN_WINSOCK=no
288 --- apache_1.3.41/src/Configure 2009-02-16 19:29:13.414338992 +0200
289 +++ apache_1.3.41-ipv6/src/Configure 2009-02-16 19:29:36.603503089 +0200
291 RULE_CYGWIN_WINSOCK=`./helpers/CutRule CYGWIN_WINSOCK $file`
292 RULE_SHARED_CORE=`./helpers/CutRule SHARED_CORE $file`
293 RULE_SHARED_CHAIN=`./helpers/CutRule SHARED_CHAIN $file`
294 +RULE_INET6=`./helpers/CutRule INET6 $file`
296 ####################################################################
297 ## Rule SHARED_CORE implies required DSO support
298 @@ -1692,6 +1693,124 @@
303 +if [ "$RULE_INET6" = "yes" ]; then
304 + echo " + enabling INET6 support"
305 + CFLAGS="$CFLAGS -DINET6"
306 + CFLAGS="$CFLAGS -Dss_family=__ss_family -Dss_len=__ss_len"
307 + IPV6_STACKTYPE="UNKNOWN"
308 + for i in KAME Linux Solaris; do
311 + if [ -f /usr/include/netinet6/in6.h -a "x`egrep '__KAME__' /usr/include/netinet6/in6.h 2>/dev/null`" != "x" ]; then
316 + if [ /usr/include/netinet/ip6.h -a -d /usr/include/linux ]; then
321 + SOL_VERSION=`(uname -v) 2>/dev/null` || SOL_VERSION="unknown"
322 + case "${PLAT}-${SOL_VERSION}" in
323 + *-solaris2.27*-*IPv6*)
324 + if [ -f /etc/hostname -o -f /etc/hostname.[a-z]*[0-9] ]; then
325 + IPV6_STACKTYPE="Solaris 7 (${SOL_VERSION})"
331 + if [ "$IPV6_STACKTYPE" != "UNKNOWN" ]; then
335 + if [ "$IPV6_STACKTYPE" != "UNKNOWN" ]; then
336 + echo " + You seem to be using $IPV6_STACKTYPE stack"
337 + if ./helpers/TestCompile func getaddrinfo; then
338 + echo " - Assuming you have working getaddrinfo in libc"
340 + if [ -f /usr/local/v6/lib/libinet6.a -a "x`egrep '^EXTRA_L' Makefile.config | grep linet6`" = "x" ]; then
341 + LIBS="$LIBS -L/usr/local/v6/lib -linet6"
342 + echo " - using getaddrinfo in libinet6"
343 + elif [ -f /usr/local/lib/libinet6.a -a "x`egrep '^EXTRA_L' Makefile.config | grep linet6`" = "x" ]; then
344 + LIBS="$LIBS -L/usr/local/lib -linet6"
345 + echo " - using getaddrinfo in libinet6"
346 + elif [ -f /usr/inet6/lib/libinet6.a -a "x`egrep '^EXTRA_L' Makefile.config | grep linet6`" = "x" ]; then
347 + echo " - using getaddrinfo in libinet6"
349 + echo "** WARNING: No getaddrinfo found, linkage may fail"
354 + echo "** WARNING: We have no explicit knowledge about the IPv6"
355 + echo "** implementation on this host. You may need to specify"
356 + echo "** EXTRA_LIBS so that we can find getaddrinfo() and"
357 + echo "** getnameinfo() library functions."
362 + LIBS="$LIBS -lresolv"
366 + CFLAGS="$CFLAGS -DNEED_GETADDRINFO -DNEED_GETNAMEINFO"
367 + if [ -f /usr/include/netdb.h -a "x`egrep 'addrinfo' /usr/include/netdb.h`" = "x" ]; then
368 + CFLAGS="$CFLAGS -DNEED_ADDRINFO"
372 +echo '#include <sys/types.h>' >testfunc.c
373 +echo '#include <sys/socket.h>' >>testfunc.c
374 +echo 'int testfunc(){ struct sockaddr sa; int i = sa.sa_len; };' >>testfunc.c
376 +eval "${MAKE-make} -f Makefile.config testfunc.o >/dev/null 2>/dev/null"
377 +if [ -f testfunc.o ]; then
378 + echo " + you have sa_len in struct sockaddr."
379 + CFLAGS="$CFLAGS -DHAVE_SOCKADDR_LEN"
381 + echo " + you don't have sa_len in struct sockaddr."
383 +rm -f testfunc.c testfunc.o
385 +echo '#include <sys/types.h>' >testfunc.c
386 +echo '#include <sys/socket.h>' >>testfunc.c
387 +echo 'struct sockaddr_storage sockaddr_storage;' >>testfunc.c
389 +eval "${MAKE-make} -f Makefile.config testfunc.o >/dev/null 2>/dev/null"
390 +if [ -f testfunc.o ]; then
391 + echo " + assuming you have struct sockaddr_storage"
393 + CFLAGS="$CFLAGS -DNEED_SOCKADDR_STORAGE"
394 + echo " + you need struct sockaddr_storage"
396 +rm -f testfunc.c testfunc.o
398 +echo '#include <sys/types.h>' >testfunc.c
399 +echo '#include <sys/socket.h>' >>testfunc.c
400 +echo 'int testfunc(){ socklen_t t; }' >>testfunc.c
402 +eval "${MAKE-make} -f Makefile.config testfunc.o >/dev/null 2>/dev/null"
403 +if [ ! -f testfunc.o ]; then
404 + CFLAGS="$CFLAGS -Dsocklen_t=int"
406 +rm -f testfunc.c testfunc.o
408 +echo '#include <sys/types.h>' >testfunc.c
409 +echo '#include <sys/socket.h>' >>testfunc.c
410 +echo 'struct sockaddr_in sin;' >>testfunc.c
411 +echo 'int main(){ int i = sin.sin_len; }' >>testfunc.c
413 +eval "${MAKE-make} -f Makefile.config testfunc.o >/dev/null 2>/dev/null"
414 +if [ -f testfunc.o ]; then
415 + CFLAGS="$CFLAGS -DSIN_LEN"
417 +rm -f testfunc.c testfunc.o
420 ####################################################################
421 ## Find out what modules we want and try and configure things for them
422 ## Module lines can look like this:
423 @@ -2296,6 +2415,38 @@
424 echo "#define AP_LONGEST_LONG $AP_LONGEST_LONG" >>$AP_CONFIG_AUTO_H
425 echo "#endif" >>$AP_CONFIG_AUTO_H
427 +if [ x`./helpers/TestCompile -r sizeof 'uint32_t'` != x"" ]; then
428 + echo "" >>$AP_CONFIG_AUTO_H
429 + echo "/* determine: use uint32_t as 32bit unsigned int */" >>$AP_CONFIG_AUTO_H
430 + echo "#ifndef ap_uint32_t" >>$AP_CONFIG_AUTO_H
431 + echo "#define ap_uint32_t uint32_t" >>$AP_CONFIG_AUTO_H
432 + echo "#endif" >>$AP_CONFIG_AUTO_H
433 + echo " - use uint32_t as 32bit unsigned int"
434 +elif [ x`./helpers/TestCompile -r sizeof 'u_int32_t'` != x"" ]; then
435 + echo "" >>$AP_CONFIG_AUTO_H
436 + echo "/* determine: use u_int32_t as 32bit unsigned int */" >>$AP_CONFIG_AUTO_H
437 + echo "#ifndef ap_uint32_t" >>$AP_CONFIG_AUTO_H
438 + echo "#define ap_uint32_t u_int32_t" >>$AP_CONFIG_AUTO_H
439 + echo "#endif" >>$AP_CONFIG_AUTO_H
440 + echo " - use u_int32_t as 32bit unsigned int"
441 +elif [ x`./helpers/TestCompile -r sizeof 'unsigned int'` = x"4" ]; then
442 + echo "" >>$AP_CONFIG_AUTO_H
443 + echo "/* determine: use unsigned int as 32bit unsigned int */" >>$AP_CONFIG_AUTO_H
444 + echo "#ifndef ap_uint32_t" >>$AP_CONFIG_AUTO_H
445 + echo "#define ap_uint32_t unsigned int" >>$AP_CONFIG_AUTO_H
446 + echo "#endif" >>$AP_CONFIG_AUTO_H
447 + echo " - use unsigned int as 32bit unsigned int"
448 +elif [ x`./helpers/TestCompile -r sizeof 'unsigned long int'` = x"4" ]; then
449 + echo "" >>$AP_CONFIG_AUTO_H
450 + echo "/* determine: use unsigned long int as 32bit unsigned int */" >>$AP_CONFIG_AUTO_H
451 + echo "#ifndef uint32_t" >>$AP_CONFIG_AUTO_H
452 + echo "#define uint32_t unsigned long int" >>$AP_CONFIG_AUTO_H
453 + echo "#endif" >>$AP_CONFIG_AUTO_H
454 + echo " - use unsigned long int as 32bit unsigned int"
456 + echo " - Warning: cannot determine what type should we use as 32bit unsigned int"
459 ####################################################################
460 ## More building ap_config_auto.h
462 --- apache_1.3.41/src/include/ap_config.h 2006-07-12 11:16:05.000000000 +0300
463 +++ apache_1.3.41-ipv6/src/include/ap_config.h 2009-02-16 19:29:36.603503089 +0200
467 #define S_IWOTH 000002
471 +typedef u_long n_long;
474 #define STDIN_FILENO 0
475 @@ -1455,6 +1459,70 @@
476 #define ap_wait_t int
480 +#define sockaddr_storage sockaddr
481 +#define ss_family sa_family
482 +#define ss_len sa_len
484 +#include "sockaddr_storage.h" /* sshida@st.rim.or.jp */
487 +#ifndef INET6_ADDRSTRLEN
488 +#define INET6_ADDRSTRLEN 46
490 +#ifndef INET_ADDRSTRLEN
491 +#define INET_ADDRSTRLEN 16
494 +#define NI_MAXHOST 1025
497 +#define NI_MAXSERV 32
500 +#if defined(NEED_GETADDRINFO) || defined(NEED_GETNAMEINFO)
502 + * minimal definitions for fake getaddrinfo()/getnameinfo().
505 +#define EAI_NODATA 1
506 +#define EAI_MEMORY 2
510 +#define AI_PASSIVE 1
511 +#define AI_CANONNAME 2
512 +#define AI_NUMERICHOST 4
513 +#define NI_NUMERICHOST 8
514 +#define NI_NAMEREQD 16
515 +#define NI_NUMERICSERV 32
519 +#ifdef NEED_GETADDRINFO
520 +#ifdef NEED_ADDRINFO
522 + int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
523 + int ai_family; /* PF_xxx */
524 + int ai_socktype; /* SOCK_xxx */
525 + int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
526 + size_t ai_addrlen; /* length of ai_addr */
527 + char *ai_canonname; /* canonical name for hostname */
528 + struct sockaddr *ai_addr; /* binary address */
529 + struct addrinfo *ai_next; /* next structure in linked list */
532 +extern char *gai_strerror(int ecode);
533 +extern void freeaddrinfo(struct addrinfo *ai);
534 +extern int getaddrinfo(const char *hostname, const char *servname,
535 + const struct addrinfo *hints, struct addrinfo **res);
537 +#ifdef NEED_GETNAMEINFO
538 +extern int getnameinfo(const struct sockaddr *sa, size_t salen,
539 + char *host, size_t hostlen, char *serv, size_t servlen,
546 --- apache_1.3.41/src/include/ap.h 2006-07-12 11:16:05.000000000 +0300
547 +++ apache_1.3.41-ipv6/src/include/ap.h 2009-02-16 19:29:36.603503089 +0200
549 * with some extensions. The extensions are:
551 * %pA takes a struct in_addr *, and prints it as a.b.c.d
552 - * %pI takes a struct sockaddr_in * and prints it as a.b.c.d:port
553 + * %pI takes a struct sockaddr * and prints it as a.b.c.d:port, or
554 + * ipv6-numeric-addr:port
555 * %pp takes a void * and outputs it in hex
557 * The %p hacks are to force gcc's printf warning code to skip
558 --- apache_1.3.41/src/include/http_conf_globals.h 2009-02-16 19:29:13.421004229 +0200
559 +++ apache_1.3.41-ipv6/src/include/http_conf_globals.h 2009-02-16 19:29:36.606835974 +0200
561 extern API_VAR_EXPORT int ap_max_requests_per_child;
562 extern API_VAR_EXPORT int ap_threads_per_child;
563 extern API_VAR_EXPORT int ap_excess_requests_per_child;
564 -extern API_VAR_EXPORT struct in_addr ap_bind_address;
565 +extern API_VAR_EXPORT struct sockaddr_storage ap_bind_address;
566 +extern API_VAR_EXPORT int ap_default_family;
567 extern listen_rec *ap_listeners;
568 extern API_VAR_EXPORT int ap_daemons_to_start;
569 extern API_VAR_EXPORT int ap_daemons_min_free;
570 --- apache_1.3.41/src/include/httpd.h 2009-02-16 19:29:13.454337891 +0200
571 +++ apache_1.3.41-ipv6/src/include/httpd.h 2009-02-16 19:29:36.606835974 +0200
574 /* Who is the client? */
576 - struct sockaddr_in local_addr; /* local address */
577 - struct sockaddr_in remote_addr; /* remote address */
578 + struct sockaddr_storage local_addr; /* local address */
579 + struct sockaddr_storage remote_addr; /* remote address */
580 char *remote_ip; /* Client's IP address */
581 char *remote_host; /* Client's DNS name, if known.
582 * NULL if DNS hasn't been checked,
584 typedef struct server_addr_rec server_addr_rec;
585 struct server_addr_rec {
586 server_addr_rec *next;
587 - struct in_addr host_addr; /* The bound address, for this server */
588 - unsigned short host_port; /* The bound port, for this server */
589 + struct sockaddr_storage host_addr; /* The bound address, for this server */
590 + unsigned short host_port; /* The bound port, for this server XXX */
591 char *virthost; /* The name given in <VirtualHost> */
595 /* These are more like real hosts than virtual hosts */
598 - struct sockaddr_in local_addr; /* local IP address and port */
599 + struct sockaddr_storage local_addr; /* local IP address and port */
601 int used; /* Only used during restart */
602 /* more stuff here, like which protocol is bound to the port */
603 @@ -1147,7 +1147,7 @@
604 #endif /*#ifdef CHARSET_EBCDIC*/
606 API_EXPORT(char *) ap_get_local_host(pool *);
607 -API_EXPORT(unsigned long) ap_get_virthost_addr(char *hostname, unsigned short *port);
608 +API_EXPORT(struct sockaddr *) ap_get_virthost_addr(char *hostname, unsigned short *port);
610 extern API_VAR_EXPORT time_t ap_restart_time;
612 --- apache_1.3.41/src/include/http_vhost.h 2006-07-12 11:16:05.000000000 +0300
613 +++ apache_1.3.41-ipv6/src/include/http_vhost.h 2009-02-16 19:29:36.606835974 +0200
615 API_EXPORT(const char *) ap_parse_vhost_addrs(pool *p, const char *hostname, server_rec *s);
617 /* handle NameVirtualHost directive */
618 -API_EXPORT_NONSTD(const char *) ap_set_name_virtual_host (cmd_parms *cmd, void *dummy, char *arg);
619 +API_EXPORT_NONSTD(const char *) ap_set_name_virtual_host (cmd_parms *cmd, void *dummy, char *h, char *p);
621 /* given an ip address only, give our best guess as to what vhost it is */
622 API_EXPORT(void) ap_update_vhost_given_ip(conn_rec *conn);
623 --- apache_1.3.41/src/include/sa_len.h 1970-01-01 03:00:00.000000000 +0300
624 +++ apache_1.3.41-ipv6/src/include/sa_len.h 2009-02-16 19:29:36.606835974 +0200
626 +/* sa_len.h : tiny version of SA_LEN (written by <yoshfuji@ecei.tohoku.ac.jp>) */
628 +#include <sys/types.h>
629 +#include <sys/socket.h>
630 +#include <netinet/in.h>
633 +#ifndef HAVE_SOCKADDR_LEN
635 +#define SA_LEN(s_) ap_sa_len((s_)->sa_family)
637 +static NET_SIZE_T ap_sa_len (sa_family_t af)
640 +#if defined(AF_INET)
642 + return (sizeof(struct sockaddr_in));
643 +#endif /* AF_INET */
644 +#if defined(AF_INET6)
646 + return (sizeof(struct sockaddr_in6));
650 +#endif /* AF_LOCAL */
651 +#if defined(AF_UNIX) && (AF_UNIX != AF_LOCAL)
653 +#endif /* AF_UNIX */
654 +#if defined(AF_FILE) && (AF_FILE != AF_LOCAL || AF_FILE != AF_UNIX)
656 +#endif /* AF_FILE */
657 +#if defined(AF_LOCAL) || defined(AF_UNIX) || defined(AF_FILE)
658 + return (sizeof(struct sockaddr_un));
659 +#endif /* defined(AF_LOCAL) || defined(AF_UNIX) || defined(AF_FILE) */
666 +#endif /* HAVE_SOCKADDR_LEN */
667 --- apache_1.3.41/src/include/sockaddr_storage.h 1970-01-01 03:00:00.000000000 +0300
668 +++ apache_1.3.41-ipv6/src/include/sockaddr_storage.h 2009-02-16 19:29:36.606835974 +0200
671 +struct sockaddr_storage
673 + RFC2553 proposes struct sockaddr_storage.
674 + This is a placeholder for all sockaddr-variant structures. This is
675 + implemented like follows:
677 + You should use this structure to hold any of sockaddr-variant
680 +#ifdef NEED_SOCKADDR_STORAGE
682 +struct sockaddr_storage {
683 +#ifdef HAVE_SOCKADDR_LEN
689 + u_char __padding[128 - 2];
695 + Alternatively, you may want to implement sockunion.h, with the
698 + NOTE: For better portability, struct sockaddr_storage should be used.
699 + union sockunion is okay, but is not really portable enough.
703 +#ifdef HAVE_SOCKADDR_LEN
711 + struct sockaddr_in su_sin;
713 + struct sockaddr_in6 su_sin6;
716 +#ifdef HAVE_SOCKADDR_LEN
717 +#define su_len su_si.si_len
719 +#define su_family su_si.si_family
720 +#define su_port su_si.si_port
722 +#endif /* NEED_SOCKADDR_STORAGE */
723 --- apache_1.3.41/src/main/getaddrinfo.c 1970-01-01 03:00:00.000000000 +0300
724 +++ apache_1.3.41-ipv6/src/main/getaddrinfo.c 2009-02-16 19:29:36.606835974 +0200
727 + * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
728 + * All rights reserved.
730 + * Redistribution and use in source and binary forms, with or without
731 + * modification, are permitted provided that the following conditions
733 + * 1. Redistributions of source code must retain the above copyright
734 + * notice, this list of conditions and the following disclaimer.
735 + * 2. Redistributions in binary form must reproduce the above copyright
736 + * notice, this list of conditions and the following disclaimer in the
737 + * documentation and/or other materials provided with the distribution.
738 + * 3. Neither the name of the project nor the names of its contributors
739 + * may be used to endorse or promote products derived from this software
740 + * without specific prior written permission.
742 + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
743 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
744 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
745 + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
746 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
747 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
748 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
749 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
750 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
751 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
755 + * fake library for ssh v6 enabler patch
757 + * This file includes getaddrinfo(), freeaddrinfo() and gai_strerror().
758 + * These funtions are defined in rfc2133.
760 + * But these functions are not implemented correctly. The minimum subset
761 + * is implemented for ssh use only. For exapmle, this routine assumes
762 + * that ai_family is AF_INET. Don't use it for another purpose.
764 + * In the case not using 'configure --enable-ipv6', this getaddrinfo.c
765 + * will be used if you have broken getaddrinfo or no getaddrinfo.
770 +#include <sys/types.h>
771 +#include <sys/socket.h>
772 +#include <netinet/in.h>
773 +#include <arpa/inet.h>
778 +static struct addrinfo *
779 +malloc_ai(port, addr, socktype, protocol)
785 + struct addrinfo *ai;
787 + if (ai = (struct addrinfo *)malloc(sizeof(struct addrinfo) +
788 + sizeof(struct sockaddr_in))) {
789 + memset(ai, 0, sizeof(struct addrinfo) + sizeof(struct sockaddr_in));
790 + ai->ai_addr = (struct sockaddr *)(ai + 1);
791 +#if defined(HAVE_SOCKADDR_LEN)
792 + ai->ai_addr->sa_len =
794 + ai->ai_addrlen = sizeof(struct sockaddr_in);
795 + ai->ai_addr->sa_family = ai->ai_family = AF_INET;
796 + ai->ai_socktype = socktype;
797 + ai->ai_protocol = protocol;
798 + ((struct sockaddr_in *)(ai)->ai_addr)->sin_port = port;
799 + ((struct sockaddr_in *)(ai)->ai_addr)->sin_addr.s_addr = addr;
812 + return "no address associated with hostname.";
814 + return "memory allocation failure.";
816 + return "unknown error.";
822 +struct addrinfo *ai;
824 + struct addrinfo *next;
827 + next = ai->ai_next;
829 + } while (ai = next);
833 +getaddrinfo(hostname, servname, hints, res)
834 +const char *hostname, *servname;
835 +const struct addrinfo *hints;
836 +struct addrinfo **res;
838 + struct addrinfo *cur, *prev = NULL;
839 + struct hostent *hp;
843 + port = htons(atoi(servname));
846 + if (hints && hints->ai_flags & AI_PASSIVE)
847 + if (*res = malloc_ai(port, htonl(0x00000000),
848 + (*res)->ai_socktype ? (*res)->ai_socktype : SOCK_STREAM,
849 + (*res)->ai_protocol))
854 + if (*res = malloc_ai(port, htonl(0x7f000001),
855 + (*res)->ai_socktype ? (*res)->ai_socktype : SOCK_STREAM,
856 + (*res)->ai_protocol))
860 + if (inet_addr(hostname) != -1)
861 + if (*res = malloc_ai(port, inet_addr(hostname),
862 + (*res)->ai_socktype ? (*res)->ai_socktype : SOCK_STREAM,
863 + (*res)->ai_protocol))
867 + if ((hp = gethostbyname(hostname)) &&
868 + hp->h_name && hp->h_name[0] && hp->h_addr_list[0]) {
869 + for (i = 0; hp->h_addr_list[i]; i++)
870 + if (cur = malloc_ai(port,
871 + ((struct in_addr *)hp->h_addr_list[i])->s_addr,
872 + (*res)->ai_socktype ? (*res)->ai_socktype : SOCK_STREAM,
873 + (*res)->ai_protocol)) {
875 + prev->ai_next = cur;
881 + freeaddrinfo(*res);
888 --- apache_1.3.41/src/main/getnameinfo.c 1970-01-01 03:00:00.000000000 +0300
889 +++ apache_1.3.41-ipv6/src/main/getnameinfo.c 2009-02-16 19:29:36.610169965 +0200
892 + * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
893 + * All rights reserved.
895 + * Redistribution and use in source and binary forms, with or without
896 + * modification, are permitted provided that the following conditions
898 + * 1. Redistributions of source code must retain the above copyright
899 + * notice, this list of conditions and the following disclaimer.
900 + * 2. Redistributions in binary form must reproduce the above copyright
901 + * notice, this list of conditions and the following disclaimer in the
902 + * documentation and/or other materials provided with the distribution.
903 + * 3. Neither the name of the project nor the names of its contributors
904 + * may be used to endorse or promote products derived from this software
905 + * without specific prior written permission.
907 + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
908 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
909 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
910 + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
911 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
912 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
913 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
914 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
915 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
916 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
920 + * fake library for ssh v6 enabler patch
922 + * This file includes getnameinfo().
923 + * These funtions are defined in rfc2133.
925 + * But these functions are not implemented correctly. The minimum subset
926 + * is implemented for ssh use only. For exapmle, this routine assumes
927 + * that ai_family is AF_INET. Don't use it for another purpose.
929 + * In the case not using 'configure --enable-ipv6', this getnameinfo.c
930 + * will be used if you have broken getnameinfo or no getnameinfo.
935 +#include <sys/types.h>
936 +#include <sys/socket.h>
937 +#include <netinet/in.h>
938 +#include <arpa/inet.h>
945 +getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
946 +const struct sockaddr *sa;
954 + struct sockaddr_in *sin = (struct sockaddr_in *)sa;
955 + struct hostent *hp;
959 + sprintf(tmpserv, "%d", ntohs(sin->sin_port));
960 + if (strlen(tmpserv) > servlen)
963 + strcpy(serv, tmpserv);
966 + if (flags & NI_NUMERICHOST)
967 + if (strlen(inet_ntoa(sin->sin_addr)) > hostlen)
970 + strcpy(host, inet_ntoa(sin->sin_addr));
974 + if (hp = gethostbyaddr((char *)&sin->sin_addr, sizeof(struct in_addr),
976 + if (strlen(hp->h_name) > hostlen)
979 + strcpy(host, hp->h_name);
986 --- apache_1.3.41/src/main/http_config.c 2009-02-16 19:29:13.427670844 +0200
987 +++ apache_1.3.41-ipv6/src/main/http_config.c 2009-02-16 19:29:36.610169965 +0200
988 @@ -1553,7 +1553,6 @@
989 ap_scoreboard_fname = DEFAULT_SCOREBOARD;
990 ap_lock_fname = DEFAULT_LOCKFILE;
991 ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
992 - ap_bind_address.s_addr = htonl(INADDR_ANY);
994 ap_listenbacklog = DEFAULT_LISTENBACKLOG;
995 ap_extended_status = 0;
996 @@ -1586,7 +1585,13 @@
998 s->addrs = ap_pcalloc(p, sizeof(server_addr_rec));
999 /* NOT virtual host; don't match any real network interface */
1000 - s->addrs->host_addr.s_addr = htonl(INADDR_ANY);
1001 + memset(&s->addrs->host_addr, 0, sizeof(s->addrs->host_addr));
1003 + s->addrs->host_addr.ss_family = ap_default_family; /* XXX: needed?, XXX: PF_xxx can be different from AF_xxx */
1005 +#ifdef HAVE_SOCKADDR_LEN
1006 + s->addrs->host_addr.ss_len = sizeof(s->addrs->host_addr); /* XXX: needed ? */
1008 s->addrs->host_port = 0; /* matches any port */
1009 s->addrs->virthost = ""; /* must be non-NULL */
1010 s->names = s->wild_names = NULL;
1011 @@ -1605,21 +1610,33 @@
1012 static void default_listeners(pool *p, server_rec *s)
1015 + struct addrinfo hints, *res0, *res;
1017 + char servbuf[NI_MAXSERV];
1019 if (ap_listeners != NULL) {
1022 + ap_snprintf(servbuf, sizeof(servbuf), "%d", s->port ? s->port : DEFAULT_HTTP_PORT);
1023 + memset (&hints, 0, sizeof(hints));
1024 + hints.ai_family = ap_default_family;
1025 + hints.ai_socktype = SOCK_STREAM;
1026 + hints.ai_flags = AI_PASSIVE;
1027 + gai = getaddrinfo(NULL, servbuf, &hints, &res0);
1029 + fprintf(stderr, "default_listeners(): getaddrinfo(PASSIVE) for family %u: %s\n",
1030 + gai_strerror(gai), ap_default_family);
1033 /* allocate a default listener */
1034 new = ap_pcalloc(p, sizeof(listen_rec));
1035 - new->local_addr.sin_family = AF_INET;
1036 - new->local_addr.sin_addr = ap_bind_address;
1037 - /* Buck ugly cast to get around terniary op bug in some (MS) compilers */
1038 - new->local_addr.sin_port = htons((unsigned short)(s->port ? s->port
1039 - : DEFAULT_HTTP_PORT));
1040 + memcpy(&new->local_addr, res0->ai_addr, res0->ai_addrlen);
1046 + freeaddrinfo(res0);
1050 --- apache_1.3.41/src/main/http_core.c 2006-07-12 11:16:05.000000000 +0300
1051 +++ apache_1.3.41-ipv6/src/main/http_core.c 2009-02-16 19:29:36.613502634 +0200
1053 #include "util_md5.h"
1054 #include "scoreboard.h"
1055 #include "fnmatch.h"
1056 +#include "sa_len.h"
1058 #ifdef USE_MMAP_FILES
1059 #include <sys/mman.h>
1061 * file if you care. So the adhoc value should do.
1063 return ap_psprintf(r->pool,"%pA%pp%pp%pp%pp",
1064 - &r->connection->local_addr.sin_addr,
1065 + &((struct sockaddr_in *)&(r->connection->local_addr))->sin_addr,
1066 (void *)ap_user_name,
1067 (void *)ap_listeners,
1068 (void *)ap_server_argv0,
1071 static ap_inline void do_double_reverse (conn_rec *conn)
1073 - struct hostent *hptr;
1074 + struct addrinfo hints, *res, *res0;
1075 + char hostbuf1[128], hostbuf2[128]; /* INET6_ADDRSTRLEN(=46) is enough */
1078 if (conn->double_reverse) {
1080 @@ -679,30 +682,54 @@
1081 conn->remote_host = ""; /* prevent another lookup */
1084 - hptr = gethostbyname(conn->remote_host);
1088 - for (haddr = hptr->h_addr_list; *haddr; haddr++) {
1089 - if (((struct in_addr *)(*haddr))->s_addr
1090 - == conn->remote_addr.sin_addr.s_addr) {
1091 - conn->double_reverse = 1;
1094 + memset(&hints, 0, sizeof(hints));
1095 + hints.ai_family = PF_UNSPEC;
1096 + hints.ai_socktype = SOCK_STREAM;
1097 + if (getaddrinfo(conn->remote_host, NULL, &hints, &res0)) {
1098 + conn->double_reverse = -1;
1101 + for (res = res0; res; res = res->ai_next) {
1102 + if (res->ai_addr->sa_family != conn->remote_addr.ss_family ||
1103 + !(res->ai_family == AF_INET
1105 + || res->ai_family == AF_INET6
1110 +#ifndef HAVE_SOCKADDR_LEN
1111 + if (res->ai_addrlen != SA_LEN((struct sockaddr *)&conn->remote_addr))
1113 + if (res->ai_addr->sa_len != conn->remote_addr.ss_len)
1116 + if (getnameinfo(res->ai_addr, res->ai_addrlen,
1117 + hostbuf1, sizeof(hostbuf1), NULL, 0,
1120 + if (getnameinfo(((struct sockaddr *)&conn->remote_addr), res->ai_addrlen,
1121 + hostbuf2, sizeof(hostbuf2), NULL, 0,
1124 + if (strcmp(hostbuf1, hostbuf2) == 0){
1129 - conn->double_reverse = -1;
1130 + conn->double_reverse = ok ? 1 : -1;
1131 + freeaddrinfo(res0);
1132 /* invalidate possible reverse-resolved hostname if forward lookup fails */
1133 - conn->remote_host = "";
1135 + conn->remote_host = "";
1138 API_EXPORT(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config,
1141 - struct in_addr *iaddr;
1142 - struct hostent *hptr;
1143 int hostname_lookups;
1144 int old_stat = SERVER_DEAD; /* we shouldn't ever be in this state */
1145 + char hostnamebuf[MAXHOSTNAMELEN];
1147 /* If we haven't checked the host name, and we want to */
1149 @@ -724,10 +751,14 @@
1150 || hostname_lookups != HOSTNAME_LOOKUP_OFF)) {
1151 old_stat = ap_update_child_status(conn->child_num, SERVER_BUSY_DNS,
1152 (request_rec*)NULL);
1153 - iaddr = &(conn->remote_addr.sin_addr);
1154 - hptr = gethostbyaddr((char *)iaddr, sizeof(struct in_addr), AF_INET);
1155 - if (hptr != NULL) {
1156 - conn->remote_host = ap_pstrdup(conn->pool, (void *)hptr->h_name);
1157 + if (!getnameinfo((struct sockaddr *)&conn->remote_addr,
1159 + SA_LEN((struct sockaddr *)&conn->remote_addr),
1161 + conn->remote_addr.ss_len,
1163 + hostnamebuf, sizeof(hostnamebuf), NULL, 0, 0)) {
1164 + conn->remote_host = ap_pstrdup(conn->pool, (void *)hostnamebuf);
1165 ap_str_tolower(conn->remote_host);
1167 if (hostname_lookups == HOSTNAME_LOOKUP_DOUBLE) {
1170 conn_rec *conn = r->connection;
1172 + char hbuf[MAXHOSTNAMELEN];
1174 d = (core_dir_config *)ap_get_module_config(r->per_dir_config,
1176 @@ -814,23 +846,22 @@
1178 if (d->use_canonical_name == USE_CANONICAL_NAME_DNS) {
1179 if (conn->local_host == NULL) {
1180 - struct in_addr *iaddr;
1181 - struct hostent *hptr;
1183 old_stat = ap_update_child_status(conn->child_num,
1184 SERVER_BUSY_DNS, r);
1185 - iaddr = &(conn->local_addr.sin_addr);
1186 - hptr = gethostbyaddr((char *)iaddr, sizeof(struct in_addr),
1188 - if (hptr != NULL) {
1189 - conn->local_host = ap_pstrdup(conn->pool,
1190 - (void *)hptr->h_name);
1191 - ap_str_tolower(conn->local_host);
1194 - conn->local_host = ap_pstrdup(conn->pool,
1195 - r->server->server_hostname);
1196 + if (getnameinfo((struct sockaddr *)&conn->local_addr,
1198 + SA_LEN((struct sockaddr *)&conn->local_addr),
1200 + conn->local_addr.ss_len,
1202 + hbuf, sizeof(hbuf), NULL, 0, 0) == 0) {
1203 + conn->local_host = ap_pstrdup(conn->pool, hbuf);
1205 + conn->local_host = ap_pstrdup(conn->pool,
1206 + r->server->server_hostname);
1208 + ap_str_tolower(conn->local_host);
1209 (void) ap_update_child_status(conn->child_num, old_stat, r);
1211 return conn->local_host;
1213 API_EXPORT(unsigned) ap_get_server_port(const request_rec *r)
1216 - unsigned cport = ntohs(r->connection->local_addr.sin_port);
1217 + unsigned cport = ntohs(((struct sockaddr_in *)&r->connection->local_addr)->sin_port);
1218 core_dir_config *d =
1219 (core_dir_config *)ap_get_module_config(r->per_dir_config, &core_module);
1221 @@ -2648,12 +2679,25 @@
1223 static const char *set_bind_address(cmd_parms *cmd, void *dummy, char *arg)
1225 + struct addrinfo hints, *res;
1226 + struct sockaddr *sa;
1229 const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
1234 - ap_bind_address.s_addr = ap_get_virthost_addr(arg, NULL);
1235 + if (strcmp(arg, "*") == 0)
1238 + sa = ap_get_virthost_addr(arg, NULL);
1239 +#ifdef HAVE_SOCKADDR_LEN
1240 + sa_len = sa->sa_len;
1242 + sa_len = SA_LEN(sa);
1244 + memcpy(&ap_bind_address, &sa, sa_len);
1248 @@ -2685,48 +2729,71 @@
1252 -static const char *set_listener(cmd_parms *cmd, void *dummy, char *ips)
1253 +static const char *set_listener(cmd_parms *cmd, void *dummy, char *h, char *p)
1256 - char *ports, *endptr;
1258 + char *host, *port;
1259 + struct addrinfo hints, *res;
1262 const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
1267 - ports = strchr(ips, ':');
1268 - if (ports != NULL) {
1269 - if (ports == ips) {
1270 - return "Missing IP address";
1272 - else if (ports[1] == '\0') {
1273 - return "Address must end in :<port-number>";
1274 + host = port = NULL;
1276 + port = strrchr(h, ':');
1277 + if (port != NULL) {
1279 + return "Missing IP address";
1281 + else if (port[1] == '\0') {
1282 + return "Address must end in :<port-number>";
1292 - *(ports++) = '\0';
1301 - new=ap_pcalloc(cmd->pool, sizeof(listen_rec));
1302 - new->local_addr.sin_family = AF_INET;
1303 - if (ports == ips) { /* no address */
1304 - new->local_addr.sin_addr.s_addr = htonl(INADDR_ANY);
1307 - new->local_addr.sin_addr.s_addr = ap_get_virthost_addr(ips, NULL);
1309 - errno = 0; /* clear errno before calling strtol */
1310 - port = ap_strtol(ports, &endptr, 10);
1311 - if (errno /* some sort of error */
1312 - || (endptr && *endptr) /* make sure no trailing characters */
1313 - || port < 1 || port > 65535) /* underflow/overflow */
1315 - return "Missing, invalid, or non-numeric port";
1316 + if (host && strcmp(host, "*") == 0)
1319 + new = ap_pcalloc(cmd->pool, sizeof(listen_rec));
1321 + memset(&hints, 0, sizeof(hints));
1322 + hints.ai_family = host ? PF_UNSPEC : ap_default_family;
1323 + hints.ai_flags = AI_PASSIVE;
1324 + hints.ai_socktype = SOCK_STREAM;
1325 + error = getaddrinfo(host, port, &hints, &res);
1326 + if (error || !res) {
1327 + fprintf(stderr, "could not resolve ");
1329 + fprintf(stderr, "host \"%s\" ", host);
1331 + fprintf(stderr, "port \"%s\" ", port);
1332 + fprintf(stderr, "--- %s\n", gai_strerror(error));
1335 + if (res->ai_next) {
1337 + fprintf(stderr, "host \"%s\" ", host);
1339 + fprintf(stderr, "port \"%s\" ", port);
1340 + fprintf(stderr, "resolved to multiple addresses, ambiguous.\n");
1343 - new->local_addr.sin_port = htons((unsigned short)port);
1345 + memcpy(&new->local_addr, res->ai_addr, res->ai_addrlen);
1349 new->next = ap_listeners;
1350 @@ -3651,7 +3718,7 @@
1351 { "ThreadStackSize", set_threadstacksize, NULL, RSRC_CONF, TAKE1,
1352 "Stack size each created thread will use."},
1354 -{ "Listen", set_listener, NULL, RSRC_CONF, TAKE1,
1355 +{ "Listen", set_listener, NULL, RSRC_CONF, TAKE12,
1356 "A port number or a numeric IP address and a port number"},
1357 { "SendBufferSize", set_send_buffer_size, NULL, RSRC_CONF, TAKE1,
1358 "Send buffer size in bytes"},
1359 @@ -3685,7 +3752,7 @@
1360 "Name of the config file to be included" },
1361 { "LogLevel", set_loglevel, NULL, RSRC_CONF, TAKE1,
1362 "Level of verbosity in error logging" },
1363 -{ "NameVirtualHost", ap_set_name_virtual_host, NULL, RSRC_CONF, TAKE1,
1364 +{ "NameVirtualHost", ap_set_name_virtual_host, NULL, RSRC_CONF, TAKE12,
1365 "A numeric IP address:port, or the name of a host" },
1367 { "BS2000Account", set_bs2000_account, NULL, RSRC_CONF, TAKE1,
1368 --- apache_1.3.41/src/main/http_main.c 2009-02-16 19:29:13.431004203 +0200
1369 +++ apache_1.3.41-ipv6/src/main/http_main.c 2009-02-16 19:29:36.620170407 +0200
1371 #include <sys/prctl.h>
1374 +#include "sa_len.h"
1377 /* special debug stuff -- PCS */
1379 @@ -210,7 +212,12 @@
1380 API_VAR_EXPORT char *ap_scoreboard_fname=NULL;
1381 API_VAR_EXPORT char *ap_lock_fname=NULL;
1382 API_VAR_EXPORT char *ap_server_argv0=NULL;
1383 -API_VAR_EXPORT struct in_addr ap_bind_address={0};
1385 +API_VAR_EXPORT int ap_default_family = PF_INET6;
1387 +API_VAR_EXPORT int ap_default_family = PF_INET;
1389 +API_VAR_EXPORT struct sockaddr_storage ap_bind_address={0};
1390 API_VAR_EXPORT int ap_daemons_to_start=0;
1391 API_VAR_EXPORT int ap_daemons_min_free=0;
1392 API_VAR_EXPORT int ap_daemons_max_free=0;
1393 @@ -1461,7 +1468,11 @@
1394 fprintf(stderr, "Usage: %s [-D name] [-d directory] [-f file]\n", bin);
1396 fprintf(stderr, " %s [-C \"directive\"] [-c \"directive\"]\n", pad);
1397 - fprintf(stderr, " %s [-v] [-V] [-h] [-l] [-L] [-S] [-t] [-T] [-F]\n", pad);
1398 + fprintf(stderr, " %s [-v] [-V] [-h] [-l] [-L] [-S] [-t] [-T] [-F]"
1403 fprintf(stderr, "Options:\n");
1405 fprintf(stderr, " -R directory : specify an alternate location for shared object files\n");
1406 @@ -1487,6 +1498,10 @@
1408 fprintf(stderr, " -F : run main process in foreground, for process supervisors\n");
1411 + fprintf(stderr, " -4 : assume IPv4 on parsing configuration file\n");
1412 + fprintf(stderr, " -6 : assume IPv6 on parsing configuration file\n");
1415 fprintf(stderr, " -n name : name the Apache service for -k options below;\n");
1416 fprintf(stderr, " -k stop|shutdown : tell running Apache to shutdown\n");
1417 @@ -3740,11 +3755,13 @@
1420 static conn_rec *new_connection(pool *p, server_rec *server, BUFF *inout,
1421 - const struct sockaddr_in *remaddr,
1422 - const struct sockaddr_in *saddr,
1423 + const struct sockaddr *remaddr,
1424 + const struct sockaddr *saddr,
1427 conn_rec *conn = (conn_rec *) ap_pcalloc(p, sizeof(conn_rec));
1428 + char hostnamebuf[MAXHOSTNAMELEN];
1431 /* Got a connection structure, so initialize what fields we can
1432 * (the rest are zeroed out by pcalloc).
1433 @@ -3753,17 +3770,29 @@
1434 conn->child_num = child_num;
1437 - conn->local_addr = *saddr;
1438 - conn->local_ip = ap_pstrdup(conn->pool,
1439 - inet_ntoa(conn->local_addr.sin_addr));
1441 + addr_len = SA_LEN(saddr);
1443 + addr_len = saddr->sa_len;
1445 + memcpy(&conn->local_addr, saddr, addr_len);
1446 + getnameinfo((struct sockaddr *)&conn->local_addr, addr_len,
1447 + hostnamebuf, sizeof(hostnamebuf), NULL, 0, NI_NUMERICHOST);
1448 + conn->local_ip = ap_pstrdup(conn->pool, hostnamebuf);
1449 conn->server = server; /* just a guess for now */
1450 ap_update_vhost_given_ip(conn);
1451 conn->base_server = conn->server;
1452 conn->client = inout;
1454 - conn->remote_addr = *remaddr;
1455 - conn->remote_ip = ap_pstrdup(conn->pool,
1456 - inet_ntoa(conn->remote_addr.sin_addr));
1458 + addr_len = SA_LEN(remaddr);
1460 + addr_len = remaddr->sa_len;
1462 + memcpy(&conn->remote_addr, remaddr, addr_len);
1463 + getnameinfo((struct sockaddr *)&conn->remote_addr, addr_len,
1464 + hostnamebuf, sizeof(hostnamebuf), NULL, 0, NI_NUMERICHOST);
1465 + conn->remote_ip = ap_pstrdup(conn->pool, hostnamebuf);
1467 conn->ctx = ap_ctx_new(conn->pool);
1469 @@ -3821,21 +3850,47 @@
1470 #define sock_disable_nagle(s, c) /* NOOP */
1473 -static int make_sock(pool *p, const struct sockaddr_in *server)
1474 +static int make_sock(pool *p, const struct sockaddr *server)
1479 + char addr[INET6_ADDRSTRLEN + 128];
1480 + char a0[INET6_ADDRSTRLEN];
1481 + char p0[NI_MAXSERV];
1486 - if (server->sin_addr.s_addr != htonl(INADDR_ANY))
1487 - ap_snprintf(addr, sizeof(addr), "address %s port %d",
1488 - inet_ntoa(server->sin_addr), ntohs(server->sin_port));
1490 - ap_snprintf(addr, sizeof(addr), "port %d", ntohs(server->sin_port));
1491 + switch(server->sa_family){
1498 + ap_log_error(APLOG_MARK, APLOG_CRIT, server_conf,
1499 + "make_sock: unsupported address family %u",
1500 + server->sa_family);
1501 + ap_unblock_alarms();
1505 + getnameinfo(server,
1511 + a0, sizeof(a0), p0, sizeof(p0), NI_NUMERICHOST | NI_NUMERICSERV);
1512 + ap_snprintf(addr, sizeof(addr), "address %s port %s", a0, p0);
1514 + if (atoi(p0) < 1024)
1518 /* note that because we're about to slack we don't use psocket */
1520 - if ((s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
1521 + if ((s = socket(server->sa_family, SOCK_STREAM, IPPROTO_TCP)) == -1) {
1522 ap_log_error(APLOG_MARK, APLOG_CRIT, server_conf,
1523 "make_sock: failed to get a socket for %s", addr);
1525 @@ -3930,15 +3985,19 @@
1528 /* MPE requires CAP=PM and GETPRIVMODE to bind to ports less than 1024 */
1529 - if (ntohs(server->sin_port) < 1024)
1534 - if (bind(s, (struct sockaddr *) server, sizeof(struct sockaddr_in)) == -1) {
1536 + if (bind(s, server, SA_LEN(server)) == -1)
1538 + if (bind(s, server, server->sa_len) == -1)
1541 ap_log_error(APLOG_MARK, APLOG_CRIT, server_conf,
1542 "make_sock: could not bind to %s", addr);
1544 - if (ntohs(server->sin_port) < 1024)
1549 @@ -3947,7 +4006,7 @@
1553 - if (ntohs(server->sin_port) < 1024)
1558 @@ -4162,15 +4221,17 @@
1560 fd = find_listener(lr);
1562 - fd = make_sock(p, &lr->local_addr);
1563 + fd = make_sock(p, (struct sockaddr *)&lr->local_addr);
1566 ap_note_cleanups_for_socket_ex(p, fd, 1);
1568 /* if we get here, (fd >= 0) && (fd < FD_SETSIZE) */
1569 - FD_SET(fd, &listenfds);
1570 - if (fd > listenmaxfd)
1573 + FD_SET(fd, &listenfds);
1574 + if (fd > listenmaxfd)
1578 if (lr->next == NULL)
1580 @@ -4521,8 +4582,8 @@
1581 static void child_main(int child_num_arg)
1584 - struct sockaddr sa_server;
1585 - struct sockaddr sa_client;
1586 + struct sockaddr_storage sa_server;
1587 + struct sockaddr_storage sa_client;
1590 /* All of initialization is a critical section, we don't care if we're
1591 @@ -4711,7 +4772,7 @@
1594 clen = sizeof(sa_client);
1595 - csd = ap_accept(sd, &sa_client, &clen);
1596 + csd = ap_accept(sd, (struct sockaddr *)&sa_client, &clen);
1597 if (csd >= 0 || errno != EINTR)
1600 @@ -4900,7 +4961,7 @@
1601 #endif /* NONBLOCK_WHEN_MULTI_LISTEN */
1603 clen = sizeof(sa_server);
1604 - if (getsockname(csd, &sa_server, &clen) < 0) {
1605 + if (getsockname(csd, (struct sockaddr *)&sa_server, &clen) < 0) {
1606 ap_log_error(APLOG_MARK, APLOG_DEBUG, server_conf,
1607 "getsockname, client %pA probably dropped the "
1609 @@ -4948,8 +5009,8 @@
1610 ap_bpushfd(conn_io, csd, dupped_csd);
1612 current_conn = new_connection(ptrans, server_conf, conn_io,
1613 - (struct sockaddr_in *) &sa_client,
1614 - (struct sockaddr_in *) &sa_server,
1615 + (struct sockaddr *)&sa_client,
1616 + (struct sockaddr *)&sa_server,
1620 @@ -5104,12 +5165,13 @@
1623 /* BS2000 requires a "special" version of fork() before a setuid() call */
1624 - if ((pid = os_fork(ap_user_name)) == -1) {
1625 + if ((pid = os_fork(ap_user_name)) == -1)
1627 - if ((pid = os_fork(s, slot)) == -1) {
1628 + if ((pid = os_fork(s, slot)) == -1)
1630 - if ((pid = fork()) == -1) {
1631 + if ((pid = fork()) == -1)
1634 ap_log_error(APLOG_MARK, APLOG_ERR, s, "fork: Unable to fork new process");
1636 /* fork didn't succeed. Fix the scoreboard or else
1637 @@ -5756,7 +5818,10 @@
1638 ap_setup_prelinked_modules();
1640 while ((c = getopt(argc, argv,
1641 - "D:C:c:xXd:Ff:vVlLR:StTh"
1642 + "D:C:c:xXd:Ff:vVlLR:StTh4"
1646 #ifdef DEBUG_SIGSTOP
1649 @@ -5834,8 +5899,14 @@
1650 ap_configtestonly = 1;
1651 ap_docrootcheck = 0;
1656 + ap_default_family = PF_INET;
1660 + ap_default_family = PF_INET6;
1666 @@ -5924,9 +5995,10 @@
1670 - struct sockaddr sa_server, sa_client;
1672 + struct sockaddr_storage sa_server, sa_client;
1674 + char servbuf[NI_MAXSERV];
1677 /* Yes this is called twice. */
1678 @@ -5981,25 +6053,32 @@
1681 l = sizeof(sa_client);
1682 - if ((getpeername(sock_in, &sa_client, &l)) < 0) {
1683 + if ((getpeername(sock_in, (struct sockaddr *)&sa_client, &l)) < 0) {
1684 /* get peername will fail if the input isn't a socket */
1685 perror("getpeername");
1686 memset(&sa_client, '\0', sizeof(sa_client));
1689 l = sizeof(sa_server);
1690 - if (getsockname(sock_in, &sa_server, &l) < 0) {
1691 + if (getsockname(sock_in, (struct sockaddr *)&sa_server, &l) < 0) {
1692 perror("getsockname");
1693 fprintf(stderr, "Error getting local address\n");
1696 - server_conf->port = ntohs(((struct sockaddr_in *) &sa_server)->sin_port);
1697 + if (getnameinfo(((struct sockaddr *)&sa_server), l,
1698 + NULL, 0, servbuf, sizeof(servbuf),
1700 + fprintf(stderr, "getnameinfo(): family=%d\n", sa_server.ss_family);
1703 + servbuf[sizeof(servbuf)-1] = '\0';
1704 + server_conf->port = atoi(servbuf);
1705 cio = ap_bcreate(ptrans, B_RDWR | B_SOCKET);
1707 cio->fd_in = sock_in;
1708 conn = new_connection(ptrans, server_conf, cio,
1709 - (struct sockaddr_in *) &sa_client,
1710 - (struct sockaddr_in *) &sa_server, -1);
1711 + (struct sockaddr *)&sa_client,
1712 + (struct sockaddr *)&sa_server, -1);
1714 while ((r = ap_read_request(conn)) != NULL) {
1716 @@ -7713,7 +7792,11 @@
1718 while ((c = getopt(argc, argv, "D:C:c:Xd:f:vVlLz:Z:wiuStThk:n:W:")) != -1) {
1720 - while ((c = getopt(argc, argv, "D:C:c:Xd:Ff:vVlLesStTh")) != -1) {
1721 + while ((c = getopt(argc, argv, "D:C:c:Xd:Ff:vVlLesStTh4"
1729 @@ -8259,6 +8342,10 @@
1740 --- apache_1.3.41/src/main/http_vhost.c 2006-07-12 11:16:05.000000000 +0300
1741 +++ apache_1.3.41-ipv6/src/main/http_vhost.c 2009-02-16 19:29:36.623502355 +0200
1743 #include "http_log.h"
1744 #include "http_vhost.h"
1745 #include "http_protocol.h"
1746 +#include "sa_len.h"
1749 * After all the definitions there's an explanation of how it's all put
1750 @@ -123,78 +124,114 @@
1751 * *paddr is the variable used to keep track of **paddr between calls
1752 * port is the default port to assume
1754 -static const char *get_addresses(pool *p, char *w, server_addr_rec ***paddr,
1756 +static const char *get_addresses(pool *p, char *w, char *pstr,
1757 + server_addr_rec ***paddr, unsigned port)
1759 - struct hostent *hep;
1760 - unsigned long my_addr;
1761 + struct addrinfo hints, *res, *res0;
1762 server_addr_rec *sar;
1764 - int i, is_an_ip_addr;
1765 + char *t = NULL, *u = NULL, *v = NULL;
1766 + char *hoststr = NULL, *portstr = NULL;
1767 + char portpool[10];
1769 + char servbuf[NI_MAXSERV];
1772 + if (w == 0 || *w == 0)
1775 - t = strchr(w, ':');
1777 - if (strcmp(t + 1, "*") == 0) {
1779 + portstr = portpool;
1780 + ap_snprintf(portpool, sizeof(portpool), "%u", port);
1785 + u = strrchr(w, ']');
1786 + if (u) { /* [host]:port or [host] */
1792 - else if ((i = atoi(t + 1))) {
1794 + /* w uv , w=v , w=v */
1795 + /* u!=0: [host]:port , u==0: [host:port , host */
1796 + t = strchr(v, ':');
1797 + if (t != NULL && strchr(t+1, ':') == NULL) {
1798 + /* [host]:port-w/o-colons, host-without-colons:port-w/o-colons */
1803 - return ":port must be numeric";
1811 - is_an_ip_addr = 0;
1812 - if (strcmp(w, "*") == 0) {
1813 - my_addr = htonl(INADDR_ANY);
1814 - is_an_ip_addr = 1;
1816 - else if (strcasecmp(w, "_default_") == 0
1817 - || strcmp(w, "255.255.255.255") == 0) {
1818 - my_addr = DEFAULT_VHOST_ADDR;
1819 - is_an_ip_addr = 1;
1821 - else if ((my_addr = ap_inet_addr(w)) != INADDR_NONE) {
1822 - is_an_ip_addr = 1;
1823 + memset(&hints, 0, sizeof(hints));
1824 + hints.ai_socktype = SOCK_STREAM;
1825 + if (strcmp(w, "*") == 0 || strlen(w) == 0) {
1827 + hints.ai_family = PF_UNSPEC;
1828 + hints.ai_flags = AI_PASSIVE;
1830 + else if (strcasecmp(w, "_default4_") == 0 ||
1831 + ((ap_default_family == PF_INET
1833 + || ap_default_family == PF_UNSPEC
1835 + ) && strcasecmp(w, "_default_") == 0)){
1836 + hoststr = "255.255.255.255";
1837 + hints.ai_family = PF_INET;
1840 + else if (strcasecmp(w, "_default6_") == 0 ||
1841 + ((ap_default_family == PF_INET6
1842 + || ap_default_family == PF_UNSPEC
1843 + ) && strcasecmp(w, "_default_") == 0)){
1844 + hoststr = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff";
1845 + hints.ai_family = PF_INET6;
1847 - if (is_an_ip_addr) {
1848 - sar = ap_pcalloc(p, sizeof(server_addr_rec));
1850 - *paddr = &sar->next;
1851 - sar->host_addr.s_addr = my_addr;
1852 - sar->host_port = port;
1853 - sar->virthost = ap_pstrdup(p, w);
1860 + hints.ai_family = PF_UNSPEC;
1863 - hep = gethostbyname(w);
1865 - if ((!hep) || (hep->h_addrtype != AF_INET || !hep->h_addr_list[0])) {
1866 + error = getaddrinfo(hoststr, portstr, &hints, &res0);
1867 + if (error || !res0) {
1868 ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, NULL,
1869 - "Cannot resolve host name %s --- ignoring!", w);
1872 + "Cannot resolve host %s port %s --- ignoring!", hoststr, portstr);
1873 + if (t != NULL) *t = ':';
1874 + if (u != NULL) *u = ']';
1878 - for (i = 0; hep->h_addr_list[i]; ++i) {
1879 + for (res=res0; res; res=res->ai_next) {
1880 + switch (res->ai_addr->sa_family) {
1887 + ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, NULL,
1888 + "Unsupported address family %u, for host %s port %s --- ignoring!",
1889 + res->ai_addr->sa_family, hoststr, portstr);
1892 sar = ap_pcalloc(p, sizeof(server_addr_rec));
1894 *paddr = &sar->next;
1895 - sar->host_addr = *(struct in_addr *) hep->h_addr_list[i];
1896 - sar->host_port = port;
1897 + memcpy(&sar->host_addr, res->ai_addr, res->ai_addrlen);
1898 + if (getnameinfo(res->ai_addr, res->ai_addrlen, NULL, 0, servbuf,
1899 + sizeof(servbuf), NI_NUMERICSERV) == 0)
1900 + sar->host_port = atoi(servbuf);
1902 + sar->host_port = 0;
1903 sar->virthost = ap_pstrdup(p, w);
1908 + freeaddrinfo(res0);
1909 + if (t != NULL) *t = ':';
1910 + if (u != NULL) *u = ']';
1915 /* start the list of addreses */
1917 while (hostname[0]) {
1918 - err = get_addresses(p, ap_getword_conf(p, &hostname), &addrs, s->port);
1919 + err = get_addresses(p, ap_getword_conf(p, &hostname), NULL,
1924 @@ -226,10 +264,11 @@
1928 -API_EXPORT_NONSTD(const char *) ap_set_name_virtual_host (cmd_parms *cmd, void *dummy, char *arg)
1929 +API_EXPORT_NONSTD(const char *) ap_set_name_virtual_host (cmd_parms *cmd, void *dummy, char *h,
1932 /* use whatever port the main server has at this point */
1933 - return get_addresses(cmd->pool, arg, &name_vhost_list_tail,
1934 + return get_addresses(cmd->pool, h, p, &name_vhost_list_tail,
1938 @@ -303,6 +342,19 @@
1939 return ((key >> 8) ^ key) % IPHASH_TABLE_SIZE;
1942 +static unsigned hash_addr(struct sockaddr *sa)
1944 + switch (sa->sa_family) {
1946 + return hash_inaddr(((struct sockaddr_in *)sa)->sin_addr.s_addr);
1949 + return hash_inaddr(((struct sockaddr_in6 *)sa)->sin6_addr.s6_addr[12]);
1952 + return hash_inaddr(sa->sa_family);
1957 static ipaddr_chain *new_ipaddr_chain(pool *p,
1958 @@ -330,25 +382,77 @@
1963 -static ap_inline ipaddr_chain *find_ipaddr(struct in_addr *server_ip,
1965 +static ap_inline ipaddr_chain *find_ipaddr(struct sockaddr *sa)
1970 + char a[NI_MAXHOST], b[NI_MAXHOST];
1972 /* scan the hash table for an exact match first */
1973 - addr = server_ip->s_addr;
1974 - bucket = hash_inaddr(addr);
1975 + bucket = hash_addr(sa);
1976 for (trav = iphash_table[bucket]; trav; trav = trav->next) {
1977 server_addr_rec *sar = trav->sar;
1978 - if ((sar->host_addr.s_addr == addr)
1979 - && (sar->host_port == 0 || sar->host_port == port
1982 + if (sar->host_addr.ss_family != sa->sa_family)
1984 + switch (sa->sa_family) {
1987 + struct sockaddr_in *sin1, *sin2;
1988 + sin1 = (struct sockaddr_in *)&sar->host_addr;
1989 + sin2 = (struct sockaddr_in *)sa;
1990 + if (sin1->sin_port == 0 || sin2->sin_port == 0
1991 + || sin1->sin_port == sin2->sin_port) {
1992 + if (memcmp(&sin1->sin_addr, &sin2->sin_addr,
1993 + sizeof(sin1->sin_addr)) == 0) {
2002 + struct sockaddr_in6 *sin1, *sin2;
2003 + sin1 = (struct sockaddr_in6 *)&sar->host_addr;
2004 + sin2 = (struct sockaddr_in6 *)sa;
2005 + if (sin1->sin6_port == 0 || sin2->sin6_port == 0
2006 + || sin1->sin6_port == sin2->sin6_port) {
2007 + if (memcmp(&sin1->sin6_addr, &sin2->sin6_addr,
2008 + sizeof(sin1->sin6_addr)) == 0) {
2015 + default: /*unsupported*/
2021 + if (sa->sa_family == AF_INET6 &&
2022 + IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)sa)->sin6_addr)) {
2024 + * This is just horrible. I just hate IPv4 mapped address. It
2025 + * complicates access control too much.
2026 + * Due to hashed lookup, we need to visit it again.
2028 + struct sockaddr_in sin;
2030 + memset(&sin, 0, sizeof(sin));
2031 + sin.sin_family = AF_INET;
2033 + sin.sin_len = sizeof(sin);
2035 + sin.sin_port = ((struct sockaddr_in6 *)sa)->sin6_port;
2036 + memcpy(&sin.sin_addr,
2037 + &((struct sockaddr_in6 *)sa)->sin6_addr.s6_addr[12],
2038 + sizeof(sin.sin_addr));
2039 + return find_ipaddr((struct sockaddr *)&sin);
2046 @@ -374,21 +478,7 @@
2048 char buf[MAX_STRING_LEN];
2050 - if (ic->sar->host_addr.s_addr == DEFAULT_VHOST_ADDR) {
2051 - len = ap_snprintf(buf, sizeof(buf), "_default_:%u",
2052 - ic->sar->host_port);
2054 - else if (ic->sar->host_addr.s_addr == INADDR_ANY) {
2055 - len = ap_snprintf(buf, sizeof(buf), "*:%u",
2056 - ic->sar->host_port);
2059 - len = ap_snprintf(buf, sizeof(buf), "%pA:%u",
2060 - &ic->sar->host_addr, ic->sar->host_port);
2062 - if (ic->sar->host_port == 0) {
2065 + len = ap_snprintf(buf, sizeof(buf), "%pI", &ic->sar->host_addr);
2066 if (ic->names == NULL) {
2067 if (ic->server == NULL)
2068 fprintf(f, "%-22s WARNING: No <VirtualHost> defined for this NameVirtualHost!\n", buf);
2069 @@ -516,10 +606,37 @@
2070 * occured in the config file, we'll copy it in that order.
2072 for (sar = name_vhost_list; sar; sar = sar->next) {
2073 - unsigned bucket = hash_inaddr(sar->host_addr.s_addr);
2074 + unsigned bucket = hash_addr((struct sockaddr *)&sar->host_addr);
2075 ipaddr_chain *ic = new_ipaddr_chain(p, NULL, sar);
2078 - if (sar->host_addr.s_addr != INADDR_ANY) {
2080 + switch (sar->host_addr.ss_family) {
2083 + struct sockaddr_in *sin;
2084 + sin = (struct sockaddr_in *)&sar->host_addr;
2085 + if (sin->sin_addr.s_addr == INADDR_ANY)
2092 + struct sockaddr_in6 *sin6;
2093 + sin6 = (struct sockaddr_in6 *)&sar->host_addr;
2094 + if (*(ap_uint32_t *)&sin6->sin6_addr.s6_addr[0] == 0
2095 + && *(ap_uint32_t *)&sin6->sin6_addr.s6_addr[4] == 0
2096 + && *(ap_uint32_t *)&sin6->sin6_addr.s6_addr[8] == 0
2097 + && *(ap_uint32_t *)&sin6->sin6_addr.s6_addr[12] == 0) {
2106 *iphash_table_tail[bucket] = ic;
2107 iphash_table_tail[bucket] = &ic->next;
2109 @@ -546,12 +663,45 @@
2110 has_default_vhost_addr = 0;
2111 for (sar = s->addrs; sar; sar = sar->next) {
2115 - if (sar->host_addr.s_addr == DEFAULT_VHOST_ADDR
2116 - || sar->host_addr.s_addr == INADDR_ANY) {
2117 - ic = find_default_server(sar->host_port);
2118 - if (!ic || !add_name_vhost_config(p, main_s, s, sar, ic)) {
2119 - if (ic && ic->sar->host_port != 0) {
2121 + switch (sar->host_addr.ss_family) {
2124 + struct sockaddr_in *sin;
2125 + sin = (struct sockaddr_in *)&sar->host_addr;
2126 + if (sin->sin_addr.s_addr == DEFAULT_VHOST_ADDR)
2128 + else if (sin->sin_addr.s_addr == INADDR_ANY)
2135 + struct sockaddr_in6 *sin6;
2136 + sin6 = (struct sockaddr_in6 *)&sar->host_addr;
2137 + if (*(ap_uint32_t *)&sin6->sin6_addr.s6_addr[0] == ~0
2138 + && *(ap_uint32_t *)&sin6->sin6_addr.s6_addr[4] == ~0
2139 + && *(ap_uint32_t *)&sin6->sin6_addr.s6_addr[8] == ~0
2140 + && *(ap_uint32_t *)&sin6->sin6_addr.s6_addr[12] == ~0) {
2149 + /* add it to default bucket for each appropriate sar
2150 + * since we need to do a port test
2152 + ipaddr_chain *other;
2154 + other = find_default_server(sar->host_port);
2155 + if (!other || !add_name_vhost_config(p, main_s, s, sar, other)) {
2156 + if (other && other->sar->host_port != 0) {
2157 ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING,
2158 main_s, "_default_ VirtualHost overlap on port %u,"
2159 " the first has precedence", sar->host_port);
2160 @@ -564,10 +714,11 @@
2163 /* see if it matches something we've already got */
2164 - ic = find_ipaddr(&sar->host_addr, sar->host_port);
2165 + ic = find_ipaddr((struct sockaddr *)&sar->host_addr);
2168 - unsigned bucket = hash_inaddr(sar->host_addr.s_addr);
2170 + hash_addr((struct sockaddr *)&sar->host_addr);
2172 ic = new_ipaddr_chain(p, s, sar);
2173 ic->next = *iphash_table_tail[bucket];
2174 @@ -604,19 +755,33 @@
2178 + char hostnamebuf[MAXHOSTNAMELEN];
2180 - if ((h = gethostbyaddr((char *) &(s->addrs->host_addr),
2181 - sizeof(struct in_addr), AF_INET))) {
2182 - s->server_hostname = ap_pstrdup(p, (char *) h->h_name);
2183 + if (!getnameinfo((struct sockaddr *)&s->addrs->host_addr,
2185 + SA_LEN((struct sockaddr *)&s->addrs->host_addr),
2187 + s->addrs->host_addr.ss_len,
2189 + hostnamebuf, sizeof(hostnamebuf),
2191 + s->server_hostname = ap_pstrdup(p, hostnamebuf);
2194 /* again, what can we do? They didn't specify a
2195 ServerName, and their DNS isn't working. -djg */
2196 + getnameinfo((struct sockaddr *)&s->addrs->host_addr,
2198 + SA_LEN((struct sockaddr *)&s->addrs->host_addr),
2200 + s->addrs->host_addr.ss_len,
2202 + hostnamebuf, sizeof(hostnamebuf),
2203 + NULL, 0, NI_NUMERICHOST);
2204 ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, main_s,
2205 "Failed to resolve server name "
2206 "for %s (check DNS) -- or specify an explicit "
2208 - inet_ntoa(s->addrs->host_addr));
2209 + "ServerName", hostnamebuf);
2210 s->server_hostname =
2211 ap_pstrdup(p, "bogus_host_without_reverse_dns");
2213 @@ -664,45 +829,80 @@
2216 const char *port_str;
2217 + const char *u, *v = NULL;
2219 /* check and copy the host part */
2220 - src = r->hostname;
2221 + u = src = r->hostname;
2225 - if (*src == '.') {
2232 - if (*src == '/' || *src == '\\') {
2235 - if (*src == ':') {
2236 - port_str = src + 1;
2237 - /* check the port part */
2239 - if (!ap_isdigit(*src)) {
2240 + if (*u == '[') { /* IPv6 numeral address in brackets */
2241 + v = strchr(u, ']');
2243 + /* missing closing bracket */
2246 + if (v == (u + 1)) {
2247 + /* bad empty address */
2250 + for (src = u+1; src < v; src++) /* copy IPv6 adress */
2256 + while (*v) { /* check if portnum is correct */
2257 + if (!ap_isdigit(*v++))
2261 - if (src[-1] == ':')
2265 + /* a known "good" port value */
2267 + iport = atoi(port_str);
2268 + if (iport < 1 || iport > 65535) {
2271 + r->parsed_uri.port_str = ap_pstrdup(r->pool, port_str);
2272 + r->parsed_uri.port = iport;
2277 + if (*src == '.') {
2284 + if (*src == '/' || *src == '\\') {
2287 - /* a known "good" port value */
2289 - iport = atoi(port_str);
2290 - if (iport < 1 || iport > 65535) {
2292 + if (*src == ':') {
2293 + port_str = src + 1;
2294 + /* sheck the port part */
2296 + if (!ap_isdigit(*src)) {
2300 + if (src[-1] == ':')
2303 + /* a known "good" port value */
2305 + iport = atoi(port_str);
2306 + if (iport < 1 || iport > 65535) {
2309 + r->parsed_uri.port_str = ap_pstrdup(r->pool, port_str);
2310 + r->parsed_uri.port = iport;
2312 - r->parsed_uri.port_str = ap_pstrdup(r->pool, port_str);
2313 - r->parsed_uri.port = iport;
2320 /* strip trailing gubbins */
2321 if (dst > host && dst[-1] == '.') {
2324 r->status = HTTP_BAD_REQUEST;
2325 ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r,
2326 - "Client sent malformed Host header");
2327 + "Client sent malformed Host header <<%s>>",u);
2331 @@ -820,11 +1020,25 @@
2332 * names we'll match have ports associated with them
2334 const char *host = r->hostname;
2335 - unsigned port = ntohs(r->connection->local_addr.sin_port);
2341 + switch (r->connection->local_addr.ss_family) {
2343 + port = ntohs(((struct sockaddr_in *)
2344 + &r->connection->local_addr)->sin_port);
2348 + port = ntohs(((struct sockaddr_in6 *)
2349 + &r->connection->local_addr)->sin6_port);
2357 /* Recall that the name_chain is a list of server_addr_recs, some of
2358 @@ -879,7 +1093,22 @@
2362 - unsigned port = ntohs(r->connection->local_addr.sin_port);
2365 + switch (r->connection->local_addr.ss_family) {
2367 + port = ntohs(((struct sockaddr_in *)
2368 + &r->connection->local_addr)->sin_port);
2372 + port = ntohs(((struct sockaddr_in6 *)
2373 + &r->connection->local_addr)->sin6_port);
2381 * This is in conjunction with the ServerPath code in http_core, so we
2382 @@ -939,10 +1168,22 @@
2383 API_EXPORT(void) ap_update_vhost_given_ip(conn_rec *conn)
2386 - unsigned port = ntohs(conn->local_addr.sin_port);
2387 + char portbuf[NI_MAXSERV];
2390 + if (getnameinfo((struct sockaddr *)&conn->local_addr,
2392 + SA_LEN((struct sockaddr *)&conn->local_addr),
2394 + conn->local_addr.ss_len,
2396 + NULL, 0, portbuf, sizeof(portbuf), NI_NUMERICSERV) != 0) {
2399 + port = atoi(portbuf);
2401 /* scan the hash table for an exact match first */
2402 - trav = find_ipaddr(&conn->local_addr.sin_addr, port);
2403 + trav = find_ipaddr((struct sockaddr *)&conn->local_addr);
2405 /* save the name_chain for later in case this is a name-vhost */
2406 conn->vhost_lookup_data = trav->names;
2407 @@ -960,6 +1201,7 @@
2412 /* otherwise we're stuck with just the main server
2413 * and no name-based vhosts
2415 --- apache_1.3.41/src/main/rfc1413.c 2006-07-12 11:16:05.000000000 +0300
2416 +++ apache_1.3.41-ipv6/src/main/rfc1413.c 2009-02-16 19:29:36.623502355 +0200
2418 #include "http_log.h" /* for aplog_error */
2419 #include "rfc1413.h"
2420 #include "http_main.h" /* set_callback_and_alarm */
2421 +#include "sa_len.h"
2424 /* Semi-well-known port */
2425 @@ -100,12 +101,13 @@
2427 /* bind_connect - bind both ends of a socket */
2428 /* Ambarish fix this. Very broken */
2429 -static int get_rfc1413(int sock, const struct sockaddr_in *our_sin,
2430 - const struct sockaddr_in *rmt_sin,
2431 +static int get_rfc1413(int sock, const struct sockaddr *our_sin,
2432 + const struct sockaddr *rmt_sin,
2433 char user[RFC1413_USERLEN+1], server_rec *srv)
2435 - struct sockaddr_in rmt_query_sin, our_query_sin;
2436 - unsigned int rmt_port, our_port;
2437 + struct sockaddr_storage rmt_query_sin, our_query_sin;
2438 + unsigned int o_rmt_port, o_our_port; /* original port pair */
2439 + unsigned int rmt_port, our_port; /* replied port pair */
2442 char buffer[RFC1413_MAXDATA + 1];
2443 @@ -120,16 +122,47 @@
2444 * addresses from the query socket.
2447 - our_query_sin = *our_sin;
2448 - our_query_sin.sin_port = htons(ANY_PORT);
2450 - our_query_sin.sin_addr.s_addr = INADDR_ANY;
2452 + memcpy(&our_query_sin, our_sin, SA_LEN(our_sin));
2453 + memcpy(&rmt_query_sin, rmt_sin, SA_LEN(rmt_sin));
2455 + memcpy(&our_query_sin, our_sin, our_sin->sa_len);
2456 + memcpy(&rmt_query_sin, rmt_sin, rmt_sin->sa_len);
2458 + switch (our_sin->sa_family) {
2461 + ((struct sockaddr_in *)&our_query_sin)->sin_addr.s_addr = INADDR_ANY; /* XXX: htonl(??) */
2463 + ((struct sockaddr_in *)&our_query_sin)->sin_port = htons(ANY_PORT);
2464 + o_our_port = ntohs(((struct sockaddr_in *)our_sin)->sin_port);
2465 + ((struct sockaddr_in *)&rmt_query_sin)->sin_port = htons(RFC1413_PORT);
2466 + o_rmt_port = ntohs(((struct sockaddr_in *)rmt_sin)->sin_port);
2471 + memcpy(&((struct sockaddr_in6 *)&our_query_sin)->sin6_addr,
2472 + &in6addr_any, sizeof(struct in6_addr));
2474 + ((struct sockaddr_in6 *)&our_query_sin)->sin6_port = htons(ANY_PORT);
2475 + o_our_port = ntohs(((struct sockaddr_in6 *)our_sin)->sin6_port);
2476 + ((struct sockaddr_in6 *)&rmt_query_sin)->sin6_port = htons(RFC1413_PORT);
2477 + o_rmt_port = ntohs(((struct sockaddr_in6 *)rmt_sin)->sin6_port);
2480 - rmt_query_sin = *rmt_sin;
2481 - rmt_query_sin.sin_port = htons(RFC1413_PORT);
2483 + /* unsupported AF */
2487 if (bind(sock, (struct sockaddr *) &our_query_sin,
2488 - sizeof(struct sockaddr_in)) < 0) {
2490 + SA_LEN((struct sockaddr *) &our_query_sin)
2492 + our_query_sin.ss_len
2495 ap_log_error(APLOG_MARK, APLOG_CRIT, srv,
2496 "bind: rfc1413: Error binding to local port");
2498 @@ -140,12 +173,18 @@
2501 if (connect(sock, (struct sockaddr *) &rmt_query_sin,
2502 - sizeof(struct sockaddr_in)) < 0)
2505 + SA_LEN((struct sockaddr *) &rmt_query_sin)
2507 + rmt_query_sin.ss_len
2514 - buflen = ap_snprintf(buffer, sizeof(buffer), "%u,%u\r\n", ntohs(rmt_sin->sin_port),
2515 - ntohs(our_sin->sin_port));
2516 + buflen = ap_snprintf(buffer, sizeof(buffer), "%u,%u\r\n", o_rmt_port,
2519 /* send query to server. Handle short write. */
2520 #ifdef CHARSET_EBCDIC
2522 ascii2ebcdic(buffer, buffer, (size_t)i);
2524 if (sscanf(buffer, "%u , %u : USERID :%*[^:]:%512s", &rmt_port, &our_port,
2525 - user) != 3 || ntohs(rmt_sin->sin_port) != rmt_port
2526 - || ntohs(our_sin->sin_port) != our_port)
2527 + user) != 3 || o_rmt_port != rmt_port || o_our_port != our_port) {
2532 * Strip trailing carriage return. It is part of the
2535 result = FROM_UNKNOWN;
2537 - sock = ap_psocket_ex(conn->pool, AF_INET, SOCK_STREAM, IPPROTO_TCP, 1);
2538 + sock = ap_psocket_ex(conn->pool, conn->remote_addr.ss_family, SOCK_STREAM, IPPROTO_TCP, 1);
2540 ap_log_error(APLOG_MARK, APLOG_CRIT, srv,
2541 "socket: rfc1413: error creating socket");
2542 @@ -253,8 +292,10 @@
2543 if (ap_setjmp(timebuf) == 0) {
2544 ap_set_callback_and_alarm(ident_timeout, ap_rfc1413_timeout);
2546 - if (get_rfc1413(sock, &conn->local_addr, &conn->remote_addr, user, srv) >= 0)
2547 + if (get_rfc1413(sock, (struct sockaddr *)&conn->local_addr,
2548 + (struct sockaddr *)&conn->remote_addr, user, srv) >= 0) {
2552 ap_set_callback_and_alarm(NULL, 0);
2554 --- apache_1.3.41/src/main/util.c 2006-07-12 11:16:05.000000000 +0300
2555 +++ apache_1.3.41-ipv6/src/main/util.c 2009-02-16 19:29:36.626835968 +0200
2556 @@ -2044,52 +2044,87 @@
2557 * Parses a host of the form <address>[:port]
2558 * :port is permitted if 'port' is not NULL
2560 -API_EXPORT(unsigned long) ap_get_virthost_addr(char *w, unsigned short *ports)
2561 +API_EXPORT(struct sockaddr *) ap_get_virthost_addr(char *w, unsigned short *ports)
2563 - struct hostent *hep;
2564 - unsigned long my_addr;
2567 - p = strchr(w, ':');
2568 + static struct sockaddr_storage ss;
2569 + struct addrinfo hints, *res;
2574 + char servbuf[NI_MAXSERV];
2580 + if (r = strrchr(w+1, ']')){
2596 + p = strchr(w, ':');
2597 + if (p != NULL && strchr(p+1, ':') != NULL)
2600 if (ports != NULL) {
2602 - if (p != NULL && strcmp(p + 1, "*") != 0)
2603 - *ports = atoi(p + 1);
2604 + if (p != NULL && *p && strcmp(p + 1, "*") != 0)
2608 + memset(&hints, 0, sizeof(hints));
2609 + hints.ai_socktype = SOCK_STREAM;
2612 if (strcmp(w, "*") == 0) {
2615 - return htonl(INADDR_ANY);
2618 - my_addr = ap_inet_addr((char *)w);
2619 - if (my_addr != INADDR_NONE) {
2624 + hints.ai_flags = AI_PASSIVE;
2625 + hints.ai_family = ap_default_family;
2628 + hints.ai_family = PF_UNSPEC;
2631 - hep = gethostbyname(w);
2632 + error = getaddrinfo(host, port, &hints, &res);
2634 - if ((!hep) || (hep->h_addrtype != AF_INET || !hep->h_addr_list[0])) {
2635 - fprintf(stderr, "Cannot resolve host name %s --- exiting!\n", w);
2636 + if (error || !res) {
2637 + fprintf(stderr, "ap_get_vitrhost_addr(): getaddrinfo(%s):%s --- exiting!\n", w, gai_strerror(error));
2641 - if (hep->h_addr_list[1]) {
2642 - fprintf(stderr, "Host %s has multiple addresses ---\n", w);
2643 + if (res->ai_next) {
2644 + fprintf(stderr, "ap_get_vitrhost_addr(): Host %s has multiple addresses ---\n", w);
2645 fprintf(stderr, "you must choose one explicitly for use as\n");
2646 fprintf(stderr, "a virtual host. Exiting!!!\n");
2655 - return ((struct in_addr *) (hep->h_addr))->s_addr;
2656 + memcpy(&ss, res->ai_addr, res->ai_addrlen);
2657 + if (getnameinfo(res->ai_addr, res->ai_addrlen,
2658 + NULL, 0, servbuf, sizeof(servbuf),
2660 + fprintf(stderr, "ap_get_virthost_addr(): getnameinfo() failed --- Exiting!!!\n");
2663 + if (ports) *ports = atoi(servbuf);
2664 + freeaddrinfo(res);
2665 + return (struct sockaddr *)&ss;
2669 @@ -2117,7 +2152,8 @@
2671 char str[MAXHOSTNAMELEN];
2672 char *server_hostname = NULL;
2673 - struct hostent *p;
2674 + struct addrinfo hints, *res;
2677 #ifdef BEOS /* BeOS returns zero as an error for gethostname */
2678 if (gethostname(str, sizeof(str) - 1) == 0) {
2679 @@ -2130,29 +2166,38 @@
2683 - str[sizeof(str) - 1] = '\0';
2684 - if ((!(p = gethostbyname(str)))
2685 - || (!(server_hostname = find_fqdn(a, p)))) {
2686 - /* Recovery - return the default servername by IP: */
2687 - if (p && p->h_addr_list && p->h_addr_list[0]) {
2688 - ap_snprintf(str, sizeof(str), "%pA", p->h_addr_list[0]);
2689 - server_hostname = ap_pstrdup(a, str);
2690 - /* We will drop through to report the IP-named server */
2694 - /* Since we found a fqdn, return it with no logged message. */
2695 - return server_hostname;
2698 - /* If we don't have an fdqn or IP, fall back to the loopback addr */
2699 - if (!server_hostname)
2700 - server_hostname = ap_pstrdup(a, "127.0.0.1");
2702 - ap_log_error(APLOG_MARK, APLOG_ALERT|APLOG_NOERRNO, NULL,
2703 - "%s: Could not determine the server's fully qualified "
2704 - "domain name, using %s for ServerName",
2705 - ap_server_argv0, server_hostname);
2706 + str[sizeof(str) - 1] = '\0';
2707 + memset(&hints, 0, sizeof(hints));
2708 + hints.ai_family = PF_UNSPEC;
2709 + hints.ai_flags = AI_CANONNAME;
2710 + error = getaddrinfo(str, NULL, &hints, &res);
2713 + /* Recovery - return the default servername by IP: */
2715 + fprintf(stderr, "%s: cannot determine local host name.\n",
2717 + fprintf(stderr, "Use the ServerName directive to set it manually.\n");
2720 + server_hostname = ap_pstrdup(a, res->ai_canonname);
2722 + else if (1) /*fqdn found*/
2724 + /* XXX should check more conditions */
2725 + server_hostname = ap_pstrdup(a, res->ai_canonname);
2729 + ap_log_error(APLOG_MARK, APLOG_ALERT|APLOG_NOERRNO, NULL,
2730 + "%s: Could not determine the server's fully qualified "
2731 + "domain name, using %s for ServerName",
2732 + ap_server_argv0, server_hostname);
2735 + /* Since we found a fdqn, return it with no logged message. */
2736 + freeaddrinfo(res);
2739 return server_hostname;
2741 @@ -2396,3 +2441,11 @@
2746 +#ifdef NEED_GETADDRINFO
2747 +#include "getaddrinfo.c"
2750 +#ifdef NEED_GETNAMEINFO
2751 +#include "getnameinfo.c"
2753 --- apache_1.3.41/src/main/util_script.c 2006-07-12 11:16:05.000000000 +0300
2754 +++ apache_1.3.41-ipv6/src/main/util_script.c 2009-02-16 19:29:36.626835968 +0200
2756 #include "http_request.h" /* for sub_req_lookup_uri() */
2757 #include "util_script.h"
2758 #include "util_date.h" /* For parseHTTPdate() */
2759 +#include "sa_len.h"
2764 array_header *hdrs_arr = ap_table_elts(r->headers_in);
2765 table_entry *hdrs = (table_entry *) hdrs_arr->elts;
2767 + char servbuf[NI_MAXSERV];
2769 /* use a temporary table which we'll overlap onto
2770 * r->subprocess_env later
2771 @@ -252,8 +254,16 @@
2772 ap_table_addn(e, "SERVER_ADMIN", s->server_admin); /* Apache */
2773 ap_table_addn(e, "SCRIPT_FILENAME", r->filename); /* Apache */
2775 - ap_table_addn(e, "REMOTE_PORT",
2776 - ap_psprintf(r->pool, "%d", ntohs(c->remote_addr.sin_port)));
2777 + servbuf[0] = '\0';
2778 + if (!getnameinfo((struct sockaddr *)&c->remote_addr,
2779 +#ifndef HAVE_SOCKADDR_LEN
2780 + SA_LEN((struct sockaddr *)&c->remote_addr),
2782 + c->remote_addr.ss_len,
2784 + NULL, 0, servbuf, sizeof(servbuf), NI_NUMERICSERV)){
2785 + ap_table_addn(e, "REMOTE_PORT", ap_pstrdup(r->pool, servbuf));
2789 ap_table_addn(e, "REMOTE_USER", c->user);
2790 --- apache_1.3.41/src/main/util_uri.c 2006-07-12 11:16:05.000000000 +0300
2791 +++ apache_1.3.41-ipv6/src/main/util_uri.c 2009-02-16 19:29:36.626835968 +0200
2792 @@ -382,6 +382,12 @@
2793 * the hostname. If there's a port it is the first colon.
2795 s = memchr(hostinfo, ':', uri - hostinfo);
2796 + if (*hostinfo == '[') {
2797 + s = memchr(hostinfo+1, ']', uri - hostinfo - 1);
2799 + s = strchr(s, ':');
2801 + s = memchr(hostinfo, ':', uri - hostinfo);
2803 /* we expect the common case to have no port */
2804 uptr->hostname = ap_pstrndup(p, hostinfo, uri - hostinfo);
2805 @@ -438,7 +444,12 @@
2806 /* We expect hostinfo to point to the first character of
2807 * the hostname. There must be a port, separated by a colon
2809 - s = strchr(hostinfo, ':');
2810 + if (*hostinfo == '[') {
2811 + s = strchr(hostinfo+1, ']');
2813 + s = strchr(s, ':');
2815 + s = strchr(hostinfo, ':');
2817 return HTTP_BAD_REQUEST;
2819 --- apache_1.3.41/src/modules/proxy/mod_proxy.c 2009-02-16 19:29:13.444337634 +0200
2820 +++ apache_1.3.41-ipv6/src/modules/proxy/mod_proxy.c 2009-02-16 19:29:36.630169925 +0200
2821 @@ -582,11 +582,31 @@
2822 struct proxy_remote *new;
2825 + char *bl = NULL, *br = NULL;
2828 if (p == NULL || p[1] != '/' || p[2] != '/' || p[3] == '\0')
2829 return "ProxyRemote: Bad syntax for a remote proxy server";
2830 - q = strchr(p + 3, ':');
2833 + br = strrchr(bl+1, ']');
2837 + if (*(br+1) == ':'){ /* [host]:xx */
2840 + else if (*(br+1) == '\0'){ /* [host] */
2844 + q = strrchr(br, ':'); /* XXX */
2847 + q = strrchr(bl, ':'); /* XXX */
2850 + q = strrchr(bl, ':');
2852 if (sscanf(q + 1, "%u", &port) != 1 || port > 65535)
2853 return "ProxyRemote: Bad syntax for a remote proxy server (bad port number)";
2856 if (strchr(f, ':') == NULL)
2857 ap_str_tolower(f); /* lowercase scheme */
2858 - ap_str_tolower(p + 3); /* lowercase hostname */
2859 + ap_str_tolower(bl); /* lowercase hostname */
2864 new = ap_push_array(conf->proxies);
2867 - new->hostname = p + 3;
2868 + new->hostname = bl;
2872 --- apache_1.3.41/src/modules/proxy/mod_proxy.h 2009-02-16 19:29:13.447671388 +0200
2873 +++ apache_1.3.41-ipv6/src/modules/proxy/mod_proxy.h 2009-02-16 19:29:36.630169925 +0200
2875 int ap_proxy_is_domainname(struct dirconn_entry *This, pool *p);
2876 int ap_proxy_is_hostname(struct dirconn_entry *This, pool *p);
2877 int ap_proxy_is_word(struct dirconn_entry *This, pool *p);
2878 -int ap_proxy_doconnect(int sock, struct sockaddr_in *addr, request_rec *r);
2879 +int ap_proxy_doconnect(int sock, struct sockaddr *addr, request_rec *r);
2880 int ap_proxy_garbage_init(server_rec *, pool *);
2881 /* This function is called by ap_table_do() for all header lines */
2882 int ap_proxy_send_hdr_line(void *p, const char *key, const char *value);
2883 --- apache_1.3.41/src/modules/proxy/proxy_connect.c 2006-07-12 11:16:05.000000000 +0300
2884 +++ apache_1.3.41-ipv6/src/modules/proxy/proxy_connect.c 2009-02-16 19:29:36.630169925 +0200
2886 const char *proxyhost, int proxyport)
2888 struct sockaddr_in server;
2889 - struct in_addr destaddr;
2890 - struct hostent server_hp;
2891 - const char *host, *err;
2892 + struct addrinfo hints, *res, *res0;
2893 + const char *hoststr;
2894 + const char *portstr = NULL;
2897 char buffer[HUGE_STRING_LEN];
2903 void *sconf = r->server->module_config;
2904 proxy_server_conf *conf =
2906 struct noproxy_entry *npent = (struct noproxy_entry *) conf->noproxies->elts;
2908 memset(&server, '\0', sizeof(server));
2909 +#ifdef HAVE_SOCKADDR_LEN
2910 + server.sin_len = sizeof(server);
2912 server.sin_family = AF_INET;
2914 /* Break the URL into host:port pairs */
2918 p = strchr(url, ':');
2920 - port = DEFAULT_HTTPS_PORT;
2922 - port = atoi(p + 1);
2925 + ap_snprintf(pbuf, sizeof(pbuf), "%d", DEFAULT_HTTPS_PORT);
2931 + port = atoi(portstr);
2933 + memset(&hints, 0, sizeof(hints));
2934 + hints.ai_family = PF_UNSPEC;
2935 + hints.ai_socktype = SOCK_STREAM;
2936 + hints.ai_protocol = IPPROTO_TCP;
2937 + error = getaddrinfo(hoststr, portstr, &hints, &res0);
2939 + return ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR,
2940 + gai_strerror(error)); /* give up */
2943 /* check if ProxyBlock directive on this host */
2944 - destaddr.s_addr = ap_inet_addr(host);
2945 - for (i = 0; i < conf->noproxies->nelts; i++) {
2946 - if ((npent[i].name != NULL && strstr(host, npent[i].name) != NULL)
2947 - || destaddr.s_addr == npent[i].addr.s_addr
2948 - || npent[i].name[0] == '*')
2949 + for (res = res0; res; res = res = res->ai_next) {
2950 + struct sockaddr_in *sin;
2954 + for (i = 0; i < conf->noproxies->nelts; i++) {
2955 + if (npent[i].name != NULL && strstr(hoststr, npent[i].name))
2957 + if (npent[i].name != NULL && strcmp(npent[i].name, "*") == 0)
2959 + switch (res->ai_family) {
2961 + sin = (struct sockaddr_in *)res->ai_addr;
2962 + if (sin->sin_addr.s_addr == npent[i].addr.s_addr)
2968 + freeaddrinfo(res0);
2969 return ap_proxyerror(r, HTTP_FORBIDDEN,
2970 "Connect to remote machine blocked");
2974 /* Check if it is an allowed port */
2975 @@ -117,34 +150,42 @@
2976 case DEFAULT_SNEWS_PORT:
2979 + freeaddrinfo(res0);
2980 return HTTP_FORBIDDEN;
2983 - else if (!allowed_port(conf, port))
2984 + else if (!allowed_port(conf, port)) {
2985 + freeaddrinfo(res0);
2986 return HTTP_FORBIDDEN;
2992 + freeaddrinfo(res0);
2994 + ap_snprintf(pbuf, sizeof(pbuf), "%d", proxyport);
2995 + memset(&hints, 0, sizeof(hints));
2996 + hints.ai_family = PF_UNSPEC;
2997 + hints.ai_socktype = SOCK_STREAM;
2998 + hints.ai_protocol = IPPROTO_TCP;
2999 + error = getaddrinfo(proxyhost, pbuf, &hints, &res0);
3001 + return HTTP_INTERNAL_SERVER_ERROR; /* XXX */
3003 ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
3004 "CONNECT to remote proxy %s on port %d", proxyhost, proxyport);
3007 ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
3008 - "CONNECT to %s on port %d", host, port);
3009 + "CONNECT to %s on port %d", hoststr, port);
3012 - /* Nasty cast to work around broken terniary expressions on MSVC */
3013 - server.sin_port = htons((unsigned short)(proxyport ? proxyport : port));
3014 - err = ap_proxy_host2addr(proxyhost ? proxyhost : host, &server_hp);
3017 - return ap_proxyerror(r,
3018 - proxyhost ? HTTP_BAD_GATEWAY : HTTP_INTERNAL_SERVER_ERROR, err);
3020 - sock = ap_psocket_ex(r->pool, PF_INET, SOCK_STREAM, IPPROTO_TCP, 1);
3022 - ap_log_rerror(APLOG_MARK, APLOG_ERR, r, "proxy: error creating socket");
3023 - return HTTP_INTERNAL_SERVER_ERROR;
3026 + for (res = res0; res; res = res->ai_next) {
3027 + sock = ap_psocket_ex(r->pool, res->ai_family, res->ai_socktype, res->ai_protocol, 1);
3031 #ifdef CHECK_FD_SETSIZE
3032 if (sock >= FD_SETSIZE) {
3033 @@ -154,19 +195,15 @@
3034 "found, you probably need to rebuild Apache with a "
3035 "larger FD_SETSIZE", sock, FD_SETSIZE);
3036 ap_pclosesocket(r->pool, sock);
3037 - return HTTP_INTERNAL_SERVER_ERROR;
3043 - while (server_hp.h_addr_list[j] != NULL) {
3044 - memcpy(&server.sin_addr, server_hp.h_addr_list[j],
3045 - sizeof(struct in_addr));
3046 - i = ap_proxy_doconnect(sock, &server, r);
3047 + i = ap_proxy_doconnect(sock, res->ai_addr, r);
3052 + freeaddrinfo(res0);
3054 ap_pclosesocket(r->pool, sock);
3055 return ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR, ap_pstrcat(r->pool,
3056 --- apache_1.3.41/src/modules/proxy/proxy_ftp.c 2006-07-12 11:16:05.000000000 +0300
3057 +++ apache_1.3.41-ipv6/src/modules/proxy/proxy_ftp.c 2009-02-16 19:29:36.633508156 +0200
3059 #include "http_main.h"
3060 #include "http_log.h"
3061 #include "http_core.h"
3062 +#include "sa_len.h"
3064 #define AUTODETECT_PWD
3066 @@ -514,8 +515,10 @@
3068 int destport, i, j, len, rc, nocache = 0;
3069 int csd = 0, sock = -1, dsock = -1;
3070 - struct sockaddr_in server;
3071 - struct hostent server_hp;
3072 + struct sockaddr_storage server;
3073 + struct addrinfo hints, *res, *res0;
3076 struct in_addr destaddr;
3079 @@ -538,11 +541,18 @@
3080 unsigned int presult, h0, h1, h2, h3, p0, p1;
3082 unsigned short pport;
3083 - struct sockaddr_in data_addr;
3084 + struct sockaddr_storage data_addr;
3085 + struct sockaddr_in *sin;
3090 +/* stuff for LPSV/EPSV */
3091 + unsigned int paf, holen, ho[16], polen, po[2];
3092 + struct sockaddr_in6 *sin6;
3096 /* stuff for responses */
3097 char resp[MAX_STRING_LEN];
3099 @@ -636,62 +646,50 @@
3103 - memset(&server, 0, sizeof(struct sockaddr_in));
3104 - server.sin_family = AF_INET;
3105 - server.sin_port = htons((unsigned short)destport);
3106 - err = ap_proxy_host2addr(desthost, &server_hp);
3108 - return ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR, err);
3110 - sock = ap_psocket_ex(p, PF_INET, SOCK_STREAM, IPPROTO_TCP, 1);
3112 - ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
3113 - "proxy: error creating socket");
3114 - return HTTP_INTERNAL_SERVER_ERROR;
3115 + ap_snprintf(portbuf, sizeof(portbuf), "%d", destport);
3116 + memset(&hints, 0, sizeof(hints));
3117 + hints.ai_family = PF_UNSPEC;
3118 + hints.ai_socktype = SOCK_STREAM;
3119 + error = getaddrinfo(desthost, portbuf, &hints, &res0);
3121 + return ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR, gai_strerror(error));
3125 + for (res = res0; res; res = res->ai_next) {
3126 + sock = ap_psocket_ex(p, res->ai_family, res->ai_socktype,
3127 + res->ai_protocol, 1);
3131 #if !defined(TPF) && !defined(BEOS)
3132 - if (conf->recv_buffer_size > 0
3133 - && setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
3134 - (const char *)&conf->recv_buffer_size, sizeof(int))
3136 - ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
3137 - "setsockopt(SO_RCVBUF): Failed to set ProxyReceiveBufferSize, using default");
3139 + if (conf->recv_buffer_size > 0
3140 + && setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
3141 + (const char *)&conf->recv_buffer_size, sizeof(int))
3143 + ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
3144 + "setsockopt(SO_RCVBUF): Failed to set ProxyReceiveBufferSize, using default");
3148 - if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&one,
3149 - sizeof(one)) == -1) {
3150 + if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&one,
3151 + sizeof(one)) == -1) {
3152 #ifndef _OSD_POSIX /* BS2000 has this option "always on" */
3153 - ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
3154 - "proxy: error setting reuseaddr option: setsockopt(SO_REUSEADDR)");
3155 - ap_pclosesocket(p, sock);
3156 - return HTTP_INTERNAL_SERVER_ERROR;
3157 + ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
3158 + "proxy: error setting reuseaddr option: setsockopt(SO_REUSEADDR)");
3159 + ap_pclosesocket(p, sock);
3160 + freeaddrinfo(res0);
3161 + return HTTP_INTERNAL_SERVER_ERROR;
3162 #endif /* _OSD_POSIX */
3165 -#ifdef SINIX_D_RESOLVER_BUG
3167 - struct in_addr *ip_addr = (struct in_addr *)*server_hp.h_addr_list;
3169 - for (; ip_addr->s_addr != 0; ++ip_addr) {
3170 - memcpy(&server.sin_addr, ip_addr, sizeof(struct in_addr));
3171 - i = ap_proxy_doconnect(sock, &server, r);
3178 - while (server_hp.h_addr_list[j] != NULL) {
3179 - memcpy(&server.sin_addr, server_hp.h_addr_list[j],
3180 - sizeof(struct in_addr));
3181 - i = ap_proxy_doconnect(sock, &server, r);
3183 + i = ap_proxy_doconnect(sock, res->ai_addr, r);
3185 + memcpy(&server, res->ai_addr, res->ai_addrlen);
3189 + ap_pclosesocket(p, sock);
3192 + freeaddrinfo(res0);
3194 return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
3195 ap_proxyerror(r, HTTP_BAD_GATEWAY, ap_pstrcat(r->pool,
3199 /* try to set up PASV data connection first */
3200 - dsock = ap_psocket_ex(p, PF_INET, SOCK_STREAM, IPPROTO_TCP, 1);
3201 + dsock = ap_psocket_ex(p, server.ss_family, SOCK_STREAM, IPPROTO_TCP, 1);
3203 return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
3204 ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR,
3205 @@ -939,11 +937,22 @@
3209 - ap_bputs("PASV" CRLF, ctrl);
3211 + if (server.ss_family == AF_INET)
3213 + else if (lpsvmode)
3217 + ap_bputs(cmd, ctrl);
3218 + ap_bputs(CRLF, ctrl);
3220 + Explain0("FTP: passive command issued");
3221 ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: PASV command issued");
3222 -/* possible results: 227, 421, 500, 501, 502, 530 */
3223 +/* possible results: 227, 228, 229, 421, 500, 501, 502, 530 */
3224 /* 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2). */
3225 + /* 228 Entering Long Passive Mode (...). */
3226 + /* 229 Entering Extended Passive Mode (...). */
3227 /* 421 Service not available, closing control connection. */
3228 /* 500 Syntax error, command unrecognized. */
3229 /* 501 Syntax error in parameters or arguments. */
3231 if (i == -1 || i == 421) {
3232 return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
3233 ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR,
3234 - "proxy: PASV: control connection is toast"));
3235 + ap_psprintf(p, "proxy: %s: control connection is toast", cmd)));
3239 @@ -982,10 +991,14 @@
3240 pport = (p1 << 8) + p0;
3241 ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: contacting host %d.%d.%d.%d:%d",
3242 h3, h2, h1, h0, pport);
3243 - data_addr.sin_family = AF_INET;
3244 - data_addr.sin_addr.s_addr = htonl(paddr);
3245 - data_addr.sin_port = htons(pport);
3246 - i = ap_proxy_doconnect(dsock, &data_addr, r);
3247 + sin = (struct sockaddr_in *)&data_addr;
3248 + sin->sin_family = AF_INET;
3250 + sin->sin_len = sizeof(*sin);
3252 + sin->sin_addr.s_addr = htonl(paddr);
3253 + sin->sin_port = htons(pport);
3254 + i = ap_proxy_doconnect(dsock, (struct sockaddr *)&data_addr, r);
3257 return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
3258 @@ -995,6 +1008,64 @@
3259 strerror(errno), NULL)));
3262 + } else if (presult == 228 && pstr != NULL
3264 +"%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u",
3265 + &paf, &holen, &ho[0], &ho[1], &ho[2], &ho[3],
3266 + &ho[4], &ho[5], &ho[6], &ho[7], &ho[8], &ho[9], &ho[10], &ho[11],
3267 + &ho[12], &ho[13], &ho[14], &ho[15], &polen, &po[0], &po[1]) == 21
3268 + && paf == 6 && holen == 16 && polen == 2) {
3270 + sin6 = (struct sockaddr_in6 *)&data_addr;
3271 + sin6->sin6_family = AF_INET6;
3273 + sin6->sin6_len = sizeof(*sin6);
3275 + for (i = 0; i < 16; i++)
3276 + sin6->sin6_addr.s6_addr[i] = ho[i] & 0xff;
3277 + sin6->sin6_port = htons(((po[0] & 0xff) << 8) | (po[1] & 0xff));
3278 + i = ap_proxy_doconnect(dsock, (struct sockaddr *)&data_addr, r);
3281 + return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
3282 + ap_proxyerror(r, HTTP_BAD_GATEWAY,
3283 + ap_pstrcat(r->pool,
3284 + "Could not connect to remote machine: ",
3285 + strerror(errno), NULL)));
3288 + } else if (presult == 229 && pstr != NULL
3289 + && pstr[0] == pstr[1] && pstr[0] == pstr[2]
3290 + && pstr[0] == pstr[strlen(pstr) - 1]) {
3291 + /* expect "|||port|" */
3293 + memcpy(&data_addr, &server, SA_LEN((struct sockaddr *)&server));
3295 + memcpy(&data_addr, &server, server.ss_len);
3297 + switch (data_addr.ss_family) {
3299 + sin = (struct sockaddr_in *)&data_addr;
3300 + sin->sin_port = htons(atoi(pstr + 3));
3303 + sin6 = (struct sockaddr_in6 *)&data_addr;
3304 + sin6->sin6_port = htons(atoi(pstr + 3));
3307 + i = ap_proxy_doconnect(dsock, (struct sockaddr *)&data_addr, r);
3310 + return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
3311 + ap_proxyerror(r, HTTP_BAD_GATEWAY,
3312 + ap_pstrcat(r->pool,
3313 + "Could not connect to remote machine: ",
3314 + strerror(errno), NULL)));
3317 + } else if (!lpsvmode && strcmp(cmd, "EPSV") == 0) {
3322 ap_pclosesocket(p, dsock); /* and try the regular way */
3323 @@ -1003,14 +1074,14 @@
3326 if (!pasvmode) { /* set up data connection */
3327 - clen = sizeof(struct sockaddr_in);
3328 + clen = sizeof(server);
3329 if (getsockname(sock, (struct sockaddr *)&server, &clen) < 0) {
3330 return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
3331 ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR,
3332 "proxy: error getting socket address"));
3335 - dsock = ap_psocket_ex(p, PF_INET, SOCK_STREAM, IPPROTO_TCP, 1);
3336 + dsock = ap_psocket_ex(p, server.ss_family, SOCK_STREAM, IPPROTO_TCP, 1);
3338 return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
3339 ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR,
3340 @@ -1026,13 +1097,28 @@
3341 #endif /* _OSD_POSIX */
3344 - if (bind(dsock, (struct sockaddr *)&server,
3345 - sizeof(struct sockaddr_in)) == -1) {
3347 + if (bind(dsock, (struct sockaddr *)&server, SA_LEN((struct sockaddr *)&server)) == -1)
3349 + if (bind(dsock, (struct sockaddr *)&server, server.ss_len) == -1)
3352 + char hostnamebuf[MAXHOSTNAMELEN], portnamebuf[MAXHOSTNAMELEN];
3354 + getnameinfo((struct sockaddr *)&server,
3356 + SA_LEN((struct sockaddr *)&server),
3360 + hostnamebuf, sizeof(hostnamebuf),
3361 + portnamebuf, sizeof(portnamebuf),
3362 + NI_NUMERICHOST | NI_NUMERICSERV);
3364 return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
3365 ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR,
3366 - ap_psprintf(p, "proxy: error binding to ftp data socket %s:%d",
3367 - inet_ntoa(server.sin_addr), server.sin_port)));
3368 + ap_psprintf(p, "proxy: error binding to ftp data socket %s:%s",
3369 + hostnamebuf, portnamebuf)));
3371 listen(dsock, 2); /* only need a short queue */
3373 @@ -1286,7 +1372,7 @@
3375 if (!pasvmode) { /* wait for connection */
3376 ap_hard_timeout("proxy ftp data connect", r);
3377 - clen = sizeof(struct sockaddr_in);
3378 + clen = sizeof(server);
3380 csd = accept(dsock, (struct sockaddr *)&server, &clen);
3381 while (csd == -1 && errno == EINTR);
3382 --- apache_1.3.41/src/modules/proxy/proxy_http.c 2009-02-16 19:29:13.447671388 +0200
3383 +++ apache_1.3.41-ipv6/src/modules/proxy/proxy_http.c 2009-02-16 19:29:36.633508156 +0200
3385 table *req_hdrs, *resp_hdrs;
3386 array_header *reqhdrs_arr;
3387 table_entry *reqhdrs_elts;
3388 - struct sockaddr_in server;
3389 - struct in_addr destaddr;
3390 - struct hostent server_hp;
3391 + struct addrinfo hints, *res, *res0;
3394 char buffer[HUGE_STRING_LEN];
3397 if (conf->cache.root == NULL)
3400 - memset(&server, '\0', sizeof(server));
3401 - server.sin_family = AF_INET;
3403 /* We break the URL into host, port, path-search */
3405 urlptr = strstr(url, "://");
3407 return HTTP_BAD_REQUEST;
3409 destport = DEFAULT_HTTP_PORT;
3410 + ap_snprintf(portstr, sizeof(portstr), "%d", DEFAULT_HTTP_PORT);
3411 + destportstr = portstr;
3413 ap_hook_use("ap::mod_proxy::http::handler::set_destport",
3414 AP_HOOK_SIG2(int,ptr),
3415 @@ -170,7 +168,20 @@
3420 + if (*desthost == '['){
3421 + char *u = strrchr(desthost+1, ']');
3425 + if (*(u+1) == ':'){ /* [host]:xx */
3427 + } else if (*(u+1) == '\0'){ /* [host] */
3430 + return HTTP_BAD_REQUEST;
3432 + return HTTP_BAD_REQUEST;
3434 strp2 = strchr(desthost, ':');
3435 if (strp2 != NULL) {
3437 @@ -180,46 +191,71 @@
3441 + memset(&hints, 0, sizeof(hints));
3442 + hints.ai_family = PF_UNSPEC;
3443 + hints.ai_socktype = SOCK_STREAM;
3444 + hints.ai_protocol = IPPROTO_TCP;
3445 + error = getaddrinfo(desthost, destportstr, &hints, &res0);
3447 + return ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR,
3448 + gai_strerror(error)); /* give up */
3451 /* check if ProxyBlock directive on this host */
3452 - destaddr.s_addr = ap_inet_addr(desthost);
3453 - for (i = 0; i < conf->noproxies->nelts; i++) {
3454 - if (destaddr.s_addr == npent[i].addr.s_addr ||
3455 - (npent[i].name != NULL &&
3456 - (npent[i].name[0] == '*' || strstr(desthost, npent[i].name) != NULL)))
3457 + for (res = res0; res; res = res->ai_next) {
3458 + struct sockaddr_in *sin;
3460 + struct sockaddr_in6 *sin6;
3465 + for (i = 0; i < conf->noproxies->nelts; i++) {
3466 + if (npent[i].name != NULL && strstr(desthost, npent[i].name))
3468 + if (npent[i].name != NULL && strcmp(npent[i].name, "*") == 0)
3470 + switch (res->ai_family) {
3472 + sin = (struct sockaddr_in *)res->ai_addr;
3473 + if (sin->sin_addr.s_addr == npent[i].addr.s_addr)
3479 + freeaddrinfo(res0);
3480 return ap_proxyerror(r, HTTP_FORBIDDEN,
3481 "Connect to remote machine blocked");
3485 if (proxyhost != NULL) {
3486 - server.sin_port = htons((unsigned short)proxyport);
3487 - err = ap_proxy_host2addr(proxyhost, &server_hp);
3491 + freeaddrinfo(res0);
3492 + ap_snprintf(pbuf, sizeof(pbuf), "%d", proxyport);
3493 + memset(&hints, 0, sizeof(hints));
3494 + hints.ai_family = PF_UNSPEC;
3495 + hints.ai_socktype = SOCK_STREAM;
3496 + hints.ai_protocol = IPPROTO_TCP;
3497 + error = getaddrinfo(proxyhost, pbuf, &hints, &res0);
3499 return DECLINED; /* try another */
3501 peer = ap_psprintf(p, "%s:%u", proxyhost, proxyport);
3505 - server.sin_port = htons((unsigned short)destport);
3506 - err = ap_proxy_host2addr(desthost, &server_hp);
3508 - return ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR, err);
3510 - peer = ap_psprintf(p, "%s:%u", desthost, destport);
3516 * we have worked out who exactly we are going to connect to, now make
3517 * that connection...
3519 - sock = ap_psocket_ex(p, PF_INET, SOCK_STREAM, IPPROTO_TCP, 1);
3521 - ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
3522 - "proxy: error creating socket");
3523 - return HTTP_INTERNAL_SERVER_ERROR;
3526 + for (res = res0; res; res = res->ai_next) {
3527 + sock = ap_psocket_ex(p, res->ai_family, res->ai_socktype, res->ai_protocol, 1);
3531 #if !defined(TPF) && !defined(BEOS)
3532 if (conf->recv_buffer_size) {
3533 @@ -232,38 +268,13 @@
3537 -#ifdef SINIX_D_RESOLVER_BUG
3539 - struct in_addr *ip_addr = (struct in_addr *)*server_hp.h_addr_list;
3541 - for (; ip_addr->s_addr != 0; ++ip_addr) {
3542 - memcpy(&server.sin_addr, ip_addr, sizeof(struct in_addr));
3543 - i = ap_proxy_doconnect(sock, &server, r);
3547 - * Even if the connection was unsuccesful we should
3548 - * reinit the socket
3550 - sock = ap_psocket_ex(p, PF_INET, SOCK_STREAM, IPPROTO_TCP, 1);
3555 - while (server_hp.h_addr_list[j] != NULL) {
3556 - memcpy(&server.sin_addr, server_hp.h_addr_list[j],
3557 - sizeof(struct in_addr));
3558 - i = ap_proxy_doconnect(sock, &server, r);
3559 + i = ap_proxy_doconnect(sock, res->ai_addr, r);
3563 - * Even if the connection was unsuccesful we should
3564 - * reinit the socket
3566 - sock = ap_psocket_ex(p, PF_INET, SOCK_STREAM, IPPROTO_TCP, 1);
3567 + ap_pclosesocket(p, sock);
3571 + freeaddrinfo(res0);
3573 if (proxyhost != NULL)
3574 return DECLINED; /* try again another way */
3575 @@ -595,17 +606,30 @@
3576 ap_table_set(resp_hdrs, "Content-Location", proxy_location_reverse_map(r, urlstr));
3578 /* check if NoCache directive on this host */
3580 + struct sockaddr_in *sin;
3582 + struct sockaddr_in6 *sin6;
3586 for (i = 0; i < conf->nocaches->nelts; i++) {
3587 - if (destaddr.s_addr == ncent[i].addr.s_addr ||
3588 - (ncent[i].name != NULL &&
3589 - (ncent[i].name[0] == '*' ||
3590 - strstr(desthost, ncent[i].name) != NULL))) {
3593 + if (ncent[i].name != NULL &&
3594 + (ncent[i].name[0] == '*' ||
3595 + strstr(desthost, ncent[i].name) != NULL)) {
3599 + switch (res->ai_addr->sa_family) {
3601 + sin = (struct sockaddr_in *)res->ai_addr;
3602 + if (sin->sin_addr.s_addr == ncent[i].addr.s_addr) {
3611 * update the cache file, possibly even fulfilling the request if it
3612 * turns out a conditional allowed us to serve the object from the
3613 --- apache_1.3.41/src/modules/proxy/proxy_util.c 2009-02-16 19:29:13.451004562 +0200
3614 +++ apache_1.3.41-ipv6/src/modules/proxy/proxy_util.c 2009-02-16 19:29:36.636835944 +0200
3616 #include "http_log.h"
3617 #include "util_uri.h"
3618 #include "util_date.h" /* get ap_checkmask() decl. */
3619 +#include "sa_len.h"
3621 static int proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r);
3622 static int proxy_match_domainname(struct dirconn_entry *This, request_rec *r);
3625 char *strp, *host, *url = *urlp;
3626 char *user = NULL, *password = NULL;
3627 + char *t = NULL, *u = NULL, *v = NULL;
3629 if (url[0] != '/' || url[1] != '/')
3630 return "Malformed URL";
3631 @@ -215,11 +217,22 @@
3632 *passwordp = password;
3635 - strp = strrchr(host, ':');
3636 - if (strp != NULL) {
3639 - for (i = 0; strp[i] != '\0'; i++)
3641 + if (*host == '['){
3642 + u = strrchr(host, ']');
3649 + t = strrchr(v, ':');
3655 + for (i=0; strp[i] != '\0'; i++)
3656 if (!ap_isdigit(strp[i]))
3659 @@ -238,17 +251,29 @@
3660 return "Missing host in URL";
3661 /* check hostname syntax */
3662 for (i = 0; host[i] != '\0'; i++)
3663 - if (!ap_isdigit(host[i]) && host[i] != '.')
3664 + if (!ap_isdigit(host[i]) && host[i] != '.' && host[i] != ':')
3666 /* must be an IP address */
3667 #if defined(WIN32) || defined(NETWARE) || defined(TPF) || defined(BEOS)
3668 if (host[i] == '\0' && (inet_addr(host) == -1))
3669 + return "Bad IP address in URL";
3671 + if (host[i] == '\0') {
3672 + struct addrinfo hints, *res0;
3674 + memset(&hints, 0, sizeof(hints));
3675 + hints.ai_family = PF_UNSPEC;
3676 + hints.ai_flags = AI_NUMERICHOST;
3677 + if (gai = getaddrinfo(host, NULL, &hints, &res0)) {
3679 + return gai_strerror(gai);
3681 - if (host[i] == '\0' && (ap_inet_addr(host) == -1 || inet_network(host) == -1))
3682 + return "Bad IP address in URL";
3685 - return "Bad IP address in URL";
3687 + freeaddrinfo(res0);
3693 @@ -1401,22 +1426,46 @@
3694 return host != NULL && strstr(host, This->name) != NULL;
3697 -int ap_proxy_doconnect(int sock, struct sockaddr_in *addr, request_rec *r)
3698 +int ap_proxy_doconnect(int sock, struct sockaddr *addr, request_rec *r)
3702 + char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV];
3703 +#ifdef NI_WITHSCOPEID
3704 + const int niflags = NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
3706 + const int niflags = NI_NUMERICHOST | NI_NUMERICSERV;
3709 ap_hard_timeout("proxy connect", r);
3710 +#ifdef HAVE_SOCKADDR_LEN
3711 + salen = addr->sa_len;
3713 + switch (addr->sa_family) {
3715 + salen = sizeof(struct sockaddr_in6);
3718 + salen = sizeof(struct sockaddr_in);
3723 - i = connect(sock, (struct sockaddr *)addr, sizeof(struct sockaddr_in));
3724 + i = connect(sock, addr, salen);
3725 #if defined(WIN32) || defined(NETWARE)
3726 if (i == SOCKET_ERROR)
3727 errno = WSAGetLastError();
3729 } while (i == -1 && errno == EINTR);
3731 + if (getnameinfo(addr, salen, hbuf, sizeof(hbuf), pbuf, sizeof(pbuf),
3733 + strcpy(hbuf, "?");
3734 + strcpy(pbuf, "?");
3736 ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
3737 "proxy connect to %s port %d failed",
3738 - inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
3743 --- apache_1.3.41/src/modules/standard/mod_access.c 2006-07-12 11:16:05.000000000 +0300
3744 +++ apache_1.3.41-ipv6/src/modules/standard/mod_access.c 2009-02-16 19:29:36.636835944 +0200
3759 struct in_addr mask;
3763 + struct in6_addr net6;
3764 + struct in6_addr mask6;
3768 enum allowdeny_type type;
3770 @@ -125,94 +134,242 @@
3773 else if ((s = strchr(where, '/'))) {
3774 - struct in_addr mask;
3775 + struct addrinfo hints, *resnet, *resmask;
3776 + struct sockaddr_storage net, mask;
3782 + a->type = T_FAIL; /*just in case*/
3783 /* trample on where, we won't be using it any more */
3787 - || (a->x.ip.net.s_addr = ap_inet_addr(where)) == INADDR_NONE) {
3789 - return "syntax error in network portion of network/netmask";
3791 + for (p = s; *p; p++) {
3798 - /* is_ip just tests if it matches [\d.]+ */
3800 + memset(&hints, 0, sizeof(hints));
3801 + hints.ai_family = PF_UNSPEC;
3802 + hints.ai_socktype = SOCK_STREAM; /*dummy*/
3803 +#ifdef AI_NUMERICHOST
3804 + hints.ai_flags = AI_NUMERICHOST; /*don't resolve*/
3807 + error = getaddrinfo(where, NULL, &hints, &resnet);
3808 + if (error || !resnet) {
3810 + freeaddrinfo(resnet);
3812 - return "syntax error in mask portion of network/netmask";
3813 + return "syntax error in network portion of network/netmask";
3815 - /* is it in /a.b.c.d form? */
3816 - if (strchr(s, '.')) {
3817 - mask.s_addr = ap_inet_addr(s);
3818 - if (mask.s_addr == INADDR_NONE) {
3820 - return "syntax error in mask portion of network/netmask";
3822 + if (resnet->ai_next) {
3823 + freeaddrinfo(resnet);
3825 + return "network/netmask resolved to multiple addresses";
3829 + memcpy(&net, resnet->ai_addr, resnet->ai_addrlen);
3830 + freeaddrinfo(resnet);
3832 - /* assume it's in /nnn form */
3834 - if (i > 32 || i <= 0) {
3836 - return "invalid mask in network/netmask";
3838 - mask.s_addr = 0xFFFFFFFFUL << (32 - i);
3839 - mask.s_addr = htonl(mask.s_addr);
3840 + switch (net.ss_family) {
3843 + a->x.ip.net.s_addr = ((struct sockaddr_in *)&net)->sin_addr.s_addr;
3848 + memcpy(&a->x.ip6.net6, &((struct sockaddr_in6 *)&net)->sin6_addr,
3849 + sizeof(a->x.ip6.net6));
3854 + return "unknown address family for network";
3856 - a->x.ip.mask = mask;
3857 - a->x.ip.net.s_addr = (a->x.ip.net.s_addr & mask.s_addr); /* pjr - This fixes PR 4770 */
3859 - else if (ap_isdigit(*where) && is_ip(where)) {
3860 - /* legacy syntax for ip addrs: a.b.c. ==> a.b.c.0/24 for example */
3866 - /* parse components */
3868 - a->x.ip.net.s_addr = 0;
3869 - a->x.ip.mask.s_addr = 0;
3873 - if (!ap_isdigit(*t)) {
3875 + if (!justdigits) {
3876 + memset(&hints, 0, sizeof(hints));
3877 + hints.ai_family = PF_UNSPEC;
3878 + hints.ai_socktype = SOCK_STREAM; /*dummy*/
3879 +#ifdef AI_NUMERICHOST
3880 + hints.ai_flags = AI_NUMERICHOST; /*don't resolve*/
3883 + error = getaddrinfo(s, NULL, &hints, &resmask);
3884 + if (error || !resmask) {
3886 + freeaddrinfo(resmask);
3888 - return "invalid ip address";
3890 - while (ap_isdigit(*t)) {
3895 + return "syntax error in mask portion of network/netmask";
3898 + if (resmask->ai_next) {
3899 + freeaddrinfo(resmask);
3901 - return "invalid ip address";
3902 + return "network/netmask resolved to multiple addresses";
3905 + memcpy(&mask, resmask->ai_addr, resmask->ai_addrlen);
3906 + freeaddrinfo(resmask);
3908 + if (net.ss_family != mask.ss_family) {
3910 - return "invalid ip address, only 4 octets allowed";
3911 + return "network/netmask resolved to different address family";
3914 - if (octet < 0 || octet > 255) {
3916 - return "each octet must be between 0 and 255 inclusive";
3918 + switch (a->type) {
3920 + a->x.ip.mask.s_addr =
3921 + ((struct sockaddr_in *)&mask)->sin_addr.s_addr;
3925 + memcpy(&a->x.ip6.mask6,
3926 + &((struct sockaddr_in6 *)&mask)->sin6_addr,
3927 + sizeof(a->x.ip6.mask6));
3934 + switch (a->type) {
3936 + if (mask < 0 || 32 < mask) {
3938 + return "netmask out of range";
3940 + a->x.ip.mask.s_addr = htonl(0xFFFFFFFFUL << (32 - mask));
3946 + if (mask < 0 || 128 < mask) {
3948 + return "netmask out of range";
3950 + for (i = 0; i < mask / 8; i++) {
3951 + a->x.ip6.mask6.s6_addr[i] = 0xff;
3954 + a->x.ip6.mask6.s6_addr[i] = 0xff << (8 - (mask % 8));
3959 - a->x.ip.net.s_addr |= (unsigned int)octet << shift;
3960 - a->x.ip.mask.s_addr |= 0xFFUL << shift;
3964 - a->x.ip.net.s_addr = ntohl(a->x.ip.net.s_addr);
3965 - a->x.ip.mask.s_addr = ntohl(a->x.ip.mask.s_addr);
3966 + /* mask network address */
3967 + switch (a->type) {
3969 + a->x.ip.net.s_addr &= a->x.ip.mask.s_addr;
3972 + a->x.ip6.net6.s6_addr32[0] &= a->x.ip6.mask6.s6_addr32[0];
3973 + a->x.ip6.net6.s6_addr32[1] &= a->x.ip6.mask6.s6_addr32[1];
3974 + a->x.ip6.net6.s6_addr32[2] &= a->x.ip6.mask6.s6_addr32[2];
3975 + a->x.ip6.net6.s6_addr32[3] &= a->x.ip6.mask6.s6_addr32[3];
3981 + struct addrinfo hints, *res;
3982 + struct sockaddr_storage ss;
3985 + a->type = T_FAIL; /*just in case*/
3987 + /* First, try using the old apache code to match */
3988 + /* legacy syntax for ip addrs: a.b.c. ==> a.b.c.0/24 for example */
3989 + if (ap_isdigit(*where) && is_ip(where)) {
3995 + /* parse components */
3997 + a->x.ip.net.s_addr = 0;
3998 + a->x.ip.mask.s_addr = 0;
4002 + if (!ap_isdigit(*t)) {
4004 + return "invalid ip address";
4006 + while (ap_isdigit(*t)) {
4014 + return "invalid ip address";
4017 + return "invalid ip address, only 4 octets allowed";
4020 + if (octet < 0 || octet > 255) {
4022 + return "each octet must be between 0 and 255 inclusive";
4024 + a->x.ip.net.s_addr |= (unsigned int)octet << shift;
4025 + a->x.ip.mask.s_addr |= 0xFFUL << shift;
4029 + a->x.ip.net.s_addr = ntohl(a->x.ip.net.s_addr);
4030 + a->x.ip.mask.s_addr = ntohl(a->x.ip.mask.s_addr);
4035 + /* IPv4/v6 numeric address */
4036 + memset(&hints, 0, sizeof(hints));
4037 + hints.ai_family = PF_UNSPEC;
4038 + hints.ai_socktype = SOCK_STREAM; /*dummy*/
4039 +#ifdef AI_NUMERICHOST
4040 + hints.ai_flags = AI_NUMERICHOST; /*don't resolve*/
4043 + error = getaddrinfo(where, NULL, &hints, &res);
4044 + if (error || !res) {
4046 + freeaddrinfo(res);
4050 + if (res->ai_next) {
4051 + freeaddrinfo(res);
4053 + return "network/netmask resolved to multiple addresses";
4055 + memcpy(&ss, res->ai_addr, res->ai_addrlen);
4056 + freeaddrinfo(res);
4058 + switch (ss.ss_family) {
4061 + a->x.ip.net.s_addr = ((struct sockaddr_in *)&ss)->sin_addr.s_addr;
4062 + memset(&a->x.ip.mask, 0xff, sizeof(a->x.ip.mask));
4067 + memcpy(&a->x.ip6.net6, &((struct sockaddr_in6 *)&ss)->sin6_addr,
4068 + sizeof(a->x.ip6.net6));
4069 + memset(&a->x.ip6.mask6, 0xff, sizeof(a->x.ip6.mask6));
4074 + return "unknown address family for network";
4080 @@ -276,13 +433,63 @@
4084 - if (ap[i].x.ip.net.s_addr != INADDR_NONE
4085 - && (r->connection->remote_addr.sin_addr.s_addr
4086 - & ap[i].x.ip.mask.s_addr) == ap[i].x.ip.net.s_addr) {
4088 + if (ap[i].x.ip.net.s_addr == INADDR_NONE)
4090 + switch (r->connection->remote_addr.ss_family) {
4092 + if ((((struct sockaddr_in *)&r->connection->remote_addr)->sin_addr.s_addr
4093 + & ap[i].x.ip.mask.s_addr) == ap[i].x.ip.net.s_addr) {
4099 + if (!IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)&r->connection->remote_addr)->sin6_addr)) /*XXX*/
4101 + if ((*(ap_uint32_t *)&((struct sockaddr_in6 *)&r->connection->remote_addr)->sin6_addr.s6_addr[12]
4102 + & ap[i].x.ip.mask.s_addr) == ap[i].x.ip.net.s_addr) {
4113 + struct in6_addr masked;
4115 + if (IN6_IS_ADDR_UNSPECIFIED(&ap[i].x.ip6.net6))
4117 + switch (r->connection->remote_addr.ss_family) {
4119 + if (!IN6_IS_ADDR_V4MAPPED(&ap[i].x.ip6.net6)) /*XXX*/
4121 + memset(&masked, 0, sizeof(masked));
4122 + masked.s6_addr[10] = masked.s6_addr[11] = 0xff;
4123 + memcpy(&masked.s6_addr[12],
4124 + &((struct sockaddr_in *)&r->connection->remote_addr)->sin_addr.s_addr,
4125 + sizeof(struct sockaddr_in));
4126 + for (j = 0; j < sizeof(struct in6_addr); j++)
4127 + masked.s6_addr[j] &= ap[i].x.ip6.mask6.s6_addr[j];
4128 + if (memcmp(&masked, &ap[i].x.ip6.net6, sizeof(masked)) == 0)
4132 + memset(&masked, 0, sizeof(masked));
4134 + &((struct sockaddr_in6 *)&r->connection->remote_addr)->sin6_addr,
4136 + for (j = 0; j < sizeof(struct in6_addr); j++)
4137 + masked.s6_addr[j] &= ap[i].x.ip6.mask6.s6_addr[j];
4138 + if (memcmp(&masked, &ap[i].x.ip6.net6, sizeof(masked)) == 0)
4147 remotehost = ap_get_remote_host(r->connection, r->per_dir_config,
4148 --- apache_1.3.41/src/modules/standard/mod_rewrite.c 2009-02-16 19:29:13.437671008 +0200
4149 +++ apache_1.3.41-ipv6/src/modules/standard/mod_rewrite.c 2009-02-16 19:29:36.646836083 +0200
4153 #include "mod_rewrite.h"
4154 +#include "sa_len.h"
4158 @@ -3667,8 +3668,19 @@
4159 result = r->connection->remote_ip;
4161 else if (strcasecmp(var, "REMOTE_PORT") == 0) {
4162 - return ap_psprintf(r->pool, "%d",
4163 - ntohs(r->connection->remote_addr.sin_port));
4164 + char servbuf[NI_MAXSERV];
4165 + servbuf[0] = '\0';
4166 + if (!getnameinfo((struct sockaddr *)&r->connection->remote_addr,
4167 +#ifndef HAVE_SOCKADDR_LEN
4168 + SA_LEN((struct sockaddr *)&r->connection->remote_addr),
4170 + r->connection->remote_addr.ss_len,
4172 + NULL, 0, servbuf, sizeof(servbuf), NI_NUMERICSERV)) {
4173 + return ap_pstrdup(r->pool, servbuf);
4175 + return ap_pstrdup(r->pool, "");
4178 else if (strcasecmp(var, "REMOTE_HOST") == 0) {
4179 result = (char *)ap_get_remote_host(r->connection,
4180 --- apache_1.3.41/src/modules/standard/mod_unique_id.c 2006-07-12 11:16:05.000000000 +0300
4181 +++ apache_1.3.41-ipv6/src/modules/standard/mod_unique_id.c 2009-02-16 19:29:36.640187389 +0200
4183 #include "http_config.h"
4184 #include "http_log.h"
4185 #include "multithread.h"
4186 +#include "sa_len.h"
4188 +/*#define SHORT_UNIQUE_ID*/
4192 - unsigned int in_addr;
4194 + struct in_addr in;
4196 +# ifdef SHORT_UNIQUE_ID
4199 + struct in6_addr in6;
4207 * this shouldn't be a problem till year 2106.
4210 -static unsigned global_in_addr;
4211 +static struct sockaddr_storage global_addr;
4216 #define MAXHOSTNAMELEN 256
4218 char str[MAXHOSTNAMELEN + 1];
4219 - struct hostent *hent;
4220 + struct addrinfo hints, *res, *res0;
4222 #ifndef NO_GETTIMEOFDAY
4227 unique_id_rec_offset[0] = XtOffsetOf(unique_id_rec, stamp);
4228 unique_id_rec_size[0] = sizeof(cur_unique_id->stamp);
4229 - unique_id_rec_offset[1] = XtOffsetOf(unique_id_rec, in_addr);
4230 - unique_id_rec_size[1] = sizeof(cur_unique_id->in_addr);
4231 + unique_id_rec_offset[1] = XtOffsetOf(unique_id_rec, addr);
4232 + unique_id_rec_size[1] = sizeof(cur_unique_id->addr);
4233 unique_id_rec_offset[2] = XtOffsetOf(unique_id_rec, pid);
4234 unique_id_rec_size[2] = sizeof(cur_unique_id->pid);
4236 @@ -227,17 +240,44 @@
4238 str[sizeof(str) - 1] = '\0';
4240 - if ((hent = gethostbyname(str)) == NULL) {
4241 + memset(&hints, 0, sizeof(hints));
4242 + hints.ai_family = PF_UNSPEC;
4243 + error = getaddrinfo(str, NULL, &hints, &res0);
4245 ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, s,
4246 - "mod_unique_id: unable to gethostbyname(\"%s\")", str);
4247 + "mod_unique_id: getaddrinfo failed for \"%s\" (%s)", str,
4248 + gai_strerror(error));
4252 - global_in_addr = ((struct in_addr *) hent->h_addr_list[0])->s_addr;
4254 + for (res = res0; res; res = res->ai_next) {
4255 + switch (res->ai_family) {
4260 + memcpy(&global_addr, res->ai_addr, res->ai_addrlen);
4265 + freeaddrinfo(res0);
4267 + ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, s,
4268 + "mod_unique_id: no known AF found for \"%s\"", str);
4272 + getnameinfo((struct sockaddr *)&global_addr,
4274 + SA_LEN((struct sockaddr *)&global_addr),
4276 + global_addr.ss_len,
4278 + str, sizeof(str), NULL, 0, NI_NUMERICHOST);
4279 ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, s,
4280 - "mod_unique_id: using ip addr %s",
4281 - inet_ntoa(*(struct in_addr *) hent->h_addr_list[0]));
4282 + "mod_unique_id: using ip addr %s", str);
4285 * If the server is pummelled with restart requests we could possibly end
4286 @@ -294,7 +334,23 @@
4287 "oh no! pids are greater than 32-bits! I'm broken!");
4290 - cur_unique_id->in_addr = global_in_addr;
4291 + memset(&cur_unique_id->addr, 0, sizeof(cur_unique_id->addr));
4292 + switch (global_addr.ss_family) {
4294 + cur_unique_id->addr.in = ((struct sockaddr_in *)&global_addr)->sin_addr;
4298 +#ifdef SHORT_UNIQUE_ID
4299 + cur_unique_id->addr.in6 =
4300 + ((struct sockaddr_in6 *)&global_addr)->sin6_addr.s6_addr32[3];
4302 + cur_unique_id->addr.in6 =
4303 + ((struct sockaddr_in6 *)&global_addr)->sin6_addr;
4310 * If we use 0 as the initial counter we have a little less protection
4311 --- apache_1.3.41/src/modules/standard/mod_usertrack.c 2006-07-12 11:16:05.000000000 +0300
4312 +++ apache_1.3.41-ipv6/src/modules/standard/mod_usertrack.c 2009-02-16 19:29:36.643502311 +0200
4314 long reqtime = (long) r->request_time;
4317 - unsigned long ipaddr = ntohl(r->connection->remote_addr.sin_addr.s_addr);
4318 + unsigned long ipaddr = ntohl(((struct sockaddr_in*)&r->connection->remote_addr)->sin_addr.s_addr);
4319 const char *rname = ap_get_remote_host(r->connection, r->per_dir_config,
4321 dcfg = ap_get_module_config(r->per_dir_config, &usertrack_module);
4322 --- apache_1.3.41/src/support/ab.c 2006-07-12 11:16:05.000000000 +0300
4323 +++ apache_1.3.41-ipv6/src/support/ab.c 2009-02-16 19:29:36.643502311 +0200
4325 #include <sys/uio.h>
4328 +#include "sa_len.h"
4330 #endif /* NO_APACHE_INCLUDES */
4334 char servername[1024]; /* name that server reports */
4335 char hostname[1024]; /* host name */
4336 char proxyhost[1024]; /* proxy host name */
4337 -int proxyport = 0; /* proxy port */
4338 +char *proxyport = NULL; /* proxy port */
4340 char path[1024]; /* path name */
4341 char postfile[1024]; /* name of file containing post data */
4343 auth[1024], /* optional (basic/uuencoded)
4344 * authentification */
4345 hdrs[4096]; /* optional arbitrary headers */
4346 -int port = 80; /* port number */
4347 +char *port = "80"; /* port number */
4349 int use_html = 0; /* use html in the report */
4352 struct data *stats; /* date for each request */
4354 fd_set readbits, writebits; /* bits for select */
4355 -struct sockaddr_in server; /* server addr structure */
4356 +struct sockaddr_storage server; /* server addr structure */
4359 #define ab_close(s) close(s)
4362 printf("Server Software: %s\n", servername);
4363 printf("Server Hostname: %s\n", hostname);
4364 - printf("Server Port: %d\n", port);
4365 + printf("Server Port: %s\n", port);
4367 printf("Document Path: %s\n", path);
4368 printf("Document Length: %d bytes\n", doclen);
4373 - c->fd = socket(AF_INET, SOCK_STREAM, 0);
4374 + c->fd = socket(server.ss_family, SOCK_STREAM, 0);
4378 @@ -853,7 +855,12 @@
4381 gettimeofday(&c->start, 0);
4382 - if (connect(c->fd, (struct sockaddr *) & server, sizeof(server)) < 0) {
4384 + if (connect(c->fd, (struct sockaddr *) & server, SA_LEN((struct sockaddr*)&server)) < 0)
4386 + if (connect(c->fd, (struct sockaddr *) & server, server.ss_len) < 0)
4389 if (errno != EINPROGRESS) {
4392 @@ -1147,7 +1154,7 @@
4393 struct timeval timeout, now;
4394 fd_set sel_read, sel_except, sel_write;
4397 + char * connectport;
4399 char * url_on_request;
4401 @@ -1190,17 +1197,21 @@
4404 /* get server information */
4405 - struct hostent *he;
4406 - he = gethostbyname(connecthost);
4408 - char theerror[1024];
4409 - ap_snprintf(theerror, sizeof(theerror),
4410 - "Bad hostname: %s\n", connecthost);
4413 - server.sin_family = he->h_addrtype;
4414 - server.sin_port = htons(connectport);
4415 - server.sin_addr.s_addr = ((unsigned long *) (he->h_addr_list[0]))[0];
4416 + struct addrinfo hints, *res;
4419 + memset(&hints, 0, sizeof(hints));
4420 + hints.ai_family = PF_UNSPEC;
4421 + hints.ai_socktype = SOCK_STREAM;
4422 + error = getaddrinfo(connecthost, connectport, &hints, &res);
4424 + char *theerror=malloc(strlen(connecthost)+16);
4425 + sprintf(theerror, "Bad hostname: %s\n", connecthost);
4429 + memcpy(&server, res->ai_addr, res->ai_addrlen);
4430 + freeaddrinfo(res);
4433 con = malloc(concurrency * sizeof(struct connection));
4434 @@ -1388,7 +1399,7 @@
4435 if (strlen(purl) > 8 && strncmp(purl, "https://", 8) == 0) {
4442 if (strlen(purl) > 8 && strncmp(purl, "https://", 8) == 0) {
4443 @@ -1409,15 +1420,15 @@
4445 strcpy(hostname, h);
4452 - (ssl != 0) && (port != 443)) || ((ssl == 0) &&
4453 + (ssl != 0) && (strcmp(port, "443"))) || ((ssl == 0) &&
4456 + (strcmp(port, "80"))))
4458 - ap_snprintf(colonport,sizeof(colonport),":%d",port);
4459 + ap_snprintf(colonport,sizeof(colonport),":%s",port);
4461 colonport[0] = '\0';
4463 @@ -1589,7 +1600,7 @@
4464 if ((p = strchr(optarg, ':'))) {
4467 - proxyport = atoi(p);
4468 + proxyport = strdup(p);
4470 strcpy(proxyhost, optarg);
4472 @@ -1672,3 +1683,7 @@
4477 +#ifdef NEED_GETADDRINFO
4478 +#include "../main/getaddrinfo.c"
4480 --- apache_1.3.41/src/support/logresolve.c 2006-07-12 11:16:05.000000000 +0300
4481 +++ apache_1.3.41-ipv6/src/support/logresolve.c 2009-02-16 19:29:36.643502311 +0200
4484 #endif /* !MPE && !WIN32*/
4486 -static void cgethost(struct in_addr ipnum, char *string, int check);
4487 +#include "sa_len.h"
4489 +static void cgethost(struct sockaddr *sa, char *string, int check);
4490 static int getline(char *s, int n);
4491 static void stats(FILE *output);
4497 - struct in_addr ipnum;
4498 + struct sockaddr_storage addr;
4502 @@ -138,17 +140,48 @@
4503 * IP numbers with their IP number as hostname, setting noname flag
4506 -static void cgethost (struct in_addr ipnum, char *string, int check)
4507 +static void cgethost (struct sockaddr *sa, char *string, int check)
4509 + ap_uint32_t hashval;
4510 + struct sockaddr_in *sin;
4512 + struct sockaddr_in6 *sin6;
4514 struct nsrec **current, *new;
4515 - struct hostent *hostdata;
4517 + char hostnamebuf[MAXHOSTNAMELEN];
4519 + switch (sa->sa_family) {
4521 + hashval = ((struct sockaddr_in *)sa)->sin_addr.s_addr;
4525 + hashval = *(ap_uint32_t *)&((struct sockaddr_in6 *)sa)->sin6_addr.s6_addr[12];
4533 + current = &nscache[((hashval + (hashval >> 8) +
4534 + (hashval >> 16) + (hashval >> 24)) % BUCKETS)];
4536 - current = &nscache[((ipnum.s_addr + (ipnum.s_addr >> 8) +
4537 - (ipnum.s_addr >> 16) + (ipnum.s_addr >> 24)) % BUCKETS)];
4538 + while (*current) {
4540 + if (SA_LEN(sa) == SA_LEN((struct sockaddr *)&(*current)->addr)
4541 + && memcmp(sa, &(*current)->addr, SA_LEN(sa)) == 0)
4543 + if (sa->sa_len == (*current)->addr.ss_len
4544 + && memcmp(sa, &(*current)->addr, sa->sa_len) == 0)
4550 - while (*current != NULL && ipnum.s_addr != (*current)->ipnum.s_addr)
4551 current = &(*current)->next;
4554 if (*current == NULL) {
4556 @@ -161,45 +194,55 @@
4560 - new->ipnum = ipnum;
4562 + memcpy(&new->addr, sa, SA_LEN(sa));
4564 + memcpy(&new->addr, sa, sa->sa_len);
4567 - hostdata = gethostbyaddr((const char *) &ipnum, sizeof(struct in_addr),
4569 - if (hostdata == NULL) {
4570 - if (h_errno > MAX_ERR)
4571 - errors[UNKNOWN_ERR]++;
4573 - errors[h_errno]++;
4574 - new->noname = h_errno;
4575 - name = strdup(inet_ntoa(ipnum));
4579 - name = strdup(hostdata->h_name);
4581 - if (name == NULL) {
4583 - fprintf(stderr, "Insufficient memory\n");
4586 - hostdata = gethostbyname(name);
4587 - if (hostdata != NULL) {
4590 - for (hptr = hostdata->h_addr_list; *hptr != NULL; hptr++)
4591 - if (((struct in_addr *) (*hptr))->s_addr == ipnum.s_addr)
4593 - if (*hptr == NULL)
4596 - if (hostdata == NULL) {
4597 - fprintf(stderr, "Bad host: %s != %s\n", name,
4598 - inet_ntoa(ipnum));
4599 - new->noname = NO_REVERSE;
4601 - name = strdup(inet_ntoa(ipnum));
4602 - errors[NO_REVERSE]++;
4603 + new->noname = getnameinfo(sa,
4609 + hostnamebuf, sizeof(hostnamebuf), NULL, 0, 0);
4610 + name = strdup(hostnamebuf);
4612 + struct addrinfo hints, *res;
4614 + memset(&hints, 0, sizeof(hints));
4615 + hints.ai_family = PF_UNSPEC;
4616 + error = getaddrinfo(hostnamebuf, NULL, &hints, &res);
4620 + if (SA_LEN(sa) == res->ai_addrlen
4621 + && memcmp(sa, res->ai_addr, SA_LEN(sa)) == 0)
4623 + if (sa->sa_len == res->ai_addrlen
4624 + && memcmp(sa, res->ai_addr, sa->sa_len) == 0)
4629 + res = res->ai_next;
4641 + hostnamebuf, sizeof(hostnamebuf), NULL, 0, NI_NUMERICHOST);
4642 + fprintf(stderr, "Bad host: %s != %s\n", name, hostnamebuf);
4643 + new->noname = NO_REVERSE;
4645 + name = strdup(hostnamebuf);
4648 new->hostname = name;
4651 struct nsrec *current;
4652 char *errstring[MAX_ERR + 3];
4653 + char hostnamebuf[MAXHOSTNAMELEN];
4655 for (i = 0; i < MAX_ERR + 3; i++)
4656 errstring[i] = "Unknown error";
4657 @@ -258,7 +302,14 @@
4659 for (i = 0; i < BUCKETS; i++)
4660 for (current = nscache[i]; current != NULL; current = current->next) {
4661 - ipstring = inet_ntoa(current->ipnum);
4662 + getnameinfo((struct sockaddr *)¤t->addr,
4664 + SA_LEN((struct sockaddr *)¤t->addr),
4666 + current->addr.ss_len,
4668 + hostnamebuf, sizeof(hostnamebuf), NULL, 0, NI_NUMERICHOST);
4669 + ipstring = hostnamebuf;
4670 if (current->noname == 0)
4671 fprintf(output, " %3d %15s - %s\n", i, ipstring,
4673 @@ -292,9 +343,10 @@
4675 int main (int argc, char *argv[])
4677 - struct in_addr ipnum;
4678 char *bar, hoststring[MAXDNAME + 1], line[MAXLINE], *statfile;
4680 + struct addrinfo hints, *res;
4685 @@ -338,8 +390,10 @@
4686 bar = strchr(line, ' ');
4689 - ipnum.s_addr = inet_addr(line);
4690 - if (ipnum.s_addr == 0xffffffffu) {
4691 + memset(&hints, 0, sizeof(hints));
4692 + hints.ai_family = PF_UNSPEC;
4693 + error = getaddrinfo(line, NULL, &hints, &res);
4698 @@ -349,11 +403,12 @@
4702 - cgethost(ipnum, hoststring, check);
4703 + cgethost(res->ai_addr, hoststring, check);
4705 printf("%s %s\n", hoststring, bar + 1);
4708 + freeaddrinfo(res);
4712 @@ -374,3 +429,11 @@
4717 +#ifdef NEED_GETADDRINFO
4718 +#include "../main/getaddrinfo.c"
4721 +#ifdef NEED_GETNAMEINFO
4722 +#include "../main/getnameinfo.c"