0

I have the following code on a Windows machine:

for(Enumeration enm = NetworkInterface.getNetworkInterfaces(); enm.hasMoreElements();){
  NetworkInterface network = (NetworkInterface) enm.nextElement();
    if(null != network.getHardwareAddress()){
      return EthernetAddress.valueOf(network.getHardwareAddress());
    }
 }

This fails because the network.getHardwareAddress() returns an empty byte array, instead of null as stated in the javadocs for NetworkInterface. Does anyone know why this may happen?

0

2 Answers 2

1

I did this and saw that the loopback (which apeared first) has no mac address.

My guess is that null is intended for when the OS returns that the MAC was unavailable. However it may have returned empty data instead.

On Linux, it doesn't show me the loopback.

Sign up to request clarification or add additional context in comments.

1 Comment

loopback is not a physical adapter and the null-return complies the spec of getHardwareAddress()
-1

The byte array returned from network.getHardwareAddress() gets null if you are not connected to any network (LAN or WAN) hence it returns null value

1 Comment

The hardware address is visible, when the adapter is active, no link required

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.