java.net.NetworkInterface
Michael Koch
konqueror@gmx.de
Sat Jun 21 08:16:00 GMT 2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Am Samstag, 21. Juni 2003 05:17 schrieb Erik Poupaert:
> 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?
This stuff isnt implemented yet for Windows but I know Mohan is
working on this. I've seen no patch from him yet but I think it will
not take much longer.
Michael
- --
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQE+9BUdWSOgCCdjSDsRAopwAKCS//PlMmMTq2VVzkr050OyndwGbACfTk6U
eCTCPq1z4Wfsrw2NRz7IPUA=
=V6zd
-----END PGP SIGNATURE-----
More information about the Java
mailing list