ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r990653 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/taskdefs/HostInfo.java
Date Sun, 29 Aug 2010 21:07:30 GMT
Author: jkf
Date: Sun Aug 29 21:07:29 2010
New Revision: 990653

URL: http://svn.apache.org/viewvc?rev=990653&view=rev
Log:
Bugzilla 49513, reported by jks/iname 
Availability of hostname is now taken into consideration when selecting a local address.

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/HostInfo.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=990653&r1=990652&r2=990653&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Sun Aug 29 21:07:29 2010
@@ -55,6 +55,14 @@ Changes that could break older environme
 Fixed bugs:
 -----------
 
+ * hostinfo now prefers addresses with a hostname over addresses without 
+   a hostname, provided the addresses have the same scope.
+   For local lookup, no IP address will be put in NAME / DOMAIN anymore.
+   For remote lookup, if a host name was provided and only an IP address is 
+   found, the IP address will no longer overwrite the host name provided to the
+   task.
+   Bugzilla Report 49513
+
  * mmap-based file copy problems under JDK 1.4 on Linux.
    Bugzilla Report 49430.
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/HostInfo.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/HostInfo.java?rev=990653&r1=990652&r2=990653&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/HostInfo.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/HostInfo.java Sun Aug 29 21:07:29
2010
@@ -129,7 +129,7 @@ public class HostInfo extends Task {
             }
             selectAddresses();
 
-            if (nameAddr != null) {
+            if (nameAddr != null && hasHostName(nameAddr)) {
                 setDomainAndName(nameAddr.getCanonicalHostName());
             } else {
                 setProperty(DOMAIN, DEF_DOMAIN);
@@ -153,6 +153,11 @@ public class HostInfo extends Task {
             setProperty(ADDR6, DEF_LOCAL_ADDR6);
         }
     }
+    
+    private boolean hasHostName(InetAddress addr)
+    {   
+        return !addr.getHostAddress().equals(addr.getCanonicalHostName());
+    }
 
     private void selectAddresses() {
         Iterator i = inetAddrs.iterator();
@@ -167,7 +172,7 @@ public class HostInfo extends Task {
             }
         }
         
-        nameAddr = selectBestAddress(best6, best4);
+        nameAddr = selectBestAddress(best4, best6);
     }
 
     private InetAddress selectBestAddress(InetAddress bestSoFar,
@@ -177,7 +182,7 @@ public class HostInfo extends Task {
             // none selected so far, so this one is better.
             best = current;
         } else {
-            if (current.isLoopbackAddress()) {
+            if (current == null || current.isLoopbackAddress()) {
                 // definitely not better than the previously selected address.
             } else if (current.isLinkLocalAddress()) {
                 // link local considered better than loopback
@@ -186,13 +191,24 @@ public class HostInfo extends Task {
                 }
             } else if (current.isSiteLocalAddress()) {
                 // site local considered better than link local (and loopback)
-                if (best.isLoopbackAddress() || best.isLinkLocalAddress()) {
+                // address with hostname resolved considered better than
+                // address without hostname
+                if (best.isLoopbackAddress()
+                        || best.isLinkLocalAddress()
+                        || !hasHostName(best)) {
                     best = current;
                 }
             } else {
-                // current is a global address, and therefore best (at least
-                // equally well)
-                best = current;
+                // current is a "Global address", considered better than 
+                // site local (and better than link local, loopback)
+                // address with hostname resolved considered better than
+                // address without hostname
+                if (best.isLoopbackAddress()
+                        || best.isLinkLocalAddress()
+                        || best.isSiteLocalAddress()
+                        || !hasHostName(best)) {
+                    best = current;
+                }
             }
         }
         return best;
@@ -204,7 +220,7 @@ public class HostInfo extends Task {
 
             selectAddresses();
 
-            if (nameAddr != null) {
+            if (nameAddr != null && hasHostName(nameAddr)) {
                 setDomainAndName(nameAddr.getCanonicalHostName());
             } else {
                 setDomainAndName(host);



Mime
View raw message