summaryrefslogtreecommitdiff
path: root/bsnmp
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2008-03-02 01:25:00 +0000
committerStef Walter <stef@memberwebs.com>2008-03-02 01:25:00 +0000
commit9a78f86f773cbf34e29ec51fc06e3f04072c88d0 (patch)
tree00054e6e536769a35b4215567755494486cc36ec /bsnmp
parentec1a79b0f75cfd34085e046ecb30382a402ea318 (diff)
- Support failover between multiple agents
- Support table queries - Major refactoring of internals.
Diffstat (limited to 'bsnmp')
-rw-r--r--bsnmp/snmp.c54
-rw-r--r--bsnmp/snmp.h5
2 files changed, 53 insertions, 6 deletions
diff --git a/bsnmp/snmp.c b/bsnmp/snmp.c
index 6b2cc01..1a7fe46 100644
--- a/bsnmp/snmp.c
+++ b/bsnmp/snmp.c
@@ -408,7 +408,7 @@ snmp_pdu_decode(struct asn_buf *b, struct snmp_pdu *pdu, int32_t *ip)
case ASN_ERR_FAILED:
case ASN_ERR_EOBUF:
- snmp_pdu_free(pdu);
+ snmp_pdu_clear(pdu);
return (SNMP_CODE_FAILED);
case ASN_ERR_BADLEN:
@@ -805,7 +805,7 @@ snmp_pdu_dump(const struct snmp_pdu *pdu)
}
void
-snmp_value_free(struct snmp_value *value)
+snmp_value_clear(struct snmp_value *value)
{
if (value->syntax == SNMP_SYNTAX_OCTETSTRING)
free(value->v.octetstring.octets);
@@ -834,12 +834,58 @@ snmp_value_copy(struct snmp_value *to, const struct snmp_value *from)
}
void
-snmp_pdu_free(struct snmp_pdu *pdu)
+snmp_pdu_clear(struct snmp_pdu *pdu)
{
u_int i;
for (i = 0; i < pdu->nbindings; i++)
- snmp_value_free(&pdu->bindings[i]);
+ snmp_value_clear(&pdu->bindings[i]);
+}
+
+int
+snmp_value_equal(const struct snmp_value *a, const struct snmp_value *b)
+{
+ if (asn_compare_oid (&a->var, &b->var) == 0)
+ return 0;
+ if (a->syntax != b->syntax)
+ return 0;
+
+ switch (a->syntax) {
+ case SNMP_SYNTAX_NULL:
+ case SNMP_SYNTAX_NOSUCHOBJECT:
+ case SNMP_SYNTAX_NOSUCHINSTANCE:
+ case SNMP_SYNTAX_ENDOFMIBVIEW:
+ return 1;
+
+ case SNMP_SYNTAX_INTEGER:
+ return a->v.integer == b->v.integer;
+
+ case SNMP_SYNTAX_OCTETSTRING:
+ if (a->v.octetstring.len != b->v.octetstring.len)
+ return 0;
+ return memcmp (a->v.octetstring.octets, b->v.octetstring.octets,
+ a->v.octetstring.len) == 0;
+
+ case SNMP_SYNTAX_OID:
+ if (a->v.oid.len != b->v.oid.len)
+ return 0;
+ return memcmp (&a->v.oid.subs, &b->v.oid.subs,
+ (b->v.oid.len * sizeof (b->v.oid.subs[0]))) == 0;
+
+ case SNMP_SYNTAX_IPADDRESS:
+ return memcmp (&a->v.ipaddress, &b->v.ipaddress, sizeof (a->v.ipaddress));
+
+ case SNMP_SYNTAX_COUNTER:
+ case SNMP_SYNTAX_GAUGE:
+ case SNMP_SYNTAX_TIMETICKS:
+ return a->v.uint32 == b->v.uint32;
+
+ case SNMP_SYNTAX_COUNTER64:
+ return a->v.counter64 == b->v.counter64;
+
+ default:
+ return 0;
+ };
}
/*
diff --git a/bsnmp/snmp.h b/bsnmp/snmp.h
index b708b3a..21390e4 100644
--- a/bsnmp/snmp.h
+++ b/bsnmp/snmp.h
@@ -152,11 +152,12 @@ enum snmp_code {
SNMP_CODE_OORANGE,
};
-void snmp_value_free(struct snmp_value *);
+void snmp_value_clear(struct snmp_value *);
int snmp_value_parse(const char *, enum snmp_syntax, union snmp_values *);
int snmp_value_copy(struct snmp_value *, const struct snmp_value *);
+int snmp_value_equal(const struct snmp_value *, const struct snmp_value *);
-void snmp_pdu_free(struct snmp_pdu *);
+void snmp_pdu_clear(struct snmp_pdu *);
enum snmp_code snmp_pdu_decode(struct asn_buf *b, struct snmp_pdu *pdu, int32_t *);
enum snmp_code snmp_pdu_encode(struct snmp_pdu *pdu, struct asn_buf *resp_b);