Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Get SocketException when trying to get Mac address.

qjvictorAug 20 2012 — edited Aug 27 2012
I got SocketException when trying to get mac address from a solaris machine:

JDK: 1.6.26.
Solaris:
Release: 5.10
Kernel architecture: sun4u
Application architecture: sparc
Hardware provider: Oracle Corporation
Domain: Kernel version: SunOS 5.10 Generic_147440-01

java code:
Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
while (en.hasMoreElements()) {
NetworkInterface intf = en.nextElement();
byte[] mac = intf.getHardwareAddress();
...
}

Stacktrace:
java.net.SocketException: Invalid argument
at java.net.NetworkInterface.getMacAddr0(Native Method)
at java.net.NetworkInterface.getHardwareAddress(NetworkInterface.java:385)

Hardware and environment:
The Solaris is on one of four domains on a M5000 server, it has its own set of hardware resources which includes the network interface.
If you run shell script commands like 'arp –a' or '/usr/bin/netstat -pn', it would display correct mac address.
But if you are using Java NetworkInterface.getHardwareAddress() api, it will throw SocketException.

Any suggestion is welcomed.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 24 2012
Added on Aug 20 2012
2 comments
1,080 views