Don't say "without SNMP"; that can confuse people into thinking it means
[obnox/wireshark/wip.git] / packet-quake2.c
index 0b5f43b9ee0624dff00d3a3fc0cc8a5c559b08b6..94635790f397062caa241643596479dd0219f6ef 100644 (file)
@@ -7,10 +7,10 @@
  *     http://www.dgs.monash.edu.au/~timf/bottim/
  *     http://www.opt-sci.Arizona.EDU/Pandora/default.asp
  *
- * $Id: packet-quake2.c,v 1.1 2001/06/21 15:15:57 girlich Exp $
+ * $Id: packet-quake2.c,v 1.9 2002/01/24 09:20:50 guy Exp $
  *
  * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * By Gerald Combs <gerald@ethereal.com>
  * Copyright 1998 Gerald Combs
  *
  * Copied from packet-quakeworld.c
@@ -39,7 +39,7 @@
 #endif
 
 #include <glib.h>
-#include "packet.h"
+#include <epan/packet.h>
 #include "prefs.h"
 
 static int proto_quake2 = -1;
@@ -64,6 +64,7 @@ static gint ett_quake2_game_seq2 = -1;
 static gint ett_quake2_game_clc = -1;
 static gint ett_quake2_game_svc = -1;
 
+static dissector_handle_t data_handle;
 
 #define PORT_MASTER 27910
 static unsigned int gbl_quake2ServerPort=PORT_MASTER;
