Export "igmp_checksum()" from the IGMP dissector and give it additional

arguments that specify the header field indices for the checksum field
and the "checksum is bad" Boolean, and have the dissectors for some
protocols that use IGMP (DVMRP, MRDISC, MSNIP) use it rather than having
their own checksumming routines.

Also, fix it to correctly add the "checksum is bad" Boolean.

svn path=/trunk/; revision=4665
This commit is contained in:
Guy Harris 2002-02-01 11:01:57 +00:00
parent 81bad7e2e6
commit c2c2154712
6 changed files with 62 additions and 98 deletions

View File

@ -1,7 +1,7 @@
# Makefile.am
# Automake file for Ethereal
#
# $Id: Makefile.am,v 1.409 2002/01/31 07:51:32 girlich Exp $
# $Id: Makefile.am,v 1.410 2002/02/01 11:01:56 guy Exp $
#
# Ethereal - Network traffic analyzer
# By Gerald Combs <gerald@ethereal.com>
@ -371,6 +371,7 @@ noinst_HEADERS = \
packet-http.h \
packet-ieee80211.h \
packet-ieee8023.h \
packet-igmp.h \
packet-ip.h \
packet-ipsec.h \
packet-ipv6.h \

View File

@ -1,7 +1,7 @@
/* packet-dvmrp.c 2001 Ronnie Sahlberg <See AUTHORS for email>
* Routines for IGMP/DVMRP packet disassembly
*
* $Id: packet-dvmrp.c,v 1.7 2002/01/21 07:36:34 guy Exp $
* $Id: packet-dvmrp.c,v 1.8 2002/02/01 11:01:56 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -65,7 +65,7 @@
#include <epan/packet.h>
#include "ipproto.h"
#include "in_cksum.h"
#include "packet-igmp.h"
#include "packet-dvmrp.h"
static int proto_dvmrp = -1;
@ -214,29 +214,6 @@ static const true_false_string tfs_cap_netmask = {
"NOT Netmask capable"
};
static void dvmrp_checksum(proto_tree *tree,tvbuff_t *tvb, int len)
{
guint16 cksum,hdrcksum;
vec_t cksum_vec[1];
cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, len);
cksum_vec[0].len = len;
hdrcksum = tvb_get_ntohs(tvb, 2);
cksum = in_cksum(&cksum_vec[0],1);
if (cksum==0) {
proto_tree_add_uint_format(tree, hf_checksum, tvb, 2, 2, hdrcksum, "Header checksum: 0x%04x (correct)", hdrcksum);
} else {
proto_tree_add_item_hidden(tree, hf_checksum_bad, tvb, 2, 2, TRUE);
proto_tree_add_uint_format(tree, hf_checksum, tvb, 2, 2, hdrcksum, "Header checksum: 0x%04x (incorrect, should be 0x%04x)", hdrcksum,in_cksum_shouldbe(hdrcksum,cksum));
}
return;
}
int
dissect_v3_report(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
{
@ -345,7 +322,7 @@ dissect_dvmrp_v3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int
}
/* checksum */
dvmrp_checksum(parent_tree, tvb, tvb_length_remaining(tvb, 0));
igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
offset += 2;
/* skip unused byte */
@ -475,7 +452,7 @@ dissect_dvmrp_v1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int
}
/* checksum */
dvmrp_checksum(parent_tree, tvb, tvb_length_remaining(tvb, 0));
igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
offset += 2;
/* decode all the v1 commands */
@ -812,4 +789,3 @@ proto_register_dvmrp(void)
proto_register_field_array(proto_dvmrp, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
}

View File

