This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
java.net.NetworkInterface
- From: Erik Poupaert <erik dot poupaert at chello dot be>
- To: java at gcc dot gnu dot org
- Date: Sat, 21 Jun 2003 03:17:18 +0000
- Subject: java.net.NetworkInterface
I finally found a way to figure out network ip address for localhost:
protected static String getHostIpAddress()
{
try
{
Enumeration networkInterfaces=NetworkInterface.getNetworkInterfaces();
for (Enumeration e = NetworkInterface.getNetworkInterfaces() ;
e.hasMoreElements() ;)
{
NetworkInterface netIf=(NetworkInterface)e.nextElement();
for(Enumeration e2=netIf.getInetAddresses(); e2.hasMoreElements();)
{
InetAddress address=(InetAddress)e2.nextElement();
String ip=address.getHostAddress();
//grab the first non-loopback address
if(!ip.equals("127.0.0.1")) return ip;
}
}
throw new RuntimeException("error resolving localhost ip address");
}
catch(Exception e)
{
throw new RuntimeException(e.getMessage());
}
}
It works fine on linux: gcc version 3.3 release.
On Windows, however (gcc version 3.3 20030409 (prerelease),
NetworkInterface.getNetworkInterfaces() indiscriminately throws a
java.net.SocketException.
Does anybody know if this problem has been solved after 20030409 in Windows? Could I
avoid this by downloading Mohan's latest build?
--