FreeBSD/contrib/bsnmp/lib/snmp.c
/*
 * Decode the PDU except for the variable bindings itself.
 * If decoding fails because of a bad binding, but the rest can be
 * decoded, ip points to the index of the failed variable (errors
 * OORANGE, BADLEN or BADVERS).
 */
Decode the PDU except for the variable bindings itself.
If decoding fails because of a bad binding, but the rest can be
decoded, ip points to the index of the failed variable (errors
OORANGE, BADLEN or BADVERS).
Decode the PDU except for the variable bindings itself . If decoding fails because of a bad binding but the rest can be decoded ip points to the index of the failed variable ( errors OORANGE BADLEN or BADVERS ) .
enum snmp_code
snmp_pdu_decode(struct asn_buf *b, struct snmp_pdu *pdu, int32_t *ip)
{
	enum snmp_code code;
	if ((code = snmp_pdu_decode_header(b, pdu)) != SNMP_CODE_OK)
		return (code);
	if (pdu->version == SNMP_V3) {
		if (pdu->security_model != SNMP_SECMODEL_USM)
			return (SNMP_CODE_FAILED);
		if ((code = snmp_pdu_decode_secmode(b, pdu)) != SNMP_CODE_OK)
			return (code);
	}
	code = snmp_pdu_decode_scoped(b, pdu, ip);
	switch (code) {
	  case SNMP_CODE_FAILED:
		snmp_pdu_free(pdu);
		break;
	  case SNMP_CODE_BADENC:
		if (pdu->version == SNMP_Verr)
			return (SNMP_CODE_BADVERS);
	  default:
		break;
	}
	return (code);
}
enum snmp_code snmp_pdu_decode ( struct asn_buf * b , struct snmp_pdu * pdu , int32_t * ip ) { enum snmp_code code ; if ( ( code = snmp_pdu_decode_header ( b , pdu ) ) != SNMP_CODE_OK ) return ( code ) ; if ( pdu -> version == SNMP_V3 ) { if ( pdu -> security_model != SNMP_SECMODEL_USM ) return ( SNMP_CODE_FAILED ) ; if ( ( code = snmp_pdu_decode_secmode ( b , pdu ) ) != SNMP_CODE_OK ) return ( code ) ; } code = snmp_pdu_decode_scoped ( b , pdu , ip ) ; switch ( code ) { case SNMP_CODE_FAILED : snmp_pdu_free ( pdu ) ; break ; case SNMP_CODE_BADENC : if ( pdu -> version == SNMP_Verr ) return ( SNMP_CODE_BADVERS ) ; default : break ; } return ( code ) ; }
Decode the PDU except for the variable bindings itself.
Decode the PDU except for the variable bindings itself .