RE: Multiple traps in a session
"Edison C." <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <[email protected]> |
Thanks for the info.
I am using code partially taken from snmptrap.c & snmpdemoapp.c to send
traps.
Here is the code. I have made comments "/* First trap*/" and "/* second
trap*/" at the code where send 2 traps. Please let me know if there is
anything wrong.
Thanks,
Edison
putenv (strdup ("POSIXLY_CORRECT=1"));
snmp_enable_stderrlog ();
snmp_sess_init (&session); /* set up defaults */
session.peername = (char *) malloc (25);
memset (session.peername, 0, 25);
strcpy (session.peername, (const char *) TrapServer);
session.version = SNMP_VERSION_1;
session.community = (u_char *) malloc (25);
memset (session.community, 0, 25);
strcpy ((char *) session.community, (const char *) CommunityString);
session.community_len = strlen ((const char *) session.community);
session.callback = snmp_input;
session.callback_magic = NULL;
netsnmp_ds_set_int (NETSNMP_DS_LIBRARY_ID,
NETSNMP_DS_LIB_DEFAULT_PORT,
SNMP_TRAP_PORT);
ss = snmp_open (&session);
if (ss == NULL)
{
/*
* diagnose snmp_open errors with the input netsnmp_session
pointer
*/
snmp_sess_perror ("snmpapp", &session);
snmp_shutdown ("snmpapp ");
return 0;
}
pdu = snmp_pdu_create (SNMP_MSG_TRAP);
pdu_in_addr_t = (in_addr_t *) pdu->agent_addr;
pdu->enterprise = (oid *) malloc (sizeof (objid_enterprise));
memcpy (pdu->enterprise, objid_enterprise, sizeof (objid_enterprise));
pdu->enterprise_length = sizeof (objid_enterprise) / sizeof (oid);
*pdu_in_addr_t = get_myaddr ();
pdu->trap_type = 6;
pdu->specific_type = 1;
pdu->time = get_uptime ();
/* add some variables here to the pdu */
/* First trap*/
status = snmp_send (ss, pdu) == 0;
if (status)
{
snmp_sess_perror ("snmpapp ", &session);
printf ("1\n");
snmp_free_pdu (pdu);
exitval = 1;
}
/* Second trap*/
status = snmp_send (ss, pdu) == 0;
if (status)
{
snmp_sess_perror ("snmpapp ", &session);
printf ("1\n");
snmp_free_pdu (pdu);
exitval = 1;
}
snmp_close (ss);
snmp_shutdown ("snmpapp ");
-----Original Message-----
From: [email protected] [mailto:[email protected]] On
Behalf Of Dave Shield
Sent: Thursday, September 06, 2007 2:34 PM
To: Edison C.
Cc: [email protected]
Subject: Re: Multiple traps in a session
On 05/09/07, Edison C. <[email protected]> wrote:
> Is there a way to send multiple traps in a session?
> Can some one give some pointers?
It's certainly possible - that's exactly what the current
agent trap sessions do.
> If I opened a session & tried sending multiple traps I get a " ***
glibc
> detected *** double free or corruption" error when attempting to send
> the second trap
What is your code for sending these traps?
In particular, what is the code for creating the two trap PDUs?
Dave
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
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