[ECOS] Re: How to get Ethernet link status?

Grant Edwards grante@visi.com
Fri Dec 19 19:25:00 GMT 2008


On 2008-12-19, Grant Edwards <grante@visi.com> wrote:
> On 2008-12-17, Grant Edwards <grante@visi.com> wrote:
>> On 2008-12-17, Jay Foster <jay@systech.com> wrote:
>>
>>> You may also be able to use the SIOCGIFSTATS socket ioctl to retrieve the
>>> eth_stats (struct ether_drv_stats) structure.  You can get the speed from
>>> the speed member and the duplex from the duplex member.  Not all ethernet
>>> drivers support the SIOCGIFSTATS ioctl.
>
> I can't figure out what you mean by "ethernet drivers support
> the SIOCGIFSTATS ioctl".  My driver suports the
> ETH_DRV_GET_IF_STATS control call, but that doesn't seem to be
> getting called.

It appears that my network tree was too old -- it wasn't
passing along the SIOCGIFSTATS command to the generic ethernet
driver layer.  I updated if.c and now the following code works:

    struct ifaddr *ifa = NULL;
    struct ifnet  *ifn = NULL;
    extern struct ifaddr **cyg_ifnet_addrs;

    // find interface pointer for "eth0"
    for (i=0; (ifa=cyg_ifnet_addrs[i]); ++i)
      {
        struct ifnet *p = ifa->ifa_ifp;
        diag_printf("ifp %p %s%d\n",p,p->if_name,p->if_unit);
        if (!strcmp(p->if_name,"eth") && p->if_unit==0)
          ifn = p;
      }
    if (ifn)
      {
        struct ether_drv_stats stats;
        ifn->if_ioctl(ifn,SIOCGIFSTATS,(void*)&stats);
        diag_printf("operational=%d, speed=%u, duplex=%d\n",stats.operational,stats.speed,stats.duplex);
      }

      
-- 
Grant Edwards                   grante             Yow! I want my nose in
                                  at               lights!
                               visi.com            


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss



More information about the Ecos-discuss mailing list