diff --git a/proto/snmp/snmp_utils.c b/proto/snmp/snmp_utils.c index 9d349cd0..3a06b0c9 100644 --- a/proto/snmp/snmp_utils.c +++ b/proto/snmp/snmp_utils.c @@ -131,8 +131,8 @@ snmp_valid_ip4_index_unsafe(struct oid *o, uint start) for (int i = 0; i < 4; i++) if (o->ids[start + i] >= 256) return 0; // false - - return 1; // true + + return 1; // true } /** @@ -163,6 +163,17 @@ snmp_put_str(byte *buf, const char *str) return buf + snmp_str_size(str); } +byte * +snmp_put_ip4(byte *buf, ip_addr addr) +{ + /* octet string has size 4 bytes */ + STORE_PTR(buf, 4); + + put_u32(buf+4, ipa_to_u32(addr)); + + return buf + 8; +} + byte * snmp_put_blank(byte *buf) { @@ -258,25 +269,35 @@ void snmp_oid_dump(struct oid *oid) } /** snmp_oid_compare - find the lexicographical order relation between @left and @right + * both @left and @right has to be non-blank. * @left: left object id relation operant * @right: right object id relation operant * - * function returns 0 if left == right -1 if left < right and 1 otherwise + * function returns 0 if left == right, + * -1 if left < right, + * and 1 otherwise */ int snmp_oid_compare(struct oid *left, struct oid *right) { const u32 INTERNET_PREFIX[] = {1, 3, 6, 1}; + /* + if (snmp_is_oid_empty(left) && snmp_is_oid_empty(right)) + return 0; + + if (snmp_is_oid_empty(right)) + return -1; + + if (snmp_is_oid_empty(left)) + return 1; + */ + if (left->prefix == 0 && right->prefix == 0) goto test_ids; if (right->prefix == 0) - { - struct oid *temp = left; - left = right; - right = temp; - } + return (-1) * snmp_oid_compare(right, left); if (left->prefix == 0) { diff --git a/proto/snmp/snmp_utils.h b/proto/snmp/snmp_utils.h index 3c38827d..913cf717 100644 --- a/proto/snmp/snmp_utils.h +++ b/proto/snmp/snmp_utils.h @@ -26,6 +26,8 @@ byte *snmp_put_str(byte *buf, const char *str); byte *snmp_put_blank(byte *buf); byte *snmp_put_oid(byte *buf, struct oid *oid); +byte *snmp_put_ip4(byte *buf, ip_addr ip4); + byte *snmp_put_fbyte(byte *buf, u8 data); void snmp_oid_ip4_index(struct oid *o, uint start, ip4_addr addr);