aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packet-clnp.c39
-rw-r--r--packet-esis.c32
-rw-r--r--packet-osi.c56
-rw-r--r--packet-osi.h14
4 files changed, 112 insertions, 29 deletions
diff --git a/packet-clnp.c b/packet-clnp.c
index d1cd4c8abb..78ec69e43d 100644
--- a/packet-clnp.c
+++ b/packet-clnp.c
@@ -1,14 +1,13 @@
/* packet-clnp.c
* Routines for ISO/OSI network and transport protocol packet disassembly
*
- * $Id: packet-clnp.c,v 1.28 2001/05/27 04:14:52 guy Exp $
+ * $Id: packet-clnp.c,v 1.29 2001/06/05 09:06:19 guy Exp $
* Laurent Deniel <deniel@worldnet.fr>
* Ralf Schneider <Ralf.Schneider@t-online.de>
*
* Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * 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
@@ -1675,10 +1674,42 @@ static void dissect_clnp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_tree_add_uint(clnp_tree, hf_clnp_pdu_length, tvb, P_CLNP_SEGLEN, 2,
segment_length);
cnf_cksum = tvb_get_ntohs(tvb, P_CLNP_CKSUM);
- proto_tree_add_uint_format(clnp_tree, hf_clnp_checksum, tvb, P_CLNP_CKSUM, 2,
+ switch (calc_checksum(tvb, 0, cnf_hdr_len, cnf_cksum)) {
+
+ default:
+ /*
+ * No checksum present, or not enough of the header present to
+ * checksum it.
+ */
+ proto_tree_add_uint_format(clnp_tree, hf_clnp_checksum, tvb,
+ P_CLNP_CKSUM, 2,
cnf_cksum,
"Checksum : 0x%04x",
cnf_cksum);
+ break;
+
+ case CKSUM_OK:
+ /*
+ * Checksum is correct.
+ */
+ proto_tree_add_uint_format(clnp_tree, hf_clnp_checksum, tvb,
+ P_CLNP_CKSUM, 2,
+ cnf_cksum,
+ "Checksum : 0x%04x (correct)",
+ cnf_cksum);
+ break;
+
+ case CKSUM_NOT_OK:
+ /*
+ * Checksum is not correct.
+ */
+ proto_tree_add_uint_format(clnp_tree, hf_clnp_checksum, tvb,
+ P_CLNP_CKSUM, 2,
+ cnf_cksum,
+ "Checksum : 0x%04x (incorrect)",
+ cnf_cksum);
+ break;
+ }
opt_len -= 9; /* Fixed part of Hesder */
} /* tree */
diff --git a/packet-esis.c b/packet-esis.c
index 906b1987ed..51b78a0183 100644
--- a/packet-esis.c
+++ b/packet-esis.c
@@ -2,13 +2,12 @@
* Routines for ISO/OSI End System to Intermediate System
* Routeing Exchange Protocol ISO 9542.
*
- * $Id: packet-esis.c,v 1.14 2001/03/30 10:51:50 guy Exp $
+ * $Id: packet-esis.c,v 1.15 2001/06/05 09:06:19 guy Exp $
* Ralf Schneider <Ralf.Schneider@t-online.de>
*
* Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * 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
@@ -292,6 +291,7 @@ dissect_esis(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
proto_tree *esis_tree = NULL;
int variable_len = 0;
u_int tmp_uint = 0;
+ char *cksum_status;
if (check_col(pinfo->fd, COL_PROTOCOL))
col_set_str(pinfo->fd, COL_PROTOCOL, "ESIS");
@@ -337,11 +337,31 @@ dissect_esis(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
tmp_uint = pntohs( ehdr.esis_checksum );
+ switch (calc_checksum( tvb, 0, ehdr.esis_length, tmp_uint )) {
+
+ case NO_CKSUM:
+ cksum_status = "Not Used";
+ break;
+
+ case DATA_MISSING:
+ cksum_status = "Not checkable - not all of packet was captured";
+ break;
+
+ case CKSUM_OK:
+ cksum_status = "Is good";
+ break;
+
+ case CKSUM_NOT_OK:
+ cksum_status = "Is wrong";
+ break;
+
+ default:
+ cksum_status = NULL;
+ g_assert_not_reached();
+ }
proto_tree_add_uint_format( esis_tree, hf_esis_checksum, tvb, 7, 2,
tmp_uint, "Checksum : 0x%x ( %s )",
- tmp_uint, calc_checksum( tvb, 0,
- ehdr.esis_length ,
- tmp_uint ) );
+ tmp_uint, cksum_status );
}
diff --git a/packet-osi.c b/packet-osi.c
index b165677243..4b5c8900a8 100644
--- a/packet-osi.c
+++ b/packet-osi.c
@@ -2,14 +2,13 @@
* Routines for ISO/OSI network and transport protocol packet disassembly
* Main entrance point and common functions
*
- * $Id: packet-osi.c,v 1.44 2001/04/16 10:04:30 guy Exp $
+ * $Id: packet-osi.c,v 1.45 2001/06/05 09:06:19 guy Exp $
* Laurent Deniel <deniel@worldnet.fr>
* Ralf Schneider <Ralf.Schneider@t-online.de>
*
* Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * 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
@@ -49,29 +48,56 @@
#include "packet-esis.h"
-gchar *calc_checksum( tvbuff_t *tvb, int offset, u_int len, u_int checksum) {
- u_int calc_sum = 0;
- u_int count = 0;
+cksum_status_t
+calc_checksum( tvbuff_t *tvb, int offset, u_int len, u_int checksum) {
const gchar *buffer;
guint available_len;
+ const guint8 *p;
+ guint32 c0, c1;
+ u_int seglen;
+ int i;
if ( 0 == checksum )
- return( "Not Used" );
+ return( NO_CKSUM );
available_len = tvb_length_remaining( tvb, offset );
if ( available_len < len )
- return( "Not checkable - not all of packet was captured" );
+ return( DATA_MISSING );
buffer = tvb_get_ptr( tvb, offset, len );
- for ( count = 0; count < len; count++ ) {
- calc_sum += (u_int) buffer[count];
+
+ /*
+ * The maximum values of c0 and c1 will occur if all bytes have the
+ * value 255; if so, then c0 will be len*255 and c1 will be
+ * (len*255 + (len-1)*255 + ... + 255), which is
+ * (len + (len - 1) + ... + 1)*255, or 255*(len*(len + 1))/2.
+ * This means it can overflow if "len" is 5804 or greater.
+ *
+ * (A+B) mod 255 = ((A mod 255) + (B mod 255) mod 255, so
+ * we can solve this by taking c0 and c1 mod 255 every
+ * 5803 bytes.
+ */
+ p = buffer;
+ c0 = 0;
+ c1 = 0;
+ while (len != 0) {
+ seglen = len;
+ if (seglen > 5803)
+ seglen = 5803;
+ for (i = 0; i < seglen; i++) {
+ c0 = c0 + *(p++);
+ c1 += c0;
+ }
+
+ c0 = c0 % 255;
+ c1 = c1 % 255;
+
+ len -= seglen;
}
- calc_sum %= 255; /* modulo 255 divison */
-
- if ( 0 == calc_sum )
- return( "Is good" );
+ if (c0 != 0 || c1 != 0)
+ return( CKSUM_NOT_OK ); /* XXX - what should the checksum be? */
else
- return( "Is wrong" ); /* XXX - what should the checksum be? */
+ return( CKSUM_OK );
}
diff --git a/packet-osi.h b/packet-osi.h
index 6694ef1ef5..6b2573526f 100644
--- a/packet-osi.h
+++ b/packet-osi.h
@@ -1,11 +1,10 @@
/* packet-osi.h
*
- * $Id: packet-osi.h,v 1.7 2001/04/01 05:48:14 hagbard Exp $
+ * $Id: packet-osi.h,v 1.8 2001/06/05 09:06:19 guy Exp $
*
* Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * 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
@@ -85,6 +84,13 @@ dissector_table_t osinl_subdissector_table;
* published API functions
*/
-extern gchar *calc_checksum ( tvbuff_t *, int, u_int, u_int );
+typedef enum {
+ NO_CKSUM, /* checksum field is 0 */
+ DATA_MISSING, /* not all the data covered by the checksum was captured */
+ CKSUM_OK, /* checksum is OK */
+ CKSUM_NOT_OK /* checksum is not OK */
+} cksum_status_t;
+
+extern cksum_status_t calc_checksum(tvbuff_t *, int, u_int, u_int);
#endif /* _PACKET_OSI_H */