@ -1,7 +1,7 @@
/* packet-igmp.c 2001 Ronnie Sahlberg <See AUTHORS for email>
* Routines for IGMP packet disassembly
*
* $Id: packet-igmp.c,v 1.17 2002/01/21 07:36:35 guy Exp $
* $Id: packet-igmp.c,v 1.18 2002/02/01 11:01:57 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -309,8 +309,8 @@ static const value_string mtrace_fwd_code_vals[] = {
proto_tree_add_uint(tree, hf_type, tvb, offset, 1, type); \
offset += 1;
static void igmp_checksum(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo,
guint len)
void igmp_checksum(proto_tree *tree, tvbuff_t *tvb, int hf_index,
int hf_index_bad, packet_info *pinfo, guint len)
{
guint16 cksum, hdrcksum;
vec_t cksum_vec[1];
@ -321,7 +321,7 @@ static void igmp_checksum(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo,
*/
len = tvb_reported_length(tvb);
}
hdrcksum = tvb_get_ntohs(tvb, 2);
if (!pinfo->fragmented && tvb_length(tvb) >= len) {
/*
@ -334,18 +334,18 @@ static void igmp_checksum(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo,
cksum = in_cksum(&cksum_vec[0],1);
if (cksum == 0) {
proto_tree_add_uint_format(tree, hf_checksum,
proto_tree_add_uint_format(tree, hf_index,
tvb, 2, 2, hdrcksum,
"Header checksum: 0x%04x (correct)", hdrcksum);
} else {
proto_tree_add_item_hidden(tree, hf_checksum_bad,
proto_tree_add_boolean_hidden(tree, hf_index_bad,
tvb, 2, 2, TRUE);
proto_tree_add_uint_format(tree, hf_checksum,
proto_tree_add_uint_format(tree, hf_index,
tvb, 2, 2, hdrcksum,
"Header checksum: 0x%04x (incorrect, should be 0x%04x)", hdrcksum,in_cksum_shouldbe(hdrcksum,cksum));
}
} else
proto_tree_add_uint(tree, hf_checksum, tvb, 2, 2, hdrcksum);
proto_tree_add_uint(tree, hf_index, tvb, 2, 2, hdrcksum);
return;
}
@ -500,8 +500,8 @@ dissect_igmp_v3_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, in
offset += 1;
/* checksum */
igmp_checksum(tree, tvb, pinfo, 0);
offset +=2;
igmp_checksum(tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
offset += 2;
/* skip reserved field */
offset += 2;
@ -530,7 +530,7 @@ dissect_igmp_v3_query(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int t
offset = dissect_v3_max_resp(tvb, pinfo, tree, offset);
/* checksum */
igmp_checksum(tree, tvb, pinfo, 0);
igmp_checksum(tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
offset += 2;
/* group address */
@ -571,7 +571,7 @@ dissect_igmp_v2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int type, i
offset += 1;
/* checksum */
igmp_checksum(tree, tvb, pinfo, 8);
igmp_checksum(tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 8);
offset += 2;
/* group address */
@ -591,7 +591,7 @@ dissect_igmp_v1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int type, i
offset += 1;
/* checksum */
igmp_checksum(tree, tvb, pinfo, 8);
igmp_checksum(tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 8);
offset += 2;
/* group address */
@ -623,7 +623,7 @@ dissect_igmp_v0(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int type, i
offset += 1;
/* checksum */
igmp_checksum(tree, tvb, pinfo, 20);
igmp_checksum(tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 20);
offset += 2;
/* identifier */
@ -680,7 +680,7 @@ dissect_igmp_mtrace(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int typ
offset += 1;
/* checksum */
igmp_checksum(tree, tvb, pinfo, 0);
igmp_checksum(tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
offset += 2;
/* group address to be traced */

32
packet-igmp.h Normal file
View File

@ -0,0 +1,32 @@
/* packet-igmp.h 2001 Ronnie Sahlberg <See AUTHORS for email>
* Declarations of routines for IGMP packet disassembly
*
* $Id: packet-igmp.h,v 1.1 2002/02/01 11:01:57 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
* Copyright 1998 Gerald Combs
*
* 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 __PACKET_MSNIP_H__
#define __PACKET_MSNIP_H__
void igmp_checksum(proto_tree *tree, tvbuff_t *tvb, int hf_index,
int hf_index_bad, packet_info *pinfo, guint len);
#endif

View File

@ -1,7 +1,7 @@
/* packet-mrdisc.c 2001 Ronnie Sahlberg <See AUTHORS for email>
* Routines for IGMP/MRDISC packet disassembly
*
* $Id: packet-mrdisc.c,v 1.6 2002/01/21 07:36:37 guy Exp $
* $Id: packet-mrdisc.c,v 1.7 2002/02/01 11:01:57 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -49,7 +49,7 @@
#include <glib.h>
#include <epan/packet.h>
#include "in_cksum.h"
#include "packet-igmp.h"
#include "packet-mrdisc.h"
@ -88,28 +88,6 @@ static const value_string mrdisc_options[] = {
};
static void mrdisc_checksum(proto_tree *tree,tvbuff_t *tvb, int len)
{
guint16 cksum,hdrcksum;
vec_t cksum_vec[1];
cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, len);
cksum_vec[0].len = len;
hdrcksum = tvb_get_ntohs(tvb, 2);
cksum = in_cksum(&cksum_vec[0],1);
if (cksum==0) {
proto_tree_add_uint_format(tree, hf_checksum, tvb, 2, 2, hdrcksum, "Header checksum: 0x%04x (correct)", hdrcksum);
} else {
proto_tree_add_item_hidden(tree, hf_checksum_bad, tvb, 2, 2, TRUE);
proto_tree_add_uint_format(tree, hf_checksum, tvb, 2, 2, hdrcksum, "Header checksum: 0x%04x (incorrect, should be 0x%04x)", hdrcksum,in_cksum_shouldbe(hdrcksum,cksum));
}
return;
}
static int
dissect_mrdisc_mra(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
{
@ -120,7 +98,7 @@ dissect_mrdisc_mra(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, i
offset += 1;
/* checksum */
mrdisc_checksum(parent_tree, tvb, tvb_length_remaining(tvb, 0));
igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
offset += 2;
/* skip unused bytes */
@ -199,7 +177,7 @@ dissect_mrdisc_mrst(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree,
offset += 1;
/* checksum */
mrdisc_checksum(parent_tree, tvb, tvb_length_remaining(tvb, 0));
igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
offset += 2;
return offset;

View File

@ -1,7 +1,7 @@
/* packet-msnip.c 2001 Ronnie Sahlberg <See AUTHORS for email>
* Routines for IGMP/MSNIP packet disassembly
*
* $Id: packet-msnip.c,v 1.5 2002/01/21 07:36:37 guy Exp $
* $Id: packet-msnip.c,v 1.6 2002/02/01 11:01:57 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -48,7 +48,7 @@
#include <glib.h>
#include <epan/packet.h>
#include "in_cksum.h"
#include "packet-igmp.h"
#include "packet-msnip.h"
@ -87,29 +87,6 @@ static const value_string msnip_rec_types[] = {
{0, NULL}
};
static void
msnip_checksum(proto_tree *tree,tvbuff_t *tvb, int len)
{
guint16 cksum,hdrcksum;
vec_t cksum_vec[1];
cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, len);
cksum_vec[0].len = len;
hdrcksum = tvb_get_ntohs(tvb, 2);
cksum = in_cksum(&cksum_vec[0],1);
if (cksum==0) {
proto_tree_add_uint_format(tree, hf_checksum, tvb, 2, 2, hdrcksum, "Header checksum: 0x%04x (correct)", hdrcksum);
} else {
proto_tree_add_item_hidden(tree, hf_checksum_bad, tvb, 2, 2, TRUE);
proto_tree_add_uint_format(tree, hf_checksum, tvb, 2, 2, hdrcksum, "Header checksum: 0x%04x (incorrect, should be 0x%04x)", hdrcksum,in_cksum_shouldbe(hdrcksum,cksum));
}
return;
}
static int
dissect_msnip_rmr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
{
@ -121,7 +98,7 @@ dissect_msnip_rmr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, in
offset += 1;
/* checksum */
msnip_checksum(parent_tree, tvb, tvb_length_remaining(tvb, 0));
igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
offset += 2;
while (count--) {
@ -170,7 +147,7 @@ dissect_msnip_is(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int
offset += 1;
/* checksum */
msnip_checksum(parent_tree, tvb, tvb_length_remaining(tvb, 0));
igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
offset += 2;
/* 16 bit holdtime */
@ -196,7 +173,7 @@ dissect_msnip_gm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int
offset += 1;
/* checksum */
msnip_checksum(parent_tree, tvb, tvb_length_remaining(tvb, 0));
igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
offset += 2;
/* holdtime */