You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by GitBox <gi...@apache.org> on 2022/04/14 12:58:37 UTC

[GitHub] [hadoop] hemanthboyina commented on a diff in pull request #3290: HADOOP-17843. Support IPV6 with IP for internal and external communication

hemanthboyina commented on code in PR #3290:
URL: https://github.com/apache/hadoop/pull/3290#discussion_r850414027


##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java:
##########
@@ -1218,4 +1219,31 @@ public static InetAddress bindToLocalAddress(InetAddress localAddr, boolean
     }
     return null;
   }
+
+  /**
+   * Parse the given address into  IP & Port number pair.
+   * @param bindAddress IP Address to parse
+   * @return Pair of IP-Address & Port number.
+   */
+  public static Pair<String, Integer> parseAddress2IpAndPort(
+      String bindAddress) {
+    String[] parts = org.apache.hadoop.util.StringUtils
+        .split(bindAddress, ':');
+    Pair <String, Integer> pair = null;
+    //If bind address is IPv6
+    if (bindAddress.split(":").length > 2) {

Review Comment:
   can use parts.length > 2, as parts is equal to bindAddress.split(":")



##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java:
##########
@@ -1218,4 +1219,31 @@ public static InetAddress bindToLocalAddress(InetAddress localAddr, boolean
     }
     return null;
   }
+
+  /**
+   * Parse the given address into  IP & Port number pair.
+   * @param bindAddress IP Address to parse
+   * @return Pair of IP-Address & Port number.
+   */
+  public static Pair<String, Integer> parseAddress2IpAndPort(
+      String bindAddress) {
+    String[] parts = org.apache.hadoop.util.StringUtils
+        .split(bindAddress, ':');
+    Pair <String, Integer> pair = null;
+    //If bind address is IPv6
+    if (bindAddress.split(":").length > 2) {
+      String target = bindAddress;
+      int i = target.lastIndexOf(":");
+      String portNum = target.substring(i + 1);

Review Comment:
   can use parts array itself to find out the port ?



-- 
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: common-issues-unsubscribe@hadoop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org