On 8 June 2010 22:00, Magnus Fromreide <[email protected]> wrote:
>      * You are telling the agent that you are returning a buffer of 256
>        bytes but you are only initializing about ten of those bytes,
>        the rest you are leaving unspecified.

That's probably more of a design flaw, rather than broken code.
Since the watcher is initialised using "strlen()", the effect is to
define a buffer that's effectively 17 bytes in size.

It would be exactly the same as

   char abcName[17+1] = "ABC Default value";


>      * Further, it looks as if you are initializing it with a local
>        variable in a function, if that is the case then it is expected
>        that the result contains utter garbage as it is whatever happens
>        to be at the stack when the handler is called.

I suspect that this is the real cause of the erroneous values.
The watched buffer *MUST* be persistent beyond the lifetime
of the initialisation routine.


The other variables (the OID, the watcher_info structure, and
the handler registration structure) can be local to the initialisation
routine - they don't need to be defined as file scoped variables,
or as static.

   But the buffer that holds the value being watched *does*
need to be either file scoped or static  (or both, as Magnus suggests)


Dave

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to