Hello,

I have some legacy code that I worked on a bit, and I am able to get it to send 
SNMPv1 traps. I want it to send SNMPv2c traps, and that's not happening (The 
SNMP trap receiver gets the varbinds, community string, timestamps and 
everything allright, but says "Invalid Notification Format"). I am wondering if 
someone would know something about it and point me to the right direction.

The code is old (possibly UCD code, but it works with NET-SNMP version 5.4. I 
am not including the entire code (I can't), but this is how it sends the traps:

/* Parse the snmpd.conf file for trapsink and other parameters */


/* Build the trap pdu */
netsnmp_pdu *pdu;
pdu = snmp_pdu_create(SNMP_MSG_TRAP);

in_addr_t * pdu_in_addr_t;
pdu_in_addr_t = (in_addr_t *)pdu->agent_addr;
*pdu_in_addr_t = get_myaddr();

/* Add the varbinds of various parameters to the pdu */
snmp_pdu_add_variable(pdu, <Oid>, <OidLength>, ASN_INTEGER, (u_char*)<integer 
value>, sizeof(<integer value>);

snmp_pdu_add_variable(pdu, <Oid>, <OidLength>, ASN_OCTET_STRING, 
(u_char*)<string value>, strlen(<string value>);

...
...
...

/* Put some protocol-related data in the trap */
pdu->enterprise_length = <trap oid length>;
pdu->trap_type = SNMP_TRAP_ENTERPRISESPECIFIC;
pdu->specific_type = <trap type>;
pdu->time = get_uptime();

/* SNMP session is initialized by using the parsed values of trapsink etc*/
snmpAgentSession* sessPtr;
sessPtr->version = SNMP_VERSION_2c;
sessPtr->peername = strdup(<peername from trapsink in snmpd.conf>);
sessPtr->remote_port = 162;
sessPtr = ::snmp_sess_open(sessPtr);

snmp_sess_send(sessPtr, pdu_to_send);

----- end of code ----

The two specific statements, 
sessPtr->version = SNMP_VERSION_1; and 
pdu = snmp_pdu_create(SNMP_MSG_TRAP);

are the ones that specify SNMPv1. When I change them to SNMP_VERSION_2c and 
SNMP_MSG_TRAP2 respectively, I am able to send the traps, but the SNMP trap 
receiver says "Invalid Notification Format".

The NET-SNMP FAQ reads that only the entry trapsink/trap2sink/trapinform in the 
file snmpd.conf determines which kind of trap is sent out. Since I am parsing 
that file myself, I don't see how snmp_sess_send() would know which trap 
(v1/v2c) to send. [I tried that too, just in case. It didn't work]

Can someone please help?

Thanks,

Kapil

 __________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to