我在
this页面上看到了在ubuntu中获取有关网卡及其统计信息的一些很好的解释.这给出了一个很好的输出,如页面上提到的那样.我也试过阅读其他文档,但找不到标志或类似的东西,我可以区分我的系统上的真实和虚拟网卡.
有区别的方法吗?
谢谢.
检查/ sys / class / net /< device_name>符号链接.如果它指向/ sys / devices / Virtual /,则它是一个虚拟接口.如果它指向“真实”设备(例如,进入/ sys / devices / pci0000:00 /),那么它不是.
编辑:
从代码中,您可以使用readlink来检查设备是否是虚拟的.这是一个非常虚拟的示例代码:
#include
#include
#include
#include
int main(int argc, char **argv) {
char theLink[128];
char thePath[128];
strcpy(thePath,"/sys/class/net/");
memset(theLink,0,128);
if (argc>1) {
strcat(thePath,argv[1]);
} else {
printf("Gimme device\n");
return 1;
}
if (readlink(thePath, theLink, 127)==-1) {
perror(argv[1]);
} else {
if (strstr(theLink,"/Virtual")) {
printf("%s is a Virtual device\n",argv[1]);
} else {
printf("%s is a physical device\n",argv[1]);
}
}
}