[lkml]   [2000]   [Nov]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread

Rob Landley <> writes:
> 3) Java sucks in many ways. Today's way is that it
> never occurred to Sun that a machine might have more
> than one IP address assigned to it, so
> InetAddress.getLocalHost() returns exactly one
> address. Unfortunately, just about EVERY machine has
> two interfaces defined, the other one being loopback
> on, and natrually the loopback is the one
> that getLocalHost() returns. (Since it's the one that
> we pretty much already know the address of anyway, and
> querying it is therefore useless, that's the one it
> queries. Thank you Sun.) There is no way to query
> the current machine's interfaces without resorting to
> native code.

I faced this problem a while ago - in the end I cheated and
put this bit of code in a shell script used to start the

NET_ADDRESSES=`/sbin/ifconfig | \
awk '/^[^ ].*HWaddr/ { HWaddr=$5; next;}
/^[^ ]/ { HWaddr=0; }
/^[ ].*addr:/ { if (HWaddr != 0) { printf("-Dethaddr.%s=%s -Dnetmask.%s=%s ",substr($2,6),HWaddr,substr($2,6),substr($4,6)); } } END {print;}'`

including ${NET_ADDRESSES} in the java command line sets
up a set of defines, one per interface. For example

-Dethaddr. -Dnetmask.

which you can use via System.getProperty() and System.getProperties()

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

 \ /
  Last update: 2005-03-22 12:45    [W:0.061 / U:0.208 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site