检查/ 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]);
}
}
}