Facing problems while sending traps using snmp api's

"Sampige, Sahana Prabhakar (STSD)" <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <3051CFF4B0ABBF418CBA816A2BF3F20336033C7851@GVW1105EXC.americas.hpqcorp.net>
Hi,
I am using net-snmp version 5.5. I am trying to send traps using the net-snmp library api's, but I am unsuccessful. But sending the trap using snmptrap command is successful with the same credentials. Below are the steps I have followed.

1. service snmptrapd stop
2. service snmpd stop
3. added the following lines to /etc/snmp/snmpd.conf
# VACM configuration entries
rwuser wes
# USM configuration entries
createUser wes MD5 setup_passphrase DES
4. service snmpd start
An entry for user wes was created in the /var/-net-snmp/snmpd.conf of the following form :
usmUser 1 3 0x80001f8880654ceb30a484dc4c 0x77657300 0x77657300 NULL .1.3.6.1.6.3.10.1.1.2 0x12317a58c0ccd9e67374456e228cdb3c .1.3.6.1.6.3.10.1.2.2 0x12317a58c0ccd9e67374456e228cdb3c ""
5. I added the following entry to /var/net-snmp/snmptrapd.conf
createuser -e 0x80001f8880654ceb30a484dc4c wes MD5 setup_passphrase DES
6. /usr/sbin/snmptrapd -f -Lf /tmp/trapLogFile -d
7. snmptrap -v 3 -n "" -a MD5 -A setup_passphrase -l authNoPriv -u wes -e 0x80001f8880654ceb30a484dc4c localhost 0 coldStart.0
Trap is received.
8. I wrote the following code to send the trap using net-snmp api's :
    netsnmp_session session, *ss;
    netsnmp_pdu *pdu;

    oid anOID[MAX_OID_LEN];
    size_t anOID_len;

    init_snmp("snmpdemoapp");
    snmp_sess_init( &session );                   /* set up defaults */
    session.peername = strdup("mella.ind.hp.com:162");

    session.version=SNMP_VERSION_3;
    
    /* set the SNMPv3 user name */
    session.securityName = strdup("wes");
    session.securityNameLen = strlen(session.securityName);
    session.securityEngineIDLen = strlen("0x80001f8880654ceb30a484dc4c");
    session.securityEngineID = (u_char*)malloc(session.securityEngineIDLen);
    memcpy(session.securityEngineID,"0x80001f8880654ceb30a484dc4c",session.securityEngineIDLen);
    session.securityLevel = SNMP_SEC_LEVEL_AUTHNOPRIV;

    /* set the authentication method to MD5 */
    session.securityAuthProto = usmHMACMD5AuthProtocol;
    session.securityAuthProtoLen = sizeof(usmHMACMD5AuthProtocol)/sizeof(oid);
    session.securityAuthKeyLen = USM_AUTH_KU_LEN;

    /* set the authentication key to a MD5 hashed version of our
       passphrase "The Net-SNMP Demo Password" (which must be at least 8
       characters long) */
    if (generate_Ku(session.securityAuthProto,
                    session.securityAuthProtoLen,
                    (u_char *) our_v3_passphrase, strlen(our_v3_passphrase),
                    session.securityAuthKey,
                    &session.securityAuthKeyLen) != SNMPERR_SUCCESS) {
        snmp_perror(argv[0]);
        snmp_log(LOG_ERR,
                 "Error generating Ku from authentication pass phrase. \n");
        exit(1);
    }

    ss = snmp_open(&session);                     /* establish the session */

    if (!ss) {
      snmp_sess_perror("ack", &session);
      SOCK_CLEANUP;

    /*
     * Create the PDU for the data for our request.
     *   1) We're going to TRAP the system.sysDescr.0 node.
     */
    pdu = snmp_pdu_create(SNMP_MSG_TRAP2);
    anOID_len = MAX_OID_LEN;
    if (!snmp_parse_oid(".1.3.6.1.2.1.1.1.0", anOID, &anOID_len)) {
      snmp_perror(".1.3.6.1.2.1.1.1.0");
      SOCK_CLEANUP;
      exit(1);
    }

    status = snmp_send(ss, pdu);

9. I get the following error in the logfile : 
snmp_parse: snmp_parse: Parsed SNMPv3 message (secName:wes, secLevel:authNoPriv): USM unknown security name (no such user exists)
Parsed SNMPv3 message (secName:wes, secLevel:authNoPriv): USM unknown security name (no such user exists)

10. I debugged net-snmp I saw that the engine id stored in snmpusm.c does not match with the request engineid.The comparison of the engine id at line snmpusm.c:3011 fails. Dump from gdb as below :
(gdb) p engineID
$11 = (u_char *) 0x9f765b8 "0x80001f8880654ceb30a484dc4c"
(gdb) p engineIDLen
$12 = 28
(gdb) p ptr->engineIDLen
$13 = 13
(gdb) p ptr->engineID
$14 = (u_char *) 0x9f8b698 "\200"

Am I missing something. Can somebody help me.

Rgds,
Sahana
------------------------------------------------------------------------------
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
_______________________________________________
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.