On Thu, 2005-01-06 at 13:15, sharath ramegowda wrote:
> i tried using the watcher handler u mentioned.

> 
> Now when i do a get on my variable:
> --------------------------------------
> 
> snmpget -v 2c -c public localhost
> .1.3.6.1.4.1.8072.2.5.2.0
> 
> NET-SNMP-EXAMPLES-MIB::netSnmpExamples.5.2.0 =
> Hex-STRING: 00 00 00 00 00 

> i am getting a hex-string output when i do a get
> whereas my set says it is a string variable.

In fact, SNMP does not include any distinction
between "hex strings" and "strings" - at least
not unless you use one of the string-based
Textual Conventions ("AsciiString" or similar).

So the snmpget command is simply trying to guess
whether the value is printable or not.
(And since it consists of all 0 characters,
then "not" seems a reasonable guess!)

So the real problem is why the value isn't
being returned.


> 
> the init_netsnmpfilename () code i have written is as
> follows:

> please help out and tell me where i have goofed up.

I can see two or three problems with that code.

Firstly:

> void init_netsnmpfilename(void)
> {
>   char str_buffer[33];

The "str_buffer" is used to hold the value throughout
the life of the agent, so it needs to remain valid for
as long as the agent is running.
  So you need to declare it as "static" (or file scoped).
But you *don't* need to declare the OID as static,
since this value is copied as part of registering the
scalar object.


>     netsnmp_create_watcher_info(
>            &str_buffer, 
>            sizeof(str_buffer),
>            ASN_OCTET_STR, 
>            WATCHER_MAX_SIZE)

The first parameter to 'netsnmp_create_watcher_info'
is a pointer to where the data will be stored, yes.
But a character array (as with any array) is *already*
a pointer, so you don't need to take the address of it.

Another problem is that the second parameter of this
call (the size of the buffer) has to serve two purposes:

  a)  The current size of the initial data
  b)  The maximum possible size of the buffer

Unfortunately, for variable-length strings, these two
values may well be different.

I'd suggest you initialise things as follows:

    netsnmp_watcher_info *winfo = 
>       netsnmp_create_watcher_info(
>            str_buffer, 
>            sizeof(str_buffer),
>            ASN_OCTET_STR, 
>            WATCHER_MAX_SIZE);
    winfo->data_size = 0;   /* Initially empty */

>   netsnmp_register_watched_scalar( 
>     netsnmp_create_handler_registration(....),
      winfo);

Dave



-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
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

Reply via email to