Hi,

I am developing a SNMP trap daemon (snmptd) using net-snmp library. I have
successfully developed the software for SNMP v1 and v2, but I am unable to
code it correctly for v3 traps.

snmptd is able to receive the traps from agent, but the callback is not
called after receiving the trap. Someone, please suggest any code
modification or something that I am missing. Without the callback being
called, I don't think I can proceed further.

*On agent*:

User-name: administrator
AuthNoPriv
Auth. protocol: MD5
Passphrase: mypassword
Engine ID: abcd1234

*Following is my code for SNMPv3*:

Created a SNMPv3 user with:

User-name: administrator
AuthNoPriv
Auth. protocol: MD5
Passphrase: mypassword
Engine ID: abcd1234


*Code*:

    netsnmp_transport *transport = NULL;
    struct snmp_session session, *ss = NULL;
    struct timeval timeout, *tvp;

    int        count, numfds, block;
    fd_set     fdset;
    char    hostname[200];
    char    port[30];

    int lport = param;

    snmp_sess_init( &session );

    session.version = SNMP_VERSION_3;
    session.peername = hostname;
    session.callback       = get_snmp_input; // Function to    interpret
incoming data
    session.callback_magic = NULL;                 // Pointer to data for
callback

    // SNMP v2
    session.community = NULL;
    session.community_len = 0;

    // SNMP v3
    session.securityName = strdup("administrator");         // The user name
    session.securityNameLen = strlen("administrator");      // Length of
securityName

    session.securityAuthKeyLen = USM_AUTH_KU_LEN;   //Length of Ku for auth
protocol
    session.securityAuthProto =
        snmp_duplicate_objid(usmHMACMD5AuthProtocol,
USM_AUTH_PROTO_MD5_LEN);
    session.securityAuthProtoLen = USM_AUTH_PROTO_MD5_LEN;

    if (generate_Ku(session.securityAuthProto,
        session.securityAuthProtoLen,
        (u_char *) "mypassword", "mypassword",
        session.securityAuthKey,
        &session.securityAuthKeyLen) != SNMPERR_SUCCESS) {
            return (-1);
    }

    session.securityPrivKeyLen = USM_PRIV_KU_LEN; //  Length of Ku for priv
protocol
    session.securityPrivProto  = snmp_duplicate_objid(usmDESPrivProtocol,
        USM_PRIV_PROTO_DES_LEN);
    session.securityPrivProtoLen = USM_PRIV_PROTO_DES_LEN;

    if (generate_Ku(session.securityAuthProto,
        session.securityAuthProtoLen,
        (u_char *) "mypassword", strlen("mypassword"),
        session.securityPrivKey,
        &session.securityPrivKeyLen) != SNMPERR_SUCCESS) {
            return (-1);
    }

    session.securityModel = SNMP_DEFAULT_SECMODEL; // snmp security
model,v1, v2c, usm */
    session.securityLevel = SNMP_SEC_LEVEL_AUTHNOPRIV;


    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);

        /* Check to see if this thread has an active port*/
        if(IsPortOnPortList(lport)) {
            /* You can't do logging in here!!!! Will terminate probe after
receiving first trap */
            if (count > 0) {
                snmp_sess_read (ss,&fdset);
                perrstring = (char *) malloc(100);
                memset(perrstring,0,100);
                snmp_sess_error(ss,&liberr,&snmperr,&perrstring);
                Free(perrstring);
                /*status2 = snmp_error();*/
            } else
        ....
        ....
    } /* End of while */

    if (ss) {
        snmp_sess_close(ss);
        ss = NULL;
    }


Waiting for your response soon.

Thanks
Gaurav
------------------------------------------------------------------------------
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

Reply via email to