test_class.file: dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsTest.java
test_class.identifier: NetUtilsTest
test_case.body: @Test
      public void testMatchIpRangeMatchWhenIpv6() throws UnknownHostException {
          assertTrue(NetUtils.matchIpRange("*.*.*.*", "192.168.1.63", 90));
          assertTrue(NetUtils.matchIpRange("234e:0:4567:0:0:0:3d:*", "234e:0:4567::3d:ff", 90));
          assertTrue(NetUtils.matchIpRange("234e:0:4567:0:0:0:3d:ee", "234e:0:4567::3d:ee", 90));
          assertTrue(NetUtils.matchIpRange("234e:0:4567::3d:ee", "234e:0:4567::3d:ee", 90));
          assertTrue(NetUtils.matchIpRange("234e:0:4567:0:0:0:3d:0-ff", "234e:0:4567::3d:ee", 90));
          assertTrue(NetUtils.matchIpRange("234e:0:4567:0:0:0:3d:0-ee", "234e:0:4567::3d:ee", 90));
  
          assertFalse(NetUtils.matchIpRange("234e:0:4567:0:0:0:3d:ff", "234e:0:4567::3d:ee", 90));
          assertFalse(NetUtils.matchIpRange("234e:0:4567:0:0:0:3d:0-ea", "234e:0:4567::3d:ee", 90));
      }
