You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by el...@apache.org on 2012/03/23 04:13:10 UTC
svn commit: r1304174 - in /hadoop/common/branches/branch-1: CHANGES.txt
src/core/org/apache/hadoop/net/DNS.java
Author: eli
Date: Fri Mar 23 03:13:10 2012
New Revision: 1304174
URL: http://svn.apache.org/viewvc?rev=1304174&view=rev
Log:
HADOOP-8154. DNS#getIPs shouldn't silently return the local host IP for bogus interface names. Contributed by Eli Collins
Modified:
hadoop/common/branches/branch-1/CHANGES.txt
hadoop/common/branches/branch-1/src/core/org/apache/hadoop/net/DNS.java
Modified: hadoop/common/branches/branch-1/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/CHANGES.txt?rev=1304174&r1=1304173&r2=1304174&view=diff
==============================================================================
--- hadoop/common/branches/branch-1/CHANGES.txt (original)
+++ hadoop/common/branches/branch-1/CHANGES.txt Fri Mar 23 03:13:10 2012
@@ -101,6 +101,9 @@ Release 1.1.0 - unreleased
MAPREDUCE-1740. NPE in getMatchingLevelForNodes when node locations are
variable depth (ahmed via tucu)
+ HADOOP-8154. DNS#getIPs shouldn't silently return the local host
+ IP for bogus interface names. (eli)
+
IMPROVEMENTS
MAPREDUCE-3597. [Rumen] Provide a way to access other info of history file
Modified: hadoop/common/branches/branch-1/src/core/org/apache/hadoop/net/DNS.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/src/core/org/apache/hadoop/net/DNS.java?rev=1304174&r1=1304173&r2=1304174&view=diff
==============================================================================
--- hadoop/common/branches/branch-1/src/core/org/apache/hadoop/net/DNS.java (original)
+++ hadoop/common/branches/branch-1/src/core/org/apache/hadoop/net/DNS.java Fri Mar 23 03:13:10 2012
@@ -30,6 +30,9 @@ import javax.naming.directory.Attributes
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
*
* A class that provides direct and reverse lookup functionalities, allowing
@@ -39,6 +42,8 @@ import javax.naming.directory.InitialDir
*/
public class DNS {
+ public static final Log LOG = LogFactory.getLog(DNS.class);
+
/**
* Returns the hostname associated with the specified IP address by the
* provided nameserver.
@@ -82,25 +87,32 @@ public class DNS {
* interface
* @throws UnknownHostException
* If an UnknownHostException is encountered in querying the
- * default interface
+ * default interface or the given interface can not be found
*
*/
public static String[] getIPs(String strInterface)
throws UnknownHostException {
+ if ("default".equals(strInterface)) {
+ return new String[] {
+ InetAddress.getLocalHost().getHostAddress()
+ };
+ }
try {
NetworkInterface netIF = NetworkInterface.getByName(strInterface);
- if (netIF == null)
- return new String[] { InetAddress.getLocalHost()
- .getHostAddress() };
- else {
+ if (netIF == null) {
+ throw new UnknownHostException("Unknown interface " + strInterface);
+ } else {
Vector<String> ips = new Vector<String>();
- Enumeration e = netIF.getInetAddresses();
+ Enumeration<InetAddress> e = netIF.getInetAddresses();
while (e.hasMoreElements())
- ips.add(((InetAddress) e.nextElement()).getHostAddress());
+ ips.add(e.nextElement().getHostAddress());
return ips.toArray(new String[] {});
}
} catch (SocketException e) {
- return new String[] { InetAddress.getLocalHost().getHostAddress() };
+ LOG.warn("Unable to get IP for interface " + strInterface, e);
+ return new String[] {
+ InetAddress.getLocalHost().getHostAddress()
+ };
}
}