Hi,
A couple more questions.
1) How to close transport and session down.
I used
if(mgr_p->session_p) {
SNMPD_LOG(LOG_INFO, SNMPD_LOG_GROUP_TRAP, "Closing session.");
snmp_sess_close(mgr_p->session_p);
}
if(mgr_p->transport_trap_server_p) {
SNMPD_LOG(LOG_INFO, SNMPD_LOG_GROUP_TRAP, "Closing transport
trap server.");
netsnmp_transport_free(mgr_p->transport_trap_server_p);
}
which seg faults on the netsnmp_transport_free. Looking through the
snmp_sess_close it does seem to close down the transport object, can
anybody confirm this or should I be using some other way of closing down.
2) dmalloc is reporting memory leaks which are in calls inet_ntoa.
Using gdb they relate to the following lines of netsnmp_udp_fmtaddr
sprintf(tmp, "UDP: [%s]:%hu->",
inet_ntoa(to->sin_addr), ntohs(to->sin_port));
sprintf(tmp + strlen(tmp), "[%s]",
inet_ntoa(addr_pair->local_addr));
Here's the stack trace
#0 0x402770a8 in inet_ntoa () from /lib/libc.so.6
#1 0x4007db38 in netsnmp_udp_fmtaddr (t=0x0, data=0xbea90a80, len=0)
at snmpUDPDomain.c:122
#2 0x4007ee3c in netsnmp_udp_transport (addr=0xbea90b54, local=1)
at snmpUDPDomain.c:616
#3 0x400809b0 in netsnmp_udp_create_tstring (str=0x0, local=1,
default_target=0x0) at snmpUDPDomain.c:1232
#4 0x4007d1dc in netsnmp_tdomain_transport_full (
application=0x1571c "sscd_snmpd", str=0x16640 "udp:162", local=1,
default_domain=0x0, default_target=0x0) at snmp_transport.c:443
#5 0x4007d9ac in netsnmp_transport_open_server (application=0x0,
str=0xbea90a80 "") at snmp_transport.c:502
#6 0x0000df04 in snmpd_trap_mgr_open () at sscd_snmpd_trap.c:358
#7 0x0000a9a4 in main (argc=2, argv=0xbea90d04) at sscd_snmpd.c:349
I've read somewhere that there is a problem with inet_ntoa and memory
leaks, is there a way of avoiding this call?
Cheers,
Martin.
On 22/07/2010 10:24, Gaurav Chaturvedi wrote:
Hi Martin,
Its good that you got the solution now.
Following are the functions which can be used in your case as per the
requirement:
*print_objid*, *fprint_objid*, *snprint_objid
Synatx:
**void print_objid(const oid **/objid/*, size_t* /objidlen/*);
void fprint_objid(FILE **/fp/*, const oid **/objid/*, size_t*
/objidlen/*);
int snprint_objid(char **/buf/*, size_t* /len/*, const oid **/objid/*,
size_t* /objidlen/*);*
Thanks
Gaurav
On Thu, Jul 22, 2010 at 2:18 PM, Martin Townsend
<martin.towns...@power-oasis.com
<mailto:martin.towns...@power-oasis.com>> wrote:
On 21/07/2010 06:05, Gaurav Chaturvedi wrote:
Hi Martin,
Please use the following code after your mentioned part of code.
You need to call "snmp_sess_select_info", "select" and
"snmp_sess_read" after snmp_sess_read() function. These functions
help in reading the data from socket and call the callback function.
Also, there is no issue in using localhost in snmptrap/snmpinform
commands.
if (transport = netsnmp_tdomain_transport(port, 1, "udp")) {
ss = snmp_sess_add(&session, transport, NULL, NULL);
}
while (1) {
numfds = 0;
FD_ZERO(&fdset);
block = 1; /* note: will be set by
snmp_sess_select_info */
tvp = &timeout;
if (block) timerclear(tvp);
snmp_sess_select_info(ss,&numfds, &fdset, tvp, &block);
if (block == 1) {
tvp = NULL;
}
count = select(numfds, &fdset, 0, 0, tvp);
if (count > 0) {
snmp_sess_read (ss,&fdset);
} else
....
....
} /* End of while */
if (ss) {
snmp_sess_close(ss);
ss = NULL;
}
Thanks
Gaurav Chaturvedi
On Tue, Jul 20, 2010 at 10:13 PM, Martin Townsend
<martin.towns...@power-oasis.com
<mailto:martin.towns...@power-oasis.com>> wrote:
Hi,
I'm having problems processing traps in my management
application, After
looking through the snmptrapd code I've added calls to
netsnmp_transport_open_server(app_name, "udp:162");
and then initialise a session with
snmp_sess_init
with the following initialisation
session_p->peername = SNMP_DEFAULT_PEERNAME; /* Original
code had
NULL here */
session_p->version = SNMP_DEFAULT_VERSION;
session_p->community_len = SNMP_DEFAULT_COMMUNITY_LEN;
session_p->retries = SNMP_DEFAULT_RETRIES;
session_p->timeout = SNMP_DEFAULT_TIMEOUT;
session_p->callback = snmp_input;
session_p->callback_magic = (void *) transport_trap_server_p;
session_p->authenticator = NULL;
session_p->isAuthoritative = SNMP_SESS_UNKNOWNAUTH;
which sets up the callback snmp_input.
then snmp_add to add the session to the opened transport server.
In snmp_input I have a printf to make sure that the routine
is getting
called that will output the operation_id value.
Then using snmptrap or snmpinform send the trap, e.g.
snmpinform -v2c -c public localhost ""
PO-RECTIFIER-TEST-MIB::alarmMajorHighBattVoltTrapPO
PO-RECTIFIER-TEST-M
IB::alarmMajorHighBattVoltPO.0 i 1
snmpinform: Timeout
with no success.
Is it ok to use snmpinform/trap with localhost and will the
code above
receive the trap PDU on localhost?
My application runs as a process that waits for commands to
arrive over
a socket so it will be blocked, would this cause problems?
Any other ideas/things to try out?
Many Thanks in advance,
Martin.
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first <http://sprint.com/first> --
http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
<mailto: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
Thank you Gaurav, using the single session api I now have a
separate pthread to handle the traps. Just in case anyone else
tries this be warned that you must store the opaque session
pointer returned from snmp_sess_add (or maybe pass it via the
callback_magic field) as it is different to the one passed to the
snmp_input callback routine of the session structure. In the
snmp_input routine I was trying to use snmp_sess_send to send the
INFORM reply message using the session pointer that was passed as
an input parameter which caused a seg fault. After stepping
through the code I could see that the opaque session pointer is
acutally a struct session_list * as returned by snmp_sess_add_ex.
PS does anyone know if there's a routine that takes an OID and
returns the name/description from the MIB?
Cheers,
Martin.
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first <http://sprint.com/first> --
http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
<mailto: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
--
Martin Townsend
PowerOasis
Suite 1, Unit 41
Shrivenham Hundred Business Park
Majors Road
Watchfield
Swindon
Wilts SN6 8TZ
Mobile 07884 444658
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
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