On Tue, 2010-06-08 at 14:47 +0530, Prakash wrote:
> Hi all,
>
> I used the following code to register string type scalar
>
> netsnmp_handler_registration *reg;
> netsnmp_watcher_info *winfo;
>
> oid abcName_oid[] = {1,3,6,1,4,1,3286,13,5,1,1,3,0};
> char abcName[256] = "ABC Default value";
> reg = netsnmp_create_handler_registration("abcName", NULL,
> abcName_oid,
> OID_LENGTH(abcName_oid), HANDLER_CAN_RWRITE);
>
> winfo = netsnmp_create_watcher_info(abcName, strlen(abcName),
> ASN_OCTET_STR, WATCHER_FIXED_SIZE);
> // if(netsnmp_register_watched_scalar(reg, winfo) < 0) {
> if(netsnmp_register_watched_instance(reg, winfo) < 0) {
> snmp_log(LOG_ERR, "Failed to register watched abcName");
> }
>
> But I am getting Hex-STRING value..
>
> snmpget -v 2c -c public -On localhost ABC-MIB::abcName
> .1.3.6.1.4.1. 3286.13.5.1.1.3 = Hex-STRING: E0 C4 52 3E FF 7F 00 00 01
> 00 00 00 00 00 00 00
> 70 C6 52 3E FF 7F 00 00 00 00 00 00 00 00 00 00
> 00 00 00 00 00 00 00 00 3D AA 83 35 31 7F 00 00
> 50 D4 10 EA BF B1 69 C8 50 D4 10 EA BF B1 69 C8
> B0 8C 60 00 00 00 00 00 BB AA 83 35 31 7F 00 00
>
> Why I am getting like this pelase help..
Because your code is buggy.
The problems I see are:
* 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.
* 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 would probably write your code like
--- abc.c ---
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
static char abcName[256] = "ABC Default value";
static const oid abcName_oid[] = {1,3,6,1,4,1,3286,13,5,1,1,3,0};
static netsnmp_watcher_info winfo;
static netsnmp_handler_registration *reg = NULL;
void
init_abc(void)
{
netsnmp_init_watcher_info6(
&winfo, abcName, 0, ASN_OCTET_STR,
WATCHER_MAX_SIZE|WATCHER_SIZE_STRLEN, sizeof(abcName), NULL);
reg = netsnmp_create_handler_registration(
"abcName", NULL, abcName_oid, OID_LENGTH(abcName_oid), HANDLER_CAN_RWRITE);
if (!reg)
snmp_log(LOG_ERR, "Failed to create registration for abcName");
else if(netsnmp_register_watched_instance(reg, &winfo) < 0)
snmp_log(LOG_ERR, "Failed to register watched abcName");
}
--- EOF ---
/MF
------------------------------------------------------------------------------
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