diff options
| -rw-r--r-- | lib/smux.h | 2 | ||||
| -rw-r--r-- | lib/snmp.c | 28 |
2 files changed, 29 insertions, 1 deletions
diff --git a/lib/smux.h b/lib/smux.h index 0efe029d3d..66a45a0e77 100644 --- a/lib/smux.h +++ b/lib/smux.h @@ -104,8 +104,10 @@ extern int smux_trap(struct variable *, size_t, const oid *, size_t, extern int oid_compare(const oid *, int, const oid *, int); extern void oid2in_addr(oid[], int, struct in_addr *); +extern void oid2int(oid oid[], int *dest); extern void *oid_copy(void *, const void *, size_t); extern void oid_copy_addr(oid[], const struct in_addr *, int); +extern void oid_copy_int(oid oid[], int *val); extern void oid2string(oid oid[], int len, char *string); extern void oid_copy_str(oid oid[], const char *string, int len); diff --git a/lib/snmp.c b/lib/snmp.c index cc317d7a3b..e92f622bb9 100644 --- a/lib/snmp.c +++ b/lib/snmp.c @@ -64,6 +64,19 @@ void oid2in_addr(oid oid[], int len, struct in_addr *addr) *pnt++ = oid[i]; } +void oid2int(oid oid[], int *dest) +{ + uint8_t i; + uint8_t *pnt; + int network_dest; + + pnt = (uint8_t *)&network_dest; + + for (i = 0; i < sizeof(int); i++) + *pnt++ = oid[i]; + *dest = ntohl(network_dest); +} + void oid_copy_addr(oid oid[], const struct in_addr *addr, int len) { int i; @@ -78,6 +91,19 @@ void oid_copy_addr(oid oid[], const struct in_addr *addr, int len) oid[i] = *pnt++; } +void oid_copy_int(oid oid[], int *val) +{ + uint8_t i; + const uint8_t *pnt; + int network_val; + + network_val = htonl(*val); + pnt = (uint8_t *)&network_val; + + for (i = 0; i < sizeof(int); i++) + oid[i] = *pnt++; +} + void oid2string(oid oid[], int len, char *string) { int i; @@ -89,7 +115,7 @@ void oid2string(oid oid[], int len, char *string) pnt = (uint8_t *)string; for (i = 0; i < len; i++) - *pnt++ = oid[i]; + *pnt++ = (uint8_t)oid[i]; } void oid_copy_str(oid oid[], const char *string, int len) |
