/* if it's a GET, match it exactly */ ((SNMP_MSG_GET == pdu->command && snmp_oid_compare(snmpEngineIDoid,//函数调用发生处 snmpEngineIDoid_len, pdu->variables->name, pdu->variables->name_length) == 0) /* if it's a GETNEXT ensure it's less than the engineID oid */ || (SNMP_MSG_GETNEXT == pdu->command && snmp_oid_compare(snmpEngineIDoid, snmpEngineIDoid_len, pdu->variables->name, pdu->variables->name_length) > 0) )) {
DEBUGMSGTL(("snmpv3_contextid", " One correct variable found\n"));
/* Note: we're explictly not handling a GETBULK. Deal. */
int snmp_oid_compare(const oid * in_name1, size_t len1, const oid * in_name2, size_t len2) { registerint len; registerconst oid *name1 = in_name1; registerconst oid *name2 = in_name2;
/* * len = minimum of len1 and len2 */ if (len1 < len2) len = len1; else len = len2; /* * find first non-matching OID */ while (len-- > 0) { /* * these must be done in seperate comparisons, since * subtracting them and using that result has problems with * subids > 2^31. */ if (*(name1) != *(name2)) { //空指针报错!!!因为name2=0 if (*(name1) < *(name2)) return-1; return1; } name1++; name2++; } /* * both OIDs equal up to length of shorter OID */ if (len1 < len2) return-1; if (len2 < len1) return1; return0; }
while (len-- > 0) { /* * these must be done in seperate comparisons, since * subtracting them and using that result has problems with * subids > 2^31. */ + if(*(name2==0)||*(name1==0)) + { + return-1; + } if (*(name1) != *(name2)) { if (*(name1) < *(name2)) return-1; return1; } name1++; name2++; }