Re: Dynmically retrieving only objects with real values?

"Dave Shield" <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
On 09/01/07, Wilson, Dave <[email protected]> wrote:
>                                          However, I do not
> want to return entries if they have no value, so in this example, I won't
> return statsname.4, but the walk will go onto the next category.  I do this
> by using code like this in the var_CommonStatsTable function:
>
>     case STATSNAME:
>         strcpy (string, tempPTR->Name);
>         *var_len = strlen(string);
>         if ( strlen(string) == 0 ) return NULL;
>         return (unsigned char *) string;

I would suggest not updating '*var_len' until after you've
checked whether this entry is valid.   It probably doesn't
make a difference, but

     case STATSNAME:
         strcpy (string, tempPTR->Name);
         if ( strlen(string) == 0 ) return NULL;
         *var_len = strlen(string);
         return (unsigned char *) string;

would be slightly safer


> This works fine for strings, but not counters because I sometimes want to
> return objects with values of 0, eg. statsval.1, but I don't want to return
> statsval.4.
>
> How do I do this so that both snmpwalk and a specific snmpget (eg. on
> statsval.3) will work?

Use exactly the same test as above:

     case STATSVALUE:
         if ( strlen(tempPTR->Name) == 0 ) return NULL;      <====
         long_ret = tempPTR->Value;
         return (unsigned char *) &long_ret;

Dave

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.