onejimmyboy commented on code in PR #7287:
URL: https://github.com/apache/rocketmq/pull/7287#discussion_r1314725974


##########
common/src/main/java/org/apache/rocketmq/common/utils/NetworkUtil.java:
##########
@@ -153,6 +154,25 @@ public static SocketAddress string2SocketAddress(final 
String addr) {
         return isa;
     }
 
+    public static void validateNamesrvAddress(final String addr) throws 
Exception {
+        int split = addr.lastIndexOf(":");
+        String host = addr.substring(0, split);
+        if (!isValidIPAddress(host)) {
+            throw new Exception("Invalid NameServer address:" + addr);
+        }
+    }
+
+    public static boolean isValidIPAddress(String ipAddress) {
+        InetAddressValidator validator = InetAddressValidator.getInstance();
+        if (validator.isValidInet4Address(ipAddress)) {
+            return true;
+        }
+        if (validator.isValidInet6Address(ipAddress)) {
+            return true;
+        }
+        return ipAddress.equals("localhost");

Review Comment:
   Good idea, it has been modified



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to