Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Character.digit(name.charAt(0), 16) != -1 could tell whether is a IP addr #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/core/org/apache/hadoop/net/NetUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,9 @@ public static void connect(Socket socket,
}
}

private static final Pattern ipPattern = // Pattern for ip
Pattern.compile("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");

/**
* Given a string representation of a host, return its ip address
* in textual presentation.
Expand All @@ -431,7 +434,8 @@ public static void connect(Socket socket,
* @return its IP address in the string format
*/
public static String normalizeHostName(String name) {
if (Character.digit(name.charAt(0), 16) != -1) { // it is an IP
// if (Character.digit(name.charAt(0), 16) != -1) { // it is an IP
if (ipPattern.matcher(name).matches()) { // it is an IP
return name;
} else {
try {
Expand Down