@@ -85,7 +86,7 @@ dissect_quake2_ConnectionlessPacket(tvbuff_t *tvb, packet_info *pinfo,
        marker = tvb_get_ntohl(tvb, 0);
        if (tree) {
                cl_item = proto_tree_add_text(tree, tvb,
-                               0, tvb_length(tvb), "Connectionless");
+                               0, -1, "Connectionless");
                if (cl_item)
                        cl_tree = proto_item_add_subtree(
                                cl_item, ett_quake2_connectionless);
@@ -101,7 +102,7 @@ dissect_quake2_ConnectionlessPacket(tvbuff_t *tvb, packet_info *pinfo,
 
         maxbufsize = MIN((gint)sizeof(text), tvb_length_remaining(tvb, offset));
         len = tvb_get_nstringz0(tvb, offset, maxbufsize, text);
-        if (tree) {
+        if (cl_tree) {
                 proto_tree_add_string(cl_tree, hf_quake2_connectionless_text,
                         tvb, offset, len + 1, text);
         }
@@ -120,7 +121,7 @@ dissect_quake2_client_commands(tvbuff_t *tvb, packet_info *pinfo,
           the information from my DM2 specs:
                http://www.planetquake.com/demospecs/dm2/
        */
-       dissect_data(tvb, 0, pinfo, tree);
+       call_dissector(data_handle,tvb, pinfo, tree);
 }
 
 
@@ -132,7 +133,7 @@ dissect_quake2_server_commands(tvbuff_t *tvb, packet_info *pinfo,
           the information from my DM2 specs:
                http://www.planetquake.com/demospecs/dm2/
        */
-       dissect_data(tvb, 0, pinfo, tree);
+       call_dissector(data_handle,tvb, pinfo, tree);
 }
 
 
@@ -170,7 +171,7 @@ dissect_quake2_GamePacket(tvbuff_t *tvb, packet_info *pinfo,
 
        if (tree) {
                game_item = proto_tree_add_text(tree, tvb,
-                               0, tvb_length(tvb), "Game");
+                               0, -1, "Game");
                if (game_item)
                        game_tree = proto_item_add_subtree(
                                game_item, ett_quake2_game);
@@ -235,8 +236,7 @@ dissect_quake2_GamePacket(tvbuff_t *tvb, packet_info *pinfo,
                        proto_tree *c_tree = NULL;
                        if (tree) {
                                c_item = proto_tree_add_text(game_tree, next_tvb,
-                               0, tvb_length(next_tvb),
-                               "Client Commands");
+                               0, -1, "Client Commands");
                                if (c_item) {
                                        c_tree = proto_item_add_subtree(
                                                c_item, ett_quake2_game_clc);
@@ -249,8 +249,7 @@ dissect_quake2_GamePacket(tvbuff_t *tvb, packet_info *pinfo,
                        proto_tree *c_tree = NULL;
                        if (tree) {
                                c_item = proto_tree_add_text(game_tree, next_tvb,
-                               0, tvb_length(next_tvb),
-                               "Server Commands");
+                               0, -1, "Server Commands");
                                if (c_item) {
                                        c_tree = proto_item_add_subtree(
                                        c_item, ett_quake2_game_svc);
@@ -269,27 +268,18 @@ dissect_quake2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        proto_item      *quake2_item = NULL;
        int             direction;
 
-       /*
-        * XXX - this is a conversation dissector, and the code to
-        * call a conversation dissector doesn't check for disabled
-        * protocols or set "pinfo->current_proto".
-        */
-       CHECK_DISPLAY_AS_DATA(proto_quake2, tvb, pinfo, tree);
-
        direction = (pinfo->destport == gbl_quake2ServerPort) ?
                        DIR_C2S : DIR_S2C;
 
-       pinfo->current_proto = "QUAKE2";
-
-       if (check_col(pinfo->fd, COL_PROTOCOL))
-               col_set_str(pinfo->fd, COL_PROTOCOL, "QUAKE2");
-       if (check_col(pinfo->fd, COL_INFO))
-               col_set_str(pinfo->fd, COL_INFO, val_to_str(direction,
+       if (check_col(pinfo->cinfo, COL_PROTOCOL))
+               col_set_str(pinfo->cinfo, COL_PROTOCOL, "QUAKE2");
+       if (check_col(pinfo->cinfo, COL_INFO))
+               col_set_str(pinfo->cinfo, COL_INFO, val_to_str(direction,
                        names_direction, "%u"));
 
        if (tree) {
                quake2_item = proto_tree_add_item(tree, proto_quake2,
-                               tvb, 0, tvb_length(tvb), FALSE);
+                               tvb, 0, -1, FALSE);
                if (quake2_item)
                        quake2_tree = proto_item_add_subtree(
                                quake2_item, ett_quake2);
@@ -304,8 +294,8 @@ dissect_quake2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        }
 
        if (tvb_get_ntohl(tvb, 0) == 0xffffffff) {
-               if (check_col(pinfo->fd, COL_INFO)) {
-                       col_append_str(pinfo->fd, COL_INFO, " Connectionless");
+               if (check_col(pinfo->cinfo, COL_INFO)) {
+                       col_append_str(pinfo->cinfo, COL_INFO, " Connectionless");
                }
                if (quake2_tree)
                        proto_tree_add_uint_format(quake2_tree,
@@ -316,8 +306,8 @@ dissect_quake2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                        tvb, pinfo, quake2_tree, direction);
        }
        else {
-               if (check_col(pinfo->fd, COL_INFO)) {
-                       col_append_str(pinfo->fd, COL_INFO, " Game");
+               if (check_col(pinfo->cinfo, COL_INFO)) {
+                       col_append_str(pinfo->cinfo, COL_INFO, " Game");
                }
                if (quake2_tree)
                        proto_tree_add_uint_format(quake2_tree,
@@ -334,19 +324,22 @@ void
 proto_reg_handoff_quake2(void)
 {
        static int Initialized=FALSE;
+       static dissector_handle_t quake2_handle;
        static int ServerPort=0;
  
-       if (Initialized) {
-               dissector_delete("udp.port", ServerPort, dissect_quake2);
-       } else {
+       if (!Initialized) {
+               quake2_handle = create_dissector_handle(dissect_quake2,
+                               proto_quake2);
                Initialized=TRUE;
+       } else {
+               dissector_delete("udp.port", ServerPort, quake2_handle);
        }
  
         /* set port for future deletes */
         ServerPort=gbl_quake2ServerPort;
  
-       dissector_add("udp.port", gbl_quake2ServerPort,
-                       dissect_quake2, proto_quake2);
+       dissector_add("udp.port", gbl_quake2ServerPort, quake2_handle);
+       data_handle = find_dissector("data");
 }
 
 
@@ -423,4 +416,3 @@ proto_register_quake2(void)
                                        "Set the UDP port for the Quake II Server",
                                        10, &gbl_quake2ServerPort);
 }
-