https://bz.apache.org/bugzilla/show_bug.cgi?id=62566
Bug ID: 62566 Summary: hostinfo task unusable if network interface is multihomed Product: Ant Version: 1.10.5 Hardware: All OS: HP-UX Status: NEW Severity: major Priority: P2 Component: Core tasks Assignee: notifications@ant.apache.org Reporter: 1983-01...@gmx.net Target Milestone: --- Using <hostinfo /> on a multihomed machine gives incorrect hostname and host address due to the best matching algorithm. I have refactored Ant's code into a seperate class with a custom traversal for my machine interfaces: > public static void main(String[] args) throws Exception { > InetAddress lo = InetAddress.getLocalHost(); > System.out.println("InetAddress.getLocalHost():"); > System.out.println(" HostName: " + lo.getHostName()); > System.out.println(" CanonicalHostName: " + lo.getCanonicalHostName()); > System.out.println(" HostAddress: " + lo.getHostAddress()); > > Enumeration<NetworkInterface> ee = > NetworkInterface.getNetworkInterfaces(); > System.out.println("Network Interfaces:"); > while (ee.hasMoreElements()) { > NetworkInterface ni = ee.nextElement(); > if (!ni.isLoopback()) { > System.out.println( > " " + ni + " (" + (ni.isVirtual() ? > "virtual" : "physical") + ")"); > List<InetAddress> addrs = > Collections.list(ni.getInetAddresses()); > > if (!addrs.isEmpty()) { > > System.out.println(" Addresses:"); > > for (InetAddress inetAddress : addrs) { > System.out.println(" " + > inetAddress); > } > } > > List<NetworkInterface> see = > Collections.list(ni.getSubInterfaces()); > if (!see.isEmpty()) { > System.out.println(" Virtual Network > Interfaces:"); > for (NetworkInterface vni : see) { > System.out.println(" " + vni + " (" > + (vni.isVirtual() ? > "virtual" : "physical") + ")"); > > List<InetAddress> vaddrs = > Collections.list(vni.getInetAddresses()); > > if (!vaddrs.isEmpty()) { > > System.out.println(" > Addresses:"); > > for (InetAddress inetAddress : > vaddrs) { > System.out.println(" > " + inetAddress); > } > } > } > } > } > } > > HostInfo hi = new HostInfo(); > hi.executeLocal(); > System.out.println("Ant's HostInfo task:"); > System.out.println(" " + hi.props); > } The output is: > bash $ java HostInfo > InetAddress.getLocalHost(): > HostName: blnn724x.ad001.siemens.net > CanonicalHostName: blnn724x.ad001.siemens.net > HostAddress: 147.54.64.24 > Network Interfaces: > name:lan0 (lan0) (physical) > Addresses: > /147.54.65.7 > /147.54.65.2 > /147.54.64.24 > Virtual Network Interfaces: > name:lan0:2 (lan0:2) (virtual) > Addresses: > /147.54.65.7 > name:lan0:1 (lan0:1) (virtual) > Addresses: > /147.54.65.2 > Ant's HostInfo task: > {ADDR6=::1, ADDR4=147.54.65.7, DOMAIN=bln3.siemens.de, NAME=hp7v} As you can see, the task is unusable on this host. I know that changing the code might break others, but a better option would be either to exclude addresses on virtual interfaces OR provide two strategies: bestmatch and localhost. I am on Java 8 and HP-UX 11.31. -- You are receiving this mail because: You are the assignee for the bug.