In net-snmp 5.5, the return value of snmp_send() says it's:
* Return on success:
* The request id of the pdu is returned, and the pdu is freed.
* Return on failure:
* Zero (0) is returned.
* The caller must call snmp_free_pdu if 0 is returned.
So, zero means failure. But zero is a valid request id:
PDU ::= SEQUENCE {
request-id INTEGER (-214783648..214783647),
so when a caller (like snmp_agent.c::netsnmp_wrap_up_request() calls snmp_send(), it seems that it must not only check that snmp_send returned zero but also that netsnmp_errno != SUCCESS (and snmp_send should make sure to set netsnmp_errno to success before trying, to enable this type of oob error reporting).
It may be simpler to change snmp_send's return value to simply return 1 if it succeeds or zero if it fails, and if needed find another way to return the request-id. I didn't see any code in agent/ that uses the request-id return value, only success/failure. Or, change the return value to only be the request-id, and make the error indication completely out of band with netsnmp_errno.
A patch that implements my proposed solution: check for errno != SUCCESS if snmp_send returns 0
I've uploaded a patch that leaves snmp_send alone, and just checks for s_snmp_errno != SNMP_SUCCESS in netsnmp_wrap_up_request(). snmp_send() already sets s_snmp_errno to 0 before doing much of anything, so if it is still zero at return it is fairly safe to assume success.
(I am using the patch with 5.6.)
moving to patches
Thanks for the patch! It has been applied to the 5.3.x and later code branches and the main development tree, and will appear in future releases of the Net-SNMP package.
SVN revision 19806