diff options
author | Guy Harris <guy@alum.mit.edu> | 2002-03-11 01:48:08 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2002-03-11 01:48:08 +0000 |
commit | 7e8c5a1741502e5951962a2668311759b7c66abc (patch) | |
tree | d52fa50e4a65667f318cd510f68427aad0128967 /packet-cops.c | |
parent | 9f8d089e2e4d16c41ae289d0992396558a5a7f83 (diff) |
If we're linking with the UCD SNMP library, make "format_oid()" append a
display of the symbolic form of the OID. Remove code that used to do
that outside of "format_oid()".
Export "format_oid()" from "packet-snmp.c" and use it in
"packet-cops.c".
Remove support for CMU SNMP and older versions of UCD SNMP from
"packet-cops.c", as it has been removed from the rest of Ethereal.
svn path=/trunk/; revision=4924
Diffstat (limited to 'packet-cops.c')
-rw-r--r-- | packet-cops.c | 209 |
1 files changed, 22 insertions, 187 deletions
diff --git a/packet-cops.c b/packet-cops.c index a9765d441b..d3caf398d1 100644 --- a/packet-cops.c +++ b/packet-cops.c @@ -4,7 +4,7 @@ * * Copyright 2000, Heikki Vatiainen <hessu@cs.tut.fi> * - * $Id: packet-cops.c,v 1.22 2002/02/26 12:26:06 guy Exp $ + * $Id: packet-cops.c,v 1.23 2002/03/11 01:48:08 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -39,147 +39,32 @@ #include "packet-ipv6.h" #include "packet-frame.h" -#if defined(HAVE_UCD_SNMP_SNMP_H) || defined(HAVE_SNMP_SNMP_H) - /* - * UCD or CMU SNMP? - */ +#ifdef HAVE_UCD_SNMP_SNMP_H +# include <ucd-snmp/asn1.h> +# include <ucd-snmp/snmp_api.h> +# include <ucd-snmp/snmp_impl.h> +# include <ucd-snmp/mib.h> +# include <ucd-snmp/default_store.h> +# include <ucd-snmp/tools.h> -#define MAX_STRING_LEN 2048 /* TBC */ - -# if defined(HAVE_UCD_SNMP_SNMP_H) /* - * UCD SNMP. + * Define values "sprint_realloc_value()" expects. */ -# include <ucd-snmp/asn1.h> -# include <ucd-snmp/snmp_api.h> -# include <ucd-snmp/snmp_impl.h> -# include <ucd-snmp/mib.h> - - /* - * Sigh. UCD SNMP 4.1.1 makes "snmp_set_suffix_only()" a macro - * that calls "ds_set_int()" with the first two arguments - * being DS_LIBRARY_ID and DS_LIB_PRINT_SUFFIX_ONLY; this means that, - * when building with 4.1.1, we need to arrange that - * <ucd-snmp/default_store.h> is included, to define those two values - * and to declare "ds_int()". - * - * However: - * - * 1) we can't include it on earlier versions (at least not 3.6.2), - * as it doesn't exist in those versions; - * - * 2) we don't want to include <ucd-snmp/ucd-snmp-includes.h>, - * as that includes <ucd-snmp/snmp.h>, and that defines a whole - * bunch of values that we also define ourselves. - * - * So we only include it if "snmp_set_suffix_only" is defined as - * a macro. - */ -# ifdef snmp_set_suffix_only -# include <ucd-snmp/default_store.h> -# endif - - /* - * XXX - for now, we assume all versions of UCD SNMP have it. - */ -# define HAVE_SPRINT_VALUE - - /* - * Define values "sprint_value()" expects. - */ -# define VALTYPE_INTEGER ASN_INTEGER -# define VALTYPE_COUNTER ASN_COUNTER -# define VALTYPE_GAUGE ASN_GAUGE -# define VALTYPE_TIMETICKS ASN_TIMETICKS -# define VALTYPE_STRING ASN_OCTET_STR -# define VALTYPE_IPADDR ASN_IPADDRESS -# define VALTYPE_OPAQUE ASN_OPAQUE -# define VALTYPE_NSAP ASN_NSAP -# define VALTYPE_OBJECTID ASN_OBJECT_ID -# define VALTYPE_BITSTR ASN_BIT_STR -# define VALTYPE_COUNTER64 ASN_COUNTER64 - -# ifdef RED_HAT_MODIFIED_UCD_SNMP -# include <ucd-snmp/parse.h> -# endif - - -# elif defined(HAVE_SNMP_SNMP_H) - /* - * CMU SNMP. - */ -# include <snmp/snmp.h> - - /* - * Some older versions of CMU SNMP may lack these values (e.g., the - * "libsnmp3.6" package for Debian, which is based on some old - * CMU SNMP, perhaps 1.0); for now, we assume they also lack - * "sprint_value()". - */ -# ifdef SMI_INTEGER -# define HAVE_SPRINT_VALUE - /* - * Define values "sprint_value()" expects. - */ -# define VALTYPE_INTEGER SMI_INTEGER -# define VALTYPE_COUNTER SMI_COUNTER32 -# define VALTYPE_GAUGE SMI_GAUGE32 -# define VALTYPE_TIMETICKS SMI_TIMETICKS -# define VALTYPE_STRING SMI_STRING -# define VALTYPE_IPADDR SMI_IPADDRESS -# define VALTYPE_OPAQUE SMI_OPAQUE -# define VALTYPE_NSAP SMI_STRING -# define VALTYPE_OBJECTID SMI_OBJID -# define VALTYPE_BITSTR ASN_BIT_STR -# define VALTYPE_COUNTER64 SMI_COUNTER64 -# endif - /* - * Now undo all the definitions they "helpfully" gave us, so we don't get - * complaints about redefining them. - * - * Why, oh why, is there no library that provides code to - * - * 1) read MIB files; - * - * 2) translate object IDs into names; - * - * 3) let you find out, for a given object ID, what the type, enum - * values, display hint, etc. are; - * - * in a *simple* fashion, without assuming that your code is part of an - * SNMP agent or client that wants a pile of definitions of PDU types, - * etc.? Is it just that 99 44/100% of the code that uses an SNMP library - * *is* part of an agent or client, and really *does* need that stuff, - * and *doesn't* need the interfaces we want? - */ -# undef SNMP_ERR_NOERROR -# undef SNMP_ERR_TOOBIG -# undef SNMP_ERR_NOSUCHNAME -# undef SNMP_ERR_BADVALUE -# undef SNMP_ERR_READONLY -# undef SNMP_ERR_NOACCESS -# undef SNMP_ERR_WRONGTYPE -# undef SNMP_ERR_WRONGLENGTH -# undef SNMP_ERR_WRONGENCODING -# undef SNMP_ERR_WRONGVALUE -# undef SNMP_ERR_NOCREATION -# undef SNMP_ERR_INCONSISTENTVALUE -# undef SNMP_ERR_RESOURCEUNAVAILABLE -# undef SNMP_ERR_COMMITFAILED -# undef SNMP_ERR_UNDOFAILED -# undef SNMP_ERR_AUTHORIZATIONERROR -# undef SNMP_ERR_NOTWRITABLE -# undef SNMP_ERR_INCONSISTENTNAME -# undef SNMP_TRAP_COLDSTART -# undef SNMP_TRAP_WARMSTART -# undef SNMP_TRAP_LINKDOWN -# undef SNMP_TRAP_LINKUP -# undef SNMP_TRAP_EGPNEIGHBORLOSS -# undef SNMP_TRAP_ENTERPRISESPECIFIC -# endif +# define VALTYPE_INTEGER ASN_INTEGER +# define VALTYPE_COUNTER ASN_COUNTER +# define VALTYPE_GAUGE ASN_GAUGE +# define VALTYPE_TIMETICKS ASN_TIMETICKS +# define VALTYPE_STRING ASN_OCTET_STR +# define VALTYPE_IPADDR ASN_IPADDRESS +# define VALTYPE_OPAQUE ASN_OPAQUE +# define VALTYPE_NSAP ASN_NSAP +# define VALTYPE_OBJECTID ASN_OBJECT_ID +# define VALTYPE_BITSTR ASN_BIT_STR +# define VALTYPE_COUNTER64 ASN_COUNTER64 #endif #include "asn1.h" +#include "format-oid.h" #include "prefs.h" #define TCP_PORT_COPS 3288 @@ -1110,27 +995,6 @@ static int dissect_cops_object_data(tvbuff_t *tvb, guint32 offset, proto_tree *t return 0; } -static gchar * -format_oid(subid_t *oid, guint oid_length) -{ - char *result; - int result_len; - int len; - unsigned int i; - char *buf; - - result_len = oid_length * 22; - result = g_malloc(result_len + 1); - buf = result; - len = sprintf(buf, "%lu", (unsigned long)oid[0]); - buf += len; - for (i = 1; i < oid_length;i++) { - len = sprintf(buf, ".%lu", (unsigned long)oid[i]); - buf += len; - } - return result; -} - static int decode_cops_pr_asn1_data(tvbuff_t *tvb, guint32 offset, proto_tree *tree, guint epdlen) { ASN1_SCK asn1; @@ -1160,10 +1024,6 @@ static int decode_cops_pr_asn1_data(tvbuff_t *tvb, guint32 offset, proto_tree *t guint variable_length; -#if defined(HAVE_UCD_SNMP_SNMP_H) || defined(HAVE_SNMP_SNMP_H) - gchar vb_oid_string[MAX_STRING_LEN]; /* TBC */ -#endif - unsigned int i; gchar *buf; int len; @@ -1294,37 +1154,12 @@ static int decode_cops_pr_asn1_data(tvbuff_t *tvb, guint32 offset, proto_tree *t length = asn1.offset - start; if (tree) { - vb_display_string = format_oid(vb_oid, - vb_oid_length); - -#if defined(HAVE_UCD_SNMP_SNMP_H) || defined(HAVE_SNMP_SNMP_H) -# ifdef RED_HAT_MODIFIED_UCD_SNMP - sprint_objid(binit(NULL, vb_oid_string, sizeof(vb_oid_string)), - vb_oid, vb_oid_length); -# else - sprint_objid(vb_oid_string, vb_oid, - vb_oid_length); -# endif - proto_tree_add_text(tree, asn1.tvb, offset, length, - "Value: %s: %s (%s)", vb_type_name, - vb_display_string, vb_oid_string); - - break; - -#else /* defined(HAVE_UCD_SNMP_SNMP_H) || defined(HAVE_SNMP_SNMP_H) */ - proto_tree_add_text(tree, asn1.tvb, offset, length, - "Value: : %s: %s",vb_type_name, vb_display_string); - break; - -#endif /* defined(HAVE_UCD_SNMP_SNMP_H) || defined(HAVE_SNMP_SNMP_H) */ - + vb_display_string = format_oid(vb_oid, vb_oid_length); proto_tree_add_text(tree, asn1.tvb, offset, length, "Value: %s: %s", vb_type_name, vb_display_string); g_free(vb_display_string); } - - #ifdef OLD if (tree) { |