Browse Source

Bugzilla 49513, reported by jks/iname

Availability of hostname is now taken into consideration when selecting a local address.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@990653 13f79535-47bb-0310-9956-ffa450edef68
master
Jacobus Martinus Kruithof 15 years ago
parent
commit
ff51ff3412
2 changed files with 32 additions and 8 deletions
  1. +8
    -0
      WHATSNEW
  2. +24
    -8
      src/main/org/apache/tools/ant/taskdefs/HostInfo.java

+ 8
- 0
WHATSNEW View File

@@ -55,6 +55,14 @@ Changes that could break older environments:
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.



+ 24
- 8
src/main/org/apache/tools/ant/taskdefs/HostInfo.java View File

@@ -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);


Loading…
Cancel
Save