This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: SNMP lockup


On 2009-05-08, Grant Edwards <grante@visi.com> wrote:

> It should also probably check to make sure index doesn't go off
> then end of if_addrs[] when large positive numbers are passed.
> Perhaps something like this:
>
> struct ifnet *cyg_snmp_get_if(int if_num)
>   {
>     int index = 0;
>     struct ifnet *ifp;
>
>     if (if_num == 0)
>       return NULL;
>
>     do
>       {
>         while (0 == ifnet_addrs[index] && index < if_index)
>           index++;
>
>         if (index >= if_index)
>           return NULL;
>
>         ifp = ifnet_addrs[index]->ifa_ifp;
>
>         if_num--;
>         index++;
>       }
>     while (if_num);
>
>     return ifp;
>   }

I've decided that's just way too convoluted.  It's already
fooled several people for several years.  How about this?

long cyg_snmp_num_interfaces(void) {
  int i,n=0;

  for (i=0; i<if_index; ++i)
    if (ifnet_addrs[i])
      n++;

  return n;
}

struct ifnet *cyg_snmp_get_if(int if_num) {
  int i,n=0;

  for (i=0; i<if_index; ++i)
    if (ifnet_addrs[i])
      if (++n == if_num)
        return ifnet_addrs[i]->ifa_ifp;

  return NULL;
}

Maybe it's just me, that that seems a lot more transparent. Or
am I missing something subtle in the original versions?

-- 
Grant



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]