FreeBSD/contrib/bsnmp/lib/snmp.c
/*
 * Parse the different PDUs contents. Any ASN error in the outer components
 * are fatal. Only errors in variable values may be tolerated. If all
 * components can be parsed it returns either ASN_ERR_OK or the first
 * error that was found.
 */
Parse the different PDUs contents. Any ASN error in the outer components
are fatal. Only errors in variable values may be tolerated. If all
components can be parsed it returns either ASN_ERR_OK or the first
error that was found.
Parse the different PDUs contents . Any ASN error in the outer components are fatal . Only errors in variable values may be tolerated . If all components can be parsed it returns either ASN_ERR_OK or the first error that was found .
enum asn_err
snmp_parse_pdus_hdr(struct asn_buf *b, struct snmp_pdu *pdu, asn_len_t *lenp)
{
	if (pdu->type == SNMP_PDU_TRAP) {
		if (asn_get_objid(b, &pdu->enterprise) != ASN_ERR_OK) {
			snmp_error("cannot parse trap enterprise");
			return (ASN_ERR_FAILED);
		}
		if (asn_get_ipaddress(b, pdu->agent_addr) != ASN_ERR_OK) {
			snmp_error("cannot parse trap agent address");
			return (ASN_ERR_FAILED);
		}
		if (asn_get_integer(b, &pdu->generic_trap) != ASN_ERR_OK) {
			snmp_error("cannot parse 'generic-trap'");
			return (ASN_ERR_FAILED);
		}
		if (asn_get_integer(b, &pdu->specific_trap) != ASN_ERR_OK) {
			snmp_error("cannot parse 'specific-trap'");
			return (ASN_ERR_FAILED);
		}
		if (asn_get_timeticks(b, &pdu->time_stamp) != ASN_ERR_OK) {
			snmp_error("cannot parse trap 'time-stamp'");
			return (ASN_ERR_FAILED);
		}
	} else {
		if (asn_get_integer(b, &pdu->request_id) != ASN_ERR_OK) {
			snmp_error("cannot parse 'request-id'");
			return (ASN_ERR_FAILED);
		}
		if (asn_get_integer(b, &pdu->error_status) != ASN_ERR_OK) {
			snmp_error("cannot parse 'error_status'");
			return (ASN_ERR_FAILED);
		}
		if (asn_get_integer(b, &pdu->error_index) != ASN_ERR_OK) {
			snmp_error("cannot parse 'error_index'");
			return (ASN_ERR_FAILED);
		}
	}
	if (asn_get_sequence(b, lenp) != ASN_ERR_OK) {
		snmp_error("cannot get varlist header");
		return (ASN_ERR_FAILED);
	}
	return (ASN_ERR_OK);
}
enum asn_err snmp_parse_pdus_hdr ( struct asn_buf * b , struct snmp_pdu * pdu , asn_len_t * lenp ) { if ( pdu -> type == SNMP_PDU_TRAP ) { if ( asn_get_objid ( b , & pdu -> enterprise ) != ASN_ERR_OK ) { snmp_error ( " " ) ; return ( ASN_ERR_FAILED ) ; } if ( asn_get_ipaddress ( b , pdu -> agent_addr ) != ASN_ERR_OK ) { snmp_error ( " " ) ; return ( ASN_ERR_FAILED ) ; } if ( asn_get_integer ( b , & pdu -> generic_trap ) != ASN_ERR_OK ) { snmp_error ( " " ) ; return ( ASN_ERR_FAILED ) ; } if ( asn_get_integer ( b , & pdu -> specific_trap ) != ASN_ERR_OK ) { snmp_error ( " " ) ; return ( ASN_ERR_FAILED ) ; } if ( asn_get_timeticks ( b , & pdu -> time_stamp ) != ASN_ERR_OK ) { snmp_error ( " " ) ; return ( ASN_ERR_FAILED ) ; } } else { if ( asn_get_integer ( b , & pdu -> request_id ) != ASN_ERR_OK ) { snmp_error ( " " ) ; return ( ASN_ERR_FAILED ) ; } if ( asn_get_integer ( b , & pdu -> error_status ) != ASN_ERR_OK ) { snmp_error ( " " ) ; return ( ASN_ERR_FAILED ) ; } if ( asn_get_integer ( b , & pdu -> error_index ) != ASN_ERR_OK ) { snmp_error ( " " ) ; return ( ASN_ERR_FAILED ) ; } } if ( asn_get_sequence ( b , lenp ) != ASN_ERR_OK ) { snmp_error ( " " ) ; return ( ASN_ERR_FAILED ) ; } return ( ASN_ERR_OK ) ; }
Parse the different PDUs contents.
Parse the different PDUs contents .