#include <stdio.h>
#include <string.h>
-#ifdef HAVE_SMI_H
+#ifdef USE_LIBSMI
#include <smi.h>
#endif
* temporary internal representation while decoding an ASN.1 data stream.
*/
struct be {
- u_int32_t asnlen;
+ uint32_t asnlen;
union {
caddr_t raw;
int32_t integer;
- u_int32_t uns;
+ uint32_t uns;
const u_char *str;
struct {
- u_int32_t high;
- u_int32_t low;
+ uint32_t high;
+ uint32_t low;
} uns64;
} data;
u_short id;
elem->asnlen = *p;
p++; len--; hdr++;
if (elem->asnlen & ASN_BIT8) {
- u_int32_t noct = elem->asnlen % ASN_BIT8;
+ uint32_t noct = elem->asnlen % ASN_BIT8;
elem->asnlen = 0;
if (len < noct) {
ND_PRINT((ndo, "[asnlen? %d<%d]", len, noct));
case COUNTER:
case GAUGE:
case TIMETICKS: {
- register u_int32_t data;
+ register uint32_t data;
ND_TCHECK2(*p, elem->asnlen);
elem->type = BE_UNS;
data = 0;
}
case COUNTER64: {
- register u_int32_t high, low;
+ register uint32_t high, low;
ND_TCHECK2(*p, elem->asnlen);
elem->type = BE_UNS64;
high = 0, low = 0;
struct be *elem)
{
u_char *p = (u_char *)elem->data.raw;
- u_int32_t asnlen = elem->asnlen;
- u_int32_t i;
+ uint32_t asnlen = elem->asnlen;
+ uint32_t i;
switch (elem->type) {
p = elem->data.str;
if (printable) {
ND_PRINT((ndo, "\""));
- if (fn_printn(p, asnlen, ndo->ndo_snapend)) {
+ if (fn_printn(ndo, p, asnlen, ndo->ndo_snapend)) {
ND_PRINT((ndo, "\""));
goto trunc;
}
}
#endif
-#ifdef LIBSMI
+#ifdef USE_LIBSMI
struct smi2be {
SmiBasetype basetype;
};
static int
-smi_decode_oid(struct be *elem, unsigned int *oid,
- unsigned int oidsize, unsigned int *oidlen)
+smi_decode_oid(netdissect_options *ndo,
+ struct be *elem, unsigned int *oid,
+ unsigned int oidsize, unsigned int *oidlen)
{
u_char *p = (u_char *)elem->data.raw;
- u_int32_t asnlen = elem->asnlen;
+ uint32_t asnlen = elem->asnlen;
int o = 0, first = -1, i = asnlen;
+ unsigned int firstval;
for (*oidlen = 0; ndo->ndo_sflag && i-- > 0; p++) {
ND_TCHECK(*p);
*/
if (first < 0) {
first = 0;
+ firstval = o / OIDMUX;
+ if (firstval > 2) firstval = 2;
+ o -= firstval * OIDMUX;
if (*oidlen < oidsize) {
- oid[*oidlen] = o / OIDMUX;
- if (oid[*oidlen] > 2) oid[*oidlen] = 2;
+ oid[(*oidlen)++] = firstval;
}
- o -= oid[*oidlen] * OIDMUX;
- if (*oidlen < oidsize) (*oidlen)++;
}
if (*oidlen < oidsize) {
oid[(*oidlen)++] = o;
return ok;
}
-static SmiNode *smi_print_variable(struct be *elem, int *status)
+static SmiNode *
+smi_print_variable(netdissect_options *ndo,
+ struct be *elem, int *status)
{
unsigned int oid[128], oidlen;
SmiNode *smiNode = NULL;
unsigned int i;
- *status = smi_decode_oid(elem, oid, sizeof(oid)/sizeof(unsigned int),
+ *status = smi_decode_oid(ndo, elem, oid, sizeof(oid) / sizeof(unsigned int),
&oidlen);
if (*status < 0)
return NULL;
}
static int
-smi_print_value(SmiNode *smiNode, u_char pduid, struct be *elem)
+smi_print_value(netdissect_options *ndo,
+ SmiNode *smiNode, u_char pduid, struct be *elem)
{
unsigned int i, oid[128], oidlen;
SmiType *smiType;
if (smiType->basetype == SMI_BASETYPE_BITS) {
/* print bit labels */
} else {
- smi_decode_oid(elem, oid,
+ smi_decode_oid(ndo, elem, oid,
sizeof(oid)/sizeof(unsigned int),
&oidlen);
smiNode = smiGetNodeByOID(oidlen, oid);
{
struct be elem;
int count = 0, ind;
-#ifdef LIBSMI
+#ifdef USE_LIBSMI
SmiNode *smiNode = NULL;
#endif
int status;
asn1_print(ndo, &elem);
return;
}
-#ifdef LIBSMI
- smiNode = smi_print_variable(&elem, &status);
+#ifdef USE_LIBSMI
+ smiNode = smi_print_variable(ndo, &elem, &status);
#else
status = asn1_print(ndo, &elem);
#endif
}
} else {
if (elem.type != BE_NULL) {
-#ifdef LIBSMI
- status = smi_print_value(smiNode, pduid, &elem);
+#ifdef USE_LIBSMI
+ status = smi_print_value(ndo, smiNode, pduid, &elem);
#else
status = asn1_print(ndo, &elem);
#endif