Nick Reilly
|
Re: Ethernet errors detection
|
Nick Reilly
06/04/2020 9:14 AM
post120728
|
Re: Ethernet errors detection
Take a look at the output of the "nicinfo" command, this reports the Ethernet stats. Note that this is entirely driver
dependent - different drivers report different stats.
The code for this is:
struct drvcom_stats dstats;
nic_stats_t *statp;
statp = &dstats.dcom_stats;
ifdcp->ifdc_cmd = DRVCOM_STATS;
ifdcp->ifdc_len = sizeof(*statp);
if ((ret = devctl(s, SIOCGDRVCOM, ifdcp,
sizeof(struct drvcom_stats), NULL)) == EOK) {
dump_stats(s, statp);
}
Link state is a separate API:
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>
int main(int argc, char **argv)
{
int s;
struct ifdatareq ifdata;
if (argc != 2) {
fprintf(stderr, "Incorrect usage\n");
return 1;
}
s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (s == -1 && errno != EPROTONOSUPPORT) {
fprintf(stderr, "can't open IPv4 socket %s", strerror(errno));
return 1;
}
memset(&ifdata, 0, sizeof(ifdata));
strlcpy(ifdata.ifdr_name, argv[1], IF_NAMESIZE);
if (ioctl(s, SIOCGIFDATA, &ifdata) == -1) {
fprintf(stderr, "ioctl failed: %s\n", strerror(errno));
exit(1);
}
fprintf(stdout, "Linkstate %d\n", ifdata.ifdr_data.ifi_link_state);
return 0;
}
|
|
|