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> 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://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
>
------------------------------------------------------------------------------
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