Thanks Dave, but " 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; " tempPTR->Name is not a string, it's an integer. Is it safe to cast it? Or is there another way to do the test? How can I determine if the pointer is referencing a real value or not? Dave -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dave Shield Sent: Wednesday, January 10, 2007 4:11 AM To: Wilson, Dave Cc: net-snmp-users@lists.sourceforge.net Subject: Re: Dynmically retrieving only objects with real values? 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 Net-snmp-users@lists.sourceforge.net Please see the following page to unsubscribe or change other options: https://lists.sourceforge.net/lists/listinfo/net-snmp-users