From 681f73adb7706ab536dd68d2eb64601f9329e522 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sat, 21 Jul 2001 10:27:13 +0000 Subject: There is really no need to have the BGP dissector and the LDP dissector have two independent "value_string" tables mapping RFC 1700 address family numbers to names, nor is there any need to have the BGP dissector and the PIM dissector have two independent sets of #defines for RFC 1700 address family numbers; put a single "value_string" table in "afn.c" and put a declaration of it, and #defines for the address family numbers, into "afn.h", and have the dissectors use that. Move the #define for PGM into "ipproto.h", and add an entry for it in the "value_string" table in "ipproto.c". Have the PGM dissector use the standard Ethereal mechanisms for resolving addresses, and have it use "value_string" tables for mapping option types, the OPX bits, and packet types to strings. Use "bytes_to_str()" to turn byte arrays into strings of hex digits. Pass the packet type string to "dissect_pgmopts()" as an argument, rather than making it a global. Don't use "proto_tree_add_XXX_format" routines if you can possibly just use "proto_tree_add_XXX"; give various fields the correct radix and type, and VALS() strings if necessary, to make that happen (and to make filtering on them more pleasant). Put the type, length, and total length of the options into the protocol tree as separate fields. Don't have separate type, length, and OPX fields for every type of option; one field will suffice. Don't format a string with "sprintf()" and then pass that string to "col_add_fstr()" with a format of "%s" and the string as an argument - "col_add_fstr()" can format strings itself (that's what the "f" stands for). Don't byte-swap and then un-byte-swap IPv4 address fields in the header, just leave them network byte order to start with. Use the correct fields for "proto_tree_add_XXX", rather than using the same field multiple times. Quit early if an address family identifier isn't AFNUM_INET, as that means the structure we use to dissect the header doesn't match the actual header. svn path=/trunk/; revision=3761 --- packet-pim.c | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) (limited to 'packet-pim.c') diff --git a/packet-pim.c b/packet-pim.c index 2618502b65..ae454bee8d 100644 --- a/packet-pim.c +++ b/packet-pim.c @@ -2,7 +2,7 @@ * Routines for PIM disassembly * (c) Copyright Jun-ichiro itojun Hagino * - * $Id: packet-pim.c,v 1.31 2001/07/02 09:42:40 guy Exp $ + * $Id: packet-pim.c,v 1.32 2001/07/21 10:27:13 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -45,6 +45,7 @@ #include "packet.h" #include "ipproto.h" +#include "afn.h" #include "packet-ipv6.h" #include "in_cksum.h" @@ -66,26 +67,6 @@ static gint ett_pim = -1; static dissector_handle_t ip_handle; static dissector_handle_t ipv6_handle; -/* - * Address family values. - */ -#define PIM_AF_RESERVED 0 -#define PIM_AF_IP 1 /* IPv4 */ -#define PIM_AF_IPV6 2 /* IPv6 */ -#define PIM_AF_NSAP 3 /* NSAP */ -#define PIM_AF_HDLC 4 /* HDLC (8-bit multidrop) */ -#define PIM_AF_BBN_1822 5 /* BBN 1822 */ -#define PIM_AF_802 6 /* 802 (D/I/X Ethernet, 802.x, FDDI) */ -#define PIM_AF_E_163 7 /* E.163 */ -#define PIM_AF_E_164 8 /* E.164 (SMDS, Frame Relay, ATM) */ -#define PIM_AF_F_69 9 /* F.69 (Telex) */ -#define PIM_AF_X_121 10 /* X.121 (X.25, Frame Relay) */ -#define PIM_AF_IPX 11 /* IPX */ -#define PIM_AF_ATALK 12 /* Appletalk */ -#define PIM_AF_DECNET_IV 13 /* DECnet Phase IV */ -#define PIM_AF_VINES 14 /* Banyan Vines */ -#define PIM_AF_E_164_NSAP 15 /* E.164 with NSAP format subaddress */ - /* * For PIM v1, see the PDF slides at * @@ -522,7 +503,7 @@ dissect_pim_addr(tvbuff_t *tvb, int offset, enum pimv2_addrtype at, int len = 0; af = tvb_get_guint8(tvb, offset); - if (af != PIM_AF_IP && af != PIM_AF_IPV6) { + if (af != AFNUM_INET && af != AFNUM_INET6) { /* * We don't handle the other formats, and addresses don't include * a length field, so we can't even show them as raw bytes. @@ -544,13 +525,13 @@ dissect_pim_addr(tvbuff_t *tvb, int offset, enum pimv2_addrtype at, switch (at) { case pimv2_unicast: switch (af) { - case PIM_AF_IP: + case AFNUM_INET: len = 4; (void)snprintf(buf, sizeof(buf), "%s", ip_to_str(tvb_get_ptr(tvb, offset + 2, len))); break; - case PIM_AF_IPV6: + case AFNUM_INET6: len = 16; (void)snprintf(buf, sizeof(buf), "%s", ip6_to_str((struct e_in6_addr *)tvb_get_ptr(tvb, offset + 2, len))); @@ -563,13 +544,13 @@ dissect_pim_addr(tvbuff_t *tvb, int offset, enum pimv2_addrtype at, case pimv2_group: mask_len = tvb_get_guint8(tvb, offset + 3); switch (af) { - case PIM_AF_IP: + case AFNUM_INET: len = 4; (void)snprintf(buf, sizeof(buf), "%s/%u", ip_to_str(tvb_get_ptr(tvb, offset + 4, len)), mask_len); break; - case PIM_AF_IPV6: + case AFNUM_INET6: len = 16; (void)snprintf(buf, sizeof(buf), "%s/%u", ip6_to_str((struct e_in6_addr *)tvb_get_ptr(tvb, offset + 4, len)), mask_len); @@ -583,13 +564,13 @@ dissect_pim_addr(tvbuff_t *tvb, int offset, enum pimv2_addrtype at, flags = tvb_get_guint8(tvb, offset + 2); mask_len = tvb_get_guint8(tvb, offset + 3); switch (af) { - case PIM_AF_IP: + case AFNUM_INET: len = 4; (void)snprintf(buf, sizeof(buf), "%s/%u", ip_to_str(tvb_get_ptr(tvb, offset + 4, len)), mask_len); break; - case PIM_AF_IPV6: + case AFNUM_INET6: len = 16; (void)snprintf(buf, sizeof(buf), "%s/%u", ip6_to_str((struct e_in6_addr *)tvb_get_ptr(tvb, offset + 4, len)), mask_len); -- cgit v1.2.3