|
42 | 42 | * Portions Copyright (c) 1994, Regents of the University of California
|
43 | 43 | * Portions taken from FreeBSD.
|
44 | 44 | *
|
45 |
| - * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.94 2005/08/02 15:16:27 tgl Exp $ |
| 45 | + * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.95 2005/08/22 16:27:36 tgl Exp $ |
46 | 46 | *
|
47 | 47 | *-------------------------------------------------------------------------
|
48 | 48 | */
|
|
54 | 54 | #include <unistd.h>
|
55 | 55 | #include <locale.h>
|
56 | 56 | #include <signal.h>
|
57 |
| -#include <errno.h> |
58 | 57 | #ifdef HAVE_LANGINFO_H
|
59 | 58 | #include <langinfo.h>
|
60 | 59 | #endif
|
61 | 60 |
|
62 | 61 | #include "libpq/pqsignal.h"
|
63 | 62 | #include "mb/pg_wchar.h"
|
| 63 | +#include "getaddrinfo.h" |
64 | 64 | #include "getopt_long.h"
|
65 | 65 |
|
66 | 66 | #ifndef HAVE_INT_OPTRESET
|
@@ -1210,11 +1210,42 @@ setup_config(void)
|
1210 | 1210 | conflines = replace_token(conflines,"@remove-line-for-nolocal@","");
|
1211 | 1211 | #endif
|
1212 | 1212 |
|
1213 |
| -#ifndef HAVE_IPV6 |
| 1213 | +#if defined(HAVE_IPV6) && defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO) |
| 1214 | + /* |
| 1215 | + * Probe to see if there is really any platform support for IPv6, and |
| 1216 | + * comment out the relevant pg_hba line if not. This avoids runtime |
| 1217 | + * warnings if getaddrinfo doesn't actually cope with IPv6. Particularly |
| 1218 | + * useful on Windows, where executables built on a machine with IPv6 |
| 1219 | + * may have to run on a machine without. |
| 1220 | + * |
| 1221 | + * We don't bother with testing if we aren't using the system version |
| 1222 | + * of getaddrinfo, since we know our own version doesn't do IPv6. |
| 1223 | + */ |
| 1224 | + { |
| 1225 | + struct addrinfo *gai_result; |
| 1226 | + struct addrinfo hints; |
| 1227 | + |
| 1228 | + /* for best results, this code should match parse_hba() */ |
| 1229 | + hints.ai_flags = AI_NUMERICHOST; |
| 1230 | + hints.ai_family = PF_UNSPEC; |
| 1231 | + hints.ai_socktype = 0; |
| 1232 | + hints.ai_protocol = 0; |
| 1233 | + hints.ai_addrlen = 0; |
| 1234 | + hints.ai_canonname = NULL; |
| 1235 | + hints.ai_addr = NULL; |
| 1236 | + hints.ai_next = NULL; |
| 1237 | + |
| 1238 | + if (getaddrinfo("::1", NULL, &hints, &gai_result) != 0) |
| 1239 | + conflines = replace_token(conflines, |
| 1240 | + "host all all ::1", |
| 1241 | + "#host all all ::1"); |
| 1242 | + } |
| 1243 | +#else /* !HAVE_IPV6 etc */ |
| 1244 | + /* If we didn't compile IPV6 support at all, always comment it out */ |
1214 | 1245 | conflines = replace_token(conflines,
|
1215 | 1246 | "host all all ::1",
|
1216 | 1247 | "#host all all ::1");
|
1217 |
| -#endif |
| 1248 | +#endif /* HAVE_IPV6 etc */ |
1218 | 1249 |
|
1219 | 1250 | /* Replace default authentication methods */
|
1220 | 1251 | conflines = replace_token(conflines,
|
|
0 commit comments