difin commented on code in PR #5686: URL: https://github.com/apache/hive/pull/5686#discussion_r2005748495
########## common/src/java/org/apache/hive/common/IPUtils.java: ########## @@ -0,0 +1,204 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hive.common; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.regex.Pattern; + +public class IPUtils { + + public static final String WILDCARD_ADDRESS_IPV4 = "0.0.0.0"; + public static final String WILDCARD_ADDRESS_IPV6 = "::"; + public static final String LOOPBACK_ADDRESS_IPV4 = "127.0.0.1"; + public static final String LOOPBACK_ADDRESS_IPV6 = "::1"; + + private static final String IPV6_PATTERN = + "([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|" + // 1:2:3:4:5:6:7:8 + "([0-9a-fA-F]{1,4}:){1,7}:|" + // 1:: or 1:2:3::8 + "([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|" + + "([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|" + + "([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|" + + "([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|" + + "([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|" + + "[0-9a-fA-F]{1,4}:(:[0-9a-fA-F]{1,4}){1,6}|" + + ":((:[0-9a-fA-F]{1,4}){1,7}|:)|" + // :: or ::1 or ::1:2 + "fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|" + // Link-local + "::(ffff(:0{1,4}){0,1}:){0,1}" + + "((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}" + + "(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|" + // IPv4-mapped (::ffff:192.168.1.1) + "([0-9a-fA-F]{1,4}:){1,4}:" + + "((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}" + + "(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])"; + + private static final String IPV4_PATTERN = + "^(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\\." + + "(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\\." + + "(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\\." + + "(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$"; + + private static final Pattern ipv6Pattern = Pattern.compile("^(" + IPV6_PATTERN + ")$"); + private static final Pattern ipv4Pattern = Pattern.compile(IPV4_PATTERN); + + private IPUtils() { + } + + /** + * Get the IPv4 or IPv6 wildcard address for binding on all network interfaces, + * depending on Java properties. + * @return the wildcard address + */ + public static String getWildcardAddress() { + boolean preferIPv6Addresses = Boolean.getBoolean("java.net.preferIPv6Addresses"); + boolean preferIPv4Stack = Boolean.getBoolean("java.net.preferIPv4Stack"); + Review Comment: Fixed -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org