I'm writing a GUI application that listen for traps from a specified IP address.
The application works like this: I set the IP of the peer and then I open a 
SNMP session with it.
Once the session is open the application periodically checks for traps (with 
snmp_select_info and select).
I can close the session and open a new session with a different (or even the 
same) peer.
The problem is that the lisening with select doesn't work on the second session.
The problem is with snmp_select_info. In fact on the second session 
snmp_select_info behaves like the old session is still open: snmp_select_info 
returns 2 active sessions instead of 1 and in the fdset.fd_array[] there is 
still the element corrisponding to the old session that is now deleted.
So later when I call select it fails and I think that's beacuse in fdset it 
finds the fd of a socket that doesn't exists anymore (in fact the error i get 
from select is "No such file or directory").
Could anyone please help me solve this problem?
Thanks (and excuse me if my English is not very good ^^')


This is the code for opening the session:
    
    init_snmp("snmpapp");
    SOCK_STARTUP;
    netsnmp_session session, *ss;
    netsnmp_transport *transport = NULL;
    transport = netsnmp_tdomain_transport("udp:162", 1, "udp");
    if (transport == NULL) {
        wxLogError("couldn't open udp:162 -- errno %d %s", errno, 
strerror(errno));
        wxLogError("SNMP failure: %s", snmp_errstring(session.s_snmp_errno));
    }
    snmp_sess_init( &session );
    //with (AgentIP->GetValue()).c_str() I take form a Text Control the IP of 
the peer             
    session.peername = strdup((AgentIP->GetValue()).c_str());
    session.version = SNMP_VERSION_1;
    session.community = "public";
    session.community_len = strlen(session.community);
    session.local_port = 162;
    //TrapListener is the functions that handles the received traps
    session.callback = &TrapListener;
    //Risposta is a Text Control used by the application for visualizing the 
content of the trap 
    session.callback_magic = (void*) Risposta;
    ss = snmp_add(&session, transport, NULL, NULL);
    if (!ss) {
      snmp_sess_perror("ack", &session);
      SOCK_CLEANUP;
      wxLogError("Error in opening SNMP session");
    }
    else {
        //WxTimer1 is a Timer that every 700ms launch the listening for traps
        WxTimer1->Start(700,false);
    }

This is the code for the listening part:

    int fds = 0, block = 0, nopsess = 0;
    fd_set fdset;
    struct timeval timeout;
    timeout.tv_sec = 0;
    timeout.tv_usec = 100000;//100 ms
    FD_ZERO(&fdset);
    int nopsess
    nopsess = snmp_select_info(&fds, &fdset, &timeout, &block);
    fds = select(fds, &fdset, 0, 0, &timeout);
    if (fds<0){
        wxLogError("Select failed, Errore number %d: %s", errno, 
strerror(errno));
    }
    if (fds>0){
        snmp_read(&fdset);
    }
    if (fds==0){
        snmp_timeout();
    }

This is the code for closing the open session an cleaning up:

    snmp_close(ss);
    SOCK_CLEANUP;


-------------------------------------------------------------------------
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-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to