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

EJP
I suggest you print out the name of the interface before trying to get its MAC address, and investigate the characteristics of the one that fails. Probably it is one that doesn't have a MAC address, e.g. 127.0.0.1.
qjvictor
Thanks for your reply.

The exception is specifically from the network interface between M5000 service processor and each domain.

In my case, I just need to catch this exception, and continue to get mac address from other interfaces.
1 - 2
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,078 views