Require that the LMP and RSVP message types be greater than 0.
[obnox/wireshark/wip.git] / packet-igmp.c
index f093b4a7db02d687887bbd8a5a71f5afdef6753b..397cc160638b5db822a1bfee178b823393573121 100644 (file)
@@ -1,7 +1,7 @@
-/* packet-igmp.c   2001 Ronnie Sahlberg <rsahlber@bigpond.net.au>
+/* packet-igmp.c   2001 Ronnie Sahlberg <See AUTHORS for email>
  * Routines for IGMP packet disassembly
  *
- * $Id: packet-igmp.c,v 1.11 2001/07/11 04:24:34 guy Exp $
+ * $Id: packet-igmp.c,v 1.19 2002/05/02 07:54:41 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
 #include <string.h>
 #include <glib.h>
 
-#include "packet.h"
+#ifdef NEED_SNPRINTF_H
+# include "snprintf.h"
+#endif
+
+#include <epan/packet.h>
 #include "ipproto.h"
 #include "in_cksum.h"
 #include "packet-dvmrp.h"
@@ -294,8 +298,8 @@ static const value_string mtrace_fwd_code_vals[] = {
 };
 
 #define PRINT_IGMP_VERSION(version)                                    \
-       if (check_col(pinfo->fd, COL_INFO)) {                           \
-               col_add_fstr(pinfo->fd, COL_INFO,                       \
+       if (check_col(pinfo->cinfo, COL_INFO)) {                                \
+               col_add_fstr(pinfo->cinfo, COL_INFO,                    \
                        "V%d %s",version,val_to_str(type, commands,     \
                                "Unknown Type:0x%02x"));                \
        }                                                               \
@@ -305,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];
@@ -317,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) {
                /*
@@ -330,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;
 }
@@ -353,8 +357,8 @@ dissect_igmp_unknown(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int ty
 {
        int len;
 
-       if (check_col(pinfo->fd, COL_INFO)) {
-               col_add_str(pinfo->fd, COL_INFO,
+       if (check_col(pinfo->cinfo, COL_INFO)) {
+               col_add_str(pinfo->cinfo, COL_INFO,
                        val_to_str(type, commands, "Unknown Type:0x%02x"));
        }
 
@@ -376,7 +380,7 @@ dissect_igmp_unknown(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int ty
  * IGMP Protocol dissectors
  *************************************************************/
 static int
-dissect_v3_max_resp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
+dissect_v3_max_resp(tvbuff_t *tvb, proto_tree *parent_tree, int offset)
 {
        proto_tree *tree;
        proto_item *item;
@@ -409,7 +413,7 @@ dissect_v3_max_resp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree,
 }
 
 static int
-dissect_v3_sqrv_bits(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
+dissect_v3_sqrv_bits(tvbuff_t *tvb, proto_tree *parent_tree, int offset)
 {
        proto_tree *tree;
        proto_item *item;
@@ -432,7 +436,7 @@ dissect_v3_sqrv_bits(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree,
 }
 
 static int
-dissect_v3_group_record(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
+dissect_v3_group_record(tvbuff_t *tvb, proto_tree *parent_tree, int offset)
 {
        proto_tree *tree;
        proto_item *item;
@@ -442,7 +446,7 @@ dissect_v3_group_record(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tr
        guint32 ip;
 
        tvb_memcpy(tvb, (guint8 *)&ip, offset+4, 4);
-       item = proto_tree_add_text(parent_tree, tvb, offset, 0, 
+       item = proto_tree_add_text(parent_tree, tvb, offset, -1,
                "Group Record : %s  %s", 
                        ip_to_str((gchar*)&ip), 
                        val_to_str(tvb_get_guint8(tvb, offset), vs_record_type,"")
@@ -496,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;
@@ -508,7 +512,7 @@ dissect_igmp_v3_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, in
        offset += 2;
        
        while (num--) {
-               offset = dissect_v3_group_record(tvb,pinfo,tree,offset);
+               offset = dissect_v3_group_record(tvb, tree, offset);
        }
 
        return offset;
@@ -523,10 +527,10 @@ dissect_igmp_v3_query(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int t
 
        num = tvb_get_ntohs(tvb, offset+9);
        /* max resp code */
-       offset = dissect_v3_max_resp(tvb, pinfo, tree, offset);
+       offset = dissect_v3_max_resp(tvb, tree, offset);
 
        /* checksum */
-       igmp_checksum(tree, tvb, pinfo, 0);
+       igmp_checksum(tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
        offset += 2;
 
        /* group address */
@@ -534,7 +538,7 @@ dissect_igmp_v3_query(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int t
        offset +=4;
 
        /* bitmask for S and QRV */
-       offset = dissect_v3_sqrv_bits(tvb, pinfo, tree, offset);
+       offset = dissect_v3_sqrv_bits(tvb, tree, offset);
 
        /* qqic */
        proto_tree_add_item(tree, hf_qqic, tvb, offset, 1, FALSE);
@@ -567,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 */
@@ -587,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 */
@@ -619,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 */
@@ -662,9 +666,9 @@ dissect_igmp_mtrace(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int typ
        else
                typestr = "Traceroute Request";
 
-       if (check_col(pinfo->fd, COL_INFO)) {
-               col_set_str(pinfo->fd, COL_INFO, typestr);
-               if (blocks) col_append_str(pinfo->fd, COL_INFO, blocks);
+       if (check_col(pinfo->cinfo, COL_INFO)) {
+               col_set_str(pinfo->cinfo, COL_INFO, typestr);
+               if (blocks) col_append_str(pinfo->cinfo, COL_INFO, blocks);
        }
 
        proto_tree_add_uint_format(tree, hf_type, tvb, offset, 1, type,
@@ -676,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 */
@@ -780,15 +784,15 @@ dissect_igmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
        unsigned char type;
        guint32 dst;
 
-       item = proto_tree_add_item(parent_tree, proto_igmp, tvb, offset, 0, FALSE);
+       item = proto_tree_add_item(parent_tree, proto_igmp, tvb, offset, -1, FALSE);
        tree = proto_item_add_subtree(item, ett_igmp);
 
 
-       if (check_col(pinfo->fd, COL_PROTOCOL)) {
-               col_set_str(pinfo->fd, COL_PROTOCOL, "IGMP");
+       if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
+               col_set_str(pinfo->cinfo, COL_PROTOCOL, "IGMP");
        }
-       if (check_col(pinfo->fd, COL_INFO)) {
-               col_clear(pinfo->fd, COL_INFO);
+       if (check_col(pinfo->cinfo, COL_INFO)) {
+               col_clear(pinfo->cinfo, COL_INFO);
        }
 
 
@@ -1081,5 +1085,8 @@ proto_register_igmp(void)
 void
 proto_reg_handoff_igmp(void)
 {
-       dissector_add("ip.proto", IP_PROTO_IGMP, dissect_igmp, proto_igmp);
+       dissector_handle_t igmp_handle;
+
+       igmp_handle = create_dissector_handle(dissect_igmp, proto_igmp);
+       dissector_add("ip.proto", IP_PROTO_IGMP, igmp_handle);
 }