Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Ethernet errors detection: (4 Items)
   
Ethernet errors detection  
Hello,

I need a way to detect any ethernet errors (e.g. crc check failed, cable unplugged, etc). Is there any api to obtain 
these errors programmatically? I tried to investigate io-pkt, but this tool is only allows to write and launch own 
drivers, but I couldn't find api to check health status of those drivers.

Thank you.
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;
}
Re: Ethernet errors detection  
Thanks a lot for response!

> 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);
> 		}
> 

Could you tell me what header files do I need for this code?

Also, as I understand, do we need to reach driver suppliers in order to extend information about Ethernet interface?
Re: Ethernet errors detection  
See net/ifdrvcom.h and hw/nicinfo.h

You will need to look at the valid_stats field in nic_ethernet_stats_t to determine which stats the driver supports. If 
that doesn't have everything you need then yes, you will need to contact the driver vendor to add support.