various string related changes, mainly replace sprintf/snprintf by g_snprintf
[obnox/wireshark/wip.git] / packet-mrdisc.c
index ceda3c85fe37744b9c8e6aea3635d74c499ba230..c0975730db76628ba23fd90123ea4ae79c00d09e 100644 (file)
@@ -1,22 +1,22 @@
 /* packet-mrdisc.c   2001 Ronnie Sahlberg <See AUTHORS for email>
  * Routines for IGMP/MRDISC packet disassembly
  *
- * $Id: packet-mrdisc.c,v 1.5 2002/01/20 22:12:26 guy Exp $
+ * $Id: packet-mrdisc.c,v 1.10 2003/11/16 23:17:19 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.
@@ -25,9 +25,9 @@
 
 
                        MRDISC
-       code                    
+       code
 
-       0x24            x       
+       0x24            x
        0x25            x
        0x26            x
 
 # include "config.h"
 #endif
 
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
 #include <stdio.h>
 #include <string.h>
 #include <glib.h>
 
-#include "packet.h"
-#include "in_cksum.h"
+#include <epan/packet.h>
+#include "packet-igmp.h"
 #include "packet-mrdisc.h"
 
 
@@ -88,28 +84,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 +94,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 */
@@ -139,7 +113,7 @@ dissect_mrdisc_mra(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, i
                guint8 type,len;
                int old_offset = offset;
 
-               item = proto_tree_add_item(parent_tree, hf_options, 
+               item = proto_tree_add_item(parent_tree, hf_options,
                        tvb, offset, -1, FALSE);
                tree = proto_item_add_subtree(item, ett_options);
 
@@ -187,7 +161,7 @@ dissect_mrdisc_mra(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, i
                        proto_item_set_len(item, offset-old_offset);
                }
        }
-       
+
        return offset;
 }
 
@@ -199,7 +173,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;
@@ -214,7 +188,7 @@ dissect_mrdisc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int o
        proto_item *item;
        guint8 type;
 
-       if (!proto_is_protocol_enabled(proto_mrdisc)) {
+       if (!proto_is_protocol_enabled(find_protocol_by_id(proto_mrdisc))) {
                /* we are not enabled, skip entire packet to be nice
                   to the igmp layer. (so clicking on IGMP will display the data)
                 */
@@ -236,7 +210,7 @@ dissect_mrdisc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int o
        type = tvb_get_guint8(tvb, offset);
        if (check_col(pinfo->cinfo, COL_INFO)) {
                col_add_fstr(pinfo->cinfo, COL_INFO,
-                       "%s",val_to_str(type, mrdisc_types, 
+                       "%s",val_to_str(type, mrdisc_types,
                                "Unknown Type:0x%02x"));
        }