|
37 | 37 | import io.netty.handler.codec.dns.DnsResponse;
|
38 | 38 | import io.netty.resolver.HostsFileEntriesResolver;
|
39 | 39 | import io.netty.resolver.InetNameResolver;
|
40 |
| -import io.netty.util.NetUtil; |
| 40 | +import io.netty.util.NetUtil2; |
41 | 41 | import io.netty.util.ReferenceCountUtil;
|
42 | 42 | import io.netty.util.concurrent.FastThreadLocal;
|
43 | 43 | import io.netty.util.concurrent.Future;
|
@@ -69,21 +69,24 @@ public class DnsNameResolver extends InetNameResolver {
|
69 | 69 | private static final String LOCALHOST = "localhost";
|
70 | 70 | private static final InetAddress LOCALHOST_ADDRESS;
|
71 | 71 |
|
72 |
| - static final InternetProtocolFamily[] DEFAULT_RESOLVE_ADDRESS_TYPES = new InternetProtocolFamily[2]; |
| 72 | + static final InternetProtocolFamily[] DEFAULT_RESOLVE_ADDRESS_TYPES; |
73 | 73 | static final String[] DEFAULT_SEACH_DOMAINS;
|
74 | 74 |
|
75 | 75 | static {
|
76 |
| - // Note that we did not use SystemPropertyUtil.getBoolean() here to emulate the behavior of JDK. |
77 |
| - if (Boolean.getBoolean("java.net.preferIPv6Addresses")) { |
78 |
| - DEFAULT_RESOLVE_ADDRESS_TYPES[0] = InternetProtocolFamily.IPv6; |
79 |
| - DEFAULT_RESOLVE_ADDRESS_TYPES[1] = InternetProtocolFamily.IPv4; |
80 |
| - LOCALHOST_ADDRESS = NetUtil.LOCALHOST6; |
81 |
| - logger.debug("-Djava.net.preferIPv6Addresses: true"); |
| 76 | + if (NetUtil2.isIpV4StackPreferred()) { |
| 77 | + DEFAULT_RESOLVE_ADDRESS_TYPES = new InternetProtocolFamily[] { InternetProtocolFamily.IPv4 }; |
| 78 | + LOCALHOST_ADDRESS = NetUtil2.LOCALHOST4; |
82 | 79 | } else {
|
83 |
| - DEFAULT_RESOLVE_ADDRESS_TYPES[0] = InternetProtocolFamily.IPv4; |
84 |
| - DEFAULT_RESOLVE_ADDRESS_TYPES[1] = InternetProtocolFamily.IPv6; |
85 |
| - LOCALHOST_ADDRESS = NetUtil.LOCALHOST4; |
86 |
| - logger.debug("-Djava.net.preferIPv6Addresses: false"); |
| 80 | + DEFAULT_RESOLVE_ADDRESS_TYPES = new InternetProtocolFamily[2]; |
| 81 | + if (NetUtil2.isIpV6AddressesPreferred()) { |
| 82 | + DEFAULT_RESOLVE_ADDRESS_TYPES[0] = InternetProtocolFamily.IPv6; |
| 83 | + DEFAULT_RESOLVE_ADDRESS_TYPES[1] = InternetProtocolFamily.IPv4; |
| 84 | + LOCALHOST_ADDRESS = NetUtil2.LOCALHOST6; |
| 85 | + } else { |
| 86 | + DEFAULT_RESOLVE_ADDRESS_TYPES[0] = InternetProtocolFamily.IPv4; |
| 87 | + DEFAULT_RESOLVE_ADDRESS_TYPES[1] = InternetProtocolFamily.IPv6; |
| 88 | + LOCALHOST_ADDRESS = NetUtil2.LOCALHOST4; |
| 89 | + } |
87 | 90 | }
|
88 | 91 | }
|
89 | 92 |
|
@@ -343,7 +346,7 @@ protected void doResolve(String inetHost, Promise<InetAddress> promise) throws E
|
343 | 346 | protected void doResolve(String inetHost,
|
344 | 347 | Promise<InetAddress> promise,
|
345 | 348 | DnsCache resolveCache) throws Exception {
|
346 |
| - final byte[] bytes = NetUtil.createByteArrayFromIpAddressString(inetHost); |
| 349 | + final byte[] bytes = NetUtil2.createByteArrayFromIpAddressString(inetHost); |
347 | 350 | if (bytes != null) {
|
348 | 351 | // The inetHost is actually an ipaddress.
|
349 | 352 | promise.setSuccess(InetAddress.getByAddress(bytes));
|
@@ -461,7 +464,7 @@ protected void doResolveAll(String inetHost,
|
461 | 464 | Promise<List<InetAddress>> promise,
|
462 | 465 | DnsCache resolveCache) throws Exception {
|
463 | 466 |
|
464 |
| - final byte[] bytes = NetUtil.createByteArrayFromIpAddressString(inetHost); |
| 467 | + final byte[] bytes = NetUtil2.createByteArrayFromIpAddressString(inetHost); |
465 | 468 | if (bytes != null) {
|
466 | 469 | // The unresolvedAddress was created via a String that contains an ipaddress.
|
467 | 470 | promise.setSuccess(Collections.singletonList(InetAddress.getByAddress(bytes)));
|
|
0 commit comments