我在ubuntu 16.04上使用java 8。类java.net.NetworkInterface有两个接口名称的方法。第一个是:
Get the name of this network interface.
Returns:
the name of this network interface
public String [More ...] getName() {
return name;
}
另一个是:
Get the display name of this network interface. A display name is a human readable String describing the network device.
Returns:
the display name of this network interface, or null if no display name is available.
public String [More ...] getDisplayName() {
return displayName;
}
当我执行ifconfig时,输出为:
enp0s25 Link encap:Ethernet HWaddr 00:24:1d:6e:03:42
inet addr:10.100.14.40 Bcast:10.100.255.255 Mask:255.255.0.0
inet6 addr: fe80::fc60:10a7:2f7e:127f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:30338414 errors:0 dropped:31 overruns:0 frame:0
TX packets:446227 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3188550996 (3.1 GB) TX bytes:53620407 (53.6 MB)
Interrupt:16 Memory:fc500000-fc520000
仅显示一个名称。如果我运行以下程序:
import java.net.*;
import java.io.*;
import java.util.*;
class MyNetworkInterface
{
public static void main(String[] args) throws Exception
{
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while(interfaces.hasMoreElements())
{
NetworkInterface n = (NetworkInterface) interfaces.nextElement();
System.out.println(n);
System.out.printf("the Name is: %s%n", n.getDisplayName());
System.out.printf("the Name: %s%n", n.getName());
}
}
}
输出结果为:
name:enp0s25 (enp0s25)
the Name is: enp0s25
the Name: enp0s25
name:lo (lo)
the Name is: lo
the Name: lo
两个名字都相同。
我的问题是: 网络接口的名称和显示名称有什么区别?为什么使用两个名字?