Squelch some compiler warnings.
[obnox/wireshark/wip.git] / packet-udp.c
index ee0010e79999562bf4c4587cc758b2bcf82e8f4b..de0db83c55c8499c52b4119c7d41d1c4b6f758f0 100644 (file)
@@ -1,10 +1,10 @@
 /* packet-udp.c
  * Routines for UDP packet disassembly
  *
- * $Id: packet-udp.c,v 1.84 2001/01/09 06:31:44 guy Exp $
+ * $Id: packet-udp.c,v 1.94 2001/06/18 02:17:53 guy Exp $
  *
  * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * By Gerald Combs <gerald@ethereal.com>
  * Copyright 1998 Gerald Combs
  *
  * Richard Sharpe, 13-Feb-1999, added dispatch table support and 
 #include <string.h>
 
 #include <glib.h>
-#include "globals.h"
+#include "packet.h"
 #include "resolv.h"
+#include "ipproto.h"
 #include "in_cksum.h"
+#include "prefs.h"
 
-#include "plugins.h"
 #include "packet-udp.h"
 
 #include "packet-ip.h"
 #include "conversation.h"
-#include "packet-vines.h"
 
 static int proto_udp = -1;             
 static int hf_udp_srcport = -1;
@@ -59,9 +59,13 @@ static int hf_udp_dstport = -1;
 static int hf_udp_port = -1;
 static int hf_udp_length = -1;
 static int hf_udp_checksum = -1;
+static int hf_udp_checksum_bad = -1;
 
 static gint ett_udp = -1;
 
+/* Place UDP summary in proto tree */
+static gboolean udp_summary_in_tree = TRUE;
+
 /* UDP structs and definitions */
 
 typedef struct _e_udphdr {
@@ -84,8 +88,6 @@ decode_udp_ports(tvbuff_t *tvb, int offset, packet_info *pinfo,
        proto_tree *tree, int uh_sport, int uh_dport)
 {
   tvbuff_t *next_tvb;
-  const u_char *next_pd;
-  int next_offset;
 
   next_tvb = tvb_new_subset(tvb, offset, -1, -1);
 
@@ -94,26 +96,7 @@ decode_udp_ports(tvbuff_t *tvb, int offset, packet_info *pinfo,
 
   if (try_conversation_dissector(&pinfo->src, &pinfo->dst, PT_UDP,
                uh_sport, uh_dport, next_tvb, pinfo, tree))
-       return;
-
-  /* try to apply the plugins */
-#ifdef HAVE_PLUGINS
-  {
-      plugin *pt_plug = plugin_list;
-
-      if (enabled_plugins_number > 0) {
-         tvb_compat(next_tvb, &next_pd, &next_offset);
-         while (pt_plug) {
-             if (pt_plug->enabled && strstr(pt_plug->protocol, "udp") &&
-                 tree && dfilter_apply(pt_plug->filter, tree, next_pd, pinfo->fd->cap_len)) {
-                 pt_plug->dissector(next_pd, next_offset, pinfo->fd, tree);
-                 return;
-             }
-             pt_plug = pt_plug->next;
-         }
-      }
-  }
-#endif
+    return;
 
   /* do lookup with the subdissector table */
   if (dissector_try_port(udp_dissector_table, uh_sport, next_tvb, pinfo, tree) ||
@@ -142,9 +125,10 @@ dissect_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
   guint16    computed_cksum;
   int        offset = 0;
 
-  CHECK_DISPLAY_AS_DATA(proto_udp, tvb, pinfo, tree);
-
-  pinfo->current_proto = "UDP";
+  if (check_col(pinfo->fd, COL_PROTOCOL))
+    col_set_str(pinfo->fd, COL_PROTOCOL, "UDP");
+  if (check_col(pinfo->fd, COL_INFO))
+    col_clear(pinfo->fd, COL_INFO);
 
   /* Avoids alignment problems on many architectures. */
   tvb_memcpy(tvb, (guint8 *)&uh, offset, sizeof(e_udphdr));
@@ -153,14 +137,18 @@ dissect_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
   uh_ulen  = ntohs(uh.uh_ulen);
   uh_sum   = ntohs(uh.uh_sum);
   
-  if (check_col(pinfo->fd, COL_PROTOCOL))
-    col_set_str(pinfo->fd, COL_PROTOCOL, "UDP");
   if (check_col(pinfo->fd, COL_INFO))
     col_add_fstr(pinfo->fd, COL_INFO, "Source port: %s  Destination port: %s",
            get_udp_port(uh_sport), get_udp_port(uh_dport));
     
   if (tree) {
-    ti = proto_tree_add_item(tree, proto_udp, tvb, offset, 8, FALSE);
+    if (udp_summary_in_tree) {
+      ti = proto_tree_add_protocol_format(tree, proto_udp, tvb, offset, 8,
+      "User Datagram Protocol, Src Port: %s (%u), Dst Port: %s (%u)",
+      get_udp_port(uh_sport), uh_sport, get_udp_port(uh_dport), uh_dport);
+    } else {
+      ti = proto_tree_add_item(tree, proto_udp, tvb, offset, 8, FALSE);
+    }
     udp_tree = proto_item_add_subtree(ti, ett_udp);
 
     proto_tree_add_uint_format(udp_tree, hf_udp_srcport, tvb, offset, 2, uh_sport,
@@ -215,6 +203,8 @@ dissect_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
         proto_tree_add_uint_format(udp_tree, hf_udp_checksum, tvb,
           offset + 6, 2, uh_sum, "Checksum: 0x%04x (correct)", uh_sum);
       } else {
+       proto_tree_add_boolean_hidden(udp_tree, hf_udp_checksum_bad, tvb,
+          offset + 6, 2, TRUE);
         proto_tree_add_uint_format(udp_tree, hf_udp_checksum, tvb,
           offset + 6, 2, uh_sum,
          "Checksum: 0x%04x (incorrect, should be 0x%04x)", uh_sum,
@@ -241,26 +231,31 @@ dissect_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 void
 proto_register_udp(void)
 {
+       module_t *udp_module;
        static hf_register_info hf[] = {
                { &hf_udp_srcport,
                { "Source Port",        "udp.srcport", FT_UINT16, BASE_DEC, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_udp_dstport,
                { "Destination Port",   "udp.dstport", FT_UINT16, BASE_DEC, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_udp_port,
                { "Source or Destination Port", "udp.port", FT_UINT16, BASE_DEC,  NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_udp_length,
                { "Length",             "udp.length", FT_UINT16, BASE_DEC, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
+
+               { &hf_udp_checksum_bad,
+               { "Bad Checksum",       "udp.checksum_bad", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
+                       "", HFILL }},
 
                { &hf_udp_checksum,
                { "Checksum",           "udp.checksum", FT_UINT16, BASE_HEX, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
        };
        static gint *ett[] = {
                &ett_udp,
@@ -275,6 +270,13 @@ proto_register_udp(void)
        udp_dissector_table = register_dissector_table("udp.port");
        register_heur_dissector_list("udp", &heur_subdissector_list);
        register_conv_dissector_list("udp", &conv_subdissector_list);
+       
+       /* Register configuration preferences */
+       udp_module = prefs_register_protocol(proto_udp, NULL);
+       prefs_register_bool_preference(udp_module, "udp_summary_in_tree",
+       "Show UDP summary in protocol treee", 
+       "Whether the UDP summary line should be shown in the protocol tree",
+       &udp_summary_in_tree);
 }
 
 void