Name: boT120536 Date: 04/09/2001
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)
There doesn't seem to be a way to get the current IP address
of my box with InetAddress. Calling InetAddress.getLocalHost()
always gives 127.0.0.1. I'm running RedHat 7.0 and we use
DHCP here.
Note that this is not the same bug as that reported for
Solaris which can be worked around by modifying the /etc/hosts
file.
Sorry for the late reply. Here's some code to
reproduce this issue:
import java.net.*;
public class TestHost
{
public static void main (String[] arg)
throws Exception
{
InetAddress local =InetAddress.getLocalHost();
System.out.println ("local = " + local);
InetAddress[] hosts = InetAddress.getAllByName("localhost");
for (int i = 0; i < hosts.length; i++) {
System.out.println ("host " + i + ": " + hosts[i]);
}
ServerSocket socket = new ServerSocket (8907);
System.out.println ("socket at " +socket.getInetAddress());
}
}
The output I get is:
local = js/127.0.0.1
host 0: localhost/127.0.0.1
socket at 0.0.0.0/0.0.0.0
This is what ifconfig reports:
eth0 Link encap:Ethernet HWaddr00:10:A4:93:05:E5
inet addr:192.168.0.14 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MTU:1500 Metric:1
RX packets:579 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:245 dropped:0 overruns:0 carrier:245
collisions:0 txqueuelen:100
Interrupt:11 Base address:0x200
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:3924 Metric:1
RX packets:64 errors:0 dropped:0 overruns:0 frame:0
TX packets:64 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
Again, the system is RedHat 7.
(Review ID: 119763)
======================================================================