]> git.pld-linux.org Git - packages/apache.git/blob - apache-ipv6-PLD.patch
- updated eapi,addon,ipv6 patches
[packages/apache.git] / apache-ipv6-PLD.patch
1 diff -Nur apache_1.3.28.orig/README.v6 apache_1.3.28/README.v6
2 --- apache_1.3.28.orig/README.v6        Thu Jan  1 01:00:00 1970
3 +++ apache_1.3.28/README.v6     Fri Jul 25 11:01:55 2003
4 @@ -0,0 +1,166 @@
5 +IPv6-ready apache 1.3.x
6 +KAME Project
7 +$Id$
8 +
9 +This patchkit enables apache 1.3.x to perform HTTP connection over IPv6.
10 +Most of optional modules are left unchanged, i.e. it won't support IPv6,
11 +and it may not compile.
12 +
13 +Basically you can write IPv6 address where IPv4 address fits.
14 +
15 +extra command-line argument:
16 +       -4      Assume IPv4 address on ambiguous directives
17 +       -6      Assume IPv6 address on ambiguous directives (default)
18 +
19 +       The above two can be used, for example, to disambiguate
20 +       "BindAddress *".
21 +
22 +base commands:
23 +    Listen
24 +       Listen is expanded to take one or two arguments.
25 +               Listen port
26 +               Listen address:port
27 +               Listen address port
28 +       This is to let you specify "Listen :: 80", since "Listen :::80"
29 +       won't work.
30 +
31 +mod_access:
32 +    deny from
33 +    allow from
34 +       "deny from" and "allow from" supports IPv6 addresses, under the
35 +       following forms:
36 +               {deny,allow} from v6addr
37 +               {deny,allow} from v6addr/v6mask
38 +               {deny,allow} from v6addr/prefixlen
39 +       Also, wildcard ("*") and string hostname matches IPv6 hosts as well.
40 +
41 +mod_proxy:
42 +    ProxyRequests on
43 +       http/ftp proxying for both IPv4 and IPv6 is possible.
44 +       Access control functions (NoProxy) are not updated yet.
45 +
46 +       NOTE: for security reasons, we recommend you to filter out
47 +       outsider's access to your proxy, by directives like below:
48 +               <Directory proxy:*>
49 +               order deny,allow
50 +               deny from all
51 +               allow from 10.0.0.0/8
52 +               allow from 3ffe:9999:8888:7777::/64
53 +               </Directory>
54 +
55 +virtual host:
56 +       If you would like to this feature, you must describe 'Listen'
57 +       part on configuration file explicitly. like below:
58 +               Listen :: 80
59 +               Listen 0.0.0.0 80
60 +
61 +    NameVirtualHost
62 +       NameVirtualHost is expanded to take one more two arguments.
63 +               NameVirtualHost address
64 +               NameVirtualHost address:port
65 +               NameVirtualHost address port
66 +       This is to let you specify IPv6 address into address part.
67 +
68 +       Note that, if colon is found in the specified address string,
69 +       the code will to resolve the address in the following way:
70 +       1. try to resolve as address:port (most of IPv6 address fails)
71 +       2. if (1) is failed, try to resolve as address only
72 +       If there's ambiguity, i.e. 3ffe:0501::1:2, the address may not be
73 +       parsed as you expect (3ffe:0501::1 with port 2, or 3ffe:0501::1:2
74 +       with default port).  To get the right effect you are encouraged
75 +       to specify it without ambiguity.  In IPv6 case "address port"
76 +       (specify address and port separated by a space) is the safest way.
77 +
78 +    <VirtualHost host:port [host:port ...]>
79 +       If you would like to specify IPv6 numeric address in host part,
80 +       use bracketed format like below:
81 +               <VirtualHost [::1]:80>
82 +       Note: Now we DO NOT handle old non-bracketed format, 
83 +               <VirtualHost 0:0:0:0:0:0:0:1:80>
84 +             so configuration file must be updated.
85 +       Note: The following is bad example to specify host ::1 port 80.
86 +             This will treated as host ::1:80.
87 +               <VirtualHost ::1:80>
88 +
89 +logresolve (src/support)
90 +       error statistics in nameserver cache code is omitted.
91 +
92 +mod_unique_id
93 +       Originally mod_unique_id used IPv4 address as a seed for UNIQUE_ID,
94 +       and took IPv4 address registered onto DNS for the hostname (UNIX
95 +       hostname taken by gethostname(3)).  Therefore, this does not work
96 +       for IPv6-only hosts as they do not have IPv4 address for them.
97 +
98 +       Now, UNIQUE_ID can be generated using IPv6 address.  IPv6 address can
99 +       be used as the seed for UNIQUE_ID.
100 +       Because of this, UNIQUE_ID will be longer than normal apache.  This
101 +       may cause problem with some of the CGI scripts.
102 +       The preference of the addresses is based on the order returned
103 +       by getaddrinfo().  If your getaddrinfo() returns IPv4 address, IPv4
104 +       adderss will be used as a seed.
105 +       Note that some of IPv6 addresses are "scoped"; If you happened to use
106 +       link-local or site-local address as a seed, the UNIQUE_ID may not be
107 +       worldwide unique.
108 +
109 +       If longer UNIQUE_ID causes a problem, define SHORT_UNIQUE_ID in
110 +       mod_unique_id.c.  In this case, length of UNIQUE_ID will be kept the
111 +       same.  However, for IPv6 addresses mod_unique_id.c will use the last
112 +       32bit (not the whole 128bit) as the seed.  Therefore, there can be
113 +       collision in UNIQUE_ID.
114 +
115 +       The behavior should be improved in the near future; we welcome your
116 +       inputs.
117 +
118 +Modules known to be incompatible with IPv6
119 +       (please report us)
120 +
121 +configure
122 +       Configure has extra option, --enable-rule=INET6.  if the option
123 +       is specified, IPv6 code will be enabled.
124 +
125 +configuration file
126 +       We do not support IPv4 mapped address (IPv6 address format like
127 +       ::ffff:10.1.1.1) in configuration file. 
128 +
129 +This kit assumes that you have working(*) getaddrinfo() and getnameinfo()
130 +library functions.  Even if you don't have one, don't panic.  We have
131 +included last-resort version (which support IPv4 only) into the kit.
132 +For more complete implementation you might want to check BIND 8.2.
133 +(*) NOTE: we have noticed that some of IPv6 stack is shipped with broken
134 +getaddrinfo().  In such cases, you should get and install BIND 8.2.
135 +
136 +When compiling this kit onto IPv6, you may need to specify some additional
137 +library paths or cpp defs (like -linet6 or -DINET6).
138 +Now you don't have to specify --enable-rule=INET6.  The "configure" script
139 +will give you some warnings if the IPv6 stack is not known to the 
140 +"configure" script.  Currently, the following IPv6 stacks are supported:
141 +- KAME IPv6 stack, http://www.kame.net/
142 +       use configure.v6 for convenience,
143 +- Linux IPv6 stack, http://www.linux.org/
144 +       use configure.v6 for convenience.
145 +- Solaris 8 IPv6 stack, http://www.sun.com/
146 +       use configure.v6 for convenience.
147 +To disable IPv6 support, specify --disable-rule=INET6 to the "configure"
148 +script.
149 +
150 +CAVEAT: This patchkit may change some of apache module API, to avoid
151 +IPv4-dependent structure member variable.  Please let us know if there's
152 +any troubles as we know very little about the apache module API.
153 +
154 +Acknowledgements
155 +       Thanks to all people submitted patches/fixes for this patch kit,
156 +       including:
157 +               "Chris P. Ross" <cross@eng.us.uu.net>
158 +
159 +Author contacts
160 +       Jun-ichiro itojun Hagino, KAME project
161 +        http://www.kame.net/
162 +        mailto:core@kame.net
163 +Linux Port
164 +       Arkadiusz Miskiewicz, Polish Linux Distribution project (IPv6)
165 +        http://www.pld.org.pl/
166 +        mailto:feedback@pld.org.pl
167 +       Satoshi SHIDA, Linux IPv6 Users Group JP
168 +        http://www.v6.linux.or.jp/
169 +       YOSHIFUJI Hideaki, USAGI Project
170 +        http://www.linux-ipv6.org/
171 diff -Nur apache_1.3.28.orig/conf/httpd.conf-dist apache_1.3.28/conf/httpd.conf-dist
172 --- apache_1.3.28.orig/conf/httpd.conf-dist     Wed Jul 16 21:36:41 2003
173 +++ apache_1.3.28/conf/httpd.conf-dist  Fri Jul 25 11:01:55 2003
174 @@ -174,6 +174,11 @@
175  #Listen 3000
176  #Listen 12.34.56.78:80
177  
178 +# Listen can take two arguments.
179 +# (this is an extension for supporting IPv6 addresses)
180 +#Listen :: 80
181 +#Listen 0.0.0.0 80
182 +
183  #
184  # BindAddress: You can support virtual hosts with this option. This directive
185  # is used to tell the server which IP address to listen to. It can either
186 diff -Nur apache_1.3.28.orig/configure.v6 apache_1.3.28/configure.v6
187 --- apache_1.3.28.orig/configure.v6     Thu Jan  1 01:00:00 1970
188 +++ apache_1.3.28/configure.v6  Fri Jul 25 11:01:55 2003
189 @@ -0,0 +1,3 @@
190 +#! /bin/sh
191 +
192 +./configure --enable-rule=INET6 --enable-module=proxy $*
193 diff -Nur apache_1.3.28.orig/src/Configuration.tmpl apache_1.3.28/src/Configuration.tmpl
194 --- apache_1.3.28.orig/src/Configuration.tmpl   Fri Jul 25 11:00:49 2003
195 +++ apache_1.3.28/src/Configuration.tmpl        Fri Jul 25 11:01:55 2003
196 @@ -191,6 +191,9 @@
197  #  Rule EXPAT=default   : If Expat can be found at the system or
198  #                         in lib/expat-lite, use it; otherwise
199  #                         skip it
200 +# INET6:
201 +#  IPv6 support.
202 +#
203  # 
204  # CYGWIN_WINSOCK: 
205  #  Use Win32 API system calls for socket communication instead 
206 @@ -205,6 +208,7 @@
207  Rule IRIXN32=yes
208  Rule PARANOID=no
209  Rule EXPAT=default
210 +Rule INET6=no
211  Rule CYGWIN_WINSOCK=no 
212  
213  # DEV_RANDOM:
214 diff -Nur apache_1.3.28.orig/src/Configure apache_1.3.28/src/Configure
215 --- apache_1.3.28.orig/src/Configure    Fri Jul 25 11:00:49 2003
216 +++ apache_1.3.28/src/Configure Fri Jul 25 11:01:55 2003
217 @@ -238,6 +238,7 @@
218  RULE_CYGWIN_WINSOCK=`./helpers/CutRule CYGWIN_WINSOCK $file` 
219  RULE_SHARED_CORE=`./helpers/CutRule SHARED_CORE $file`
220  RULE_SHARED_CHAIN=`./helpers/CutRule SHARED_CHAIN $file`
221 +RULE_INET6=`./helpers/CutRule INET6 $file`
222  
223  ####################################################################
224  ## Rule SHARED_CORE implies required DSO support
225 @@ -1724,6 +1725,124 @@
226      esac
227  fi
228  
229 +# INET6 support.
230 +if [ "$RULE_INET6" = "yes" ]; then
231 +    echo " + enabling INET6 support"
232 +    CFLAGS="$CFLAGS -DINET6"
233 +    CFLAGS="$CFLAGS -Dss_family=__ss_family -Dss_len=__ss_len"
234 +    IPV6_STACKTYPE="UNKNOWN"
235 +    for i in KAME Linux Solaris; do
236 +       case "$i" in
237 +       KAME)
238 +           if [ -f /usr/include/netinet6/in6.h -a "x`egrep '__KAME__' /usr/include/netinet6/in6.h 2>/dev/null`" != "x" ]; then
239 +               IPV6_STACKTYPE=$i
240 +           fi
241 +           ;;
242 +       Linux)
243 +           if [ /usr/include/netinet/ip6.h -a -d /usr/include/linux ]; then
244 +               IPV6_STACKTYPE=$i
245 +           fi
246 +           ;;
247 +       Solaris)
248 +           SOL_VERSION=`(uname -v) 2>/dev/null` || SOL_VERSION="unknown"
249 +           case "${PLAT}-${SOL_VERSION}" in
250 +               *-solaris2.27*-*IPv6*)
251 +                   if [ -f /etc/hostname -o -f /etc/hostname.[a-z]*[0-9] ]; then
252 +                       IPV6_STACKTYPE="Solaris 7 (${SOL_VERSION})"
253 +                   fi
254 +                   ;;
255 +           esac
256 +           ;;
257 +       esac
258 +       if [ "$IPV6_STACKTYPE" != "UNKNOWN" ]; then
259 +           break
260 +       fi
261 +    done
262 +    if [ "$IPV6_STACKTYPE" != "UNKNOWN" ]; then
263 +       echo " + You seem to be using $IPV6_STACKTYPE stack"
264 +       if ./helpers/TestCompile func getaddrinfo; then
265 +           echo "   - Assuming you have working getaddrinfo in libc" 
266 +       else
267 +           if [ -f /usr/local/v6/lib/libinet6.a -a "x`egrep '^EXTRA_L' Makefile.config | grep linet6`" = "x" ]; then
268 +               LIBS="$LIBS -L/usr/local/v6/lib -linet6"
269 +               echo "   - using getaddrinfo in libinet6" 
270 +           elif [ -f /usr/local/lib/libinet6.a -a "x`egrep '^EXTRA_L' Makefile.config | grep linet6`" = "x" ]; then
271 +               LIBS="$LIBS -L/usr/local/lib -linet6"
272 +               echo "   - using getaddrinfo in libinet6"
273 +           elif [ -f /usr/inet6/lib/libinet6.a -a "x`egrep '^EXTRA_L' Makefile.config | grep linet6`" = "x" ]; then
274 +               echo "   - using getaddrinfo in libinet6"
275 +           else
276 +               echo "** WARNING: No getaddrinfo found, linkage may fail" 
277 +           fi
278 +       fi
279 +    else
280 +       echo ""
281 +       echo "** WARNING: We have no explicit knowledge about the IPv6"
282 +       echo "** implementation on this host.  You may need to specify"
283 +       echo "** EXTRA_LIBS so that we can find getaddrinfo() and"
284 +       echo "** getnameinfo() library functions."
285 +       echo ""
286 +    fi
287 +    case $PLAT in
288 +       *-solaris2* )
289 +           LIBS="$LIBS -lresolv"
290 +           ;;
291 +    esac
292 +else
293 +    CFLAGS="$CFLAGS -DNEED_GETADDRINFO -DNEED_GETNAMEINFO"
294 +    if [ -f /usr/include/netdb.h -a "x`egrep 'addrinfo' /usr/include/netdb.h`" = "x" ]; then
295 +       CFLAGS="$CFLAGS -DNEED_ADDRINFO"
296 +    fi
297 +fi
298 +
299 +echo '#include <sys/types.h>' >testfunc.c
300 +echo '#include <sys/socket.h>' >>testfunc.c
301 +echo 'int testfunc(){ struct sockaddr sa; int i = sa.sa_len; };' >>testfunc.c
302 +rm -f testfunc.o
303 +eval "${MAKE-make} -f Makefile.config testfunc.o >/dev/null 2>/dev/null"
304 +if [ -f testfunc.o ]; then
305 +    echo " + you have sa_len in struct sockaddr."
306 +    CFLAGS="$CFLAGS -DHAVE_SOCKADDR_LEN"
307 +else
308 +    echo " + you don't have sa_len in struct sockaddr."
309 +fi
310 +rm -f testfunc.c testfunc.o
311 +
312 +echo '#include <sys/types.h>' >testfunc.c
313 +echo '#include <sys/socket.h>' >>testfunc.c
314 +echo 'struct sockaddr_storage sockaddr_storage;' >>testfunc.c
315 +rm -f testfunc.o
316 +eval "${MAKE-make} -f Makefile.config testfunc.o >/dev/null 2>/dev/null"
317 +if [ -f testfunc.o ]; then
318 +    echo " + assuming you have struct sockaddr_storage"
319 +else
320 +    CFLAGS="$CFLAGS -DNEED_SOCKADDR_STORAGE"
321 +    echo " + you need struct sockaddr_storage"
322 +fi
323 +rm -f testfunc.c testfunc.o
324 +
325 +echo '#include <sys/types.h>' >testfunc.c
326 +echo '#include <sys/socket.h>' >>testfunc.c
327 +echo 'int testfunc(){ socklen_t t; }' >>testfunc.c
328 +rm -f testfunc.o
329 +eval "${MAKE-make} -f Makefile.config testfunc.o >/dev/null 2>/dev/null"
330 +if [ ! -f testfunc.o ]; then
331 +    CFLAGS="$CFLAGS -Dsocklen_t=int"
332 +fi
333 +rm -f testfunc.c testfunc.o
334 +
335 +echo '#include <sys/types.h>' >testfunc.c
336 +echo '#include <sys/socket.h>' >>testfunc.c
337 +echo 'struct sockaddr_in sin;' >>testfunc.c
338 +echo 'int main(){ int i = sin.sin_len; }' >>testfunc.c
339 +rm -f testfunc.o
340 +eval "${MAKE-make} -f Makefile.config testfunc.o >/dev/null 2>/dev/null"
341 +if [ -f testfunc.o ]; then
342 +    CFLAGS="$CFLAGS -DSIN_LEN"
343 +fi
344 +rm -f testfunc.c testfunc.o
345 +
346 +
347  ####################################################################
348  ## Find out what modules we want and try and configure things for them
349  ## Module lines can look like this:
350 @@ -2320,6 +2439,38 @@
351  echo "#define AP_LONGEST_LONG $AP_LONGEST_LONG" >>$AP_CONFIG_AUTO_H
352  echo "#endif" >>$AP_CONFIG_AUTO_H
353  
354 +if [ x`./helpers/TestCompile -r sizeof 'uint32_t'` != x"" ]; then
355 +    echo "" >>$AP_CONFIG_AUTO_H
356 +    echo "/* determine: use uint32_t as 32bit unsigned int */" >>$AP_CONFIG_AUTO_H
357 +    echo "#ifndef ap_uint32_t" >>$AP_CONFIG_AUTO_H
358 +    echo "#define ap_uint32_t uint32_t" >>$AP_CONFIG_AUTO_H
359 +    echo "#endif" >>$AP_CONFIG_AUTO_H
360 +    echo "   - use uint32_t as 32bit unsigned int"
361 +elif [ x`./helpers/TestCompile -r sizeof 'u_int32_t'` != x"" ]; then
362 +    echo "" >>$AP_CONFIG_AUTO_H
363 +    echo "/* determine: use u_int32_t as 32bit unsigned int */" >>$AP_CONFIG_AUTO_H
364 +    echo "#ifndef ap_uint32_t" >>$AP_CONFIG_AUTO_H
365 +    echo "#define ap_uint32_t u_int32_t" >>$AP_CONFIG_AUTO_H
366 +    echo "#endif" >>$AP_CONFIG_AUTO_H
367 +    echo "   - use u_int32_t as 32bit unsigned int"
368 +elif [ x`./helpers/TestCompile -r sizeof 'unsigned int'` = x"4" ]; then
369 +    echo "" >>$AP_CONFIG_AUTO_H
370 +    echo "/* determine: use unsigned int as 32bit unsigned int */" >>$AP_CONFIG_AUTO_H
371 +    echo "#ifndef ap_uint32_t" >>$AP_CONFIG_AUTO_H
372 +    echo "#define ap_uint32_t unsigned int" >>$AP_CONFIG_AUTO_H
373 +    echo "#endif" >>$AP_CONFIG_AUTO_H
374 +    echo "   - use unsigned int as 32bit unsigned int"
375 +elif [ x`./helpers/TestCompile -r sizeof 'unsigned long int'` = x"4" ]; then
376 +    echo "" >>$AP_CONFIG_AUTO_H
377 +    echo "/* determine: use unsigned long int as 32bit unsigned int */" >>$AP_CONFIG_AUTO_H
378 +    echo "#ifndef uint32_t" >>$AP_CONFIG_AUTO_H
379 +    echo "#define uint32_t unsigned long int" >>$AP_CONFIG_AUTO_H
380 +    echo "#endif" >>$AP_CONFIG_AUTO_H
381 +    echo "   - use unsigned long int as 32bit unsigned int"
382 +else
383 +    echo "  - Warning: cannot determine what type should we use as 32bit unsigned int"
384 +fi
385 +
386  ####################################################################
387  ## More building ap_config_auto.h
388  ##
389 diff -Nur apache_1.3.28.orig/src/ap/ap_snprintf.c apache_1.3.28/src/ap/ap_snprintf.c
390 --- apache_1.3.28.orig/src/ap/ap_snprintf.c     Mon Feb  3 18:13:17 2003
391 +++ apache_1.3.28/src/ap/ap_snprintf.c  Fri Jul 25 11:01:55 2003
392 @@ -73,6 +73,7 @@
393  #include <string.h>
394  #include <stdlib.h>
395  #include <math.h>
396 +#include "sa_len.h"
397  #ifdef WIN32
398  #include <float.h>
399  #endif
400 @@ -510,6 +511,42 @@
401  
402  
403  
404 +#ifdef INET6
405 +static char *conv_sockaddr(struct sockaddr *sa, char *buf_end, int *len)
406 +{
407 +    char *p = buf_end;
408 +    char hostnamebuf[MAXHOSTNAMELEN];
409 +    char portnamebuf[MAXHOSTNAMELEN];
410 +    char *q;
411 +    int salen;
412 +
413 +#ifndef SIN6_LEN
414 +    salen = SA_LEN(sa);
415 +#else
416 +    salen = sa->sa_len;
417 +#endif
418 +    if (getnameinfo(sa, salen, hostnamebuf, sizeof(hostnamebuf),
419 +           portnamebuf, sizeof(portnamebuf), NI_NUMERICHOST | NI_NUMERICSERV)) {
420 +       strcpy(hostnamebuf, "???");
421 +       strcpy(portnamebuf, "???");
422 +    }
423 +    if (strcmp(portnamebuf,"0") == 0)
424 +       strcpy(portnamebuf, "*");
425 +    q = portnamebuf + strlen(portnamebuf);
426 +    while (portnamebuf < q)
427 +       *--p = *--q;
428 +    *--p = ':';
429 +    q = hostnamebuf + strlen(hostnamebuf);
430 +    while (hostnamebuf < q)
431 +       *--p = *--q;
432 +
433 +    *len = buf_end - p;
434 +    return (p);
435 +}
436 +#endif /*INET6*/
437 +
438 +
439 +
440  /*
441   * Convert a floating point number to a string formats 'f', 'e' or 'E'.
442   * The result is placed in buf, and len denotes the length of the string
443 @@ -1057,6 +1094,7 @@
444                     /* print a struct sockaddr_in as a.b.c.d:port */
445                 case 'I':
446                     {
447 +#ifndef INET6
448                         struct sockaddr_in *si;
449  
450                         si = va_arg(ap, struct sockaddr_in *);
451 @@ -1065,6 +1103,16 @@
452                             if (adjust_precision && precision < s_len)
453                                 s_len = precision;
454                         }
455 +#else
456 +                       struct sockaddr *sa;
457 +
458 +                       sa = va_arg(ap, struct sockaddr *);
459 +                       if (sa != NULL) {
460 +                           s = conv_sockaddr(sa, &num_buf[NUM_BUF_SIZE], &s_len);
461 +                           if (adjust_precision && precision < s_len)
462 +                               s_len = precision;
463 +                       }
464 +#endif
465                         else {
466                             s = S_NULL;
467                             s_len = S_NULL_LEN;
468 diff -Nur apache_1.3.28.orig/src/include/ap.h apache_1.3.28/src/include/ap.h
469 --- apache_1.3.28.orig/src/include/ap.h Mon Feb  3 18:13:17 2003
470 +++ apache_1.3.28/src/include/ap.h      Fri Jul 25 11:01:55 2003
471 @@ -95,7 +95,8 @@
472   * with some extensions.  The extensions are:
473   *
474   * %pA takes a struct in_addr *, and prints it as a.b.c.d
475 - * %pI takes a struct sockaddr_in * and prints it as a.b.c.d:port
476 + * %pI takes a struct sockaddr * and prints it as a.b.c.d:port, or
477 + *     ipv6-numeric-addr:port
478   * %pp  takes a void * and outputs it in hex
479   *
480   * The %p hacks are to force gcc's printf warning code to skip
481 diff -Nur apache_1.3.28.orig/src/include/ap_config.h apache_1.3.28/src/include/ap_config.h
482 --- apache_1.3.28.orig/src/include/ap_config.h  Mon May  5 13:45:49 2003
483 +++ apache_1.3.28/src/include/ap_config.h       Fri Jul 25 11:01:55 2003
484 @@ -411,6 +411,10 @@
485  #endif
486  #ifndef S_IWOTH
487  #define S_IWOTH 000002
488 +#ifndef rlim_t
489 +typedef int rlim_t;
490 +#endif
491 +typedef u_long n_long;
492  #endif
493  
494  #define STDIN_FILENO  0
495 @@ -1523,6 +1527,70 @@
496  #define ap_wait_t int
497  #endif
498  
499 +#ifndef INET6
500 +#define sockaddr_storage       sockaddr
501 +#define ss_family              sa_family
502 +#define ss_len                 sa_len
503 +#else
504 +#include "sockaddr_storage.h"  /* sshida@st.rim.or.jp */
505 +#endif
506 +
507 +#ifndef INET6_ADDRSTRLEN
508 +#define INET6_ADDRSTRLEN       46
509 +#endif
510 +#ifndef INET_ADDRSTRLEN
511 +#define INET_ADDRSTRLEN                16
512 +#endif
513 +#ifndef NI_MAXHOST
514 +#define NI_MAXHOST             1025
515 +#endif
516 +#ifndef NI_MAXSERV
517 +#define        NI_MAXSERV              32
518 +#endif
519 +
520 +#if defined(NEED_GETADDRINFO) || defined(NEED_GETNAMEINFO)
521 +/*
522 + * minimal definitions for fake getaddrinfo()/getnameinfo().
523 + */
524 +#ifndef EAI_NODATA
525 +#define EAI_NODATA     1
526 +#define EAI_MEMORY     2
527 +#endif
528 +
529 +#ifndef AI_PASSIVE
530 +#define AI_PASSIVE     1
531 +#define AI_CANONNAME   2
532 +#define AI_NUMERICHOST 4
533 +#define NI_NUMERICHOST 8
534 +#define NI_NAMEREQD    16
535 +#define NI_NUMERICSERV 32
536 +#endif
537 +#endif
538 +
539 +#ifdef NEED_GETADDRINFO
540 +#ifdef NEED_ADDRINFO
541 +struct addrinfo {
542 +       int     ai_flags;       /* AI_PASSIVE, AI_CANONNAME */
543 +       int     ai_family;      /* PF_xxx */
544 +       int     ai_socktype;    /* SOCK_xxx */
545 +       int     ai_protocol;    /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
546 +       size_t  ai_addrlen;     /* length of ai_addr */
547 +       char    *ai_canonname;  /* canonical name for hostname */
548 +       struct sockaddr *ai_addr;       /* binary address */
549 +       struct addrinfo *ai_next;       /* next structure in linked list */
550 +};
551 +#endif
552 +extern char *gai_strerror(int ecode);
553 +extern void freeaddrinfo(struct addrinfo *ai);
554 +extern int getaddrinfo(const char *hostname, const char *servname,
555 +       const struct addrinfo *hints, struct addrinfo **res);
556 +#endif
557 +#ifdef NEED_GETNAMEINFO
558 +extern int getnameinfo(const struct sockaddr *sa, size_t salen,
559 +       char *host, size_t hostlen, char *serv, size_t servlen,
560 +       int flag);
561 +#endif
562 +
563  #ifdef __cplusplus
564  }
565  #endif
566 diff -Nur apache_1.3.28.orig/src/include/http_conf_globals.h apache_1.3.28/src/include/http_conf_globals.h
567 --- apache_1.3.28.orig/src/include/http_conf_globals.h  Fri Jul 25 11:00:49 2003
568 +++ apache_1.3.28/src/include/http_conf_globals.h       Fri Jul 25 11:01:55 2003
569 @@ -82,7 +82,8 @@
570  extern API_VAR_EXPORT int ap_max_requests_per_child;
571  extern API_VAR_EXPORT int ap_threads_per_child;
572  extern API_VAR_EXPORT int ap_excess_requests_per_child;
573 -extern API_VAR_EXPORT struct in_addr ap_bind_address;
574 +extern API_VAR_EXPORT struct sockaddr_storage ap_bind_address;
575 +extern API_VAR_EXPORT int ap_default_family;
576  extern listen_rec *ap_listeners;
577  extern API_VAR_EXPORT int ap_daemons_to_start;
578  extern API_VAR_EXPORT int ap_daemons_min_free;
579 diff -Nur apache_1.3.28.orig/src/include/http_vhost.h apache_1.3.28/src/include/http_vhost.h
580 --- apache_1.3.28.orig/src/include/http_vhost.h Mon Feb  3 18:13:19 2003
581 +++ apache_1.3.28/src/include/http_vhost.h      Fri Jul 25 11:01:55 2003
582 @@ -73,7 +73,7 @@
583  API_EXPORT(const char *) ap_parse_vhost_addrs(pool *p, const char *hostname, server_rec *s);
584  
585  /* handle NameVirtualHost directive */
586 -API_EXPORT_NONSTD(const char *) ap_set_name_virtual_host (cmd_parms *cmd, void *dummy, char *arg);
587 +API_EXPORT_NONSTD(const char *) ap_set_name_virtual_host (cmd_parms *cmd, void *dummy, char *h, char *p);
588  
589  /* given an ip address only, give our best guess as to what vhost it is */
590  API_EXPORT(void) ap_update_vhost_given_ip(conn_rec *conn);
591 diff -Nur apache_1.3.28.orig/src/include/httpd.h apache_1.3.28/src/include/httpd.h
592 --- apache_1.3.28.orig/src/include/httpd.h      Fri Jul 25 11:00:49 2003
593 +++ apache_1.3.28/src/include/httpd.h   Fri Jul 25 11:01:55 2003
594 @@ -904,8 +904,8 @@
595  
596      /* Who is the client? */
597  
598 -    struct sockaddr_in local_addr;     /* local address */
599 -    struct sockaddr_in remote_addr;    /* remote address */
600 +    struct sockaddr_storage local_addr;        /* local address */
601 +    struct sockaddr_storage remote_addr; /* remote address */
602      char *remote_ip;           /* Client's IP address */
603      char *remote_host;         /* Client's DNS name, if known.
604                                  * NULL if DNS hasn't been checked,
605 @@ -947,8 +947,8 @@
606  typedef struct server_addr_rec server_addr_rec;
607  struct server_addr_rec {
608      server_addr_rec *next;
609 -    struct in_addr host_addr;  /* The bound address, for this server */
610 -    unsigned short host_port;  /* The bound port, for this server */
611 +    struct sockaddr_storage host_addr; /* The bound address, for this server */
612 +    unsigned short host_port;  /* The bound port, for this server XXX */
613      char *virthost;            /* The name given in <VirtualHost> */
614  };
615  
616 @@ -1016,7 +1016,7 @@
617  /* These are more like real hosts than virtual hosts */
618  struct listen_rec {
619      listen_rec *next;
620 -    struct sockaddr_in local_addr;     /* local IP address and port */
621 +    struct sockaddr_storage local_addr;        /* local IP address and port */
622      int fd;
623      int used;                  /* Only used during restart */        
624  /* more stuff here, like which protocol is bound to the port */
625 @@ -1184,7 +1184,7 @@
626  #endif /*#ifdef CHARSET_EBCDIC*/
627  
628  API_EXPORT(char *) ap_get_local_host(pool *);
629 -API_EXPORT(unsigned long) ap_get_virthost_addr(char *hostname, unsigned short *port);
630 +API_EXPORT(struct sockaddr *) ap_get_virthost_addr(char *hostname, unsigned short *port);
631  
632  extern API_VAR_EXPORT time_t ap_restart_time;
633  
634 diff -Nur apache_1.3.28.orig/src/include/sa_len.h apache_1.3.28/src/include/sa_len.h
635 --- apache_1.3.28.orig/src/include/sa_len.h     Thu Jan  1 01:00:00 1970
636 +++ apache_1.3.28/src/include/sa_len.h  Fri Jul 25 11:01:55 2003
637 @@ -0,0 +1,41 @@
638 +/* sa_len.h : tiny version of SA_LEN (written by <yoshfuji@ecei.tohoku.ac.jp>) */
639
640 +#include <sys/types.h>
641 +#include <sys/socket.h>
642 +#include <netinet/in.h>
643 +#include <sys/un.h>
644 +
645 +#ifndef HAVE_SOCKADDR_LEN
646 +#ifndef SA_LEN
647 +#define SA_LEN(s_)     ap_sa_len((s_)->sa_family)
648 +
649 +static NET_SIZE_T ap_sa_len (sa_family_t af)
650 +{
651 +    switch (af){
652 +#if defined(AF_INET)
653 +    case AF_INET:
654 +       return (sizeof(struct sockaddr_in));
655 +#endif /* AF_INET */
656 +#if defined(AF_INET6)
657 +    case AF_INET6:
658 +       return (sizeof(struct sockaddr_in6));
659 +#endif
660 +#ifdef AF_LOCAL
661 +    case AF_LOCAL:
662 +#endif /* AF_LOCAL */
663 +#if defined(AF_UNIX) && (AF_UNIX != AF_LOCAL)
664 +    case AF_UNIX:
665 +#endif /* AF_UNIX */
666 +#if defined(AF_FILE) && (AF_FILE != AF_LOCAL || AF_FILE != AF_UNIX)
667 +    case AF_FILE:
668 +#endif /* AF_FILE */
669 +#if defined(AF_LOCAL) || defined(AF_UNIX) || defined(AF_FILE)
670 +       return (sizeof(struct sockaddr_un));
671 +#endif /* defined(AF_LOCAL) || defined(AF_UNIX) || defined(AF_FILE) */
672 +    default:
673 +       return 0;
674 +    }
675 +    return 0;
676 +}
677 +#endif /* SA_LEN */
678 +#endif /* HAVE_SOCKADDR_LEN */
679 diff -Nur apache_1.3.28.orig/src/include/sockaddr_storage.h apache_1.3.28/src/include/sockaddr_storage.h
680 --- apache_1.3.28.orig/src/include/sockaddr_storage.h   Thu Jan  1 01:00:00 1970
681 +++ apache_1.3.28/src/include/sockaddr_storage.h        Fri Jul 25 11:01:55 2003
682 @@ -0,0 +1,53 @@
683 +/*
684 +struct sockaddr_storage
685 +
686 +   RFC2553 proposes struct sockaddr_storage.
687 +   This is a placeholder for all sockaddr-variant structures. This is
688 +   implemented like follows:
689 +
690 +   You should use this structure to hold any of sockaddr-variant
691 +   structures.
692 +*/
693 +#ifdef NEED_SOCKADDR_STORAGE
694 +
695 +struct sockaddr_storage {
696 +#ifdef HAVE_SOCKADDR_LEN
697 +       u_char ss_len;
698 +       u_char ss_family;
699 +#else
700 +       u_short ss_family;
701 +#endif
702 +       u_char __padding[128 - 2];
703 +};
704 +
705 +/*
706 +union sockunion
707 +
708 +   Alternatively, you may want to implement sockunion.h, with the
709 +   following content:
710 +
711 +   NOTE: For better portability, struct sockaddr_storage should be used.
712 +   union sockunion is okay, but is not really portable enough.
713 +*/
714 +union sockunion {
715 +       struct sockinet {
716 +#ifdef HAVE_SOCKADDR_LEN
717 +               u_char si_len;
718 +               u_char si_family;
719 +#else
720 +               u_short si_family;
721 +#endif
722 +               u_short si_port;
723 +       } su_si;
724 +       struct sockaddr_in  su_sin;
725 +#ifdef INET6
726 +       struct sockaddr_in6 su_sin6;
727 +#endif
728 +};
729 +#ifdef HAVE_SOCKADDR_LEN
730 +#define su_len         su_si.si_len
731 +#endif
732 +#define su_family      su_si.si_family
733 +#define su_port                su_si.si_port
734 +
735 +#endif /* NEED_SOCKADDR_STORAGE */
736 diff -Nur apache_1.3.28.orig/src/main/getaddrinfo.c apache_1.3.28/src/main/getaddrinfo.c
737 --- apache_1.3.28.orig/src/main/getaddrinfo.c   Thu Jan  1 01:00:00 1970
738 +++ apache_1.3.28/src/main/getaddrinfo.c        Fri Jul 25 11:01:55 2003
739 @@ -0,0 +1,162 @@
740 +/*
741 + * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
742 + * All rights reserved.
743 + * 
744 + * Redistribution and use in source and binary forms, with or without
745 + * modification, are permitted provided that the following conditions
746 + * are met:
747 + * 1. Redistributions of source code must retain the above copyright
748 + *    notice, this list of conditions and the following disclaimer.
749 + * 2. Redistributions in binary form must reproduce the above copyright
750 + *    notice, this list of conditions and the following disclaimer in the
751 + *    documentation and/or other materials provided with the distribution.
752 + * 3. Neither the name of the project nor the names of its contributors
753 + *    may be used to endorse or promote products derived from this software
754 + *    without specific prior written permission.
755 + * 
756 + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
757 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
758 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
759 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
760 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
761 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
762 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
763 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
764 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
765 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
766 + * SUCH DAMAGE.
767 + */
768 +/*
769 + * fake library for ssh v6 enabler patch
770 + *
771 + * This file includes getaddrinfo(), freeaddrinfo() and gai_strerror().
772 + * These funtions are defined in rfc2133.
773 + *
774 + * But these functions are not implemented correctly. The minimum subset
775 + * is implemented for ssh use only. For exapmle, this routine assumes
776 + * that ai_family is AF_INET. Don't use it for another purpose.
777 + * 
778 + * In the case not using 'configure --enable-ipv6', this getaddrinfo.c
779 + * will be used if you have broken getaddrinfo or no getaddrinfo.
780 + */
781 +
782 +#if 0
783 +#include <stdlib.h>
784 +#include <sys/types.h>
785 +#include <sys/socket.h>
786 +#include <netinet/in.h>
787 +#include <arpa/inet.h>
788 +#include <netdb.h>
789 +#include "gai.h"
790 +#endif
791 +
792 +static struct addrinfo *
793 +malloc_ai(port, addr, socktype, protocol)
794 +int port;
795 +u_long addr;
796 +int socktype;
797 +int protocol;
798 +{
799 +  struct addrinfo *ai;
800 +
801 +  if (ai = (struct addrinfo *)malloc(sizeof(struct addrinfo) +
802 +                                    sizeof(struct sockaddr_in))) {
803 +    memset(ai, 0, sizeof(struct addrinfo) + sizeof(struct sockaddr_in));
804 +    ai->ai_addr = (struct sockaddr *)(ai + 1);
805 +#if defined(HAVE_SOCKADDR_LEN)
806 +    ai->ai_addr->sa_len = 
807 +#endif
808 +      ai->ai_addrlen = sizeof(struct sockaddr_in);
809 +    ai->ai_addr->sa_family = ai->ai_family = AF_INET;
810 +    ai->ai_socktype = socktype;
811 +    ai->ai_protocol = protocol;
812 +    ((struct sockaddr_in *)(ai)->ai_addr)->sin_port = port;
813 +    ((struct sockaddr_in *)(ai)->ai_addr)->sin_addr.s_addr = addr;
814 +    return ai;
815 +  } else {
816 +    return NULL;
817 +  }
818 +}
819 +
820 +char *
821 +gai_strerror(ecode)
822 +int ecode;
823 +{
824 +  switch (ecode) {
825 +  case EAI_NODATA:
826 +    return "no address associated with hostname.";
827 +  case EAI_MEMORY:
828 +    return "memory allocation failure.";
829 +  default:
830 +    return "unknown error.";
831 +  }
832 +}    
833 +
834 +void
835 +freeaddrinfo(ai)
836 +struct addrinfo *ai;
837 +{
838 +  struct addrinfo *next;
839 +  
840 +  do {
841 +    next = ai->ai_next;
842 +    free(ai);
843 +  } while (ai = next);
844 +}
845 +
846 +int
847 +getaddrinfo(hostname, servname, hints, res)
848 +const char *hostname, *servname;
849 +const struct addrinfo *hints;
850 +struct addrinfo **res;
851 +{
852 +  struct addrinfo *cur, *prev = NULL;
853 +  struct hostent *hp;
854 +  int i, port;
855 +  
856 +  if (servname)
857 +    port = htons(atoi(servname));
858 +  else
859 +    port = 0;
860 +  if (hints && hints->ai_flags & AI_PASSIVE)
861 +    if (*res = malloc_ai(port, htonl(0x00000000), 
862 +                        (*res)->ai_socktype ? (*res)->ai_socktype : SOCK_STREAM,
863 +                        (*res)->ai_protocol))
864 +      return 0;
865 +    else
866 +      return EAI_MEMORY;
867 +  if (!hostname)
868 +    if (*res = malloc_ai(port, htonl(0x7f000001),
869 +                        (*res)->ai_socktype ? (*res)->ai_socktype : SOCK_STREAM,
870 +                        (*res)->ai_protocol))
871 +      return 0;
872 +    else
873 +      return EAI_MEMORY;
874 +  if (inet_addr(hostname) != -1)
875 +    if (*res = malloc_ai(port, inet_addr(hostname),
876 +                        (*res)->ai_socktype ? (*res)->ai_socktype : SOCK_STREAM,
877 +                        (*res)->ai_protocol))
878 +      return 0;
879 +    else
880 +      return EAI_MEMORY;
881 +  if ((hp = gethostbyname(hostname)) &&
882 +      hp->h_name && hp->h_name[0] && hp->h_addr_list[0]) {
883 +    for (i = 0; hp->h_addr_list[i]; i++)
884 +      if (cur = malloc_ai(port,
885 +                         ((struct in_addr *)hp->h_addr_list[i])->s_addr,
886 +                         (*res)->ai_socktype ? (*res)->ai_socktype : SOCK_STREAM,
887 +                         (*res)->ai_protocol)) {
888 +       if (prev)
889 +         prev->ai_next = cur;
890 +       else
891 +         *res = cur;
892 +       prev = cur;
893 +      } else {
894 +       if (*res)
895 +         freeaddrinfo(*res);
896 +       return EAI_MEMORY;
897 +      }
898 +    return 0;
899 +  }
900 +  return EAI_NODATA;
901 +}
902 diff -Nur apache_1.3.28.orig/src/main/getnameinfo.c apache_1.3.28/src/main/getnameinfo.c
903 --- apache_1.3.28.orig/src/main/getnameinfo.c   Thu Jan  1 01:00:00 1970
904 +++ apache_1.3.28/src/main/getnameinfo.c        Fri Jul 25 11:01:55 2003
905 @@ -0,0 +1,95 @@
906 +/*
907 + * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
908 + * All rights reserved.
909 + * 
910 + * Redistribution and use in source and binary forms, with or without
911 + * modification, are permitted provided that the following conditions
912 + * are met:
913 + * 1. Redistributions of source code must retain the above copyright
914 + *    notice, this list of conditions and the following disclaimer.
915 + * 2. Redistributions in binary form must reproduce the above copyright
916 + *    notice, this list of conditions and the following disclaimer in the
917 + *    documentation and/or other materials provided with the distribution.
918 + * 3. Neither the name of the project nor the names of its contributors
919 + *    may be used to endorse or promote products derived from this software
920 + *    without specific prior written permission.
921 + * 
922 + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
923 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
924 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
925 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
926 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
927 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
928 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
929 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
930 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
931 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
932 + * SUCH DAMAGE.
933 + */
934 +/*
935 + * fake library for ssh v6 enabler patch
936 + *
937 + * This file includes getnameinfo().
938 + * These funtions are defined in rfc2133.
939 + *
940 + * But these functions are not implemented correctly. The minimum subset
941 + * is implemented for ssh use only. For exapmle, this routine assumes
942 + * that ai_family is AF_INET. Don't use it for another purpose.
943 + * 
944 + * In the case not using 'configure --enable-ipv6', this getnameinfo.c
945 + * will be used if you have broken getnameinfo or no getnameinfo.
946 + */
947 +
948 +#if 0
949 +#include <stdlib.h>
950 +#include <sys/types.h>
951 +#include <sys/socket.h>
952 +#include <netinet/in.h>
953 +#include <arpa/inet.h>
954 +#include <netdb.h>
955 +#include <string.h>
956 +#include "gai.h"
957 +#endif
958 +
959 +int
960 +getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
961 +const struct sockaddr *sa;
962 +size_t salen;
963 +char *host;
964 +size_t hostlen;
965 +char *serv;
966 +size_t servlen;
967 +int flags;
968 +{
969 +  struct sockaddr_in *sin = (struct sockaddr_in *)sa;
970 +  struct hostent *hp;
971 +  char tmpserv[16];
972 +  
973 +  if (serv) {
974 +    sprintf(tmpserv, "%d", ntohs(sin->sin_port));
975 +    if (strlen(tmpserv) > servlen)
976 +      return EAI_MEMORY;
977 +    else
978 +      strcpy(serv, tmpserv);
979 +  }
980 +  if (host)
981 +    if (flags & NI_NUMERICHOST)
982 +      if (strlen(inet_ntoa(sin->sin_addr)) > hostlen)
983 +       return EAI_MEMORY;
984 +      else {
985 +       strcpy(host, inet_ntoa(sin->sin_addr));
986 +       return 0;
987 +      }
988 +    else
989 +      if (hp = gethostbyaddr((char *)&sin->sin_addr, sizeof(struct in_addr),
990 +                            AF_INET))
991 +       if (strlen(hp->h_name) > hostlen)
992 +         return EAI_MEMORY;
993 +       else {
994 +         strcpy(host, hp->h_name);
995 +         return 0;
996 +       }
997 +      else
998 +       return EAI_NODATA;
999 +  return 0;
1000 +}
1001 diff -Nur apache_1.3.28.orig/src/main/http_config.c apache_1.3.28/src/main/http_config.c
1002 --- apache_1.3.28.orig/src/main/http_config.c   Fri Jul 25 11:00:49 2003
1003 +++ apache_1.3.28/src/main/http_config.c        Fri Jul 25 11:01:55 2003
1004 @@ -1591,7 +1591,6 @@
1005      ap_scoreboard_fname = DEFAULT_SCOREBOARD;
1006      ap_lock_fname = DEFAULT_LOCKFILE;
1007      ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
1008 -    ap_bind_address.s_addr = htonl(INADDR_ANY);
1009      ap_listeners = NULL;
1010      ap_listenbacklog = DEFAULT_LISTENBACKLOG;
1011      ap_extended_status = 0;
1012 @@ -1624,7 +1623,13 @@
1013      s->next = NULL;
1014      s->addrs = ap_pcalloc(p, sizeof(server_addr_rec));
1015      /* NOT virtual host; don't match any real network interface */
1016 -    s->addrs->host_addr.s_addr = htonl(INADDR_ANY);
1017 +    memset(&s->addrs->host_addr, 0, sizeof(s->addrs->host_addr));
1018 +#if 0
1019 +    s->addrs->host_addr.ss_family = ap_default_family; /* XXX: needed?, XXX: PF_xxx can be different from AF_xxx */
1020 +#endif
1021 +#ifdef HAVE_SOCKADDR_LEN
1022 +    s->addrs->host_addr.ss_len = sizeof(s->addrs->host_addr); /* XXX: needed ? */
1023 +#endif
1024      s->addrs->host_port = 0;   /* matches any port */
1025      s->addrs->virthost = "";   /* must be non-NULL */
1026      s->names = s->wild_names = NULL;
1027 @@ -1643,21 +1648,33 @@
1028  static void default_listeners(pool *p, server_rec *s)
1029  {
1030      listen_rec *new;
1031 +    struct addrinfo hints, *res0, *res;
1032 +    int gai;
1033 +    char servbuf[NI_MAXSERV];
1034  
1035      if (ap_listeners != NULL) {
1036         return;
1037      }
1038 +    ap_snprintf(servbuf, sizeof(servbuf), "%d", s->port ? s->port : DEFAULT_HTTP_PORT);
1039 +    memset (&hints, 0, sizeof(hints));
1040 +    hints.ai_family = ap_default_family;
1041 +    hints.ai_socktype = SOCK_STREAM;
1042 +    hints.ai_flags = AI_PASSIVE;
1043 +    gai = getaddrinfo(NULL, servbuf, &hints, &res0);
1044 +    if (gai){
1045 +       fprintf(stderr, "default_listeners(): getaddrinfo(PASSIVE) for family %u: %s\n",
1046 +               gai_strerror(gai), ap_default_family);
1047 +       exit (1);
1048 +    }
1049      /* allocate a default listener */
1050      new = ap_pcalloc(p, sizeof(listen_rec));
1051 -    new->local_addr.sin_family = AF_INET;
1052 -    new->local_addr.sin_addr = ap_bind_address;
1053 -    /* Buck ugly cast to get around terniary op bug in some (MS) compilers */
1054 -    new->local_addr.sin_port = htons((unsigned short)(s->port ? s->port 
1055 -                                                        : DEFAULT_HTTP_PORT));
1056 +    memcpy(&new->local_addr, res0->ai_addr, res0->ai_addrlen);
1057      new->fd = -1;
1058      new->used = 0;
1059      new->next = NULL;
1060      ap_listeners = new;
1061 +
1062 +    freeaddrinfo(res0);
1063  }
1064  
1065  
1066 diff -Nur apache_1.3.28.orig/src/main/http_core.c apache_1.3.28/src/main/http_core.c
1067 --- apache_1.3.28.orig/src/main/http_core.c     Mon Jul  7 15:02:28 2003
1068 +++ apache_1.3.28/src/main/http_core.c  Fri Jul 25 12:11:48 2003
1069 @@ -71,6 +71,7 @@
1070  #include "util_md5.h"
1071  #include "scoreboard.h"
1072  #include "fnmatch.h"
1073 +#include "sa_len.h"
1074  
1075  #ifdef USE_MMAP_FILES
1076  #include <sys/mman.h>
1077 @@ -651,7 +652,9 @@
1078   */
1079  static ap_inline void do_double_reverse (conn_rec *conn)
1080  {
1081 -    struct hostent *hptr;
1082 +    struct addrinfo hints, *res, *res0;
1083 +    char hostbuf1[128], hostbuf2[128]; /* INET6_ADDRSTRLEN(=46) is enough */
1084 +    int ok = 0;
1085  
1086      if (conn->double_reverse) {
1087         /* already done */
1088 @@ -663,19 +666,43 @@
1089          conn->remote_host = ""; /* prevent another lookup */
1090         return;
1091      }
1092 -    hptr = gethostbyname(conn->remote_host);
1093 -    if (hptr) {
1094 -       char **haddr;
1095 -
1096 -       for (haddr = hptr->h_addr_list; *haddr; haddr++) {
1097 -           if (((struct in_addr *)(*haddr))->s_addr
1098 -               == conn->remote_addr.sin_addr.s_addr) {
1099 -               conn->double_reverse = 1;
1100 -               return;
1101 -           }
1102 +    memset(&hints, 0, sizeof(hints));
1103 +    hints.ai_family = PF_UNSPEC;
1104 +    hints.ai_socktype = SOCK_STREAM;
1105 +    if (getaddrinfo(conn->remote_host, NULL, &hints, &res0)) {
1106 +       conn->double_reverse = -1;
1107 +       return;
1108 +    }
1109 +    for (res = res0; res; res = res->ai_next) {
1110 +       if (res->ai_addr->sa_family != conn->remote_addr.ss_family ||
1111 +           !(res->ai_family == AF_INET 
1112 +#ifdef INET6
1113 +             || res->ai_family == AF_INET6
1114 +#endif
1115 +             )
1116 +           )
1117 +           continue;
1118 +#ifndef HAVE_SOCKADDR_LEN
1119 +       if (res->ai_addrlen != SA_LEN((struct sockaddr *)&conn->remote_addr))
1120 +#else
1121 +       if (res->ai_addr->sa_len != conn->remote_addr.ss_len)
1122 +#endif
1123 +           continue;
1124 +       if (getnameinfo(res->ai_addr, res->ai_addrlen,
1125 +            hostbuf1, sizeof(hostbuf1), NULL, 0,
1126 +            NI_NUMERICHOST))
1127 +           continue;
1128 +       if (getnameinfo(((struct sockaddr *)&conn->remote_addr), res->ai_addrlen,
1129 +            hostbuf2, sizeof(hostbuf2), NULL, 0,
1130 +            NI_NUMERICHOST))
1131 +           continue;
1132 +       if (strcmp(hostbuf1, hostbuf2) == 0){
1133 +           ok = 1;
1134 +           break;
1135         }
1136      }
1137 -    conn->double_reverse = -1;
1138 +    conn->double_reverse = ok ? 1 : -1;
1139 +    freeaddrinfo(res0);
1140      /* invalidate possible reverse-resolved hostname if forward lookup fails */
1141      conn->remote_host = "";
1142  }
1143 @@ -683,10 +710,9 @@
1144  API_EXPORT(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config,
1145                                             int type)
1146  {
1147 -    struct in_addr *iaddr;
1148 -    struct hostent *hptr;
1149      int hostname_lookups;
1150      int old_stat = SERVER_DEAD;        /* we shouldn't ever be in this state */
1151 +    char hostnamebuf[MAXHOSTNAMELEN];
1152  
1153      /* If we haven't checked the host name, and we want to */
1154      if (dir_config) {
1155 @@ -708,10 +734,14 @@
1156             || hostname_lookups != HOSTNAME_LOOKUP_OFF)) {
1157         old_stat = ap_update_child_status(conn->child_num, SERVER_BUSY_DNS,
1158                                           (request_rec*)NULL);
1159 -       iaddr = &(conn->remote_addr.sin_addr);
1160 -       hptr = gethostbyaddr((char *)iaddr, sizeof(struct in_addr), AF_INET);
1161 -       if (hptr != NULL) {
1162 -           conn->remote_host = ap_pstrdup(conn->pool, (void *)hptr->h_name);
1163 +       if (!getnameinfo((struct sockaddr *)&conn->remote_addr,
1164 +#ifndef SIN6_LEN
1165 +               SA_LEN((struct sockaddr *)&conn->remote_addr),
1166 +#else
1167 +               conn->remote_addr.ss_len,
1168 +#endif
1169 +               hostnamebuf, sizeof(hostnamebuf), NULL, 0, 0)) {
1170 +           conn->remote_host = ap_pstrdup(conn->pool, (void *)hostnamebuf);
1171             ap_str_tolower(conn->remote_host);
1172            
1173             if (hostname_lookups == HOSTNAME_LOOKUP_DOUBLE) {
1174 @@ -789,6 +819,7 @@
1175  {
1176      conn_rec *conn = r->connection;
1177      core_dir_config *d;
1178 +    char hbuf[MAXHOSTNAMELEN];
1179  
1180      d = (core_dir_config *)ap_get_module_config(r->per_dir_config,
1181                                                 &core_module);
1182 @@ -798,23 +829,22 @@
1183      }
1184      if (d->use_canonical_name == USE_CANONICAL_NAME_DNS) {
1185          if (conn->local_host == NULL) {
1186 -           struct in_addr *iaddr;
1187 -           struct hostent *hptr;
1188              int old_stat;
1189             old_stat = ap_update_child_status(conn->child_num,
1190                                               SERVER_BUSY_DNS, r);
1191 -           iaddr = &(conn->local_addr.sin_addr);
1192 -           hptr = gethostbyaddr((char *)iaddr, sizeof(struct in_addr),
1193 -                                AF_INET);
1194 -           if (hptr != NULL) {
1195 -               conn->local_host = ap_pstrdup(conn->pool,
1196 -                                             (void *)hptr->h_name);
1197 -               ap_str_tolower(conn->local_host);
1198 -           }
1199 -           else {
1200 -               conn->local_host = ap_pstrdup(conn->pool,
1201 -                                             r->server->server_hostname);
1202 +           if (getnameinfo((struct sockaddr *)&conn->local_addr,
1203 +#ifndef SIN6_LEN
1204 +                   SA_LEN((struct sockaddr *)&conn->local_addr),
1205 +#else
1206 +                   conn->local_addr.ss_len,
1207 +#endif
1208 +                   hbuf, sizeof(hbuf), NULL, 0, 0) == 0) {
1209 +               conn->local_host = ap_pstrdup(conn->pool, hbuf);
1210 +           } else {
1211 +               conn->local_host = ap_pstrdup(conn->pool,
1212 +                   r->server->server_hostname);
1213             }
1214 +           ap_str_tolower(conn->local_host);
1215             (void) ap_update_child_status(conn->child_num, old_stat, r);
1216         }
1217         return conn->local_host;
1218 @@ -833,11 +863,13 @@
1219  
1220      if (d->use_canonical_name == USE_CANONICAL_NAME_OFF
1221         || d->use_canonical_name == USE_CANONICAL_NAME_DNS) {
1222 -        return r->hostname ? ntohs(r->connection->local_addr.sin_port)
1223 -                          : port;
1224 -    }
1225 -    /* default */
1226 -    return port;
1227 +        return r->hostname
1228 +           ?  ntohs(((struct sockaddr_in *)&r->connection->local_addr)->sin_port)
1229 +           : port;
1230 +    }
1231 +    return r->hostname
1232 +       ? ntohs(((struct sockaddr_in *)&r->connection->local_addr)->sin_port)
1233 +       : port;
1234  }
1235  
1236  API_EXPORT(char *) ap_construct_url(pool *p, const char *uri,
1237 @@ -2569,12 +2601,25 @@
1238  
1239  static const char *set_bind_address(cmd_parms *cmd, void *dummy, char *arg) 
1240  {
1241 +    struct addrinfo hints, *res;
1242 +    struct sockaddr *sa;
1243 +    size_t sa_len;
1244 +    int error;
1245      const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
1246      if (err != NULL) {
1247          return err;
1248      }
1249  
1250 -    ap_bind_address.s_addr = ap_get_virthost_addr(arg, NULL);
1251 +    if (strcmp(arg, "*") == 0)
1252 +      arg = NULL;
1253 +
1254 +    sa = ap_get_virthost_addr(arg, NULL);
1255 +#ifdef HAVE_SOCKADDR_LEN
1256 +    sa_len = sa->sa_len;
1257 +#else
1258 +    sa_len = SA_LEN(sa);
1259 +#endif
1260 +    memcpy(&ap_bind_address, &sa, sa_len);
1261      return NULL;
1262  }
1263  
1264 @@ -2606,48 +2651,71 @@
1265      return NULL;
1266  }
1267  
1268 -static const char *set_listener(cmd_parms *cmd, void *dummy, char *ips)
1269 +static const char *set_listener(cmd_parms *cmd, void *dummy, char *h, char *p)
1270  {
1271      listen_rec *new;
1272 -    char *ports, *endptr;
1273 -    long port;
1274 +    char *host, *port;
1275 +    struct addrinfo hints, *res;
1276 +    int error;
1277      
1278      const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
1279      if (err != NULL) {
1280          return err;
1281      }
1282  
1283 -    ports = strchr(ips, ':');
1284 -    if (ports != NULL) {
1285 -       if (ports == ips) {
1286 -           return "Missing IP address";
1287 -       }
1288 -       else if (ports[1] == '\0') {
1289 -           return "Address must end in :<port-number>";
1290 +    host = port = NULL;
1291 +    if (!p) {
1292 +        port = strrchr(h, ':');
1293 +        if (port != NULL) {
1294 +           if (port == h) {
1295 +               return "Missing IP address";
1296 +           }
1297 +           else if (port[1] == '\0') {
1298 +               return "Address must end in :<port-number>";
1299 +           }
1300 +           *(port++) = '\0';
1301 +           if (*h)
1302 +               host = h;
1303 +        }
1304 +        else {
1305 +           host = NULL;
1306 +           port = h;
1307         }
1308 -       *(ports++) = '\0';
1309 -    }
1310 -    else {
1311 -       ports = ips;
1312 +    } else {
1313 +       host = h;
1314 +       port = p;
1315      }
1316  
1317 -    new=ap_pcalloc(cmd->pool, sizeof(listen_rec));
1318 -    new->local_addr.sin_family = AF_INET;
1319 -    if (ports == ips) { /* no address */
1320 -       new->local_addr.sin_addr.s_addr = htonl(INADDR_ANY);
1321 -    }
1322 -    else {
1323 -       new->local_addr.sin_addr.s_addr = ap_get_virthost_addr(ips, NULL);
1324 -    }
1325 -    errno = 0; /* clear errno before calling strtol */
1326 -    port = ap_strtol(ports, &endptr, 10);
1327 -    if (errno /* some sort of error */
1328 -       || (endptr && *endptr) /* make sure no trailing characters */
1329 -       || port < 1 || port > 65535) /* underflow/overflow */
1330 -    {
1331 -       return "Missing, invalid, or non-numeric port";
1332 +    if (host && strcmp(host, "*") == 0)
1333 +       host = NULL;
1334 +    
1335 +    new = ap_pcalloc(cmd->pool, sizeof(listen_rec));
1336 +
1337 +    memset(&hints, 0, sizeof(hints));
1338 +    hints.ai_family = host ? PF_UNSPEC : ap_default_family;
1339 +    hints.ai_flags = AI_PASSIVE;
1340 +    hints.ai_socktype = SOCK_STREAM;
1341 +    error = getaddrinfo(host, port, &hints, &res);
1342 +    if (error || !res) {
1343 +       fprintf(stderr, "could not resolve ");
1344 +       if (host)
1345 +           fprintf(stderr, "host \"%s\" ", host);
1346 +       if (port)
1347 +           fprintf(stderr, "port \"%s\" ", port);
1348 +       fprintf(stderr, "--- %s\n", gai_strerror(error));
1349 +       exit(1);
1350 +    }
1351 +    if (res->ai_next) {
1352 +        if (host)
1353 +           fprintf(stderr, "host \"%s\" ", host);
1354 +       if (port)
1355 +           fprintf(stderr, "port \"%s\" ", port);
1356 +       fprintf(stderr, "resolved to multiple addresses, ambiguous.\n");
1357 +       exit(1);
1358      }
1359 -    new->local_addr.sin_port = htons((unsigned short)port);
1360 +
1361 +    memcpy(&new->local_addr, res->ai_addr, res->ai_addrlen);
1362 +
1363      new->fd = -1;
1364      new->used = 0;
1365      new->next = ap_listeners;
1366 @@ -3524,7 +3592,7 @@
1367  { "ThreadStackSize", set_threadstacksize, NULL, RSRC_CONF, TAKE1,
1368    "Stack size each created thread will use."},
1369  #endif
1370 -{ "Listen", set_listener, NULL, RSRC_CONF, TAKE1,
1371 +{ "Listen", set_listener, NULL, RSRC_CONF, TAKE12,
1372    "A port number or a numeric IP address and a port number"},
1373  { "SendBufferSize", set_send_buffer_size, NULL, RSRC_CONF, TAKE1,
1374    "Send buffer size in bytes"},
1375 @@ -3558,7 +3626,7 @@
1376    "Name of the config file to be included" },
1377  { "LogLevel", set_loglevel, NULL, RSRC_CONF, TAKE1,
1378    "Level of verbosity in error logging" },
1379 -{ "NameVirtualHost", ap_set_name_virtual_host, NULL, RSRC_CONF, TAKE1,
1380 +{ "NameVirtualHost", ap_set_name_virtual_host, NULL, RSRC_CONF, TAKE12,
1381    "A numeric IP address:port, or the name of a host" },
1382  #ifdef _OSD_POSIX
1383  { "BS2000Account", set_bs2000_account, NULL, RSRC_CONF, TAKE1,
1384 diff -Nur apache_1.3.28.orig/src/main/http_main.c apache_1.3.28/src/main/http_main.c
1385 --- apache_1.3.28.orig/src/main/http_main.c     Fri Jul 25 11:00:49 2003
1386 +++ apache_1.3.28/src/main/http_main.c  Fri Jul 25 12:13:12 2003
1387 @@ -124,6 +124,8 @@
1388  #include <bstring.h>           /* for IRIX, FD_SET calls bzero() */
1389  #endif
1390  
1391 +#include "sa_len.h"
1392 +
1393  #ifdef MULTITHREAD
1394  /* special debug stuff -- PCS */
1395  
1396 @@ -249,7 +251,12 @@
1397  API_VAR_EXPORT char *ap_scoreboard_fname=NULL;
1398  API_VAR_EXPORT char *ap_lock_fname=NULL;
1399  API_VAR_EXPORT char *ap_server_argv0=NULL;
1400 -API_VAR_EXPORT struct in_addr ap_bind_address={0};
1401 +#ifdef INET6
1402 +API_VAR_EXPORT int ap_default_family = PF_INET6;
1403 +#else
1404 +API_VAR_EXPORT int ap_default_family = PF_INET;
1405 +#endif
1406 +API_VAR_EXPORT struct sockaddr_storage ap_bind_address={0};
1407  API_VAR_EXPORT int ap_daemons_to_start=0;
1408  API_VAR_EXPORT int ap_daemons_min_free=0;
1409  API_VAR_EXPORT int ap_daemons_max_free=0;
1410 @@ -1448,7 +1455,11 @@
1411      fprintf(stderr, "Usage: %s [-D name] [-d directory] [-f file]\n", bin);
1412  #endif
1413      fprintf(stderr, "       %s [-C \"directive\"] [-c \"directive\"]\n", pad);
1414 -    fprintf(stderr, "       %s [-v] [-V] [-h] [-l] [-L] [-S] [-t] [-T] [-F]\n", pad);
1415 +    fprintf(stderr, "       %s [-v] [-V] [-h] [-l] [-L] [-S] [-t] [-T] [-F]"
1416 +#ifdef INET6
1417 +           " [-46]"
1418 +#endif
1419 +           "\n", pad);
1420      fprintf(stderr, "Options:\n");
1421  #ifdef SHARED_CORE
1422      fprintf(stderr, "  -R directory     : specify an alternate location for shared object files\n");
1423 @@ -1474,6 +1485,10 @@
1424  #ifndef WIN32
1425      fprintf(stderr, "  -F               : run main process in foreground, for process supervisors\n");
1426  #endif
1427 +#ifdef INET6
1428 +    fprintf(stderr, "  -4               : assume IPv4 on parsing configuration file\n");
1429 +    fprintf(stderr, "  -6               : assume IPv6 on parsing configuration file\n");
1430 +#endif
1431  #ifdef WIN32
1432      fprintf(stderr, "  -n name          : name the Apache service for -k options below;\n");
1433      fprintf(stderr, "  -k stop|shutdown : tell running Apache to shutdown\n");
1434 @@ -3630,11 +3645,13 @@
1435  
1436  
1437  static conn_rec *new_connection(pool *p, server_rec *server, BUFF *inout,
1438 -                            const struct sockaddr_in *remaddr,
1439 -                            const struct sockaddr_in *saddr,
1440 +                            const struct sockaddr *remaddr,
1441 +                            const struct sockaddr *saddr,
1442                              int child_num)
1443  {
1444      conn_rec *conn = (conn_rec *) ap_pcalloc(p, sizeof(conn_rec));
1445 +    char hostnamebuf[MAXHOSTNAMELEN];
1446 +    size_t addr_len;
1447  
1448      /* Got a connection structure, so initialize what fields we can
1449       * (the rest are zeroed out by pcalloc).
1450 @@ -3643,17 +3660,29 @@
1451      conn->child_num = child_num;
1452  
1453      conn->pool = p;
1454 -    conn->local_addr = *saddr;
1455 -    conn->local_ip = ap_pstrdup(conn->pool,
1456 -                               inet_ntoa(conn->local_addr.sin_addr));
1457 +#ifndef SIN6_LEN
1458 +    addr_len = SA_LEN(saddr);
1459 +#else 
1460 +    addr_len = saddr->sa_len;
1461 +#endif
1462 +    memcpy(&conn->local_addr, saddr, addr_len); 
1463 +    getnameinfo((struct sockaddr *)&conn->local_addr, addr_len,
1464 +            hostnamebuf, sizeof(hostnamebuf), NULL, 0, NI_NUMERICHOST);  
1465 +    conn->local_ip = ap_pstrdup(conn->pool, hostnamebuf);
1466      conn->server = server; /* just a guess for now */
1467      ap_update_vhost_given_ip(conn);
1468      conn->base_server = conn->server;
1469      conn->client = inout;
1470  
1471 -    conn->remote_addr = *remaddr;
1472 -    conn->remote_ip = ap_pstrdup(conn->pool,
1473 -                             inet_ntoa(conn->remote_addr.sin_addr));
1474 +#ifndef SIN6_LEN 
1475 +    addr_len = SA_LEN(remaddr);
1476 +#else 
1477 +    addr_len = remaddr->sa_len;
1478 +#endif
1479 +    memcpy(&conn->remote_addr, remaddr, addr_len);
1480 +    getnameinfo((struct sockaddr *)&conn->remote_addr, addr_len,
1481 +           hostnamebuf, sizeof(hostnamebuf), NULL, 0, NI_NUMERICHOST);
1482 +    conn->remote_ip = ap_pstrdup(conn->pool, hostnamebuf);           
1483  #ifdef EAPI
1484      conn->ctx = ap_ctx_new(conn->pool);
1485  #endif /* EAPI */
1486 @@ -3711,21 +3740,47 @@
1487  #define sock_disable_nagle(s, c)       /* NOOP */
1488  #endif
1489  
1490 -static int make_sock(pool *p, const struct sockaddr_in *server)
1491 +static int make_sock(pool *p, const struct sockaddr *server)
1492  {
1493      int s;
1494      int one = 1;
1495 -    char addr[512];
1496 +    char addr[INET6_ADDRSTRLEN + 128];
1497 +    char a0[INET6_ADDRSTRLEN];
1498 +    char p0[NI_MAXSERV];
1499 +#ifdef MPE
1500 +    int privport = 0;
1501 +#endif
1502  
1503 -    if (server->sin_addr.s_addr != htonl(INADDR_ANY))
1504 -       ap_snprintf(addr, sizeof(addr), "address %s port %d",
1505 -               inet_ntoa(server->sin_addr), ntohs(server->sin_port));
1506 -    else
1507 -       ap_snprintf(addr, sizeof(addr), "port %d", ntohs(server->sin_port));
1508 +    switch(server->sa_family){
1509 +    case AF_INET:
1510 +#ifdef INET6
1511 +    case AF_INET6:
1512 +#endif
1513 +      break;
1514 +    default:
1515 +      ap_log_error(APLOG_MARK, APLOG_CRIT, server_conf,
1516 +                   "make_sock: unsupported address family %u", 
1517 +                  server->sa_family);
1518 +      ap_unblock_alarms();
1519 +      exit(1);
1520 +    }
1521 +    
1522 +    getnameinfo(server,
1523 +#ifndef SIN6_LEN
1524 +               SA_LEN(server),
1525 +#else
1526 +               server->sa_len,
1527 +#endif
1528 +               a0, sizeof(a0), p0, sizeof(p0), NI_NUMERICHOST | NI_NUMERICSERV);
1529 +    ap_snprintf(addr, sizeof(addr), "address %s port %s", a0, p0);
1530 +#ifdef MPE
1531 +    if (atoi(p0) < 1024)
1532 +      privport++;
1533 +#endif
1534  
1535      /* note that because we're about to slack we don't use psocket */
1536      ap_block_alarms();
1537 -    if ((s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
1538 +    if ((s = socket(server->sa_family, SOCK_STREAM, IPPROTO_TCP)) == -1) {
1539             ap_log_error(APLOG_MARK, APLOG_CRIT, server_conf,
1540                     "make_sock: failed to get a socket for %s", addr);
1541  
1542 @@ -3828,15 +3883,19 @@
1543  
1544  #ifdef MPE
1545  /* MPE requires CAP=PM and GETPRIVMODE to bind to ports less than 1024 */
1546 -    if (ntohs(server->sin_port) < 1024)
1547 +    if (privport)
1548         GETPRIVMODE();
1549  #endif
1550 -
1551 -    if (bind(s, (struct sockaddr *) server, sizeof(struct sockaddr_in)) == -1) {
1552 +#ifndef SIN6_LEN
1553 +    if (bind(s, server, SA_LEN(server)) == -1)
1554 +#else
1555 +    if (bind(s, server, server->sa_len) == -1)
1556 +#endif
1557 +    {
1558         ap_log_error(APLOG_MARK, APLOG_CRIT, server_conf,
1559             "make_sock: could not bind to %s", addr);
1560  #ifdef MPE
1561 -       if (ntohs(server->sin_port) < 1024)
1562 +       if (privport)
1563             GETUSERMODE();
1564  #endif
1565  
1566 @@ -3849,7 +3908,7 @@
1567         exit(1);
1568      }
1569  #ifdef MPE
1570 -    if (ntohs(server->sin_port) < 1024)
1571 +    if (privport)
1572         GETUSERMODE();
1573  #endif
1574  
1575 @@ -4002,15 +4061,17 @@
1576      for (;;) {
1577         fd = find_listener(lr);
1578         if (fd < 0) {
1579 -           fd = make_sock(p, &lr->local_addr);
1580 +           fd = make_sock(p, (struct sockaddr *)&lr->local_addr);
1581         }
1582         else {
1583             ap_note_cleanups_for_socket_ex(p, fd, 1);
1584         }
1585         /* if we get here, (fd >= 0) && (fd < FD_SETSIZE) */
1586 -       FD_SET(fd, &listenfds);
1587 -       if (fd > listenmaxfd)
1588 -           listenmaxfd = fd;
1589 +       if (fd > 0) {
1590 +           FD_SET(fd, &listenfds);
1591 +           if (fd > listenmaxfd)
1592 +               listenmaxfd = fd;
1593 +       }
1594         lr->fd = fd;
1595         if (lr->next == NULL)
1596             break;
1597 @@ -4327,8 +4388,8 @@
1598  static void child_main(int child_num_arg)
1599  {
1600      NET_SIZE_T clen;
1601 -    struct sockaddr sa_server;
1602 -    struct sockaddr sa_client;
1603 +    struct sockaddr_storage sa_server;
1604 +    struct sockaddr_storage sa_client;
1605      listen_rec *lr;
1606  
1607      /* All of initialization is a critical section, we don't care if we're
1608 @@ -4505,7 +4566,7 @@
1609             usr1_just_die = 0;
1610             for (;;) {
1611                 clen = sizeof(sa_client);
1612 -               csd = ap_accept(sd, &sa_client, &clen);
1613 +               csd = ap_accept(sd, (struct sockaddr *)&sa_client, &clen);
1614                 if (csd >= 0 || errno != EINTR)
1615                     break;
1616                 if (deferred_die) {
1617 @@ -4671,7 +4732,7 @@
1618          */
1619  
1620         clen = sizeof(sa_server);
1621 -       if (getsockname(csd, &sa_server, &clen) < 0) {
1622 +       if (getsockname(csd, (struct sockaddr *)&sa_server, &clen) < 0) {
1623             ap_log_error(APLOG_MARK, APLOG_DEBUG, server_conf, 
1624                           "getsockname, client %pA probably dropped the "
1625                           "connection", 
1626 @@ -4719,8 +4780,8 @@
1627         ap_bpushfd(conn_io, csd, dupped_csd);
1628  
1629         current_conn = new_connection(ptrans, server_conf, conn_io,
1630 -                                         (struct sockaddr_in *) &sa_client,
1631 -                                         (struct sockaddr_in *) &sa_server,
1632 +                                         (struct sockaddr *)&sa_client,
1633 +                                         (struct sockaddr *)&sa_server,
1634                                           my_child_num);
1635  
1636         /*
1637 @@ -4875,12 +4936,13 @@
1638  
1639  #ifdef _OSD_POSIX
1640      /* BS2000 requires a "special" version of fork() before a setuid() call */
1641 -    if ((pid = os_fork(ap_user_name)) == -1) {
1642 +    if ((pid = os_fork(ap_user_name)) == -1)
1643  #elif defined(TPF)
1644 -    if ((pid = os_fork(s, slot)) == -1) {
1645 +    if ((pid = os_fork(s, slot)) == -1)
1646  #else
1647 -    if ((pid = fork()) == -1) {
1648 +    if ((pid = fork()) == -1)
1649  #endif
1650 +    {
1651         ap_log_error(APLOG_MARK, APLOG_ERR, s, "fork: Unable to fork new process");
1652  
1653         /* fork didn't succeed. Fix the scoreboard or else
1654 @@ -5497,7 +5559,10 @@
1655      ap_setup_prelinked_modules();
1656  
1657      while ((c = getopt(argc, argv,
1658 -                                   "D:C:c:xXd:Ff:vVlLR:StTh"
1659 +                                   "D:C:c:xXd:Ff:vVlLR:StTh4"
1660 +#ifdef INET6
1661 +                                   "6"
1662 +#endif
1663  #ifdef DEBUG_SIGSTOP
1664                                     "Z:"
1665  #endif
1666 @@ -5575,8 +5640,14 @@
1667             ap_configtestonly = 1;
1668             ap_docrootcheck = 0;
1669             break;
1670 -       case 'h':
1671 -           usage(argv[0]);
1672 +       case '4':
1673 +           ap_default_family = PF_INET;
1674 +           break;
1675 +#ifdef INET6
1676 +       case '6':
1677 +           ap_default_family = PF_INET6;
1678 +           break;
1679 +#endif
1680         case '?':
1681             usage(argv[0]);
1682         }
1683 @@ -5665,9 +5736,10 @@
1684      else {
1685         conn_rec *conn;
1686         request_rec *r;
1687 -       struct sockaddr sa_server, sa_client;
1688         BUFF *cio;
1689 +       struct sockaddr_storage sa_server, sa_client;
1690         NET_SIZE_T l;
1691 +       char servbuf[NI_MAXSERV];
1692  
1693         ap_set_version();
1694         /* Yes this is called twice. */
1695 @@ -5722,25 +5794,32 @@
1696  #endif
1697  
1698         l = sizeof(sa_client);
1699 -       if ((getpeername(sock_in, &sa_client, &l)) < 0) {
1700 +       if ((getpeername(sock_in, (struct sockaddr *)&sa_client, &l)) < 0) {
1701  /* get peername will fail if the input isn't a socket */
1702             perror("getpeername");
1703             memset(&sa_client, '\0', sizeof(sa_client));
1704         }
1705  
1706         l = sizeof(sa_server);
1707 -       if (getsockname(sock_in, &sa_server, &l) < 0) {
1708 +       if (getsockname(sock_in, (struct sockaddr *)&sa_server, &l) < 0) {
1709             perror("getsockname");
1710             fprintf(stderr, "Error getting local address\n");
1711             exit(1);
1712         }
1713 -       server_conf->port = ntohs(((struct sockaddr_in *) &sa_server)->sin_port);
1714 +       if (getnameinfo(((struct sockaddr *)&sa_server), l,
1715 +                       NULL, 0, servbuf, sizeof(servbuf), 
1716 +                       NI_NUMERICSERV)){
1717 +           fprintf(stderr, "getnameinfo(): family=%d\n", sa_server.ss_family);
1718 +           exit(1);
1719 +       }
1720 +       servbuf[sizeof(servbuf)-1] = '\0';
1721 +       server_conf->port = atoi(servbuf);
1722         cio = ap_bcreate(ptrans, B_RDWR | B_SOCKET);
1723          cio->fd = sock_out;
1724          cio->fd_in = sock_in;
1725         conn = new_connection(ptrans, server_conf, cio,
1726 -                                 (struct sockaddr_in *) &sa_client,
1727 -                                 (struct sockaddr_in *) &sa_server, -1);
1728 +                                 (struct sockaddr *)&sa_client,
1729 +                                 (struct sockaddr *)&sa_server, -1);
1730  
1731         while ((r = ap_read_request(conn)) != NULL) {
1732  
1733 @@ -7447,7 +7526,11 @@
1734  
1735      while ((c = getopt(argc, argv, "D:C:c:Xd:f:vVlLz:Z:wiuStThk:n:W:")) != -1) {
1736  #else /* !WIN32 */
1737 -    while ((c = getopt(argc, argv, "D:C:c:Xd:Ff:vVlLesStTh")) != -1) {
1738 +    while ((c = getopt(argc, argv, "D:C:c:Xd:Ff:vVlLesStTh4"
1739 +#ifdef INET6
1740 +               "6"
1741 +#endif
1742 +               )) != -1) {
1743  #endif
1744          char **new;
1745         switch (c) {
1746 @@ -7993,6 +8076,10 @@
1747         case 't':
1748         case 'T':
1749         case 'h':
1750 +       case '4':
1751 +#ifdef INET6
1752 +       case '6':
1753 +#endif
1754         case '?':
1755             break;
1756         case 'R':
1757 diff -Nur apache_1.3.28.orig/src/main/http_vhost.c apache_1.3.28/src/main/http_vhost.c
1758 --- apache_1.3.28.orig/src/main/http_vhost.c    Mon Feb  3 18:13:23 2003
1759 +++ apache_1.3.28/src/main/http_vhost.c Fri Jul 25 11:01:55 2003
1760 @@ -68,6 +68,7 @@
1761  #include "http_log.h"
1762  #include "http_vhost.h"
1763  #include "http_protocol.h"
1764 +#include "sa_len.h"
1765  
1766  /*
1767   * After all the definitions there's an explanation of how it's all put
1768 @@ -165,78 +166,114 @@
1769   * *paddr is the variable used to keep track of **paddr between calls
1770   * port is the default port to assume
1771   */
1772 -static const char *get_addresses(pool *p, char *w, server_addr_rec ***paddr,
1773 -                           unsigned port)
1774 +static const char *get_addresses(pool *p, char *w, char *pstr,
1775 +       server_addr_rec ***paddr, unsigned port)
1776  {
1777 -    struct hostent *hep;
1778 -    unsigned long my_addr;
1779 +    struct addrinfo hints, *res, *res0;
1780      server_addr_rec *sar;
1781 -    char *t;
1782 -    int i, is_an_ip_addr;
1783 +    char *t = NULL, *u = NULL, *v = NULL;
1784 +    char *hoststr = NULL, *portstr = NULL;
1785 +    char portpool[10];
1786 +    int error;
1787 +    char servbuf[NI_MAXSERV];
1788  
1789 -    if (*w == 0)
1790 +    if (w == 0 || *w == 0)
1791         return NULL;
1792  
1793 -    t = strchr(w, ':');
1794 -    if (t) {
1795 -       if (strcmp(t + 1, "*") == 0) {
1796 -           port = 0;
1797 +    portstr = portpool;
1798 +    ap_snprintf(portpool, sizeof(portpool), "%u", port);
1799 +    if (!pstr) {
1800 +       v = w;
1801 +       u = NULL;
1802 +       if (*w == '['){
1803 +           u = strrchr(w, ']');
1804 +           if (u) {    /* [host]:port or [host] */
1805 +               w++;
1806 +               *u = '\0';
1807 +               v = u + 1;
1808 +           }
1809         }
1810 -       else if ((i = atoi(t + 1))) {
1811 -           port = i;
1812 +       /*        w   uv     ,       w=v        , w=v  */  
1813 +       /* u!=0: [host]:port , u==0: [host:port , host */
1814 +       t = strchr(v, ':');
1815 +       if (t != NULL && strchr(t+1, ':') == NULL) {
1816 +           /* [host]:port-w/o-colons, host-without-colons:port-w/o-colons */
1817 +           *t = '\0';
1818 +           portstr = t + 1;
1819         }
1820         else {
1821 -           return ":port must be numeric";
1822 +           portstr = "0";
1823         }
1824 -       *t = 0;
1825 +    } else {
1826 +       portstr = pstr;
1827      }
1828  
1829 -    is_an_ip_addr = 0;
1830 -    if (strcmp(w, "*") == 0) {
1831 -       my_addr = htonl(INADDR_ANY);
1832 -       is_an_ip_addr = 1;
1833 -    }
1834 -    else if (strcasecmp(w, "_default_") == 0
1835 -            || strcmp(w, "255.255.255.255") == 0) {
1836 -       my_addr = DEFAULT_VHOST_ADDR;
1837 -       is_an_ip_addr = 1;
1838 -    }
1839 -    else if ((my_addr = ap_inet_addr(w)) != INADDR_NONE) {
1840 -       is_an_ip_addr = 1;
1841 +    memset(&hints, 0, sizeof(hints));
1842 +    hints.ai_socktype = SOCK_STREAM;
1843 +    if (strcmp(w, "*") == 0 || strlen(w) == 0) {
1844 +       hoststr = NULL;
1845 +       hints.ai_family = PF_UNSPEC;
1846 +       hints.ai_flags = AI_PASSIVE;
1847 +    }
1848 +    else if (strcasecmp(w, "_default4_") == 0 ||
1849 +            ((ap_default_family == PF_INET
1850 +#ifndef INET6
1851 +              || ap_default_family == PF_UNSPEC
1852 +#endif
1853 +              ) && strcasecmp(w, "_default_") == 0)){
1854 +       hoststr = "255.255.255.255";
1855 +       hints.ai_family = PF_INET;
1856 +    }
1857 +#ifdef INET6
1858 +    else if (strcasecmp(w, "_default6_") == 0 ||
1859 +            ((ap_default_family == PF_INET6
1860 +              || ap_default_family == PF_UNSPEC
1861 +              ) && strcasecmp(w, "_default_") == 0)){
1862 +       hoststr = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff";
1863 +       hints.ai_family = PF_INET6;
1864      }
1865 -    if (is_an_ip_addr) {
1866 -       sar = ap_pcalloc(p, sizeof(server_addr_rec));
1867 -       **paddr = sar;
1868 -       *paddr = &sar->next;
1869 -       sar->host_addr.s_addr = my_addr;
1870 -       sar->host_port = port;
1871 -       sar->virthost = ap_pstrdup(p, w);
1872 -       if (t != NULL)
1873 -           *t = ':';
1874 -       return NULL;
1875 +#endif
1876 +    else{
1877 +       hoststr = w;
1878 +       hints.ai_family = PF_UNSPEC;
1879      }
1880  
1881 -    hep = gethostbyname(w);
1882 -
1883 -    if ((!hep) || (hep->h_addrtype != AF_INET || !hep->h_addr_list[0])) {
1884 +    error = getaddrinfo(hoststr, portstr, &hints, &res0);
1885 +    if (error || !res0) {
1886         ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, NULL,
1887 -           "Cannot resolve host name %s --- ignoring!", w);
1888 -       if (t != NULL)
1889 -           *t = ':';
1890 +           "Cannot resolve host %s port %s --- ignoring!", hoststr, portstr);
1891 +       if (t != NULL) *t = ':';
1892 +       if (u != NULL) *u = ']';
1893         return NULL;
1894      }
1895 -
1896 -    for (i = 0; hep->h_addr_list[i]; ++i) {
1897 +    for (res=res0; res; res=res->ai_next) {
1898 +       switch (res->ai_addr->sa_family) {
1899 +       case AF_INET:
1900 +#ifdef INET6
1901 +       case AF_INET6:
1902 +#endif
1903 +           break;
1904 +       default:
1905 +           ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, NULL,
1906 +                        "Unsupported address family %u, for host %s port %s --- ignoring!",
1907 +                        res->ai_addr->sa_family, hoststr, portstr);
1908 +           continue;
1909 +       }
1910         sar = ap_pcalloc(p, sizeof(server_addr_rec));
1911         **paddr = sar;
1912         *paddr = &sar->next;
1913 -       sar->host_addr = *(struct in_addr *) hep->h_addr_list[i];
1914 -       sar->host_port = port;
1915 +       memcpy(&sar->host_addr, res->ai_addr, res->ai_addrlen);
1916 +       if (getnameinfo(res->ai_addr, res->ai_addrlen, NULL, 0, servbuf,
1917 +                       sizeof(servbuf), NI_NUMERICSERV) == 0)
1918 +               sar->host_port = atoi(servbuf);
1919 +       else
1920 +               sar->host_port = 0;
1921         sar->virthost = ap_pstrdup(p, w);
1922      }
1923  
1924 -    if (t != NULL)
1925 -       *t = ':';
1926 +    freeaddrinfo(res0);
1927 +    if (t != NULL) *t = ':';
1928 +    if (u != NULL) *u = ']';
1929      return NULL;
1930  }
1931  
1932 @@ -250,7 +287,8 @@
1933      /* start the list of addreses */
1934      addrs = &s->addrs;
1935      while (hostname[0]) {
1936 -       err = get_addresses(p, ap_getword_conf(p, &hostname), &addrs, s->port);
1937 +       err = get_addresses(p, ap_getword_conf(p, &hostname), NULL,
1938 +               &addrs, s->port);
1939         if (err) {
1940             *addrs = NULL;
1941             return err;
1942 @@ -268,10 +306,11 @@
1943  }
1944  
1945  
1946 -API_EXPORT_NONSTD(const char *) ap_set_name_virtual_host (cmd_parms *cmd, void *dummy, char *arg)
1947 +API_EXPORT_NONSTD(const char *) ap_set_name_virtual_host (cmd_parms *cmd, void *dummy, char *h, 
1948 +       char *p)
1949  {
1950      /* use whatever port the main server has at this point */
1951 -    return get_addresses(cmd->pool, arg, &name_vhost_list_tail,
1952 +    return get_addresses(cmd->pool, h, p, &name_vhost_list_tail,
1953                             cmd->server->port);
1954  }
1955  
1956 @@ -345,6 +384,19 @@
1957      return ((key >> 8) ^ key) % IPHASH_TABLE_SIZE;
1958  }
1959  
1960 +static unsigned hash_addr(struct sockaddr *sa)
1961 +{
1962 +    switch (sa->sa_family) {
1963 +    case AF_INET:
1964 +       return hash_inaddr(((struct sockaddr_in *)sa)->sin_addr.s_addr);
1965 +#ifdef INET6
1966 +    case AF_INET6:
1967 +       return hash_inaddr(((struct sockaddr_in6 *)sa)->sin6_addr.s6_addr[12]);
1968 +#endif
1969 +    default:
1970 +       return hash_inaddr(sa->sa_family);
1971 +    }
1972 +}
1973  
1974  
1975  static ipaddr_chain *new_ipaddr_chain(pool *p,
1976 @@ -372,25 +424,77 @@
1977      return new;
1978  }
1979  
1980 -
1981 -static ap_inline ipaddr_chain *find_ipaddr(struct in_addr *server_ip,
1982 -    unsigned port)
1983 +static ap_inline ipaddr_chain *find_ipaddr(struct sockaddr *sa)
1984  {
1985      unsigned bucket;
1986      ipaddr_chain *trav;
1987 -    unsigned addr;
1988 +    char a[NI_MAXHOST], b[NI_MAXHOST];
1989  
1990      /* scan the hash table for an exact match first */
1991 -    addr = server_ip->s_addr;
1992 -    bucket = hash_inaddr(addr);
1993 +    bucket = hash_addr(sa);
1994      for (trav = iphash_table[bucket]; trav; trav = trav->next) {
1995         server_addr_rec *sar = trav->sar;
1996 -       if ((sar->host_addr.s_addr == addr)
1997 -           && (sar->host_port == 0 || sar->host_port == port
1998 -               || port == 0)) {
1999 -           return trav;
2000 +       if (sar->host_addr.ss_family != sa->sa_family)
2001 +           continue;
2002 +       switch (sa->sa_family) {
2003 +       case AF_INET:
2004 +         {
2005 +           struct sockaddr_in *sin1, *sin2;
2006 +           sin1 = (struct sockaddr_in *)&sar->host_addr;
2007 +           sin2 = (struct sockaddr_in *)sa;
2008 +           if (sin1->sin_port == 0 || sin2->sin_port == 0
2009 +            || sin1->sin_port == sin2->sin_port) {
2010 +               if (memcmp(&sin1->sin_addr, &sin2->sin_addr,
2011 +                       sizeof(sin1->sin_addr)) == 0) {
2012 +                   return trav;
2013 +               }
2014 +           }
2015 +           break;
2016 +         }
2017 +#ifdef INET6
2018 +       case AF_INET6:
2019 +         {
2020 +           struct sockaddr_in6 *sin1, *sin2;
2021 +           sin1 = (struct sockaddr_in6 *)&sar->host_addr;
2022 +           sin2 = (struct sockaddr_in6 *)sa;
2023 +           if (sin1->sin6_port == 0 || sin2->sin6_port == 0
2024 +            || sin1->sin6_port == sin2->sin6_port) {
2025 +               if (memcmp(&sin1->sin6_addr, &sin2->sin6_addr,
2026 +                       sizeof(sin1->sin6_addr)) == 0) {
2027 +                   return trav;
2028 +               }
2029 +           }
2030 +           break;
2031 +         }
2032 +#endif
2033 +       default: /*unsupported*/
2034 +           break;
2035         }
2036      }
2037 +
2038 +#ifdef INET6
2039 +    if (sa->sa_family == AF_INET6 &&
2040 +       IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)sa)->sin6_addr)) {
2041 +       /*
2042 +        * This is just horrible.  I just hate IPv4 mapped address.  It
2043 +        * complicates access control too much.
2044 +        * Due to hashed lookup, we need to visit it again.
2045 +        */
2046 +       struct sockaddr_in sin;
2047 +
2048 +       memset(&sin, 0, sizeof(sin));
2049 +       sin.sin_family = AF_INET;
2050 +#ifdef SIN6_LEN
2051 +       sin.sin_len = sizeof(sin);
2052 +#endif
2053 +       sin.sin_port = ((struct sockaddr_in6 *)sa)->sin6_port;
2054 +       memcpy(&sin.sin_addr,
2055 +           &((struct sockaddr_in6 *)sa)->sin6_addr.s6_addr[12],
2056 +           sizeof(sin.sin_addr));
2057 +       return find_ipaddr((struct sockaddr *)&sin);
2058 +    }
2059 +#endif
2060 +
2061      return NULL;
2062  }
2063  
2064 @@ -416,21 +520,7 @@
2065      int len;
2066      char buf[MAX_STRING_LEN];
2067  
2068 -    if (ic->sar->host_addr.s_addr == DEFAULT_VHOST_ADDR) {
2069 -       len = ap_snprintf(buf, sizeof(buf), "_default_:%u",
2070 -               ic->sar->host_port);
2071 -    }
2072 -    else if (ic->sar->host_addr.s_addr == INADDR_ANY) {
2073 -       len = ap_snprintf(buf, sizeof(buf), "*:%u",
2074 -               ic->sar->host_port);
2075 -    }
2076 -    else {
2077 -       len = ap_snprintf(buf, sizeof(buf), "%pA:%u",
2078 -               &ic->sar->host_addr, ic->sar->host_port);
2079 -    }
2080 -    if (ic->sar->host_port == 0) {
2081 -       buf[len-1] = '*';
2082 -    }
2083 +    len = ap_snprintf(buf, sizeof(buf), "%pI", &ic->sar->host_addr);
2084      if (ic->names == NULL) {
2085         if (ic->server == NULL)
2086             fprintf(f, "%-22s WARNING: No <VirtualHost> defined for this NameVirtualHost!\n", buf);
2087 @@ -558,10 +648,37 @@
2088       * occured in the config file, we'll copy it in that order.
2089       */
2090      for (sar = name_vhost_list; sar; sar = sar->next) {
2091 -       unsigned bucket = hash_inaddr(sar->host_addr.s_addr);
2092 +       unsigned bucket = hash_addr((struct sockaddr *)&sar->host_addr);
2093         ipaddr_chain *ic = new_ipaddr_chain(p, NULL, sar);
2094 +       int wildcard;
2095 +
2096 +       wildcard = 0;
2097 +       switch (sar->host_addr.ss_family) {
2098 +       case AF_INET:
2099 +         {
2100 +           struct sockaddr_in *sin;
2101 +           sin = (struct sockaddr_in *)&sar->host_addr;
2102 +           if (sin->sin_addr.s_addr == INADDR_ANY)
2103 +               wildcard++;
2104 +           break;
2105 +         }
2106 +#ifdef INET6
2107 +       case AF_INET6:
2108 +         {
2109 +           struct sockaddr_in6 *sin6;
2110 +           sin6 = (struct sockaddr_in6 *)&sar->host_addr;
2111 +           if (*(ap_uint32_t *)&sin6->sin6_addr.s6_addr[0] == 0
2112 +            && *(ap_uint32_t *)&sin6->sin6_addr.s6_addr[4] == 0
2113 +            && *(ap_uint32_t *)&sin6->sin6_addr.s6_addr[8] == 0
2114 +            && *(ap_uint32_t *)&sin6->sin6_addr.s6_addr[12] == 0) {
2115 +               wildcard++;
2116 +           }
2117 +           break;
2118 +         }
2119 +#endif
2120 +       }
2121  
2122 -       if (sar->host_addr.s_addr != INADDR_ANY) {
2123 +       if (!wildcard) {
2124             *iphash_table_tail[bucket] = ic;
2125             iphash_table_tail[bucket] = &ic->next;
2126         }
2127 @@ -588,12 +705,45 @@
2128         has_default_vhost_addr = 0;
2129         for (sar = s->addrs; sar; sar = sar->next) {
2130             ipaddr_chain *ic;
2131 +           int wildcard;
2132 +
2133 +           wildcard = 0;
2134 +           switch (sar->host_addr.ss_family) {
2135 +           case AF_INET:
2136 +             {
2137 +               struct sockaddr_in *sin;
2138 +               sin = (struct sockaddr_in *)&sar->host_addr;
2139 +               if (sin->sin_addr.s_addr == DEFAULT_VHOST_ADDR)
2140 +                   wildcard++;
2141 +               else if (sin->sin_addr.s_addr == INADDR_ANY)
2142 +                   wildcard++;
2143 +               break;
2144 +             }
2145 +#ifdef INET6
2146 +           case AF_INET6:
2147 +             {
2148 +               struct sockaddr_in6 *sin6;
2149 +               sin6 = (struct sockaddr_in6 *)&sar->host_addr;
2150 +               if (*(ap_uint32_t *)&sin6->sin6_addr.s6_addr[0] == ~0
2151 +                && *(ap_uint32_t *)&sin6->sin6_addr.s6_addr[4] == ~0
2152 +                && *(ap_uint32_t *)&sin6->sin6_addr.s6_addr[8] == ~0
2153 +                && *(ap_uint32_t *)&sin6->sin6_addr.s6_addr[12] == ~0) {
2154 +                   wildcard++;
2155 +               }
2156 +               break;
2157 +             }
2158 +#endif
2159 +           }
2160  
2161 -           if (sar->host_addr.s_addr == DEFAULT_VHOST_ADDR
2162 -               || sar->host_addr.s_addr == INADDR_ANY) {
2163 -               ic = find_default_server(sar->host_port);
2164 -               if (!ic || !add_name_vhost_config(p, main_s, s, sar, ic)) {
2165 -                   if (ic && ic->sar->host_port != 0) {
2166 +           if (wildcard) {
2167 +               /* add it to default bucket for each appropriate sar
2168 +                * since we need to do a port test
2169 +                */
2170 +               ipaddr_chain *other;
2171 +
2172 +               other = find_default_server(sar->host_port);
2173 +               if (!other || !add_name_vhost_config(p, main_s, s, sar, other)) {
2174 +                   if (other && other->sar->host_port != 0) {
2175                         ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING,
2176                             main_s, "_default_ VirtualHost overlap on port %u,"
2177                             " the first has precedence", sar->host_port);
2178 @@ -606,10 +756,11 @@
2179             }
2180             else {
2181                 /* see if it matches something we've already got */
2182 -               ic = find_ipaddr(&sar->host_addr, sar->host_port);
2183 +               ic = find_ipaddr((struct sockaddr *)&sar->host_addr);
2184  
2185                 if (!ic) {
2186 -                   unsigned bucket = hash_inaddr(sar->host_addr.s_addr);
2187 +                   unsigned bucket =
2188 +                       hash_addr((struct sockaddr *)&sar->host_addr);
2189  
2190                     ic = new_ipaddr_chain(p, s, sar);
2191                     ic->next = *iphash_table_tail[bucket];
2192 @@ -646,19 +797,33 @@
2193             }
2194             else {
2195                 struct hostent *h;
2196 +               char hostnamebuf[MAXHOSTNAMELEN];
2197  
2198 -               if ((h = gethostbyaddr((char *) &(s->addrs->host_addr),
2199 -                                       sizeof(struct in_addr), AF_INET))) {
2200 -                   s->server_hostname = ap_pstrdup(p, (char *) h->h_name);
2201 +               if (!getnameinfo((struct sockaddr *)&s->addrs->host_addr,
2202 +#ifndef SIN6_LEN
2203 +                       SA_LEN((struct sockaddr *)&s->addrs->host_addr),
2204 +#else  
2205 +                       s->addrs->host_addr.ss_len,
2206 +#endif
2207 +                       hostnamebuf, sizeof(hostnamebuf),
2208 +                       NULL, 0, 0)) {
2209 +                   s->server_hostname = ap_pstrdup(p, hostnamebuf);
2210                 }
2211                 else {
2212                     /* again, what can we do?  They didn't specify a
2213                        ServerName, and their DNS isn't working. -djg */
2214 +                   getnameinfo((struct sockaddr *)&s->addrs->host_addr,
2215 +#ifndef SIN6_LEN
2216 +                       SA_LEN((struct sockaddr *)&s->addrs->host_addr),
2217 +#else  
2218 +                       s->addrs->host_addr.ss_len,
2219 +#endif
2220 +                       hostnamebuf, sizeof(hostnamebuf),
2221 +                       NULL, 0, NI_NUMERICHOST);
2222                     ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, main_s,
2223                             "Failed to resolve server name "
2224                             "for %s (check DNS) -- or specify an explicit "
2225 -                           "ServerName",
2226 -                           inet_ntoa(s->addrs->host_addr));
2227 +                           "ServerName", hostnamebuf);
2228                     s->server_hostname =
2229                         ap_pstrdup(p, "bogus_host_without_reverse_dns");
2230                 }
2231 @@ -705,35 +870,58 @@
2232      char *host = ap_palloc(r->pool, strlen(r->hostname) + 1);
2233      const char *src;
2234      char *dst;
2235 +    const char *u = NULL, *v = NULL;
2236  
2237      /* check and copy the host part */
2238 -    src = r->hostname;
2239 +    u = src = r->hostname;
2240  
2241      dst = host;
2242 -    while (*src) {
2243 -       if (*src == '.') {
2244 -           *dst++ = *src++;
2245 -           if (*src == '.')
2246 -               goto bad;
2247 -           else
2248 -               continue;
2249 -       }
2250 -       if (*src == '/' || *src == '\\') {
2251 -           goto bad;
2252 -       }
2253 -        if (*src == ':') {
2254 -            /* check the port part */
2255 -            while (*++src) {
2256 -                if (!ap_isdigit(*src)) {
2257 -                    goto bad;
2258 -                }
2259 -            }
2260 -            if (src[-1] == ':')
2261 -                goto bad;
2262 -            else
2263 -                break;
2264 +     if (*u == '[') { /* IPv6 numeral address in brackets */
2265 +         v = strchr(u, ']');
2266 +       if (v == NULL) {
2267 +           /* missing closing bracket */
2268 +             goto bad;
2269 +       }
2270 +         if (v == (u + 1)) {
2271 +             /* bad empty address */
2272 +             goto bad;
2273 +       }
2274 +       for (src = u+1; src < v; src++)  /* copy IPv6 adress */
2275 +           *dst = *src;
2276 +       v++;
2277 +       if (*v == ':') {
2278 +          v++;
2279 +          while (*v) {  /* check if portnum is correct */
2280 +              if (!ap_isdigit(*v++))
2281 +                  goto bad;
2282 +          }
2283          }
2284 -       *dst++ = *src++;
2285 +     } else {
2286 +         while (*src) {
2287 +           if (*src == '.') {
2288 +               *dst++ = *src++;
2289 +               if (*src == '.')
2290 +                   goto bad;
2291 +               else
2292 +                   continue;
2293 +           }
2294 +           if (*src == '/' || *src == '\\') {
2295 +               goto bad;
2296 +           }
2297 +           if (*src == ':') {
2298 +               /* sheck the port part */
2299 +               while (*++src) {
2300 +                   if (!ap_isdigit(*src)) {
2301 +                       goto bad;
2302 +                   }
2303 +               }
2304 +               if (src[-1] == ':')
2305 +                   goto bad;
2306 +               else
2307 +                   break;
2308 +           }
2309 +           *dst++ = *src++;
2310 +         }
2311      }
2312      /* strip trailing gubbins */
2313      if (dst > host && dst[-1] == '.') {
2314 @@ -748,7 +936,7 @@
2315  bad:
2316      r->status = HTTP_BAD_REQUEST;
2317      ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r,
2318 -                 "Client sent malformed Host header");
2319 +                 "Client sent malformed Host header <<%s>>",u);
2320      return;
2321  }
2322  
2323 @@ -851,11 +1039,25 @@
2324       *   names we'll match have ports associated with them
2325       */
2326      const char *host = r->hostname;
2327 -    unsigned port = ntohs(r->connection->local_addr.sin_port);
2328 +    unsigned port;
2329      server_rec *s;
2330      server_rec *last_s;
2331      name_chain *src;
2332  
2333 +    switch (r->connection->local_addr.ss_family) {
2334 +    case AF_INET:
2335 +       port = ntohs(((struct sockaddr_in *)
2336 +                   &r->connection->local_addr)->sin_port);
2337 +       break;
2338 +#ifdef INET6
2339 +    case AF_INET6:
2340 +       port = ntohs(((struct sockaddr_in6 *)
2341 +                   &r->connection->local_addr)->sin6_port);
2342 +       break;
2343 +#endif
2344 +    default:
2345 +       port = 0;       /*XXX*/
2346 +    }
2347      last_s = NULL;
2348  
2349      /* Recall that the name_chain is a list of server_addr_recs, some of
2350 @@ -910,7 +1112,22 @@
2351      server_rec *s;
2352      server_rec *last_s;
2353      name_chain *src;
2354 -    unsigned port = ntohs(r->connection->local_addr.sin_port);
2355 +    unsigned port;
2356 +
2357 +    switch (r->connection->local_addr.ss_family) {
2358 +    case AF_INET:
2359 +       port = ntohs(((struct sockaddr_in *)
2360 +                   &r->connection->local_addr)->sin_port);
2361 +       break;
2362 +#ifdef INET6
2363 +    case AF_INET6:
2364 +       port = ntohs(((struct sockaddr_in6 *)
2365 +                   &r->connection->local_addr)->sin6_port);
2366 +       break;
2367 +#endif
2368 +    default:
2369 +       port = 0;       /*XXX*/
2370 +    }
2371  
2372      /*
2373       * This is in conjunction with the ServerPath code in http_core, so we
2374 @@ -970,10 +1187,22 @@
2375  API_EXPORT(void) ap_update_vhost_given_ip(conn_rec *conn)
2376  {
2377      ipaddr_chain *trav;
2378 -    unsigned port = ntohs(conn->local_addr.sin_port);
2379 +    char portbuf[NI_MAXSERV];
2380 +    unsigned port;
2381 +
2382 +    if (getnameinfo((struct sockaddr *)&conn->local_addr,
2383 +#ifndef SIN6_LEN
2384 +       SA_LEN((struct sockaddr *)&conn->local_addr),
2385 +#else  
2386 +       conn->local_addr.ss_len,
2387 +#endif
2388 +       NULL, 0, portbuf, sizeof(portbuf), NI_NUMERICSERV) != 0) {
2389 +       goto fail;
2390 +    }
2391 +    port = atoi(portbuf);
2392  
2393      /* scan the hash table for an exact match first */
2394 -    trav = find_ipaddr(&conn->local_addr.sin_addr, port);
2395 +    trav = find_ipaddr((struct sockaddr *)&conn->local_addr);
2396      if (trav) {
2397         /* save the name_chain for later in case this is a name-vhost */
2398         conn->vhost_lookup_data = trav->names;
2399 @@ -991,6 +1220,7 @@
2400         return;
2401      }
2402  
2403 +fail:
2404      /* otherwise we're stuck with just the main server
2405       * and no name-based vhosts
2406       */
2407 diff -Nur apache_1.3.28.orig/src/main/rfc1413.c apache_1.3.28/src/main/rfc1413.c
2408 --- apache_1.3.28.orig/src/main/rfc1413.c       Mon Feb  3 18:13:23 2003
2409 +++ apache_1.3.28/src/main/rfc1413.c    Fri Jul 25 12:15:05 2003
2410 @@ -82,6 +82,7 @@
2411  #include "http_log.h"          /* for aplog_error */
2412  #include "rfc1413.h"
2413  #include "http_main.h"         /* set_callback_and_alarm */
2414 +#include "sa_len.h"
2415  
2416  /* Local stuff. */
2417  /* Semi-well-known port */
2418 @@ -109,12 +110,13 @@
2419  
2420  /* bind_connect - bind both ends of a socket */
2421  /* Ambarish fix this. Very broken */
2422 -static int get_rfc1413(int sock, const struct sockaddr_in *our_sin,
2423 -                      const struct sockaddr_in *rmt_sin, 
2424 +static int get_rfc1413(int sock, const struct sockaddr *our_sin,
2425 +                      const struct sockaddr *rmt_sin, 
2426                        char user[RFC1413_USERLEN+1], server_rec *srv)
2427  {
2428 -    struct sockaddr_in rmt_query_sin, our_query_sin;
2429 -    unsigned int rmt_port, our_port;
2430 +    struct sockaddr_storage rmt_query_sin, our_query_sin;
2431 +    unsigned int o_rmt_port, o_our_port;       /* original port pair */
2432 +    unsigned int rmt_port, our_port;           /* replied port pair */
2433      int i;
2434      char *cp;
2435      char buffer[RFC1413_MAXDATA + 1];
2436 @@ -129,16 +131,47 @@
2437       * addresses from the query socket.
2438       */
2439  
2440 -    our_query_sin = *our_sin;
2441 -    our_query_sin.sin_port = htons(ANY_PORT);
2442 -#ifdef MPE 
2443 -    our_query_sin.sin_addr.s_addr = INADDR_ANY;
2444 +#ifndef SIN6_LEN
2445 +    memcpy(&our_query_sin, our_sin, SA_LEN(our_sin));
2446 +    memcpy(&rmt_query_sin, rmt_sin, SA_LEN(rmt_sin));
2447 +#else
2448 +    memcpy(&our_query_sin, our_sin, our_sin->sa_len);
2449 +    memcpy(&rmt_query_sin, rmt_sin, rmt_sin->sa_len);
2450  #endif
2451 -    rmt_query_sin = *rmt_sin;
2452 -    rmt_query_sin.sin_port = htons(RFC1413_PORT);
2453 +    switch (our_sin->sa_family) {
2454 +    case AF_INET:
2455 +#ifdef MPE
2456 +      ((struct sockaddr_in *)&our_query_sin)->sin_addr.s_addr = INADDR_ANY; /* XXX: htonl(??) */
2457 +#endif
2458 +      ((struct sockaddr_in *)&our_query_sin)->sin_port = htons(ANY_PORT);
2459 +      o_our_port = ntohs(((struct sockaddr_in *)our_sin)->sin_port);
2460 +      ((struct sockaddr_in *)&rmt_query_sin)->sin_port = htons(RFC1413_PORT);
2461 +      o_rmt_port = ntohs(((struct sockaddr_in *)rmt_sin)->sin_port);
2462 +      break;
2463 +#ifdef INET6
2464 +    case AF_INET6:
2465 +#ifdef MPE
2466 +      memcpy(&((struct sockaddr_in6 *)&our_query_sin)->sin6_addr, 
2467 +            &in6addr_any, sizeof(struct in6_addr));
2468 +#endif
2469 +      ((struct sockaddr_in6 *)&our_query_sin)->sin6_port = htons(ANY_PORT);
2470 +      o_our_port = ntohs(((struct sockaddr_in6 *)our_sin)->sin6_port);
2471 +      ((struct sockaddr_in6 *)&rmt_query_sin)->sin6_port = htons(RFC1413_PORT);
2472 +      o_rmt_port = ntohs(((struct sockaddr_in6 *)rmt_sin)->sin6_port);
2473 +      break;
2474 +#endif
2475 +    default:
2476 +      /* unsupported AF */
2477 +      return -1;
2478 +    }
2479  
2480      if (bind(sock, (struct sockaddr *) &our_query_sin,
2481 -            sizeof(struct sockaddr_in)) < 0) {
2482 +#ifndef SIN6_LEN
2483 +            SA_LEN((struct sockaddr *) &our_query_sin)
2484 +#else
2485 +            our_query_sin.ss_len
2486 +#endif
2487 +            ) < 0) {
2488         ap_log_error(APLOG_MARK, APLOG_CRIT, srv,
2489                     "bind: rfc1413: Error binding to local port");
2490         return -1;
2491 @@ -149,12 +182,18 @@
2492   * the service
2493   */
2494      if (connect(sock, (struct sockaddr *) &rmt_query_sin,
2495 -               sizeof(struct sockaddr_in)) < 0)
2496 -                   return -1;
2497 +#ifndef SIN6_LEN
2498 +               SA_LEN((struct sockaddr *) &rmt_query_sin)
2499 +#else
2500 +               rmt_query_sin.ss_len
2501 +#endif
2502 +               ) < 0) {
2503 +       return -1;
2504 +    }
2505  
2506  /* send the data */
2507 -    buflen = ap_snprintf(buffer, sizeof(buffer), "%u,%u\r\n", ntohs(rmt_sin->sin_port),
2508 -               ntohs(our_sin->sin_port));
2509 +    buflen = ap_snprintf(buffer, sizeof(buffer), "%u,%u\r\n", o_rmt_port,
2510 +               o_our_port);
2511  
2512      /* send query to server. Handle short write. */
2513  #ifdef CHARSET_EBCDIC
2514 @@ -219,9 +258,9 @@
2515      ascii2ebcdic(buffer, buffer, (size_t)i);
2516  #endif
2517      if (sscanf(buffer, "%u , %u : USERID :%*[^:]:%512s", &rmt_port, &our_port,
2518 -              user) != 3 || ntohs(rmt_sin->sin_port) != rmt_port
2519 -       || ntohs(our_sin->sin_port) != our_port)
2520 +              user) != 3 || o_rmt_port != rmt_port || o_our_port != our_port) {
2521         return -1;
2522 +    }
2523  
2524      /*
2525       * Strip trailing carriage return. It is part of the
2526 @@ -243,7 +282,7 @@
2527  
2528      result = FROM_UNKNOWN;
2529  
2530 -    sock = ap_psocket_ex(conn->pool, AF_INET, SOCK_STREAM, IPPROTO_TCP, 1);
2531 +    sock = ap_psocket_ex(conn->pool, conn->remote_addr.ss_family, SOCK_STREAM, IPPROTO_TCP, 1);
2532      if (sock < 0) {
2533         ap_log_error(APLOG_MARK, APLOG_CRIT, srv,
2534                     "socket: rfc1413: error creating socket");
2535 @@ -256,8 +295,10 @@
2536      if (ap_setjmp(timebuf) == 0) {
2537         ap_set_callback_and_alarm(ident_timeout, ap_rfc1413_timeout);
2538  
2539 -       if (get_rfc1413(sock, &conn->local_addr, &conn->remote_addr, user, srv) >= 0)
2540 +       if (get_rfc1413(sock, (struct sockaddr *)&conn->local_addr,
2541 +               (struct sockaddr *)&conn->remote_addr, user, srv) >= 0) {
2542             result = user;
2543 +       }
2544      }
2545      ap_set_callback_and_alarm(NULL, 0);
2546      ap_pclosesocket(conn->pool, sock);
2547 diff -Nur apache_1.3.28.orig/src/main/util.c apache_1.3.28/src/main/util.c
2548 --- apache_1.3.28.orig/src/main/util.c  Mon Feb  3 18:13:23 2003
2549 +++ apache_1.3.28/src/main/util.c       Fri Jul 25 11:01:55 2003
2550 @@ -2017,52 +2017,87 @@
2551   * Parses a host of the form <address>[:port]
2552   * :port is permitted if 'port' is not NULL
2553   */
2554 -API_EXPORT(unsigned long) ap_get_virthost_addr(char *w, unsigned short *ports)
2555 +API_EXPORT(struct sockaddr *) ap_get_virthost_addr(char *w, unsigned short *ports)
2556  {
2557 -    struct hostent *hep;
2558 -    unsigned long my_addr;
2559 -    char *p;
2560 -
2561 -    p = strchr(w, ':');
2562 +    static struct sockaddr_storage ss;
2563 +    struct addrinfo hints, *res;
2564 +    char *p, *r;
2565 +    char *host;
2566 +    char *port = "0";
2567 +    int error;
2568 +    char servbuf[NI_MAXSERV];
2569 +
2570 +    if (w == NULL)
2571 +       w = "*";
2572 +    p = r = NULL;
2573 +    if (*w == '['){
2574 +       if (r = strrchr(w+1, ']')){
2575 +           *r = '\0';
2576 +           p = r + 1;
2577 +           switch(*p){
2578 +           case ':':
2579 +             p++;
2580 +             /* nobreak; */
2581 +           case '\0':
2582 +             w++;
2583 +             break;
2584 +           default:
2585 +             p = NULL;
2586 +           }
2587 +       }
2588 +    }
2589 +    else{
2590 +       p = strchr(w, ':');
2591 +       if (p != NULL && strchr(p+1, ':') != NULL)
2592 +           p = NULL;
2593 +    }
2594      if (ports != NULL) {
2595 -       *ports = 0;
2596 -       if (p != NULL && strcmp(p + 1, "*") != 0)
2597 -           *ports = atoi(p + 1);
2598 +       if (p != NULL && *p && strcmp(p + 1, "*") != 0)
2599 +           port = p + 1;
2600      }
2601  
2602 +    memset(&hints, 0, sizeof(hints));
2603 +    hints.ai_socktype = SOCK_STREAM;
2604      if (p != NULL)
2605         *p = '\0';
2606      if (strcmp(w, "*") == 0) {
2607 -       if (p != NULL)
2608 -           *p = ':';
2609 -       return htonl(INADDR_ANY);
2610 -    }
2611 -
2612 -    my_addr = ap_inet_addr((char *)w);
2613 -    if (my_addr != INADDR_NONE) {
2614 -       if (p != NULL)
2615 -           *p = ':';
2616 -       return my_addr;
2617 +       host = NULL;
2618 +       hints.ai_flags = AI_PASSIVE;
2619 +       hints.ai_family = ap_default_family;
2620 +    } else {
2621 +       host = w;
2622 +       hints.ai_family = PF_UNSPEC;
2623      }
2624  
2625 -    hep = gethostbyname(w);
2626 +    error = getaddrinfo(host, port, &hints, &res);
2627  
2628 -    if ((!hep) || (hep->h_addrtype != AF_INET || !hep->h_addr_list[0])) {
2629 -       fprintf(stderr, "Cannot resolve host name %s --- exiting!\n", w);
2630 +    if (error || !res) {
2631 +       fprintf(stderr, "ap_get_vitrhost_addr(): getaddrinfo(%s):%s --- exiting!\n", w, gai_strerror(error));
2632         exit(1);
2633      }
2634  
2635 -    if (hep->h_addr_list[1]) {
2636 -       fprintf(stderr, "Host %s has multiple addresses ---\n", w);
2637 +    if (res->ai_next) {
2638 +       fprintf(stderr, "ap_get_vitrhost_addr(): Host %s has multiple addresses ---\n", w);
2639         fprintf(stderr, "you must choose one explicitly for use as\n");
2640         fprintf(stderr, "a virtual host.  Exiting!!!\n");
2641         exit(1);
2642      }
2643  
2644 +    if (r != NULL)
2645 +       *r = ']';
2646      if (p != NULL)
2647         *p = ':';
2648  
2649 -    return ((struct in_addr *) (hep->h_addr))->s_addr;
2650 +    memcpy(&ss, res->ai_addr, res->ai_addrlen);
2651 +    if (getnameinfo(res->ai_addr, res->ai_addrlen,
2652 +                   NULL, 0, servbuf, sizeof(servbuf),
2653 +                   NI_NUMERICSERV)){
2654 +       fprintf(stderr, "ap_get_virthost_addr(): getnameinfo() failed --- Exiting!!!\n");
2655 +       exit(1);
2656 +    }
2657 +    if (ports) *ports = atoi(servbuf);
2658 +    freeaddrinfo(res);
2659 +    return (struct sockaddr *)&ss;
2660  }
2661  
2662  
2663 @@ -2090,7 +2125,8 @@
2664  #endif
2665      char str[MAXHOSTNAMELEN];
2666      char *server_hostname = NULL;
2667 -    struct hostent *p;
2668 +    struct addrinfo hints, *res;
2669 +    int error;
2670  
2671  #ifdef BEOS /* BeOS returns zero as an error for gethostname */
2672      if (gethostname(str, sizeof(str) - 1) == 0) {
2673 @@ -2103,29 +2139,38 @@
2674      }
2675      else 
2676      {
2677 -        str[sizeof(str) - 1] = '\0';
2678 -        if ((!(p = gethostbyname(str))) 
2679 -            || (!(server_hostname = find_fqdn(a, p)))) {
2680 -            /* Recovery - return the default servername by IP: */
2681 -            if (p && p->h_addr_list && p->h_addr_list[0]) {
2682 -                ap_snprintf(str, sizeof(str), "%pA", p->h_addr_list[0]);
2683 -               server_hostname = ap_pstrdup(a, str);
2684 -                /* We will drop through to report the IP-named server */
2685 -            }
2686 -        }
2687 -       else
2688 -            /* Since we found a fqdn, return it with no logged message. */
2689 -            return server_hostname;
2690 -    }
2691 -
2692 -    /* If we don't have an fdqn or IP, fall back to the loopback addr */
2693 -    if (!server_hostname) 
2694 -        server_hostname = ap_pstrdup(a, "127.0.0.1");
2695 -    
2696 -    ap_log_error(APLOG_MARK, APLOG_ALERT|APLOG_NOERRNO, NULL,
2697 -                "%s: Could not determine the server's fully qualified "
2698 -                 "domain name, using %s for ServerName",
2699 -                 ap_server_argv0, server_hostname);
2700 +       str[sizeof(str) - 1] = '\0';
2701 +       memset(&hints, 0, sizeof(hints));
2702 +       hints.ai_family = PF_UNSPEC;
2703 +       hints.ai_flags = AI_CANONNAME;
2704 +       error = getaddrinfo(str, NULL, &hints, &res);
2705 +       if (error)
2706 +       {
2707 +              /* Recovery - return the default servername by IP: */
2708 +
2709 +           fprintf(stderr, "%s: cannot determine local host name.\n",
2710 +                 ap_server_argv0);
2711 +           fprintf(stderr, "Use the ServerName directive to set it manually.\n");
2712 +           exit(1);
2713 +
2714 +           server_hostname = ap_pstrdup(a, res->ai_canonname);
2715 +       }
2716 +       else if (1)     /*fqdn found*/
2717 +       {
2718 +           /* XXX should check more conditions */
2719 +           server_hostname = ap_pstrdup(a, res->ai_canonname);
2720 +       }
2721 +        else
2722 +       {
2723 +           ap_log_error(APLOG_MARK, APLOG_ALERT|APLOG_NOERRNO, NULL,
2724 +                        "%s: Could not determine the server's fully qualified "
2725 +                        "domain name, using %s for ServerName",
2726 +                        ap_server_argv0, server_hostname);
2727 +       }
2728 +
2729 +       /* Since we found a fdqn, return it with no logged message. */
2730 +       freeaddrinfo(res);
2731 +      }
2732      
2733      return server_hostname;
2734  }
2735 @@ -2369,3 +2414,11 @@
2736      }
2737      *dest = 0;
2738  }
2739 +
2740 +#ifdef NEED_GETADDRINFO
2741 +#include "getaddrinfo.c"
2742 +#endif
2743 +
2744 +#ifdef NEED_GETNAMEINFO
2745 +#include "getnameinfo.c"
2746 +#endif
2747 diff -Nur apache_1.3.28.orig/src/main/util_script.c apache_1.3.28/src/main/util_script.c
2748 --- apache_1.3.28.orig/src/main/util_script.c   Mon Feb  3 18:13:23 2003
2749 +++ apache_1.3.28/src/main/util_script.c        Fri Jul 25 11:01:55 2003
2750 @@ -67,6 +67,7 @@
2751  #include "http_request.h"      /* for sub_req_lookup_uri() */
2752  #include "util_script.h"
2753  #include "util_date.h"         /* For parseHTTPdate() */
2754 +#include "sa_len.h"
2755  
2756  #ifdef OS2
2757  #define INCL_DOS
2758 @@ -203,6 +204,7 @@
2759      array_header *hdrs_arr = ap_table_elts(r->headers_in);
2760      table_entry *hdrs = (table_entry *) hdrs_arr->elts;
2761      int i;
2762 +    char servbuf[NI_MAXSERV];
2763  
2764      /* use a temporary table which we'll overlap onto
2765       * r->subprocess_env later
2766 @@ -294,8 +296,16 @@
2767      ap_table_addn(e, "SERVER_ADMIN", s->server_admin); /* Apache */
2768      ap_table_addn(e, "SCRIPT_FILENAME", r->filename);  /* Apache */
2769  
2770 -    ap_table_addn(e, "REMOTE_PORT",
2771 -                 ap_psprintf(r->pool, "%d", ntohs(c->remote_addr.sin_port)));
2772 +    servbuf[0] = '\0';
2773 +    if (!getnameinfo((struct sockaddr *)&c->remote_addr,
2774 +#ifndef HAVE_SOCKADDR_LEN
2775 +                    SA_LEN((struct sockaddr *)&c->remote_addr),
2776 +#else
2777 +                    c->remote_addr.ss_len,
2778 +#endif
2779 +                    NULL, 0, servbuf, sizeof(servbuf), NI_NUMERICSERV)){
2780 +       ap_table_addn(e, "REMOTE_PORT", ap_pstrdup(r->pool, servbuf));
2781 +    }
2782  
2783      if (c->user) {
2784         ap_table_addn(e, "REMOTE_USER", c->user);
2785 diff -Nur apache_1.3.28.orig/src/main/util_uri.c apache_1.3.28/src/main/util_uri.c
2786 --- apache_1.3.28.orig/src/main/util_uri.c      Mon Feb  3 18:13:24 2003
2787 +++ apache_1.3.28/src/main/util_uri.c   Fri Jul 25 11:01:55 2003
2788 @@ -424,6 +424,12 @@
2789           * the hostname.  If there's a port it is the first colon.
2790           */
2791          s = memchr(hostinfo, ':', uri - hostinfo);
2792 +       if (*hostinfo == '[') {
2793 +           s = memchr(hostinfo+1, ']', uri - hostinfo - 1);
2794 +           if (s)
2795 +               s = strchr(s, ':');
2796 +       } else
2797 +           s = memchr(hostinfo, ':', uri - hostinfo);              
2798          if (s == NULL) {
2799              /* we expect the common case to have no port */
2800              uptr->hostname = ap_pstrndup(p, hostinfo, uri - hostinfo);
2801 @@ -480,7 +486,12 @@
2802      /* We expect hostinfo to point to the first character of
2803       * the hostname.  There must be a port, separated by a colon
2804       */
2805 -    s = strchr(hostinfo, ':');
2806 +    if (*hostinfo == '[') {
2807 +        s = strchr(hostinfo+1, ']');
2808 +        if (s)
2809 +            s = strchr(s, ':');
2810 +    } else
2811 +        s = strchr(hostinfo, ':');
2812      if (s == NULL) {
2813          return HTTP_BAD_REQUEST;
2814      }
2815 diff -Nur apache_1.3.28.orig/src/modules/proxy/mod_proxy.c apache_1.3.28/src/modules/proxy/mod_proxy.c
2816 --- apache_1.3.28.orig/src/modules/proxy/mod_proxy.c    Fri Jul 25 11:00:49 2003
2817 +++ apache_1.3.28/src/modules/proxy/mod_proxy.c Fri Jul 25 11:01:55 2003
2818 @@ -574,11 +574,31 @@
2819      struct proxy_remote *new;
2820      char *p, *q;
2821      int port;
2822 +    char *bl = NULL, *br = NULL;
2823  
2824      p = strchr(r, ':');
2825      if (p == NULL || p[1] != '/' || p[2] != '/' || p[3] == '\0')
2826          return "ProxyRemote: Bad syntax for a remote proxy server";
2827 -    q = strchr(p + 3, ':');
2828 +    bl = p + 3;
2829 +    if (*bl == '['){
2830 +       br = strrchr(bl+1, ']');
2831 +       if (br){
2832 +           bl++;
2833 +           *br = '\0';
2834 +           if (*(br+1) == ':'){        /* [host]:xx */
2835 +               q = br+1;
2836 +           }
2837 +           else if (*(br+1) == '\0'){  /* [host] */
2838 +               q = NULL;
2839 +           }
2840 +           else
2841 +               q = strrchr(br, ':');   /* XXX */
2842 +       }
2843 +       else
2844 +           q = strrchr(bl, ':');       /* XXX */
2845 +    }
2846 +    else
2847 +       q = strrchr(bl, ':');
2848      if (q != NULL) {
2849          if (sscanf(q + 1, "%u", &port) != 1 || port > 65535)
2850              return "ProxyRemote: Bad syntax for a remote proxy server (bad port number)";
2851 @@ -589,7 +609,7 @@
2852      *p = '\0';
2853      if (strchr(f, ':') == NULL)
2854          ap_str_tolower(f);      /* lowercase scheme */
2855 -    ap_str_tolower(p + 3);      /* lowercase hostname */
2856 +    ap_str_tolower(bl);         /* lowercase hostname */
2857  
2858      if (port == -1) {
2859          int i;
2860 @@ -602,7 +622,7 @@
2861      new = ap_push_array(conf->proxies);
2862      new->scheme = f;
2863      new->protocol = r;
2864 -    new->hostname = p + 3;
2865 +    new->hostname = bl;
2866      new->port = port;
2867      return NULL;
2868  }
2869 diff -Nur apache_1.3.28.orig/src/modules/proxy/mod_proxy.h apache_1.3.28/src/modules/proxy/mod_proxy.h
2870 --- apache_1.3.28.orig/src/modules/proxy/mod_proxy.h    Mon Feb  3 18:13:26 2003
2871 +++ apache_1.3.28/src/modules/proxy/mod_proxy.h Fri Jul 25 11:01:55 2003
2872 @@ -310,7 +310,7 @@
2873  int ap_proxy_is_domainname(struct dirconn_entry *This, pool *p);
2874  int ap_proxy_is_hostname(struct dirconn_entry *This, pool *p);
2875  int ap_proxy_is_word(struct dirconn_entry *This, pool *p);
2876 -int ap_proxy_doconnect(int sock, struct sockaddr_in *addr, request_rec *r);
2877 +int ap_proxy_doconnect(int sock, struct sockaddr *addr, request_rec *r);
2878  int ap_proxy_garbage_init(server_rec *, pool *);
2879  /* This function is called by ap_table_do() for all header lines */
2880  int ap_proxy_send_hdr_line(void *p, const char *key, const char *value);
2881 diff -Nur apache_1.3.28.orig/src/modules/proxy/proxy_connect.c apache_1.3.28/src/modules/proxy/proxy_connect.c
2882 --- apache_1.3.28.orig/src/modules/proxy/proxy_connect.c        Mon Feb  3 18:13:26 2003
2883 +++ apache_1.3.28/src/modules/proxy/proxy_connect.c     Fri Jul 25 11:27:12 2003
2884 @@ -113,14 +113,15 @@
2885                                   const char *proxyhost, int proxyport)
2886  {
2887      struct sockaddr_in server;
2888 -    struct in_addr destaddr;
2889 -    struct hostent server_hp;
2890 -    const char *host, *err;
2891 +    struct addrinfo hints, *res, *res0;
2892 +    const char *hoststr;
2893 +    const char *portstr = NULL;
2894      char *p;
2895      int port, sock;
2896      char buffer[HUGE_STRING_LEN];
2897 -    int nbytes, i, j;
2898 +    int nbytes, i;
2899      fd_set fds;
2900 +    int error;
2901  
2902      void *sconf = r->server->module_config;
2903      proxy_server_conf *conf =
2904 @@ -128,27 +129,59 @@
2905      struct noproxy_entry *npent = (struct noproxy_entry *) conf->noproxies->elts;
2906  
2907      memset(&server, '\0', sizeof(server));
2908 +#ifdef HAVE_SOCKADDR_LEN
2909 +    server.sin_len = sizeof(server);
2910 +#endif
2911      server.sin_family = AF_INET;
2912  
2913      /* Break the URL into host:port pairs */
2914  
2915 -    host = url;
2916 +    hoststr = url;
2917      p = strchr(url, ':');
2918 -    if (p == NULL)
2919 -        port = DEFAULT_HTTPS_PORT;
2920 -    else {
2921 -        port = atoi(p + 1);
2922 +    if (p == NULL) {
2923 +       char pbuf[32];
2924 +       ap_snprintf(pbuf, sizeof(pbuf), "%d", DEFAULT_HTTPS_PORT);
2925 +       portstr = pbuf;
2926 +    } else {
2927 +       portstr = p + 1;
2928          *p = '\0';
2929      }
2930 +    port = atoi(portstr);
2931 +
2932 +    memset(&hints, 0, sizeof(hints));
2933 +    hints.ai_family = PF_UNSPEC;
2934 +    hints.ai_socktype = SOCK_STREAM;
2935 +    hints.ai_protocol = IPPROTO_TCP;
2936 +    error = getaddrinfo(hoststr, portstr, &hints, &res0);
2937 +    if (error) {
2938 +       return ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR,
2939 +                   gai_strerror(error));       /* give up */
2940 +    }
2941  
2942  /* check if ProxyBlock directive on this host */
2943 -    destaddr.s_addr = ap_inet_addr(host);
2944 -    for (i = 0; i < conf->noproxies->nelts; i++) {
2945 -        if ((npent[i].name != NULL && strstr(host, npent[i].name) != NULL)
2946 -            || destaddr.s_addr == npent[i].addr.s_addr
2947 -            || npent[i].name[0] == '*')
2948 +    for (res = res0; res; res = res = res->ai_next) {
2949 +       struct sockaddr_in *sin;
2950 +       int fail;
2951 +
2952 +       fail = 0;
2953 +       for (i = 0; i < conf->noproxies->nelts; i++) {
2954 +           if (npent[i].name != NULL && strstr(hoststr, npent[i].name))
2955 +               fail++;
2956 +           if (npent[i].name != NULL && strcmp(npent[i].name, "*") == 0)
2957 +               fail++;
2958 +           switch (res->ai_family) {
2959 +           case AF_INET:
2960 +               sin = (struct sockaddr_in *)res->ai_addr;
2961 +               if (sin->sin_addr.s_addr == npent[i].addr.s_addr)
2962 +                   fail++;
2963 +               break;
2964 +           }
2965 +       }
2966 +       if (fail) {
2967 +           freeaddrinfo(res0);
2968              return ap_proxyerror(r, HTTP_FORBIDDEN,
2969                                   "Connect to remote machine blocked");
2970 +       }
2971      }
2972  
2973      /* Check if it is an allowed port */
2974 @@ -159,34 +192,42 @@
2975          case DEFAULT_SNEWS_PORT:
2976              break;
2977          default:
2978 +           freeaddrinfo(res0);
2979              return HTTP_FORBIDDEN;
2980          }
2981      }
2982 -    else if (!allowed_port(conf, port))
2983 +    else if (!allowed_port(conf, port)) {
2984 +       freeaddrinfo(res0);
2985          return HTTP_FORBIDDEN;
2986 +    }
2987  
2988      if (proxyhost) {
2989 +       char pbuf[10];
2990 +
2991 +       freeaddrinfo(res0);
2992 +
2993 +       ap_snprintf(pbuf, sizeof(pbuf), "%d", proxyport);
2994 +       memset(&hints, 0, sizeof(hints));
2995 +       hints.ai_family = PF_UNSPEC;
2996 +       hints.ai_socktype = SOCK_STREAM;
2997 +       hints.ai_protocol = IPPROTO_TCP;
2998 +       error = getaddrinfo(proxyhost, pbuf, &hints, &res0);
2999 +       if (error)
3000 +           return HTTP_INTERNAL_SERVER_ERROR;  /* XXX */
3001 +
3002          ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
3003               "CONNECT to remote proxy %s on port %d", proxyhost, proxyport);
3004      }
3005      else {
3006          ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
3007 -                     "CONNECT to %s on port %d", host, port);
3008 +                     "CONNECT to %s on port %d", hoststr, port);
3009      }
3010  
3011 -    /* Nasty cast to work around broken terniary expressions on MSVC */
3012 -    server.sin_port = htons((unsigned short)(proxyport ? proxyport : port));
3013 -    err = ap_proxy_host2addr(proxyhost ? proxyhost : host, &server_hp);
3014 -
3015 -    if (err != NULL)
3016 -        return ap_proxyerror(r,
3017 -            proxyhost ? HTTP_BAD_GATEWAY : HTTP_INTERNAL_SERVER_ERROR, err);
3018 -
3019 -    sock = ap_psocket_ex(r->pool, PF_INET, SOCK_STREAM, IPPROTO_TCP, 1);
3020 -    if (sock == -1) {
3021 -        ap_log_rerror(APLOG_MARK, APLOG_ERR, r, "proxy: error creating socket");
3022 -        return HTTP_INTERNAL_SERVER_ERROR;
3023 -    }
3024 +    sock = i = -1;
3025 +    for (res = res0; res; res = res->ai_next) {
3026 +       sock = ap_psocket_ex(r->pool, res->ai_family, res->ai_socktype, res->ai_protocol, 1);
3027 +       if (sock == -1)
3028 +           continue;
3029  
3030  #ifdef CHECK_FD_SETSIZE
3031      if (sock >= FD_SETSIZE) {
3032 @@ -196,19 +237,15 @@
3033                       "found, you probably need to rebuild Apache with a "
3034                       "larger FD_SETSIZE", sock, FD_SETSIZE);
3035          ap_pclosesocket(r->pool, sock);
3036 -        return HTTP_INTERNAL_SERVER_ERROR;
3037 +       continue;
3038      }
3039  #endif
3040  
3041 -    j = 0;
3042 -    while (server_hp.h_addr_list[j] != NULL) {
3043 -        memcpy(&server.sin_addr, server_hp.h_addr_list[j],
3044 -               sizeof(struct in_addr));
3045 -        i = ap_proxy_doconnect(sock, &server, r);
3046 +       i = ap_proxy_doconnect(sock, res->ai_addr, r);
3047          if (i == 0)
3048              break;
3049 -        j++;
3050      }
3051 +    freeaddrinfo(res0);
3052      if (i == -1) {
3053          ap_pclosesocket(r->pool, sock);
3054          return ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR, ap_pstrcat(r->pool,
3055 diff -Nur apache_1.3.28.orig/src/modules/proxy/proxy_ftp.c apache_1.3.28/src/modules/proxy/proxy_ftp.c
3056 --- apache_1.3.28.orig/src/modules/proxy/proxy_ftp.c    Mon Feb  3 18:13:26 2003
3057 +++ apache_1.3.28/src/modules/proxy/proxy_ftp.c Fri Jul 25 11:18:38 2003
3058 @@ -62,6 +62,7 @@
3059  #include "http_main.h"
3060  #include "http_log.h"
3061  #include "http_core.h"
3062 +#include "sa_len.h"
3063  
3064  #define AUTODETECT_PWD
3065  
3066 @@ -555,8 +556,10 @@
3067      const char *err;
3068      int port, 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;
3074 +    char portbuf[10];
3075 +    int error;
3076      struct in_addr destaddr;
3077      table *resp_hdrs;
3078      BUFF *ctrl = NULL;
3079 @@ -577,11 +580,18 @@
3080      unsigned int presult, h0, h1, h2, h3, p0, p1;
3081      unsigned int paddr;
3082      unsigned short pport;
3083 -    struct sockaddr_in data_addr;
3084 +    struct sockaddr_storage data_addr;
3085 +    struct sockaddr_in *sin;
3086      int pasvmode = 0;
3087      char pasv[64];
3088      char *pstr;
3089  
3090 +/* stuff for LPSV/EPSV */
3091 +    unsigned int paf, holen, ho[16], polen, po[2];
3092 +    struct sockaddr_in6 *sin6;
3093 +    int lpsvmode = 0;
3094 +    char *cmd;
3095 +
3096  /* stuff for responses */
3097      char resp[MAX_STRING_LEN];
3098      char *size = NULL;
3099 @@ -658,62 +668,50 @@
3100      if (parms != NULL)
3101          *(parms++) = '\0';
3102  
3103 -    memset(&server, 0, sizeof(struct sockaddr_in));
3104 -    server.sin_family = AF_INET;
3105 -    server.sin_port = htons((unsigned short)port);
3106 -    err = ap_proxy_host2addr(host, &server_hp);
3107 -    if (err != NULL)
3108 -        return ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR, err);
3109 -
3110 -    sock = ap_psocket_ex(p, PF_INET, SOCK_STREAM, IPPROTO_TCP, 1);
3111 -    if (sock == -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", port);
3116 +    memset(&hints, 0, sizeof(hints));
3117 +    hints.ai_family = PF_UNSPEC;
3118 +    hints.ai_socktype = SOCK_STREAM;
3119 +    error = getaddrinfo(host, portbuf, &hints, &res0);
3120 +    if (error) {
3121 +        return ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR, gai_strerror(error));
3122      }
3123  
3124 +    i = -1;
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);
3128 +       if (sock == -1)
3129 +           continue;
3130 +
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))
3135 -        == -1) {
3136 -        ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
3137 -                      "setsockopt(SO_RCVBUF): Failed to set ProxyReceiveBufferSize, using default");
3138 -    }
3139 +        if (conf->recv_buffer_size > 0
3140 +            && setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
3141 +                          (const char *)&conf->recv_buffer_size, sizeof(int))
3142 +            == -1) {
3143 +            ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
3144 +                          "setsockopt(SO_RCVBUF): Failed to set ProxyReceiveBufferSize, using default");
3145 +        }
3146  #endif
3147  
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 */
3163 -    }
3164 -
3165 -#ifdef SINIX_D_RESOLVER_BUG
3166 -    {
3167 -        struct in_addr *ip_addr = (struct in_addr *)*server_hp.h_addr_list;
3168 -
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);
3172 -            if (i == 0)
3173 -                break;
3174          }
3175 -    }
3176 -#else
3177 -    j = 0;
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);
3182 -        if (i == 0)
3183 +        i = ap_proxy_doconnect(sock, res->ai_addr, r);
3184 +        if (i == 0) {
3185 +           memcpy(&server, res->ai_addr, res->ai_addrlen);
3186              break;
3187 -        j++;
3188 +       }
3189 +       ap_pclosesocket(p, sock);
3190      }
3191 -#endif
3192 +    freeaddrinfo(res0);
3193      if (i == -1) {
3194          return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
3195                        ap_proxyerror(r, HTTP_BAD_GATEWAY, ap_pstrcat(r->pool,
3196 @@ -944,7 +942,7 @@
3197      }
3198  
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);
3202      if (dsock == -1) {
3203          return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
3204                                  ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR,
3205 @@ -961,11 +959,22 @@
3206      }
3207  #endif
3208  
3209 -    ap_bputs("PASV" CRLF, ctrl);
3210 +lpsvagain:
3211 +    if (server.ss_family == AF_INET)
3212 +       cmd = "PASV";
3213 +    else if (lpsvmode)
3214 +       cmd = "LPSV";
3215 +    else
3216 +       cmd = "EPSV";
3217 +    ap_bputs(cmd, ctrl);
3218 +    ap_bputs(CRLF, ctrl);
3219      ap_bflush(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. */
3230 @@ -976,7 +985,7 @@
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)));
3236      }
3237      else {
3238          pasv[i - 1] = '\0';
3239 @@ -1004,10 +1013,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;
3249 +#ifdef SIN6_LEN
3250 +           sin->sin_len = sizeof(*sin);
3251 +#endif
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);
3255  
3256              if (i == -1) {
3257                  return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
3258 @@ -1017,6 +1030,64 @@
3259                                                     strerror(errno), NULL)));
3260              }
3261              pasvmode = 1;
3262 +       } else if (presult == 228 && pstr != NULL
3263 +               && sscanf(pstr,
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) {
3269 +           int i;
3270 +           sin6 = (struct sockaddr_in6 *)&data_addr;
3271 +           sin6->sin6_family = AF_INET6;
3272 +#ifdef SIN6_LEN
3273 +           sin6->sin6_len = sizeof(*sin6);
3274 +#endif
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);
3279 +
3280 +           if (i == -1) {
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)));
3286 +           }
3287 +           pasvmode = 1;
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|" */
3292 +#ifndef SIN6_LEN
3293 +           memcpy(&data_addr, &server, SA_LEN((struct sockaddr *)&server));
3294 +#else
3295 +           memcpy(&data_addr, &server, server.ss_len);
3296 +#endif
3297 +           switch (data_addr.ss_family) {
3298 +           case AF_INET:
3299 +               sin = (struct sockaddr_in *)&data_addr;
3300 +               sin->sin_port = htons(atoi(pstr + 3));
3301 +               break;
3302 +           case AF_INET6:
3303 +               sin6 = (struct sockaddr_in6 *)&data_addr;
3304 +               sin6->sin6_port = htons(atoi(pstr + 3));
3305 +               break;
3306 +           }
3307 +           i = ap_proxy_doconnect(dsock, (struct sockaddr *)&data_addr, r);
3308 +
3309 +           if (i == -1) {
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)));
3315 +           }
3316 +           pasvmode = 1;
3317 +       } else if (!lpsvmode && strcmp(cmd, "EPSV") == 0) {
3318 +           lpsvmode = 1;
3319 +           goto lpsvagain;
3320          }
3321          else {
3322              ap_pclosesocket(p, dsock);  /* and try the regular way */
3323 @@ -1025,14 +1096,14 @@
3324      }
3325  
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"));
3333          }
3334  
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);
3337          if (dsock == -1) {
3338              return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
3339                                  ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR,
3340 @@ -1048,13 +1119,28 @@
3341  #endif                          /* _OSD_POSIX */
3342          }
3343  
3344 -        if (bind(dsock, (struct sockaddr *)&server,
3345 -                 sizeof(struct sockaddr_in)) == -1) {
3346 +#ifndef SIN6_LEN
3347 +       if (bind(dsock, (struct sockaddr *)&server, SA_LEN((struct sockaddr *)&server)) == -1)
3348 +#else
3349 +       if (bind(dsock, (struct sockaddr *)&server, server.ss_len) == -1)
3350 +#endif
3351 +       {
3352 +           char hostnamebuf[MAXHOSTNAMELEN], portnamebuf[MAXHOSTNAMELEN];
3353 +
3354 +           getnameinfo((struct sockaddr *)&server,
3355 +#ifndef SIN6_LEN
3356 +                   SA_LEN((struct sockaddr *)&server),
3357 +#else
3358 +                   server.ss_len,
3359 +#endif
3360 +               hostnamebuf, sizeof(hostnamebuf),
3361 +               portnamebuf, sizeof(portnamebuf),
3362 +               NI_NUMERICHOST | NI_NUMERICSERV);
3363  
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)));
3370          }
3371          listen(dsock, 2);       /* only need a short queue */
3372      }
3373 @@ -1308,7 +1394,7 @@
3374  
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);
3379          do
3380              csd = accept(dsock, (struct sockaddr *)&server, &clen);
3381          while (csd == -1 && errno == EINTR);
3382 diff -Nur apache_1.3.28.orig/src/modules/proxy/proxy_http.c apache_1.3.28/src/modules/proxy/proxy_http.c
3383 --- apache_1.3.28.orig/src/modules/proxy/proxy_http.c   Fri Jul 25 11:00:49 2003
3384 +++ apache_1.3.28/src/modules/proxy/proxy_http.c        Fri Jul 25 11:25:37 2003
3385 @@ -156,9 +156,8 @@
3386      table *req_hdrs, *resp_hdrs;
3387      array_header *reqhdrs_arr;
3388      table_entry *reqhdrs_elts;
3389 -    struct sockaddr_in server;
3390 -    struct in_addr destaddr;
3391 -    struct hostent server_hp;
3392 +    struct addrinfo hints, *res, *res0;
3393 +    int error;
3394      BUFF *f;
3395      char buffer[HUGE_STRING_LEN];
3396      char portstr[32];
3397 @@ -184,9 +183,6 @@
3398      if (conf->cache.root == NULL)
3399          nocache = 1;
3400  
3401 -    memset(&server, '\0', sizeof(server));
3402 -    server.sin_family = AF_INET;
3403 -
3404      /* We break the URL into host, port, path-search */
3405  
3406      urlptr = strstr(url, "://");
3407 @@ -194,6 +190,8 @@
3408          return HTTP_BAD_REQUEST;
3409      urlptr += 3;
3410      destport = DEFAULT_HTTP_PORT;
3411 +    ap_snprintf(portstr, sizeof(portstr), "%d", DEFAULT_HTTP_PORT);
3412 +    destportstr = portstr;           
3413  #ifdef EAPI
3414      ap_hook_use("ap::mod_proxy::http::handler::set_destport", 
3415                  AP_HOOK_SIG2(int,ptr), 
3416 @@ -212,7 +210,20 @@
3417          urlptr = strp;
3418          desthost = q;
3419      }
3420 -
3421 +   if (*desthost == '['){
3422 +       char *u = strrchr(desthost+1, ']');
3423 +       if (u){
3424 +          desthost++;
3425 +          *u = '\0';
3426 +          if (*(u+1) == ':'){ /* [host]:xx */
3427 +              strp2 = u+1;
3428 +          } else if (*(u+1) == '\0'){   /* [host] */
3429 +              strp2 = NULL;
3430 +          } else
3431 +              return HTTP_BAD_REQUEST;
3432 +       } else
3433 +           return HTTP_BAD_REQUEST;
3434 +   } else
3435      strp2 = strchr(desthost, ':');
3436      if (strp2 != NULL) {
3437          *(strp2++) = '\0';
3438 @@ -222,46 +233,71 @@
3439          }
3440      }
3441  
3442 +    memset(&hints, 0, sizeof(hints));
3443 +    hints.ai_family = PF_UNSPEC;
3444 +    hints.ai_socktype = SOCK_STREAM;
3445 +    hints.ai_protocol = IPPROTO_TCP;
3446 +    error = getaddrinfo(desthost, destportstr, &hints, &res0);
3447 +    if (error) {
3448 +        return ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR,
3449 +               gai_strerror(error));       /* give up */
3450 +    }
3451 +    
3452      /* check if ProxyBlock directive on this host */
3453 -    destaddr.s_addr = ap_inet_addr(desthost);
3454 -    for (i = 0; i < conf->noproxies->nelts; i++) {
3455 -        if (destaddr.s_addr == npent[i].addr.s_addr ||
3456 -            (npent[i].name != NULL &&
3457 -             (npent[i].name[0] == '*' || strstr(desthost, npent[i].name) != NULL)))
3458 +    for (res = res0; res; res = res->ai_next) {
3459 +        struct sockaddr_in *sin;
3460 +#ifdef INET6
3461 +        struct sockaddr_in6 *sin6;
3462 +#endif
3463 +        int fail;
3464 +
3465 +        fail = 0;
3466 +        for (i = 0; i < conf->noproxies->nelts; i++) {
3467 +            if (npent[i].name != NULL && strstr(desthost, npent[i].name))
3468 +                fail++;
3469 +            if (npent[i].name != NULL && strcmp(npent[i].name, "*") == 0)
3470 +                fail++;
3471 +            switch (res->ai_family) {
3472 +                case AF_INET:
3473 +                    sin = (struct sockaddr_in *)res->ai_addr;
3474 +                    if (sin->sin_addr.s_addr == npent[i].addr.s_addr)
3475 +                        fail++;
3476 +                    break;
3477 +           }
3478 +        }
3479 +        if (fail) {
3480 +            freeaddrinfo(res0);
3481              return ap_proxyerror(r, HTTP_FORBIDDEN,
3482                                   "Connect to remote machine blocked");
3483 +       }
3484      }
3485  
3486      if (proxyhost != NULL) {
3487 -        server.sin_port = htons((unsigned short)proxyport);
3488 -        err = ap_proxy_host2addr(proxyhost, &server_hp);
3489 -        if (err != NULL)
3490 +        char pbuf[10];
3491 +
3492 +        freeaddrinfo(res0);
3493 +        ap_snprintf(pbuf, sizeof(pbuf), "%d", proxyport);
3494 +        memset(&hints, 0, sizeof(hints));
3495 +        hints.ai_family = PF_UNSPEC;
3496 +        hints.ai_socktype = SOCK_STREAM;
3497 +        hints.ai_protocol = IPPROTO_TCP;
3498 +        error = getaddrinfo(proxyhost, pbuf, &hints, &res0);
3499 +        if (error)
3500              return DECLINED;    /* try another */
3501  #ifdef EAPI
3502         peer = ap_psprintf(p, "%s:%u", proxyhost, proxyport);  
3503  #endif
3504      }
3505 -    else {
3506 -        server.sin_port = htons((unsigned short)destport);
3507 -        err = ap_proxy_host2addr(desthost, &server_hp);
3508 -        if (err != NULL)
3509 -            return ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR, err);
3510 -#ifdef EAPI
3511 -       peer =  ap_psprintf(p, "%s:%u", desthost, destport);  
3512 -#endif
3513 -    }
3514 -
3515  
3516      /*
3517       * we have worked out who exactly we are going to connect to, now make
3518       * that connection...
3519       */
3520 -    sock = ap_psocket_ex(p, PF_INET, SOCK_STREAM, IPPROTO_TCP, 1);
3521 -    if (sock == -1) {
3522 -        ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
3523 -                      "proxy: error creating socket");
3524 -        return HTTP_INTERNAL_SERVER_ERROR;
3525 -    }
3526 +    sock = i = -1;
3527 +    for (res = res0; res; res = res->ai_next) {
3528 +        sock = ap_psocket_ex(p, res->ai_family, res->ai_socktype, res->ai_protocol, 1);
3529 +        if (sock < 0)
3530 +            continue;
3531  
3532  #if !defined(TPF) && !defined(BEOS)
3533      if (conf->recv_buffer_size) {
3534 @@ -274,28 +310,12 @@
3535      }
3536  #endif
3537  
3538 -#ifdef SINIX_D_RESOLVER_BUG
3539 -    {
3540 -        struct in_addr *ip_addr = (struct in_addr *)*server_hp.h_addr_list;
3541 -
3542 -        for (; ip_addr->s_addr != 0; ++ip_addr) {
3543 -            memcpy(&server.sin_addr, ip_addr, sizeof(struct in_addr));
3544 -            i = ap_proxy_doconnect(sock, &server, r);
3545 -            if (i == 0)
3546 -                break;
3547 -        }
3548 -    }
3549 -#else
3550 -    j = 0;
3551 -    while (server_hp.h_addr_list[j] != NULL) {
3552 -        memcpy(&server.sin_addr, server_hp.h_addr_list[j],
3553 -               sizeof(struct in_addr));
3554 -        i = ap_proxy_doconnect(sock, &server, r);
3555 +       i = ap_proxy_doconnect(sock, res->ai_addr, r);
3556          if (i == 0)
3557              break;
3558 -        j++;
3559 +       ap_pclosesocket(p, sock); 
3560      }
3561 -#endif
3562 +    freeaddrinfo(res0);
3563      if (i == -1) {
3564          if (proxyhost != NULL)
3565              return DECLINED;    /* try again another way */
3566 @@ -597,17 +617,30 @@
3567          ap_table_set(resp_hdrs, "Content-Location", proxy_location_reverse_map(r, urlstr));
3568  
3569  /* check if NoCache directive on this host */
3570 +  {
3571 +    struct sockaddr_in *sin;
3572 +#ifdef INET6
3573 +    struct sockaddr_in6 *sin6;
3574 +#endif
3575 +
3576      if (nocache == 0) {
3577          for (i = 0; i < conf->nocaches->nelts; i++) {
3578 -            if (destaddr.s_addr == ncent[i].addr.s_addr ||
3579 -                (ncent[i].name != NULL &&
3580 -                 (ncent[i].name[0] == '*' ||
3581 -                  strstr(desthost, ncent[i].name) != NULL))) {
3582 -                nocache = 1;
3583 -                break;
3584 +           if (ncent[i].name != NULL && 
3585 +               (ncent[i].name[0] == '*' ||
3586 +                strstr(desthost, ncent[i].name) != NULL)) {
3587 +               nocache = 1;
3588 +               break;
3589 +           }
3590 +           switch (res->ai_addr->sa_family) {
3591 +           case AF_INET:
3592 +               sin = (struct sockaddr_in *)res->ai_addr;
3593 +               if (sin->sin_addr.s_addr == ncent[i].addr.s_addr) {
3594 +                   nocache = 1;
3595 +                   break;
3596 +               }
3597              }
3598          }
3599 -
3600 +    }
3601          /*
3602           * update the cache file, possibly even fulfilling the request if it
3603           * turns out a conditional allowed us to serve the object from the
3604 diff -Nur apache_1.3.28.orig/src/modules/proxy/proxy_util.c apache_1.3.28/src/modules/proxy/proxy_util.c
3605 --- apache_1.3.28.orig/src/modules/proxy/proxy_util.c   Mon Feb  3 18:13:26 2003
3606 +++ apache_1.3.28/src/modules/proxy/proxy_util.c        Fri Jul 25 11:01:55 2003
3607 @@ -64,6 +64,7 @@
3608  #include "http_log.h"
3609  #include "util_uri.h"
3610  #include "util_date.h"          /* get ap_checkmask() decl. */
3611 +#include "sa_len.h"
3612  
3613  static int proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r);
3614  static int proxy_match_domainname(struct dirconn_entry *This, request_rec *r);
3615 @@ -219,6 +220,7 @@
3616      int i;
3617      char *strp, *host, *url = *urlp;
3618      char *user = NULL, *password = NULL;
3619 +    char *t = NULL, *u = NULL, *v = NULL;
3620  
3621      if (url[0] != '/' || url[1] != '/')
3622          return "Malformed URL";
3623 @@ -257,11 +259,22 @@
3624          *passwordp = password;
3625      }
3626  
3627 -    strp = strrchr(host, ':');
3628 -    if (strp != NULL) {
3629 -        *(strp++) = '\0';
3630 -
3631 -        for (i = 0; strp[i] != '\0'; i++)
3632 +    v = host;
3633 +    if (*host == '['){
3634 +       u = strrchr(host, ']');
3635 +       if (u){
3636 +           host++;
3637 +           *u = '\0';
3638 +           v = u + 1;
3639 +       }
3640 +    }
3641 +    t = strrchr(v, ':');
3642 +    if (t){
3643 +       *t = '\0';
3644 +       strp = t + 1;
3645 +    }
3646 +    if (strp) {
3647 +       for (i=0; strp[i] != '\0'; i++)
3648              if (!ap_isdigit(strp[i]))
3649                  break;
3650  
3651 @@ -280,17 +293,29 @@
3652          return "Missing host in URL";
3653  /* check hostname syntax */
3654      for (i = 0; host[i] != '\0'; i++)
3655 -        if (!ap_isdigit(host[i]) && host[i] != '.')
3656 +        if (!ap_isdigit(host[i]) && host[i] != '.' && host[i] != ':')
3657              break;
3658      /* must be an IP address */
3659  #if defined(WIN32) || defined(NETWARE) || defined(TPF) || defined(BEOS)
3660      if (host[i] == '\0' && (inet_addr(host) == -1))
3661 +       return "Bad IP address in URL";
3662 +#else
3663 +    if (host[i] == '\0') {
3664 +       struct addrinfo hints, *res0;
3665 +       int gai;
3666 +       memset(&hints, 0, sizeof(hints));
3667 +       hints.ai_family = PF_UNSPEC;
3668 +       hints.ai_flags = AI_NUMERICHOST;
3669 +       if (gai = getaddrinfo(host, NULL, &hints, &res0)) {
3670 +#if 0
3671 +           return gai_strerror(gai);
3672  #else
3673 -    if (host[i] == '\0' && (ap_inet_addr(host) == -1 || inet_network(host) == -1))
3674 +           return "Bad IP address in URL";
3675  #endif
3676 -    {
3677 -        return "Bad IP address in URL";
3678 +       }
3679 +       freeaddrinfo(res0);
3680      }
3681 +#endif
3682  
3683  /*    if (strchr(host,'.') == NULL && domain != NULL)
3684     host = pstrcat(p, host, domain, NULL);
3685 @@ -1359,22 +1384,46 @@
3686      return host != NULL && strstr(host, This->name) != NULL;
3687  }
3688  
3689 -int ap_proxy_doconnect(int sock, struct sockaddr_in *addr, request_rec *r)
3690 +int ap_proxy_doconnect(int sock, struct sockaddr *addr, request_rec *r)
3691  {
3692      int i;
3693 +    int salen;
3694 +    char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV];
3695 +#ifdef NI_WITHSCOPEID
3696 +    const int niflags = NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
3697 +#else
3698 +    const int niflags = NI_NUMERICHOST | NI_NUMERICSERV;
3699 +#endif
3700  
3701      ap_hard_timeout("proxy connect", r);
3702 +#ifdef HAVE_SOCKADDR_LEN
3703 +    salen = addr->sa_len;
3704 +#else
3705 +    switch (addr->sa_family) {
3706 +    case AF_INET6:
3707 +       salen = sizeof(struct sockaddr_in6);
3708 +       break;
3709 +    default:
3710 +       salen = sizeof(struct sockaddr_in);
3711 +       break;
3712 +    }
3713 +#endif
3714      do {
3715 -        i = connect(sock, (struct sockaddr *)addr, sizeof(struct sockaddr_in));
3716 +        i = connect(sock, addr, salen);
3717  #if defined(WIN32) || defined(NETWARE)
3718          if (i == SOCKET_ERROR)
3719              errno = WSAGetLastError();
3720  #endif                          /* WIN32 */
3721      } while (i == -1 && errno == EINTR);
3722      if (i == -1) {
3723 +       if (getnameinfo(addr, salen, hbuf, sizeof(hbuf), pbuf, sizeof(pbuf),
3724 +               niflags) != 0) {
3725 +           strcpy(hbuf, "?");
3726 +           strcpy(pbuf, "?");
3727 +       }
3728          ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
3729                        "proxy connect to %s port %d failed",
3730 -                      inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
3731 +                      hbuf, pbuf);
3732      }
3733      ap_kill_timeout(r);
3734  
3735 diff -Nur apache_1.3.28.orig/src/modules/standard/mod_access.c apache_1.3.28/src/modules/standard/mod_access.c
3736 --- apache_1.3.28.orig/src/modules/standard/mod_access.c        Mon Feb  3 18:13:27 2003
3737 +++ apache_1.3.28/src/modules/standard/mod_access.c     Fri Jul 25 11:01:55 2003
3738 @@ -74,7 +74,10 @@
3739      T_ALL,
3740      T_IP,
3741      T_HOST,
3742 -    T_FAIL
3743 +    T_FAIL,
3744 +#ifdef INET6
3745 +    T_IP6,
3746 +#endif
3747  };
3748  
3749  typedef struct {
3750 @@ -82,9 +85,15 @@
3751      union {
3752         char *from;
3753         struct {
3754 -           unsigned long net;
3755 -           unsigned long mask;
3756 +           struct in_addr net;
3757 +           struct in_addr mask;
3758         } ip;
3759 +#ifdef INET6
3760 +       struct {
3761 +           struct in6_addr net6;
3762 +           struct in6_addr mask6;
3763 +       } ip6;
3764 +#endif
3765      } x;
3766      enum allowdeny_type type;
3767  } allowdeny;
3768 @@ -167,90 +176,230 @@
3769  
3770      }
3771      else if ((s = strchr(where, '/'))) {
3772 -       unsigned long mask;
3773 +       struct addrinfo hints, *resnet, *resmask;
3774 +       struct sockaddr_storage net, mask;
3775 +       int error;
3776 +       char *p;
3777 +       int justdigits;
3778  
3779 -       a->type = T_IP;
3780 +       a->type = T_FAIL;       /*just in case*/
3781         /* trample on where, we won't be using it any more */
3782         *s++ = '\0';
3783  
3784 -       if (!is_ip(where)
3785 -           || (a->x.ip.net = ap_inet_addr(where)) == INADDR_NONE) {
3786 +       justdigits = 0;
3787 +       for (p = s; *p; p++) {
3788 +           if (!isdigit(*p))
3789 +               break;
3790 +       }
3791 +       if (!*p)
3792 +           justdigits++;
3793 +
3794 +       memset(&hints, 0, sizeof(hints));
3795 +       hints.ai_family = PF_UNSPEC;
3796 +       hints.ai_socktype = SOCK_STREAM;        /*dummy*/
3797 +#ifdef AI_NUMERICHOST
3798 +       hints.ai_flags = AI_NUMERICHOST;        /*don't resolve*/
3799 +#endif
3800 +       resnet = NULL;
3801 +       error = getaddrinfo(where, NULL, &hints, &resnet);
3802 +       if (error || !resnet) {
3803 +           if (resnet)
3804 +               freeaddrinfo(resnet);
3805             a->type = T_FAIL;
3806             return "syntax error in network portion of network/netmask";
3807         }
3808 +       if (resnet->ai_next) {
3809 +           freeaddrinfo(resnet);
3810 +           a->type = T_FAIL;
3811 +           return "network/netmask resolved to multiple addresses";
3812 +       }
3813 +       memcpy(&net, resnet->ai_addr, resnet->ai_addrlen);
3814 +       freeaddrinfo(resnet);
3815  
3816 -       /* is_ip just tests if it matches [\d.]+ */
3817 -       if (!is_ip(s)) {
3818 +       switch (net.ss_family) {
3819 +       case AF_INET:
3820 +           a->type = T_IP;
3821 +           a->x.ip.net.s_addr = ((struct sockaddr_in *)&net)->sin_addr.s_addr;
3822 +           break;
3823 +#ifdef INET6
3824 +       case AF_INET6:
3825 +           a->type = T_IP6;
3826 +           memcpy(&a->x.ip6.net6, &((struct sockaddr_in6 *)&net)->sin6_addr,
3827 +               sizeof(a->x.ip6.net6));
3828 +           break;
3829 +#endif
3830 +       default:
3831             a->type = T_FAIL;
3832 -           return "syntax error in mask portion of network/netmask";
3833 +           return "unknown address family for network";
3834         }
3835 -       /* is it in /a.b.c.d form? */
3836 -       if (strchr(s, '.')) {
3837 -           mask = ap_inet_addr(s);
3838 -           if (mask == INADDR_NONE) {
3839 +
3840 +       if (!justdigits) {
3841 +           memset(&hints, 0, sizeof(hints));
3842 +           hints.ai_family = PF_UNSPEC;
3843 +           hints.ai_socktype = SOCK_STREAM;    /*dummy*/ 
3844 +#ifdef AI_NUMERICHOST
3845 +           hints.ai_flags = AI_NUMERICHOST;    /*don't resolve*/
3846 +#endif
3847 +           resmask = NULL;
3848 +           error = getaddrinfo(s, NULL, &hints, &resmask);
3849 +           if (error || !resmask) {
3850 +               if (resmask)
3851 +                   freeaddrinfo(resmask);
3852                 a->type = T_FAIL;
3853                 return "syntax error in mask portion of network/netmask";
3854             }
3855 -       }
3856 -       else {
3857 -           /* assume it's in /nnn form */
3858 -           mask = atoi(s);
3859 -           if (mask > 32 || mask <= 0) {
3860 -               a->type = T_FAIL;
3861 -               return "invalid mask in network/netmask";
3862 -           }
3863 -           mask = 0xFFFFFFFFUL << (32 - mask);
3864 -           mask = htonl(mask);
3865 -       }
3866 -       a->x.ip.mask = mask;
3867 -        a->x.ip.net  = (a->x.ip.net & mask);   /* pjr - This fixes PR 4770 */
3868 -    }
3869 -    else if (ap_isdigit(*where) && is_ip(where)) {
3870 -       /* legacy syntax for ip addrs: a.b.c. ==> a.b.c.0/24 for example */
3871 -       int shift;
3872 -       char *t;
3873 -       int octet;
3874 -
3875 -       a->type = T_IP;
3876 -       /* parse components */
3877 -       s = where;
3878 -       a->x.ip.net = 0;
3879 -       a->x.ip.mask = 0;
3880 -       shift = 24;
3881 -       while (*s) {
3882 -           t = s;
3883 -           if (!ap_isdigit(*t)) {
3884 +           if (resmask->ai_next) {
3885 +               freeaddrinfo(resmask);
3886                 a->type = T_FAIL;
3887 -               return "invalid ip address";
3888 +               return "network/netmask resolved to multiple addresses";
3889             }
3890 -           while (ap_isdigit(*t)) {
3891 -               ++t;
3892 -           }
3893 -           if (*t == '.') {
3894 -               *t++ = 0;
3895 -           }
3896 -           else if (*t) {
3897 +           memcpy(&mask, resmask->ai_addr, resmask->ai_addrlen);
3898 +           freeaddrinfo(resmask);
3899 +
3900 +           if (net.ss_family != mask.ss_family) {
3901                 a->type = T_FAIL;
3902 -               return "invalid ip address";
3903 +               return "network/netmask resolved to different address family";
3904             }
3905 -           if (shift < 0) {
3906 -               return "invalid ip address, only 4 octets allowed";
3907 +
3908 +           switch (a->type) {
3909 +           case T_IP:
3910 +               a->x.ip.mask.s_addr =
3911 +                   ((struct sockaddr_in *)&mask)->sin_addr.s_addr;
3912 +               break;
3913 +#ifdef INET6
3914 +           case T_IP6:
3915 +               memcpy(&a->x.ip6.mask6,
3916 +                   &((struct sockaddr_in6 *)&mask)->sin6_addr,
3917 +                   sizeof(a->x.ip6.mask6));
3918 +               break;
3919 +#endif
3920             }
3921 -           octet = atoi(s);
3922 -           if (octet < 0 || octet > 255) {
3923 -               a->type = T_FAIL;
3924 -               return "each octet must be between 0 and 255 inclusive";
3925 +       } else {
3926 +           int mask;
3927 +           mask = atoi(s);
3928 +           switch (a->type) {
3929 +           case T_IP:
3930 +               if (mask < 0 || 32 < mask) {
3931 +                   a->type = T_FAIL;
3932 +                   return "netmask out of range";
3933 +               }
3934 +               a->x.ip.mask.s_addr = htonl(0xFFFFFFFFUL << (32 - mask));
3935 +               break;
3936 +#ifdef INET6
3937 +           case T_IP6:
3938 +             {
3939 +               int i;
3940 +               if (mask < 0 || 128 < mask) {
3941 +                   a->type = T_FAIL;
3942 +                   return "netmask out of range";
3943 +               }
3944 +               for (i = 0; i < mask / 8; i++) {
3945 +                   a->x.ip6.mask6.s6_addr[i] = 0xff;
3946 +               }
3947 +               if (mask % 8)
3948 +                   a->x.ip6.mask6.s6_addr[i] = 0xff << (8 - (mask % 8));
3949 +               break;
3950 +             }
3951 +#endif
3952             }
3953 -           a->x.ip.net |= octet << shift;
3954 -           a->x.ip.mask |= 0xFFUL << shift;
3955 -           s = t;
3956 -           shift -= 8;
3957         }
3958 -       a->x.ip.net = ntohl(a->x.ip.net);
3959 -       a->x.ip.mask = ntohl(a->x.ip.mask);
3960      }
3961      else {
3962 -       a->type = T_HOST;
3963 +       struct addrinfo hints, *res;
3964 +       struct sockaddr_storage ss;
3965 +       int error;
3966 +
3967 +       a->type = T_FAIL;       /*just in case*/
3968 +
3969 +       /* First, try using the old apache code to match */
3970 +       /* legacy syntax for ip addrs: a.b.c. ==> a.b.c.0/24 for example */
3971 +       if (ap_isdigit(*where) && is_ip(where)) {
3972 +           int shift;
3973 +           char *t;
3974 +           int octet;
3975 +
3976 +           a->type = T_IP;
3977 +           /* parse components */
3978 +           s = where;
3979 +           a->x.ip.net.s_addr = 0;
3980 +           a->x.ip.mask.s_addr = 0;
3981 +           shift = 24;
3982 +           while (*s) {
3983 +               t = s;
3984 +               if (!ap_isdigit(*t)) {
3985 +                   a->type = T_FAIL;
3986 +                   return "invalid ip address";
3987 +               }
3988 +               while (ap_isdigit(*t)) {
3989 +                   ++t;
3990 +               }
3991 +               if (*t == '.') {
3992 +                   *t++ = 0;
3993 +               }
3994 +               else if (*t) {
3995 +                   a->type = T_FAIL;
3996 +                   return "invalid ip address";
3997 +               }
3998 +               if (shift < 0) {
3999 +                   return "invalid ip address, only 4 octets allowed";
4000 +               }
4001 +               octet = atoi(s);
4002 +               if (octet < 0 || octet > 255) {
4003 +                   a->type = T_FAIL;
4004 +                   return "each octet must be between 0 and 255 inclusive";
4005 +               }
4006 +               a->x.ip.net.s_addr |= octet << shift;
4007 +               a->x.ip.mask.s_addr |= 0xFFUL << shift;
4008 +               s = t;
4009 +               shift -= 8;
4010 +           }
4011 +           a->x.ip.net.s_addr = ntohl(a->x.ip.net.s_addr);
4012 +           a->x.ip.mask.s_addr = ntohl(a->x.ip.mask.s_addr);
4013 +
4014 +           return NULL;
4015 +       }
4016 +
4017 +       /* IPv4/v6 numeric address */
4018 +       memset(&hints, 0, sizeof(hints));
4019 +       hints.ai_family = PF_UNSPEC;
4020 +       hints.ai_socktype = SOCK_STREAM;        /*dummy*/
4021 +#ifdef AI_NUMERICHOST
4022 +       hints.ai_flags = AI_NUMERICHOST;        /*don't resolve*/
4023 +#endif
4024 +       res = NULL;
4025 +       error = getaddrinfo(where, NULL, &hints, &res);
4026 +       if (error || !res) {
4027 +           if (res)
4028 +               freeaddrinfo(res);
4029 +           a->type = T_HOST;
4030 +           return NULL;
4031 +       }
4032 +       if (res->ai_next) {
4033 +           freeaddrinfo(res);
4034 +           a->type = T_FAIL;
4035 +           return "network/netmask resolved to multiple addresses";
4036 +       }
4037 +       memcpy(&ss, res->ai_addr, res->ai_addrlen);
4038 +       freeaddrinfo(res);
4039 +
4040 +       switch (ss.ss_family) {
4041 +       case AF_INET:
4042 +           a->type = T_IP;
4043 +           a->x.ip.net.s_addr = ((struct sockaddr_in *)&ss)->sin_addr.s_addr;
4044 +           memset(&a->x.ip.mask, 0xff, sizeof(a->x.ip.mask));
4045 +           break;
4046 +#ifdef INET6
4047 +       case AF_INET6:
4048 +           a->type = T_IP6;
4049 +           memcpy(&a->x.ip6.net6, &((struct sockaddr_in6 *)&ss)->sin6_addr,
4050 +               sizeof(a->x.ip6.net6));
4051 +           memset(&a->x.ip6.mask6, 0xff, sizeof(a->x.ip6.mask6));
4052 +           break;
4053 +#endif
4054 +       default:
4055 +           a->type = T_FAIL;
4056 +           return "unknown address family for network";
4057 +       }
4058      }
4059  
4060      return NULL;
4061 @@ -315,12 +464,63 @@
4062             return 1;
4063  
4064         case T_IP:
4065 -           if (ap[i].x.ip.net != INADDR_NONE
4066 -               && (r->connection->remote_addr.sin_addr.s_addr
4067 -                   & ap[i].x.ip.mask) == ap[i].x.ip.net) {
4068 -               return 1;
4069 +           if (ap[i].x.ip.net.s_addr == INADDR_NONE)
4070 +               break;
4071 +           switch (r->connection->remote_addr.ss_family) {
4072 +           case AF_INET:
4073 +               if ((((struct sockaddr_in *)&r->connection->remote_addr)->sin_addr.s_addr
4074 +                       & ap[i].x.ip.mask.s_addr) == ap[i].x.ip.net.s_addr) {
4075 +                   return 1;
4076 +               }
4077 +               break;
4078 +#ifdef INET6
4079 +           case AF_INET6:
4080 +               if (!IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)&r->connection->remote_addr)->sin6_addr))    /*XXX*/
4081 +                   break;
4082 +               if ((*(ap_uint32_t *)&((struct sockaddr_in6 *)&r->connection->remote_addr)->sin6_addr.s6_addr[12]
4083 +                       & ap[i].x.ip.mask.s_addr) == ap[i].x.ip.net.s_addr) {
4084 +                   return 1;
4085 +               }
4086 +               break;
4087 +#endif
4088 +           }
4089 +           break;
4090 +
4091 +#ifdef INET6
4092 +       case T_IP6:
4093 +         {
4094 +           struct in6_addr masked;
4095 +           int j;
4096 +           if (IN6_IS_ADDR_UNSPECIFIED(&ap[i].x.ip6.net6))
4097 +               break;
4098 +           switch (r->connection->remote_addr.ss_family) {
4099 +           case AF_INET:
4100 +               if (!IN6_IS_ADDR_V4MAPPED(&ap[i].x.ip6.net6))   /*XXX*/
4101 +                   break;
4102 +               memset(&masked, 0, sizeof(masked));
4103 +               masked.s6_addr[10] = masked.s6_addr[11] = 0xff;
4104 +               memcpy(&masked.s6_addr[12],
4105 +                   &((struct sockaddr_in *)&r->connection->remote_addr)->sin_addr.s_addr,
4106 +                   sizeof(struct sockaddr_in));
4107 +               for (j = 0; j < sizeof(struct in6_addr); j++)
4108 +                       masked.s6_addr[j] &= ap[i].x.ip6.mask6.s6_addr[j];
4109 +               if (memcmp(&masked, &ap[i].x.ip6.net6, sizeof(masked)) == 0)
4110 +                   return 1;
4111 +               break;
4112 +           case AF_INET6:
4113 +               memset(&masked, 0, sizeof(masked));
4114 +               memcpy(&masked,
4115 +                   &((struct sockaddr_in6 *)&r->connection->remote_addr)->sin6_addr,
4116 +                   sizeof(masked));
4117 +               for (j = 0; j < sizeof(struct in6_addr); j++)
4118 +                   masked.s6_addr[j] &= ap[i].x.ip6.mask6.s6_addr[j];
4119 +               if (memcmp(&masked, &ap[i].x.ip6.net6, sizeof(masked)) == 0)
4120 +                   return 1;
4121 +               break;
4122             }
4123             break;
4124 +         }
4125 +#endif
4126  
4127         case T_HOST:
4128             if (!gothost) {
4129 diff -Nur apache_1.3.28.orig/src/modules/standard/mod_unique_id.c apache_1.3.28/src/modules/standard/mod_unique_id.c
4130 --- apache_1.3.28.orig/src/modules/standard/mod_unique_id.c     Mon Feb  3 18:13:30 2003
4131 +++ apache_1.3.28/src/modules/standard/mod_unique_id.c  Fri Jul 25 11:01:55 2003
4132 @@ -67,10 +67,22 @@
4133  #include "http_config.h"
4134  #include "http_log.h"
4135  #include "multithread.h"
4136 +#include "sa_len.h"
4137 +
4138 +/*#define SHORT_UNIQUE_ID*/
4139  
4140  typedef struct {
4141      unsigned int stamp;
4142 -    unsigned int in_addr;
4143 +    union {
4144 +       struct in_addr in;
4145 +#ifdef INET6
4146 +# ifdef SHORT_UNIQUE_ID
4147 +       ap_uint32_t in6;
4148 +# else
4149 +       struct in6_addr in6;
4150 +# endif
4151 +#endif
4152 +    } addr;
4153      unsigned int pid;
4154  #ifdef MULTITHREAD
4155      unsigned int tid;
4156 @@ -142,7 +154,7 @@
4157   * this shouldn't be a problem till year 2106.
4158   */
4159  
4160 -static unsigned global_in_addr;
4161 +static struct sockaddr_storage global_addr;
4162  
4163  #ifdef WIN32
4164  
4165 @@ -221,7 +233,8 @@
4166  #define MAXHOSTNAMELEN 256
4167  #endif
4168      char str[MAXHOSTNAMELEN + 1];
4169 -    struct hostent *hent;
4170 +    struct addrinfo hints, *res, *res0;
4171 +    int error;
4172  #ifndef NO_GETTIMEOFDAY
4173      struct timeval tv;
4174  #endif
4175 @@ -232,8 +245,8 @@
4176       */
4177      unique_id_rec_offset[0] = XtOffsetOf(unique_id_rec, stamp);
4178      unique_id_rec_size[0] = sizeof(cur_unique_id->stamp);
4179 -    unique_id_rec_offset[1] = XtOffsetOf(unique_id_rec, in_addr);
4180 -    unique_id_rec_size[1] = sizeof(cur_unique_id->in_addr);
4181 +    unique_id_rec_offset[1] = XtOffsetOf(unique_id_rec, addr);
4182 +    unique_id_rec_size[1] = sizeof(cur_unique_id->addr);
4183      unique_id_rec_offset[2] = XtOffsetOf(unique_id_rec, pid);
4184      unique_id_rec_size[2] = sizeof(cur_unique_id->pid);
4185  #ifdef MULTITHREAD
4186 @@ -269,17 +282,44 @@
4187      }
4188      str[sizeof(str) - 1] = '\0';
4189  
4190 -    if ((hent = gethostbyname(str)) == NULL) {
4191 +    memset(&hints, 0, sizeof(hints));
4192 +    hints.ai_family = PF_UNSPEC;
4193 +    error = getaddrinfo(str, NULL, &hints, &res0);
4194 +    if (error) {
4195          ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, s,
4196 -                    "mod_unique_id: unable to gethostbyname(\"%s\")", str);
4197 +                     "mod_unique_id: getaddrinfo failed for \"%s\" (%s)", str,
4198 +                    gai_strerror(error));
4199          exit(1);
4200      }
4201  
4202 -    global_in_addr = ((struct in_addr *) hent->h_addr_list[0])->s_addr;
4203 +    error = 1;
4204 +    for (res = res0; res; res = res->ai_next) {
4205 +       switch (res->ai_family) {
4206 +       case AF_INET:
4207 +#ifdef INET6
4208 +       case AF_INET6:
4209 +#endif
4210 +           memcpy(&global_addr, res->ai_addr, res->ai_addrlen);
4211 +           error = 0;
4212 +           break;
4213 +       }
4214 +    }
4215 +    freeaddrinfo(res0);
4216 +    if (error) {
4217 +        ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, s,
4218 +                    "mod_unique_id: no known AF found for \"%s\"", str);
4219 +        exit(1);
4220 +    }
4221  
4222 +    getnameinfo((struct sockaddr *)&global_addr,
4223 +#ifndef SIN6_LEN
4224 +       SA_LEN((struct sockaddr *)&global_addr),
4225 +#else
4226 +       global_addr.ss_len,
4227 +#endif
4228 +       str, sizeof(str), NULL, 0, NI_NUMERICHOST);
4229      ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, s,
4230 -                "mod_unique_id: using ip addr %s",
4231 -                inet_ntoa(*(struct in_addr *) hent->h_addr_list[0]));
4232 +                 "mod_unique_id: using ip addr %s", str);
4233  
4234      /*
4235       * If the server is pummelled with restart requests we could possibly end
4236 @@ -336,7 +376,23 @@
4237                      "oh no! pids are greater than 32-bits!  I'm broken!");
4238      }
4239  
4240 -    cur_unique_id->in_addr = global_in_addr;
4241 +    memset(&cur_unique_id->addr, 0, sizeof(cur_unique_id->addr));
4242 +    switch (global_addr.ss_family) {
4243 +    case AF_INET:
4244 +       cur_unique_id->addr.in = ((struct sockaddr_in *)&global_addr)->sin_addr;
4245 +       break;
4246 +#ifdef INET6
4247 +    case AF_INET6:
4248 +#ifdef SHORT_UNIQUE_ID
4249 +       cur_unique_id->addr.in6 =
4250 +           ((struct sockaddr_in6 *)&global_addr)->sin6_addr.s6_addr32[3];
4251 +#else
4252 +       cur_unique_id->addr.in6 =
4253 +           ((struct sockaddr_in6 *)&global_addr)->sin6_addr;
4254 +#endif
4255 +       break;
4256 +#endif
4257 +    }
4258  
4259      /*
4260       * If we use 0 as the initial counter we have a little less protection
4261 diff -Nur apache_1.3.28.orig/src/support/ab.c apache_1.3.28/src/support/ab.c
4262 --- apache_1.3.28.orig/src/support/ab.c Sun Jul  6 19:52:27 2003
4263 +++ apache_1.3.28/src/support/ab.c      Fri Jul 25 11:01:55 2003
4264 @@ -158,6 +158,8 @@
4265  #include <sys/uio.h>
4266  #endif
4267  
4268 +#include "sa_len.h"
4269 +
4270  #endif                         /* NO_APACHE_INCLUDES */
4271  
4272  #ifdef USE_SSL
4273 @@ -246,7 +248,7 @@
4274  char servername[1024];         /* name that server reports */
4275  char hostname[1024];           /* host name */
4276  char proxyhost[1024];          /* proxy host name */
4277 -int proxyport = 0;             /* proxy port */
4278 +char *proxyport = NULL;                /* proxy port */
4279  int isproxy = 0;
4280  char path[1024];               /* path name */
4281  char postfile[1024];           /* name of file containing post data */
4282 @@ -262,7 +264,7 @@
4283       auth[1024],               /* optional (basic/uuencoded)
4284                                  * authentification */
4285       hdrs[4096];               /* optional arbitrary headers */
4286 -int port = 80;                 /* port number */
4287 +char *port = "80";             /* port number */
4288  
4289  int use_html = 0;              /* use html in the report */
4290  char *tablestring;
4291 @@ -299,7 +301,7 @@
4292  struct data *stats;            /* date for each request */
4293  
4294  fd_set readbits, writebits;    /* bits for select */
4295 -struct sockaddr_in server;     /* server addr structure */
4296 +struct sockaddr_storage server;      /* server addr structure */
4297  
4298  #ifndef BEOS
4299  #define ab_close(s) close(s)
4300 @@ -525,7 +527,7 @@
4301      printf("\r                                                                           \r");
4302      printf("Server Software:        %s\n", servername);
4303      printf("Server Hostname:        %s\n", hostname);
4304 -    printf("Server Port:            %d\n", port);
4305 +    printf("Server Port:            %s\n", port);
4306      printf("\n");
4307      printf("Document Path:          %s\n", path);
4308      printf("Document Length:        %d bytes\n", doclen);
4309 @@ -878,7 +880,7 @@
4310      c->cbx = 0;
4311      c->gotheader = 0;
4312  
4313 -    c->fd = socket(AF_INET, SOCK_STREAM, 0);
4314 +    c->fd = socket(server.ss_family, SOCK_STREAM, 0);
4315      if (c->fd < 0) {
4316         what = "SOCKET";
4317         goto _bad;
4318 @@ -895,7 +897,12 @@
4319  
4320  again:
4321      gettimeofday(&c->start, 0);
4322 -    if (connect(c->fd, (struct sockaddr *) & server, sizeof(server)) < 0) {
4323 +#ifndef SIN6_LEN
4324 +    if (connect(c->fd, (struct sockaddr *) & server, SA_LEN((struct sockaddr*)&server)) < 0)
4325 +#else
4326 +    if (connect(c->fd, (struct sockaddr *) & server, server.ss_len) < 0)
4327 +#endif
4328 +    {
4329         if (errno != EINPROGRESS) {
4330             what = "CONNECT";
4331             goto _bad;
4332 @@ -1189,7 +1196,7 @@
4333      struct timeval timeout, now;
4334      fd_set sel_read, sel_except, sel_write;
4335      long i;
4336 -    int connectport;
4337 +    char * connectport;
4338      char * connecthost;
4339      char * url_on_request;
4340  
4341 @@ -1232,17 +1239,21 @@
4342      }
4343      {
4344         /* get server information */
4345 -       struct hostent *he;
4346 -       he = gethostbyname(connecthost);
4347 -       if (!he) {
4348 -           char theerror[1024];
4349 -           ap_snprintf(theerror, sizeof(theerror),
4350 -                        "Bad hostname: %s\n", connecthost);
4351 -           err(theerror);
4352 -       }
4353 -       server.sin_family = he->h_addrtype;
4354 -       server.sin_port = htons(connectport);
4355 -       server.sin_addr.s_addr = ((unsigned long *) (he->h_addr_list[0]))[0];
4356 +       struct addrinfo hints, *res;
4357 +       int error;
4358 +
4359 +       memset(&hints, 0, sizeof(hints));
4360 +       hints.ai_family = PF_UNSPEC;
4361 +       hints.ai_socktype = SOCK_STREAM;
4362 +       error = getaddrinfo(connecthost, connectport, &hints, &res);
4363 +       if (error) {
4364 +               char *theerror=malloc(strlen(connecthost)+16);
4365 +               sprintf(theerror, "Bad hostname: %s\n", connecthost);
4366 +               err(theerror);
4367 +               free(theerror);
4368 +       }
4369 +       memcpy(&server, res->ai_addr, res->ai_addrlen);
4370 +       freeaddrinfo(res);
4371      }
4372  
4373      con = malloc(concurrency * sizeof(struct connection));
4374 @@ -1430,7 +1441,7 @@
4375      if (strlen(purl) > 8 && strncmp(purl, "https://", 8) == 0) {
4376         purl += 8;
4377         ssl = 1;
4378 -       port = 443;
4379 +       port = "443";
4380      }
4381  #else
4382      if (strlen(purl) > 8 && strncmp(purl, "https://", 8) == 0) {
4383 @@ -1451,15 +1462,15 @@
4384      *cp = '\0';
4385      strcpy(hostname, h);
4386      if (p != NULL)
4387 -       port = atoi(p);
4388 +       port = strdup(p);
4389  
4390      if ((
4391  #ifdef USE_SSL
4392 -       (ssl != 0) && (port != 443)) || ((ssl == 0) && 
4393 +       (ssl != 0) && (strcmp(port, "443"))) || ((ssl == 0) && 
4394  #endif
4395 -       (port != 80))) 
4396 +       (strcmp(port, "80")))) 
4397     {
4398 -       ap_snprintf(colonport,sizeof(colonport),":%d",port);
4399 +       ap_snprintf(colonport,sizeof(colonport),":%s",port);
4400     } else {
4401         colonport[0] = '\0';
4402     }
4403 @@ -1622,7 +1633,7 @@
4404                 if ((p = strchr(optarg, ':'))) {
4405                     *p = '\0';
4406                     p++;
4407 -                   proxyport = atoi(p);
4408 +                   proxyport = strdup(p);
4409                 };
4410                 strcpy(proxyhost, optarg);
4411                 isproxy = 1;
4412 @@ -1705,3 +1716,7 @@
4413  
4414      exit(0);
4415  }
4416 +
4417 +#ifdef NEED_GETADDRINFO
4418 +#include "../main/getaddrinfo.c"
4419 +#endif
4420 diff -Nur apache_1.3.28.orig/src/support/logresolve.c apache_1.3.28/src/support/logresolve.c
4421 --- apache_1.3.28.orig/src/support/logresolve.c Wed May 23 00:52:21 2001
4422 +++ apache_1.3.28/src/support/logresolve.c      Fri Jul 25 11:01:55 2003
4423 @@ -54,7 +54,9 @@
4424  #endif /* BEOS */
4425  #endif /* !MPE && !WIN32*/
4426  
4427 -static void cgethost(struct in_addr ipnum, char *string, int check);
4428 +#include "sa_len.h"
4429 +
4430 +static void cgethost(struct sockaddr *sa, char *string, int check);
4431  static int getline(char *s, int n);
4432  static void stats(FILE *output);
4433  
4434 @@ -91,7 +93,7 @@
4435   */
4436  
4437  struct nsrec {
4438 -    struct in_addr ipnum;
4439 +    struct sockaddr_storage addr;
4440      char *hostname;
4441      int noname;
4442      struct nsrec *next;
4443 @@ -122,17 +124,48 @@
4444   * IP numbers with their IP number as hostname, setting noname flag
4445   */
4446  
4447 -static void cgethost (struct in_addr ipnum, char *string, int check)
4448 +static void cgethost (struct sockaddr *sa, char *string, int check)
4449  {
4450 +    ap_uint32_t hashval;
4451 +    struct sockaddr_in *sin;
4452 +#ifdef INET6
4453 +    struct sockaddr_in6 *sin6;
4454 +#endif
4455      struct nsrec **current, *new;
4456 -    struct hostent *hostdata;
4457      char *name;
4458 +    char hostnamebuf[MAXHOSTNAMELEN];
4459 +
4460 +    switch (sa->sa_family) {
4461 +    case AF_INET:
4462 +       hashval = ((struct sockaddr_in *)sa)->sin_addr.s_addr;
4463 +       break;
4464 +#ifdef INET6
4465 +    case AF_INET6:
4466 +       hashval = *(ap_uint32_t *)&((struct sockaddr_in6 *)sa)->sin6_addr.s6_addr[12];
4467 +       break;
4468 +#endif
4469 +    default:
4470 +       hashval = 0;
4471 +       break;
4472 +    }
4473 +
4474 +    current = &nscache[((hashval + (hashval >> 8) +
4475 +                        (hashval >> 16) + (hashval >> 24)) % BUCKETS)];
4476  
4477 -    current = &nscache[((ipnum.s_addr + (ipnum.s_addr >> 8) +
4478 -                        (ipnum.s_addr >> 16) + (ipnum.s_addr >> 24)) % BUCKETS)];
4479 +    while (*current) {
4480 +#ifndef SIN6_LEN
4481 +       if (SA_LEN(sa) == SA_LEN((struct sockaddr *)&(*current)->addr)
4482 +        && memcmp(sa, &(*current)->addr, SA_LEN(sa)) == 0)
4483 +#else
4484 +       if (sa->sa_len == (*current)->addr.ss_len
4485 +        && memcmp(sa, &(*current)->addr, sa->sa_len) == 0)
4486 +#endif
4487 +       {
4488 +           break;
4489 +       }
4490  
4491 -    while (*current != NULL && ipnum.s_addr != (*current)->ipnum.s_addr)
4492         current = &(*current)->next;
4493 +    }
4494  
4495      if (*current == NULL) {
4496         cachesize++;
4497 @@ -145,45 +178,55 @@
4498         *current = new;
4499         new->next = NULL;
4500  
4501 -       new->ipnum = ipnum;
4502 +#ifndef SIN6_LEN
4503 +       memcpy(&new->addr, sa, SA_LEN(sa));
4504 +#else
4505 +       memcpy(&new->addr, sa, sa->sa_len);
4506 +#endif
4507  
4508 -       hostdata = gethostbyaddr((const char *) &ipnum, sizeof(struct in_addr),
4509 -                                AF_INET);
4510 -       if (hostdata == NULL) {
4511 -           if (h_errno > MAX_ERR)
4512 -               errors[UNKNOWN_ERR]++;
4513 -           else
4514 -               errors[h_errno]++;
4515 -           new->noname = h_errno;
4516 -           name = strdup(inet_ntoa(ipnum));
4517 -       }
4518 -       else {
4519 -           new->noname = 0;
4520 -           name = strdup(hostdata->h_name);
4521 -           if (check) {
4522 -               if (name == NULL) {
4523 -                   perror("strdup");
4524 -                   fprintf(stderr, "Insufficient memory\n");
4525 -                   exit(1);
4526 -               }
4527 -               hostdata = gethostbyname(name);
4528 -               if (hostdata != NULL) {
4529 -                   char **hptr;
4530 -
4531 -                   for (hptr = hostdata->h_addr_list; *hptr != NULL; hptr++)
4532 -                       if (((struct in_addr *) (*hptr))->s_addr == ipnum.s_addr)
4533 -                           break;
4534 -                   if (*hptr == NULL)
4535 -                       hostdata = NULL;
4536 -               }
4537 -               if (hostdata == NULL) {
4538 -                   fprintf(stderr, "Bad host: %s != %s\n", name,
4539 -                           inet_ntoa(ipnum));
4540 -                   new->noname = NO_REVERSE;
4541 -                   free(name);
4542 -                   name = strdup(inet_ntoa(ipnum));
4543 -                   errors[NO_REVERSE]++;
4544 +       new->noname = getnameinfo(sa,
4545 +#ifndef SIN6_LEN
4546 +               SA_LEN(sa),
4547 +#else
4548 +               sa->sa_len,
4549 +#endif
4550 +                   hostnamebuf, sizeof(hostnamebuf), NULL, 0, 0);
4551 +       name = strdup(hostnamebuf);
4552 +       if (check) {
4553 +           struct addrinfo hints, *res;
4554 +           int error;
4555 +           memset(&hints, 0, sizeof(hints));
4556 +           hints.ai_family = PF_UNSPEC;
4557 +           error = getaddrinfo(hostnamebuf, NULL, &hints, &res);
4558 +           if (!error) {
4559 +               while (res) {
4560 +#ifndef SIN6_LEN
4561 +                   if (SA_LEN(sa) == res->ai_addrlen
4562 +                    && memcmp(sa, res->ai_addr, SA_LEN(sa)) == 0)
4563 +#else
4564 +                   if (sa->sa_len == res->ai_addrlen
4565 +                    && memcmp(sa, res->ai_addr, sa->sa_len) == 0)
4566 +#endif
4567 +                   {
4568 +                       break;
4569 +                   }
4570 +                   res = res->ai_next;
4571                 }
4572 +               if (!res)
4573 +                   error++;
4574 +           }
4575 +           if (error) {
4576 +               getnameinfo(sa,
4577 +#ifndef SIN6_LEN
4578 +                   SA_LEN(sa),
4579 +#else
4580 +                   sa->sa_len,
4581 +#endif
4582 +                   hostnamebuf, sizeof(hostnamebuf), NULL, 0, NI_NUMERICHOST);
4583 +               fprintf(stderr, "Bad host: %s != %s\n", name, hostnamebuf);
4584 +               new->noname = NO_REVERSE;
4585 +               free(name);
4586 +               name = strdup(hostnamebuf);
4587             }
4588         }
4589         new->hostname = name;
4590 @@ -211,6 +254,7 @@
4591      char *ipstring;
4592      struct nsrec *current;
4593      char *errstring[MAX_ERR + 3];
4594 +    char hostnamebuf[MAXHOSTNAMELEN];
4595  
4596      for (i = 0; i < MAX_ERR + 3; i++)
4597         errstring[i] = "Unknown error";
4598 @@ -242,7 +286,14 @@
4599  
4600      for (i = 0; i < BUCKETS; i++)
4601         for (current = nscache[i]; current != NULL; current = current->next) {
4602 -           ipstring = inet_ntoa(current->ipnum);
4603 +           getnameinfo((struct sockaddr *)&current->addr,
4604 +#ifndef SIN6_LEN
4605 +                   SA_LEN((struct sockaddr *)&current->addr),
4606 +#else
4607 +                   current->addr.ss_len,
4608 +#endif
4609 +                   hostnamebuf, sizeof(hostnamebuf), NULL, 0, NI_NUMERICHOST);
4610 +           ipstring = hostnamebuf;
4611             if (current->noname == 0)
4612                 fprintf(output, "  %3d  %15s - %s\n", i, ipstring,
4613                         current->hostname);
4614 @@ -276,9 +327,10 @@
4615  
4616  int main (int argc, char *argv[])
4617  {
4618 -    struct in_addr ipnum;
4619      char *bar, hoststring[MAXDNAME + 1], line[MAXLINE], *statfile;
4620      int i, check;
4621 +    struct addrinfo hints, *res;
4622 +    int error;
4623  
4624  #ifdef WIN32
4625      WSADATA wsaData;
4626 @@ -322,8 +374,10 @@
4627         bar = strchr(line, ' ');
4628         if (bar != NULL)
4629             *bar = '\0';
4630 -       ipnum.s_addr = inet_addr(line);
4631 -       if (ipnum.s_addr == 0xffffffffu) {
4632 +       memset(&hints, 0, sizeof(hints));
4633 +       hints.ai_family = PF_UNSPEC;
4634 +       error = getaddrinfo(line, NULL, &hints, &res);
4635 +       if (error) {
4636             if (bar != NULL)
4637                 *bar = ' ';
4638             puts(line);
4639 @@ -333,11 +387,12 @@
4640  
4641         resolves++;
4642  
4643 -       cgethost(ipnum, hoststring, check);
4644 +       cgethost(res->ai_addr, hoststring, check);
4645         if (bar != NULL)
4646             printf("%s %s\n", hoststring, bar + 1);
4647         else
4648             puts(hoststring);
4649 +       freeaddrinfo(res);
4650      }
4651  
4652  #ifdef WIN32
4653 @@ -358,3 +413,11 @@
4654  
4655      return (0);
4656  }
4657 +
4658 +#ifdef NEED_GETADDRINFO
4659 +#include "../main/getaddrinfo.c"
4660 +#endif
4661 +
4662 +#ifdef NEED_GETNAMEINFO
4663 +#include "../main/getnameinfo.c"
4664 +#endif
4665 --- apache_1.3.28/src/modules/standard/mod_usertrack.c.orig     Mon Feb  3 18:13:30 2003
4666 +++ apache_1.3.28/src/modules/standard/mod_usertrack.c  Fri Jul 25 13:13:43 2003
4667 @@ -162,7 +162,7 @@
4668      long reqtime = (long) r->request_time;
4669      long clocktime;
4670  
4671 -    unsigned long ipaddr = ntohl(r->connection->remote_addr.sin_addr.s_addr);
4672 +    unsigned long ipaddr = ntohl(((struct sockaddr_in*)&r->connection->remote_addr)->sin_addr.s_addr);
4673      const char *rname = ap_get_remote_host(r->connection, r->per_dir_config,
4674                                            REMOTE_NAME);
4675      dcfg = ap_get_module_config(r->per_dir_config, &usertrack_module);
This page took 0.36674 seconds and 3 git commands to generate.