我在此页面上看到了一些很好的解释,用于在 ubuntu 中获取有关网卡及其统计信息的信息。如页面上所述,这给出了很好的输出。我也尝试阅读其他文档,但找不到可以区分系统上真实网卡和虚拟网卡的标志或类似内容。
有没有办法区分?谢谢。
我有一个 FreeBSD 11 系统,在其中我得到以下ifconfig
命令输出
# ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
inet 127.0.0.1 netmask 0xff000000
nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
groups: lo
xn0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=503<RXCSUM,TXCSUM,TSO4,LRO>
ether 0e:c2:a2:36:c1:b4
inet 10.0.0.71 netmask 0xffffff00 broadcast 10.0.0.255
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
media: Ethernet manual
status: active
这里有两个疑问:
.conf
文件控制)而不是更改我的监视方法(例如解析来自iftop
或其他命令的响应)提前致谢 !
编辑
具体来说,在该二进制文件中使用了一个 C 库来获取结果为零的统计信息。我附上了一个示例代码,它也为 rx/tx 字节返回零值,因为该信息不可用。它使用库getifaddrs
中的函数sys/sockets
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <ifaddrs.h>
struct if_data {
unsigned char ifi_type;
unsigned char ifi_physical;
unsigned char ifi_addrlen;
unsigned char ifi_hdrlen;
unsigned char ifi_recvquota;
unsigned char ifi_xmitquota;
unsigned long ifi_mtu;
unsigned long ifi_metric;
unsigned long ifi_baudrate;
unsigned long ifi_ipackets;
unsigned long ifi_ierrors;
unsigned long ifi_opackets;
unsigned long ifi_oerrors;
unsigned long ifi_collisions;
unsigned long ifi_ibytes;
unsigned long ifi_obytes;
unsigned long ifi_imcasts;
unsigned long ifi_omcasts;
unsigned long ifi_iqdrops;
unsigned long ifi_noproto;
unsigned long ifi_recvtiming;
unsigned long ifi_xmittiming;
struct timeval ifi_lastchange;
};
int main()
{
struct ifaddrs *ifap, *ifa;
struct if_data *ifadata = NULL;
char *dev_name;
if (getifaddrs(&ifap) < 0) {
printf ("returning for null");
return 1;
}
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
if (ifa->ifa_flags & 0x01) {
if ( ifa->ifa_addr->sa_family == AF_LINK) {
if (ifa->ifa_data) {
ifadata = (struct if_data *)ifa->ifa_data;
dev_name = ifa->ifa_name;
if (ifadata->ifi_ipackets == 0 && ifadata->ifi_opackets == 0)
{
printf("returning as zero for %s", dev_name);
continue;
}
printf("name=%s ipkts=%ld opkts=%ld\n", dev_name,
ifadata->ifi_ipackets, ifadata->ifi_opackets);
printf("%lu", ifadata->ifi_ibytes);
printf("%lu", ifadata->ifi_ipackets);
printf("%lu", ifadata->ifi_ierrors);
printf("%lu", ifadata->ifi_iqdrops);
printf("%lu", ifadata->ifi_imcasts);
printf("%lu", ifadata->ifi_obytes);
printf("%lu", ifadata->ifi_opackets);
printf("%lu", ifadata->ifi_oerrors);
}
}
}
}
freeifaddrs(ifap);
return 0;
}