diff options
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | format-oid.h | 30 | ||||
-rw-r--r-- | packet-cops.c | 209 | ||||
-rw-r--r-- | packet-snmp.c | 80 |
4 files changed, 89 insertions, 233 deletions
diff --git a/Makefile.am b/Makefile.am index 10e7cb24b0..e40b8c46b2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ # Makefile.am # Automake file for Ethereal # -# $Id: Makefile.am,v 1.414 2002/03/04 22:39:21 guy Exp $ +# $Id: Makefile.am,v 1.415 2002/03/11 01:48:08 guy Exp $ # # Ethereal - Network traffic analyzer # By Gerald Combs <gerald@ethereal.com> @@ -466,6 +466,7 @@ ETHEREAL_COMMON_SRC = \ etypes.h \ follow.c \ follow.h \ + format-oid.h \ greproto.h \ in_cksum.c \ in_cksum.h \ diff --git a/format-oid.h b/format-oid.h new file mode 100644 index 0000000000..de6093f150 --- /dev/null +++ b/format-oid.h @@ -0,0 +1,30 @@ +/* format-oid.h + * Declare routine for formatting OIDs + * + * $Id: format-oid.h,v 1.1 2002/03/11 01:48:08 guy Exp $ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@ethereal.com> + * Copyright 1998 Didier Jorand + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __FORMAT_OID_H__ +#define __FORMAT_OID_H__ + +extern gchar *format_oid(subid_t *oid, guint oid_length); + +#endif 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) { diff --git a/packet-snmp.c b/packet-snmp.c index 8e6799e499..9f9ac91c17 100644 --- a/packet-snmp.c +++ b/packet-snmp.c @@ -8,7 +8,7 @@ * * See RFCs 1905, 1906, 1909, and 1910 for SNMPv2u. * - * $Id: packet-snmp.c,v 1.85 2002/03/11 01:40:28 guy Exp $ + * $Id: packet-snmp.c,v 1.86 2002/03/11 01:48:08 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -91,6 +91,7 @@ #include "asn1.h" #include "packet-snmp.h" +#include "format-oid.h" /* Null string of type "guchar[]". */ static const guchar nullstring[] = ""; @@ -446,7 +447,7 @@ dissect_snmp_error(tvbuff_t *tvb, int offset, packet_info *pinfo, } } -static gchar * +gchar * format_oid(subid_t *oid, guint oid_length) { char *result; @@ -454,8 +455,30 @@ format_oid(subid_t *oid, guint oid_length) int len; unsigned int i; char *buf; +#ifdef HAVE_UCD_SNMP_SNMP_H + u_char *oid_string; + size_t oid_string_len; + size_t oid_out_len; +#endif result_len = oid_length * 22; + +#ifdef HAVE_UCD_SNMP_SNMP_H + /* + * Get the decoded form of the OID, and add its length to the + * length of the result string. + * + * XXX - check for "malloc" and "sprint_realloc_objid()" failure. + */ + oid_string_len = 256; + oid_string = malloc(oid_string_len); + *oid_string = '\0'; + oid_out_len = 0; + sprint_realloc_objid(&oid_string, &oid_string_len, &oid_out_len, 1, + oid, oid_length); + result_len += strlen(oid_string) + 3; +#endif + result = g_malloc(result_len + 1); buf = result; len = sprintf(buf, "%lu", (unsigned long)oid[0]); @@ -464,6 +487,15 @@ format_oid(subid_t *oid, guint oid_length) len = sprintf(buf, ".%lu", (unsigned long)oid[i]); buf += len; } + +#ifdef HAVE_UCD_SNMP_SNMP_H + /* + * Append the decoded form of the OID. + */ + sprintf(buf, " (%s)", oid_string); + free(oid_string); +#endif + return result; } @@ -853,11 +885,6 @@ dissect_common_pdu(tvbuff_t *tvb, int offset, packet_info *pinfo, guint variable_length; subid_t *variable_oid; guint variable_oid_length; -#ifdef HAVE_UCD_SNMP_SNMP_H - u_char *vb_oid_string; - size_t vb_oid_string_len; - size_t vb_oid_out_len; -#endif int ret; guint cls, con, tag; @@ -951,25 +978,8 @@ dissect_common_pdu(tvbuff_t *tvb, int offset, packet_info *pinfo, } if (tree) { oid_string = format_oid(enterprise, enterprise_length); -#ifdef HAVE_UCD_SNMP_SNMP_H - /* - * XXX - check for "malloc" and - * "sprint_realloc_objid()" failure. - */ - vb_oid_string_len = 256; - vb_oid_string = malloc(vb_oid_string_len); - *vb_oid_string = '\0'; - vb_oid_out_len = 0; - sprint_realloc_objid(&vb_oid_string, &vb_oid_string_len, - &vb_oid_out_len, 1, enterprise, - enterprise_length); - proto_tree_add_text(tree, tvb, offset, length, - "Enterprise: %s (%s)", oid_string, vb_oid_string); - free(vb_oid_string); -#else /* HAVE_UCD_SNMP_SNMP_H */ proto_tree_add_text(tree, tvb, offset, length, "Enterprise: %s", oid_string); -#endif /* HAVE_UCD_SNMP_SNMP_H */ g_free(oid_string); } g_free(enterprise); @@ -1118,28 +1128,8 @@ dissect_common_pdu(tvbuff_t *tvb, int offset, packet_info *pinfo, if (tree) { oid_string = format_oid(variable_oid, variable_oid_length); - -#ifdef HAVE_UCD_SNMP_SNMP_H - /* - * XXX - check for "malloc" and - * "sprint_realloc_objid()" failure. - */ - vb_oid_string_len = 256; - vb_oid_string = malloc(vb_oid_string_len); - *vb_oid_string = '\0'; - vb_oid_out_len = 0; - sprint_realloc_objid(&vb_oid_string, &vb_oid_string_len, - &vb_oid_out_len, 1, variable_oid, - variable_oid_length); - proto_tree_add_text(tree, tvb, offset, sequence_length, - "Object identifier %d: %s (%s)", vb_index, - oid_string, vb_oid_string); - free(vb_oid_string); -#else /* HAVE_UCD_SNMP_SNMP_H */ proto_tree_add_text(tree, tvb, offset, sequence_length, - "Object identifier %d: %s", vb_index, - oid_string); -#endif /* HAVE_UCD_SNMP_SNMP_H */ + "Object identifier %d: %s", vb_index, oid_string); g_free(oid_string); } offset += sequence_length; |