test_case.class_method_signature: NetUtilsTest.testMatchIpRangeMatchWhenIpv6()
test_case.full_signature: @Test public void testMatchIpRangeMatchWhenIpv6()
test_case.identifier: testMatchIpRangeMatchWhenIpv6
test_case.invocations: assertTrue matchIpRange assertTrue matchIpRange assertTrue matchIpRange assertTrue matchIpRange assertTrue matchIpRange assertTrue matchIpRange assertFalse matchIpRange assertFalse matchIpRange
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testMatchIpRangeMatchWhenIpv6()
focal_class.declarator: logger
focal_class.modifier: private static
focal_class.original_string: private static Logger logger;
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: RND_PORT_START = 30000
focal_class.modifier: private static final
focal_class.original_string: private static final int RND_PORT_START = 30000;
focal_class.type: int
focal_class.var_name: RND_PORT_START
focal_class.declarator: RND_PORT_RANGE = 10000
focal_class.modifier: private static final
focal_class.original_string: private static final int RND_PORT_RANGE = 10000;
focal_class.type: int
focal_class.var_name: RND_PORT_RANGE
focal_class.declarator: MIN_PORT = 0
focal_class.modifier: private static final
focal_class.original_string: private static final int MIN_PORT = 0;
focal_class.type: int
focal_class.var_name: MIN_PORT
focal_class.declarator: MAX_PORT = 65535
focal_class.modifier: private static final
focal_class.original_string: private static final int MAX_PORT = 65535;
focal_class.type: int
focal_class.var_name: MAX_PORT
focal_class.declarator: ADDRESS_PATTERN = Pattern.compile("^\\d{1,3}(\\.\\d{1,3}){3}\\:\\d{1,5}$")
focal_class.modifier: private static final
focal_class.original_string: private static final Pattern ADDRESS_PATTERN = Pattern.compile("^\\d{1,3}(\\.\\d{1,3}){3}\\:\\d{1,5}$");
focal_class.type: Pattern
focal_class.var_name: ADDRESS_PATTERN
focal_class.declarator: LOCAL_IP_PATTERN = Pattern.compile("127(\\.\\d{1,3}){3}$")
focal_class.modifier: private static final
focal_class.original_string: private static final Pattern LOCAL_IP_PATTERN = Pattern.compile("127(\\.\\d{1,3}){3}$");
focal_class.type: Pattern
focal_class.var_name: LOCAL_IP_PATTERN
focal_class.declarator: IP_PATTERN = Pattern.compile("\\d{1,3}(\\.\\d{1,3}){3,5}$")
focal_class.modifier: private static final
focal_class.original_string: private static final Pattern IP_PATTERN = Pattern.compile("\\d{1,3}(\\.\\d{1,3}){3,5}$");
focal_class.type: Pattern
focal_class.var_name: IP_PATTERN
focal_class.declarator: HOST_NAME_CACHE = new LRUCache<>(1000)
focal_class.modifier: private static final
focal_class.original_string: private static final Map<String, String> HOST_NAME_CACHE = new LRUCache<>(1000);
focal_class.type: Map<String, String>
focal_class.var_name: HOST_NAME_CACHE
focal_class.declarator: LOCAL_ADDRESS = null
focal_class.modifier: private static volatile
focal_class.original_string: private static volatile InetAddress LOCAL_ADDRESS = null;
focal_class.type: InetAddress
focal_class.var_name: LOCAL_ADDRESS
focal_class.declarator: SPLIT_IPV4_CHARACTER = "\\."
focal_class.modifier: private static final
focal_class.original_string: private static final String SPLIT_IPV4_CHARACTER = "\\.";
focal_class.type: String
focal_class.var_name: SPLIT_IPV4_CHARACTER
focal_class.declarator: SPLIT_IPV6_CHARACTER = ":"
focal_class.modifier: private static final
focal_class.original_string: private static final String SPLIT_IPV6_CHARACTER = ":";
focal_class.type: String
focal_class.var_name: SPLIT_IPV6_CHARACTER
focal_class.declarator: HOST_ADDRESS
focal_class.modifier: private static volatile
focal_class.original_string: private static volatile String HOST_ADDRESS;
focal_class.type: String
focal_class.var_name: HOST_ADDRESS
focal_class.file: dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java
focal_class.identifier: NetUtils
focal_class.class_method_signature: NetUtils.getRandomPort()
focal_class.full_signature: public static int getRandomPort()
focal_class.identifier: getRandomPort
focal_class.modifiers: public static
focal_class.parameters: ()
focal_class.return: int
focal_class.signature: int getRandomPort()
focal_class.class_method_signature: NetUtils.getAvailablePort()
focal_class.full_signature: public static int getAvailablePort()
focal_class.identifier: getAvailablePort
focal_class.modifiers: public static
focal_class.parameters: ()
focal_class.return: int
focal_class.signature: int getAvailablePort()
focal_class.class_method_signature: NetUtils.getAvailablePort(int port)
focal_class.full_signature: public static int getAvailablePort(int port)
focal_class.identifier: getAvailablePort
focal_class.modifiers: public static
focal_class.parameters: (int port)
focal_class.return: int
focal_class.signature: int getAvailablePort(int port)
focal_class.class_method_signature: NetUtils.isInvalidPort(int port)
focal_class.full_signature: public static boolean isInvalidPort(int port)
focal_class.identifier: isInvalidPort
focal_class.modifiers: public static
focal_class.parameters: (int port)
focal_class.return: boolean
focal_class.signature: boolean isInvalidPort(int port)
focal_class.class_method_signature: NetUtils.isValidAddress(String address)
focal_class.full_signature: public static boolean isValidAddress(String address)
focal_class.identifier: isValidAddress
focal_class.modifiers: public static
focal_class.parameters: (String address)
focal_class.return: boolean
focal_class.signature: boolean isValidAddress(String address)
focal_class.class_method_signature: NetUtils.isLocalHost(String host)
focal_class.full_signature: public static boolean isLocalHost(String host)
focal_class.identifier: isLocalHost
focal_class.modifiers: public static
focal_class.parameters: (String host)
focal_class.return: boolean
focal_class.signature: boolean isLocalHost(String host)
focal_class.class_method_signature: NetUtils.isAnyHost(String host)
focal_class.full_signature: public static boolean isAnyHost(String host)
focal_class.identifier: isAnyHost
focal_class.modifiers: public static
focal_class.parameters: (String host)
focal_class.return: boolean
focal_class.signature: boolean isAnyHost(String host)
focal_class.class_method_signature: NetUtils.isInvalidLocalHost(String host)
focal_class.full_signature: public static boolean isInvalidLocalHost(String host)
focal_class.identifier: isInvalidLocalHost
focal_class.modifiers: public static
focal_class.parameters: (String host)
focal_class.return: boolean
focal_class.signature: boolean isInvalidLocalHost(String host)
focal_class.class_method_signature: NetUtils.isValidLocalHost(String host)
focal_class.full_signature: public static boolean isValidLocalHost(String host)
focal_class.identifier: isValidLocalHost
focal_class.modifiers: public static
focal_class.parameters: (String host)
focal_class.return: boolean
focal_class.signature: boolean isValidLocalHost(String host)
focal_class.class_method_signature: NetUtils.getLocalSocketAddress(String host, int port)
focal_class.full_signature: public static InetSocketAddress getLocalSocketAddress(String host, int port)
focal_class.identifier: getLocalSocketAddress
focal_class.modifiers: public static
focal_class.parameters: (String host, int port)
focal_class.return: InetSocketAddress
focal_class.signature: InetSocketAddress getLocalSocketAddress(String host, int port)
focal_class.class_method_signature: NetUtils.isValidV4Address(InetAddress address)
focal_class.full_signature: static boolean isValidV4Address(InetAddress address)
focal_class.identifier: isValidV4Address
focal_class.modifiers: static
focal_class.parameters: (InetAddress address)
focal_class.return: boolean
focal_class.signature: boolean isValidV4Address(InetAddress address)
focal_class.class_method_signature: NetUtils.isPreferIPV6Address()
focal_class.full_signature: static boolean isPreferIPV6Address()
focal_class.identifier: isPreferIPV6Address
focal_class.modifiers: static
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean isPreferIPV6Address()
focal_class.class_method_signature: NetUtils.normalizeV6Address(Inet6Address address)
focal_class.full_signature: static InetAddress normalizeV6Address(Inet6Address address)
focal_class.identifier: normalizeV6Address
focal_class.modifiers: static
focal_class.parameters: (Inet6Address address)
focal_class.return: InetAddress
focal_class.signature: InetAddress normalizeV6Address(Inet6Address address)
focal_class.class_method_signature: NetUtils.getLocalHost()
focal_class.full_signature: public static String getLocalHost()
focal_class.identifier: getLocalHost
focal_class.modifiers: public static
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getLocalHost()
focal_class.class_method_signature: NetUtils.filterLocalHost(String host)
focal_class.full_signature: public static String filterLocalHost(String host)
focal_class.identifier: filterLocalHost
focal_class.modifiers: public static
focal_class.parameters: (String host)
focal_class.return: String
focal_class.signature: String filterLocalHost(String host)
focal_class.class_method_signature: NetUtils.getIpByConfig()
focal_class.full_signature: public static String getIpByConfig()
focal_class.identifier: getIpByConfig
focal_class.modifiers: public static
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getIpByConfig()
focal_class.class_method_signature: NetUtils.getLocalAddress()
focal_class.full_signature: public static InetAddress getLocalAddress()
focal_class.identifier: getLocalAddress
focal_class.modifiers: public static
focal_class.parameters: ()
focal_class.return: InetAddress
focal_class.signature: InetAddress getLocalAddress()
focal_class.class_method_signature: NetUtils.toValidAddress(InetAddress address)
focal_class.full_signature: private static Optional<InetAddress> toValidAddress(InetAddress address)
focal_class.identifier: toValidAddress
focal_class.modifiers: private static
focal_class.parameters: (InetAddress address)
focal_class.return: Optional<InetAddress>
focal_class.signature: Optional<InetAddress> toValidAddress(InetAddress address)
focal_class.class_method_signature: NetUtils.getLocalAddress0()
focal_class.full_signature: private static InetAddress getLocalAddress0()
focal_class.identifier: getLocalAddress0
focal_class.modifiers: private static
focal_class.parameters: ()
focal_class.return: InetAddress
focal_class.signature: InetAddress getLocalAddress0()
focal_class.class_method_signature: NetUtils.ignoreNetworkInterface(NetworkInterface networkInterface)
focal_class.full_signature: private static boolean ignoreNetworkInterface(NetworkInterface networkInterface)
focal_class.identifier: ignoreNetworkInterface
focal_class.modifiers: private static
focal_class.parameters: (NetworkInterface networkInterface)
focal_class.return: boolean
focal_class.signature: boolean ignoreNetworkInterface(NetworkInterface networkInterface)
focal_class.class_method_signature: NetUtils.getValidNetworkInterfaces()
focal_class.full_signature: private static List<NetworkInterface> getValidNetworkInterfaces()
focal_class.identifier: getValidNetworkInterfaces
focal_class.modifiers: private static
focal_class.parameters: ()
focal_class.return: List<NetworkInterface>
focal_class.signature: List<NetworkInterface> getValidNetworkInterfaces()
focal_class.class_method_signature: NetUtils.isPreferredNetworkInterface(NetworkInterface networkInterface)
focal_class.full_signature: public static boolean isPreferredNetworkInterface(NetworkInterface networkInterface)
focal_class.identifier: isPreferredNetworkInterface
focal_class.modifiers: public static
focal_class.parameters: (NetworkInterface networkInterface)
focal_class.return: boolean
focal_class.signature: boolean isPreferredNetworkInterface(NetworkInterface networkInterface)
focal_class.class_method_signature: NetUtils.findNetworkInterface()
focal_class.full_signature: public static NetworkInterface findNetworkInterface()
focal_class.identifier: findNetworkInterface
focal_class.modifiers: public static
focal_class.parameters: ()
focal_class.return: NetworkInterface
focal_class.signature: NetworkInterface findNetworkInterface()
focal_class.class_method_signature: NetUtils.getHostName(String address)
focal_class.full_signature: public static String getHostName(String address)
focal_class.identifier: getHostName
focal_class.modifiers: public static
focal_class.parameters: (String address)
focal_class.return: String
focal_class.signature: String getHostName(String address)
focal_class.class_method_signature: NetUtils.getIpByHost(String hostName)
focal_class.full_signature: public static String getIpByHost(String hostName)
focal_class.identifier: getIpByHost
focal_class.modifiers: public static
focal_class.parameters: (String hostName)
focal_class.return: String
focal_class.signature: String getIpByHost(String hostName)
focal_class.class_method_signature: NetUtils.toAddressString(InetSocketAddress address)
focal_class.full_signature: public static String toAddressString(InetSocketAddress address)
focal_class.identifier: toAddressString
focal_class.modifiers: public static
focal_class.parameters: (InetSocketAddress address)
focal_class.return: String
focal_class.signature: String toAddressString(InetSocketAddress address)
focal_class.class_method_signature: NetUtils.toAddress(String address)
focal_class.full_signature: public static InetSocketAddress toAddress(String address)
focal_class.identifier: toAddress
focal_class.modifiers: public static
focal_class.parameters: (String address)
focal_class.return: InetSocketAddress
focal_class.signature: InetSocketAddress toAddress(String address)
focal_class.class_method_signature: NetUtils.toURL(String protocol, String host, int port, String path)
focal_class.full_signature: public static String toURL(String protocol, String host, int port, String path)
focal_class.identifier: toURL
focal_class.modifiers: public static
focal_class.parameters: (String protocol, String host, int port, String path)
focal_class.return: String
focal_class.signature: String toURL(String protocol, String host, int port, String path)
focal_class.class_method_signature: NetUtils.joinMulticastGroup(MulticastSocket multicastSocket, InetAddress multicastAddress)
focal_class.full_signature: public static void joinMulticastGroup(MulticastSocket multicastSocket, InetAddress multicastAddress)
focal_class.identifier: joinMulticastGroup
focal_class.modifiers: public static
focal_class.parameters: (MulticastSocket multicastSocket, InetAddress multicastAddress)
focal_class.return: void
focal_class.signature: void joinMulticastGroup(MulticastSocket multicastSocket, InetAddress multicastAddress)
focal_class.class_method_signature: NetUtils.setInterface(MulticastSocket multicastSocket, boolean preferIpv6)
focal_class.full_signature: public static void setInterface(MulticastSocket multicastSocket, boolean preferIpv6)
focal_class.identifier: setInterface
focal_class.modifiers: public static
focal_class.parameters: (MulticastSocket multicastSocket, boolean preferIpv6)
focal_class.return: void
focal_class.signature: void setInterface(MulticastSocket multicastSocket, boolean preferIpv6)
focal_class.class_method_signature: NetUtils.matchIpExpression(String pattern, String host, int port)
focal_class.full_signature: public static boolean matchIpExpression(String pattern, String host, int port)
focal_class.identifier: matchIpExpression
focal_class.modifiers: public static
focal_class.parameters: (String pattern, String host, int port)
focal_class.return: boolean
focal_class.signature: boolean matchIpExpression(String pattern, String host, int port)
focal_class.class_method_signature: NetUtils.matchIpRange(String pattern, String host, int port)
focal_class.full_signature: public static boolean matchIpRange(String pattern, String host, int port)
focal_class.identifier: matchIpRange
focal_class.modifiers: public static
focal_class.parameters: (String pattern, String host, int port)
focal_class.return: boolean
focal_class.signature: boolean matchIpRange(String pattern, String host, int port)
focal_class.class_method_signature: NetUtils.isMulticastAddress(String host)
focal_class.full_signature: public static boolean isMulticastAddress(String host)
focal_class.identifier: isMulticastAddress
focal_class.modifiers: public static
focal_class.parameters: (String host)
focal_class.return: boolean
focal_class.signature: boolean isMulticastAddress(String host)
focal_class.class_method_signature: NetUtils.ipPatternContainExpression(String pattern)
focal_class.full_signature: private static boolean ipPatternContainExpression(String pattern)
focal_class.identifier: ipPatternContainExpression
focal_class.modifiers: private static
focal_class.parameters: (String pattern)
focal_class.return: boolean
focal_class.signature: boolean ipPatternContainExpression(String pattern)
focal_class.class_method_signature: NetUtils.checkHostPattern(String pattern, String[] mask, boolean isIpv4)
focal_class.full_signature: private static void checkHostPattern(String pattern, String[] mask, boolean isIpv4)
focal_class.identifier: checkHostPattern
focal_class.modifiers: private static
focal_class.parameters: (String pattern, String[] mask, boolean isIpv4)
focal_class.return: void
focal_class.signature: void checkHostPattern(String pattern, String[] mask, boolean isIpv4)
focal_class.class_method_signature: NetUtils.getPatternHostAndPort(String pattern, boolean isIpv4)
focal_class.full_signature: private static String[] getPatternHostAndPort(String pattern, boolean isIpv4)
focal_class.identifier: getPatternHostAndPort
focal_class.modifiers: private static
focal_class.parameters: (String pattern, boolean isIpv4)
focal_class.return: String[]
focal_class.signature: String[] getPatternHostAndPort(String pattern, boolean isIpv4)
focal_class.class_method_signature: NetUtils.getNumOfIpSegment(String ipSegment, boolean isIpv4)
focal_class.full_signature: private static Integer getNumOfIpSegment(String ipSegment, boolean isIpv4)
focal_class.identifier: getNumOfIpSegment
focal_class.modifiers: private static
focal_class.parameters: (String ipSegment, boolean isIpv4)
focal_class.return: Integer
focal_class.signature: Integer getNumOfIpSegment(String ipSegment, boolean isIpv4)
focal_method.body: public static boolean matchIpRange(String pattern, String host, int port) throws UnknownHostException {
          if (pattern == null || host == null) {
              throw new IllegalArgumentException("Illegal Argument pattern or hostName. Pattern:" + pattern + ", Host:" + host);
          }
          pattern = pattern.trim();
          if ("*.*.*.*".equals(pattern) || "*".equals(pattern)) {
              return true;
          }
  
          InetAddress inetAddress = InetAddress.getByName(host);
          boolean isIpv4 = isValidV4Address(inetAddress);
          String[] hostAndPort = getPatternHostAndPort(pattern, isIpv4);
          if (hostAndPort[1] != null && !hostAndPort[1].equals(String.valueOf(port))) {
              return false;
          }
          pattern = hostAndPort[0];
  
          String splitCharacter = SPLIT_IPV4_CHARACTER;
          if (!isIpv4) {
              splitCharacter = SPLIT_IPV6_CHARACTER;
          }
          String[] mask = pattern.split(splitCharacter);
          //check format of pattern
          checkHostPattern(pattern, mask, isIpv4);
  
          host = inetAddress.getHostAddress();
          if (pattern.equals(host)) {
              return true;
          }
  
          // short name condition
          if (!ipPatternContainExpression(pattern)) {
              InetAddress patternAddress = InetAddress.getByName(pattern);
              return patternAddress.getHostAddress().equals(host);
              }
  
          String[] ipAddress = host.split(splitCharacter);
          for (int i = 0; i < mask.length; i++) {
              if ("*".equals(mask[i]) || mask[i].equals(ipAddress[i])) {
                  continue;
              } else if (mask[i].contains("-")) {
                  String[] rangeNumStrs = StringUtils.split(mask[i], '-');
                  if (rangeNumStrs.length != 2) {
                      throw new IllegalArgumentException("There is wrong format of ip Address: " + mask[i]);
                  }
                  Integer min = getNumOfIpSegment(rangeNumStrs[0], isIpv4);
                  Integer max = getNumOfIpSegment(rangeNumStrs[1], isIpv4);
                  Integer ip = getNumOfIpSegment(ipAddress[i], isIpv4);
                  if (ip < min || ip > max) {
                      return false;
                  }
              } else if ("0".equals(ipAddress[i]) && ("0".equals(mask[i]) || "00".equals(mask[i]) || "000".equals(mask[i]) || "0000".equals(mask[i]))) {
                  continue;
              } else if (!mask[i].equals(ipAddress[i])) {
                  return false;
              }
          }
          return true;
      }
focal_method.class_method_signature: NetUtils.matchIpRange(String pattern, String host, int port)
focal_method.full_signature: public static boolean matchIpRange(String pattern, String host, int port)
focal_method.identifier: matchIpRange
focal_method.invocations: trim equals equals getByName isValidV4Address getPatternHostAndPort equals valueOf split checkHostPattern getHostAddress equals ipPatternContainExpression getByName equals getHostAddress split equals equals contains split getNumOfIpSegment getNumOfIpSegment getNumOfIpSegment equals equals equals equals equals equals
focal_method.modifiers: public static
focal_method.parameters: (String pattern, String host, int port)
focal_method.return: boolean
focal_method.signature: boolean matchIpRange(String pattern, String host, int port)