Re: Changing the octet stream?
"Dave Shield" <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <[email protected]> |
[ First - *please* don't mail me privately, without copying
any responses to the mailing list. I don't have the time
or inclination to offer private, unpaid, SNMP consultancy.
Plus I'm away this weekend, so won't be able to reply.
Keep discussions to the list, where others can both learn
and offer advice. Thanks. ]
On 14/07/06, Manuel Cano Muñoz <[email protected]> wrote:
> I'm changing the octect stream I've just registered and I can't see the
> changes.
> /*
> Here I try to modify the string to simulate a process that updates
> its value.
> What new_string does is allocate a new char *, write some test to
> that new char* and return its value.
> */
>
> nstAgentSubagentString = new_string();
No - that won't work.
The watcher helper assumes that it has a fixed location in memory
that it's watching. Allocate a buffer for the string, and update the
value that it holds. You can't suddently decide to use a different
location altogether for the new string.
> If I try to modify (in new_string) the data nstAgentSubagentString points
> to, it crashes.
'Cos the helper is looking at the old location (which is probably no
longer valid).
> How could I modify the data, changing it length also?
char nstAgentSubagentString[ WATCHER_MAX_SIZE ];
sprintf( nstAgentSubagentString, "This is a text (sic)." );
winfo->data_size = strlen(nstAgentSubagentString);
// blah, blah, blah
sprintf( nstAgentSubagentString, "This is a test." );
winfo->data_size = strlen(nstAgentSubagentString);
Dave
[Original message retained for full context]
On 14/07/06, Manuel Cano Muñoz <[email protected]> wrote:
> I'm changing the octect stream I've just registered and I can't see the
> changes.
> I'm obviously doins something wrong, or, better, not doing it at all.
>
> Code:
>
> [From modified nstAgentSubagentObject.c]
>
> char * nstAgentSubagentString = "This is a text.";
>
> void
> init_nstAgentSubagentObject(void)
> {
> netsnmp_handler_registration * reg = 0;
> netsnmp_watcher_info * winfo = 0;
>
> [skip code]
>
> reg = netsnmp_create_handler_registration(
> "nstAgentSubagentString", NULL,
> nstAgentSubagentString_oid,
> OID_LENGTH(nstAgentSubagentString_oid),
> HANDLER_CAN_RONLY);
> if (reg == 0)
> {
> printf ("Error: can't create handler.");
> }
>
> winfo = netsnmp_create_watcher_info(
> nstAgentSubagentString, sizeof(nstAgentSubagentString),
> ASN_OCTET_STR, WATCHER_MAX_SIZE);
> if (winfo == 0)
> {
> printf ("Error: can't create info.");
> }
>
> snmp_log(LOG_INFO, "The size of the initial string is %d\n",
> strlen(nstAgentSubagentString));
> winfo->data_size = strlen(nstAgentSubagentString);
>
> netsnmp_register_watched_scalar (reg, winfo);
>
> [skip]
>
> --------------------------------------------------------------------
>
> [From main in example-demon.c]
>
> extern char * nstAgentSubagentString;
>
> int main (int argc, char **argv)
> {
> int agentx_subagent=0; /* change this if you want to be a SNMP master agent
> */
> int background = 0; /* change this if you want to run in the background */
>
> [skip code]
>
> if (!agentx_subagent)
> init_master_agent(); /* open the port to listen on (defaults to udp:161) */
>
> /* In case we recevie a request to stop (kill -TERM or kill -INT) */
> keep_running = 1;
> signal(SIGTERM, stop_server);
> signal(SIGINT, stop_server);
>
> snmp_log(LOG_INFO,"example-demon is up and running.\n");
>
> /* your main loop here... */
> while(keep_running) {
> /* if you use select(), see snmp_select_info() in snmp_api(3) */
> /* --- OR --- */
>
> snmp_log(LOG_INFO, "The string is: %s.\n", nstAgentSubagentString);
>
> agent_check_and_process(1); /* 0 == don't block */
>
> snmp_log(LOG_INFO, "In the while.\n");
>
> /*
> Here I try to modify the string to simulate a process that updates
> its value.
> What new_string does is allocate a new char *, write some test to
> that new char* and return its value.
> */
>
> nstAgentSubagentString = new_string();
>
> }
>
> /* at shutdown time */
> snmp_shutdown("example-demon");
> SOCK_CLEANUP;
>
>
> [END]
>
> If I try to modify (in new_string) the data nstAgentSubagentString points
> to, it crashes.
> How could I modify the data, changing it length also?
>
>
>
> Thanks.
>
> P.S.
>
> char * new_string ()
> {
>
> /*
> s = malloc(strlen(STR));
> if (! s)
> {
> snmp_log(LOG_INFO, "There is no memory.");
> abort ();
> }
>
> strcpy (s, STR);
> */
> memcpy (nstAgentSubagentString, "AAAA", 4);
>
> return nstAgentSubagentString;
> }
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
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