开发者

Why does java NetworkInterface.getHardwareAddress return empty byte array on Windows?

I have the following code on a Windows machine:

for(Enumeration enm = NetworkInterface.getNetworkInterfaces(); enm.hasMoreElements();){
  NetworkIn开发者_开发问答terface 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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