Rob Landley <[EMAIL PROTECTED]> 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 127.0.0.1, 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
application

    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.172.16.1.1=00:00:0A:BC:CD:78 -Dnetmask.172.16.1.1=255.255.0.0

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 [EMAIL PROTECTED]
Please read the FAQ at http://www.tux.org/lkml/

Reply via email to