hadoop-common-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hong Tang (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HADOOP-6682) NetUtils:normalizeHostName does not process hostnames starting with [a-f] correctly
Date Tue, 06 Apr 2010 04:42:27 GMT

    [ https://issues.apache.org/jira/browse/HADOOP-6682?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12853739#action_12853739
] 

Hong Tang commented on HADOOP-6682:
-----------------------------------

Similar issue came up in MAPREDUCE-1222. The following code might be useful:

{noformat}
+  static Pattern IP_PATTERN;
+  
+  static {
+    // 0-255
+    String IPV4BK1 = "(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)";
+    // .b.c.d - where b/c/d are 0-255, and optionally adding two more
+    // backslashes before each period
+    String IPV4BKN = "(?:\\\\?\\." + IPV4BK1 + "){3}";
+    String IPV4_PATTERN = IPV4BK1 + IPV4BKN;
+    
+    // first hexadecimal number
+    String IPV6BK1 = "(?:[0-9a-fA-F]{1,4})";
+    // remaining 7 hexadecimal numbers, each preceded with ":".
+    String IPV6BKN = "(?::" + IPV6BK1 + "){7}";
+    String IPV6_PATTERN = IPV6BK1 + IPV6BKN;
+
+    IP_PATTERN = Pattern.compile(
+        "^(?:" + IPV4_PATTERN + "|" + IPV6_PATTERN + ")$");
+  }
+
+ 
+  static boolean isIPAddress(String hostname) {
+    return IP_PATTERN.matcher(hostname).matches();
+  }
{noformat}

> NetUtils:normalizeHostName does not process hostnames starting with [a-f] correctly
> -----------------------------------------------------------------------------------
>
>                 Key: HADOOP-6682
>                 URL: https://issues.apache.org/jira/browse/HADOOP-6682
>             Project: Hadoop Common
>          Issue Type: Bug
>          Components: io
>            Reporter: Jakob Homan
>
>   public static String normalizeHostName(String name) {
>     if (Character.digit(name.charAt(0), 16) != -1) {
>       return name;
> This code is attempting to short-circuit the hostname->ip resolution on the assumption
that if name starts with a digit, it's already an ip address.  This is of questionable value,
but because it checks for a hex digit, it will fail on names starting with [a-f].  Such names
will not be converted to an ip address, but be returned unchanged.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message