Move sourcelists into Makefile.common
[obnox/wireshark/wip.git] / packet-quake.c
index e337f4d77c5bc718290ddab95569f8b2356ece15..715c06efc71c34908b39dc094dc29711e0a17b95 100644 (file)
@@ -1,27 +1,27 @@
 /* packet-quake.c
- * Routines for quake packet dissection
+ * Routines for Quake packet dissection
  *
  * Uwe Girlich <uwe@planetquake.com>
  *     http://www.idsoftware.com/q1source/q1source.zip
  *
- * $Id: packet-quake.c,v 1.4 2000/08/13 14:08:36 deniel Exp $
+ * $Id: packet-quake.c,v 1.30 2003/06/12 08:33:29 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-tftp.c
- * 
+ *
  * 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.
 # include "config.h"
 #endif
 
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
-#ifdef HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-
 #include <glib.h>
-#include "packet.h"
-#include "conversation.h"
+#include <epan/packet.h>
+#include <epan/conversation.h>
+#include "prefs.h"
 
 static int proto_quake = -1;
-static int hf_quake_header_flags = -1; 
-static int hf_quake_header_length = -1; 
-static int hf_quake_header_sequence = -1; 
+static int hf_quake_header_flags = -1;
+static int hf_quake_header_length = -1;
+static int hf_quake_header_sequence = -1;
 static int hf_quake_control_command = -1;
 
 static int hf_quake_CCREQ_CONNECT_game = -1;
@@ -79,11 +72,14 @@ static gint ett_quake_control = -1;
 static gint ett_quake_control_colors = -1;
 static gint ett_quake_flags = -1;
 
+static dissector_handle_t quake_handle;
+static dissector_handle_t data_handle;
 
 /* I took these names directly out of the Q1 source. */
 #define NETFLAG_LENGTH_MASK 0x0000ffff
 #define NET_HEADERSIZE 8
 #define DEFAULTnet_hostport 26000
+static unsigned int gbl_quakeServerPort=DEFAULTnet_hostport;
 
 #define NETFLAG_LENGTH_MASK     0x0000ffff
 #define NETFLAG_DATA            0x00010000
@@ -91,14 +87,14 @@ static gint ett_quake_flags = -1;
 #define NETFLAG_NAK                     0x00040000
 #define NETFLAG_EOM                     0x00080000
 #define NETFLAG_UNRELIABLE      0x00100000
-#define NETFLAG_CTL                     0x80000000                              
+#define NETFLAG_CTL                     0x80000000
 
 
 #define CCREQ_CONNECT           0x01
 #define CCREQ_SERVER_INFO       0x02
 #define CCREQ_PLAYER_INFO       0x03
 #define CCREQ_RULE_INFO         0x04
+
 #define CCREP_ACCEPT            0x81
 #define CCREP_REJECT            0x82
 #define CCREP_SERVER_INFO       0x83
@@ -154,105 +150,64 @@ static const value_string names_colors[] = {
 static void dissect_quake(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
 
 
-static gint
-tvb_get_stringz(tvbuff_t *tvb, gint offset, gint maxlength, guint8* buffer)
-{
-       int i;
-       char* zeropos = NULL;
-       gint stringlen = 0;
-
-       if (maxlength == 0) {
-               buffer[0] = 0;
-               return 0;
-       }
-
-       tvb_memcpy(tvb, buffer, offset, maxlength);
-       for (i=0 ; i<maxlength ; i++) {
-               if (buffer[i] == 0) {
-                       stringlen = i;
-                       zeropos = buffer+i;
-                       break;
-               }
-       }
-       if (zeropos == NULL) {
-               buffer[maxlength-1] = 0;
-               return maxlength-1;
-       }
-       return stringlen;
-}
-
 
 static void
 dissect_quake_CCREQ_CONNECT
-(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+(tvbuff_t *tvb, proto_tree *tree)
 {
-       gint maxbufsize;
-       char game[QUAKE_MAXSTRING];
-       guint8 version;
-       gint len;
+       gint offset;
+       proto_item *ti;
 
-       maxbufsize = MIN(sizeof(game), tvb_length(tvb));
-       len = tvb_get_stringz(tvb, 0, maxbufsize, game);
-       version = tvb_get_guint8(tvb, len + 1);
+       offset = 0;
 
        if (tree) {
-               proto_tree_add_string(tree, hf_quake_CCREQ_CONNECT_game,
-                       tvb, 0, len + 1, game);
-               proto_tree_add_uint(tree, hf_quake_CCREQ_CONNECT_version,
-                       tvb, len + 1, 1, version);
+               ti = proto_tree_add_item(tree, hf_quake_CCREQ_CONNECT_game,
+                       tvb, offset, -1, TRUE);
+               offset += proto_item_get_len(ti);
+
+               proto_tree_add_item(tree, hf_quake_CCREQ_CONNECT_version,
+                       tvb, offset, 1, TRUE);
        }
 }
 
 
 static void
 dissect_quake_CCREQ_SERVER_INFO
-(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+(tvbuff_t *tvb, proto_tree *tree)
 {
-       gint maxbufsize;
-       char game[QUAKE_MAXSTRING];
-       guint8 version;
-       gint len;
+       gint offset;
+       proto_item *ti;
 
-       maxbufsize = MIN(sizeof(game), tvb_length(tvb));
-       len = tvb_get_stringz(tvb, 0, maxbufsize, game);
-       version = tvb_get_guint8(tvb, len + 1);
+       offset = 0;
 
        if (tree) {
-               proto_tree_add_string(tree, hf_quake_CCREQ_SERVER_INFO_game,
-                       tvb, 0, len + 1, game);
-               proto_tree_add_uint(tree, hf_quake_CCREQ_SERVER_INFO_version,
-                       tvb, len + 1, 1, version);
+               ti = proto_tree_add_item(tree, hf_quake_CCREQ_SERVER_INFO_game,
+                       tvb, offset, -1, TRUE);
+               offset += proto_item_get_len(ti);
+               proto_tree_add_item(tree, hf_quake_CCREQ_SERVER_INFO_version,
+                       tvb, offset, 1, TRUE);
        }
 }
 
 
 static void
 dissect_quake_CCREQ_PLAYER_INFO
-(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+(tvbuff_t *tvb, proto_tree *tree)
 {
-       guint8 player;
-
-       player = tvb_get_guint8(tvb, 0);
        if (tree) {
-                proto_tree_add_uint(tree, hf_quake_CCREQ_PLAYER_INFO_player,
-                       tvb, 0, 1, player);
+                proto_tree_add_item(tree, hf_quake_CCREQ_PLAYER_INFO_player,
+                       tvb, 0, 1, TRUE);
        }
 }
 
 
 static void
 dissect_quake_CCREQ_RULE_INFO
-(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+(tvbuff_t *tvb, proto_tree *tree)
 {
-       char rule[QUAKE_MAXSTRING];
-       gint maxbufsize;
-       gint len;
-
-       maxbufsize = MIN(sizeof(rule), tvb_length(tvb));
-       len = tvb_get_stringz(tvb, 0, maxbufsize, rule);
        if (tree) {
-               proto_tree_add_string(tree, hf_quake_CCREQ_RULE_INFO_lastrule,
-                       tvb, 0, len + 1, rule);
+               proto_tree_add_item(tree, hf_quake_CCREQ_RULE_INFO_lastrule,
+                       tvb, 0, -1, TRUE);
        }
 }
 
@@ -265,10 +220,10 @@ dissect_quake_CCREP_ACCEPT
        conversation_t *c;
 
        port = tvb_get_letohl(tvb, 0);
-       c = conversation_new( &pi.src, &pi.dst, PT_UDP, port, pi.destport, NULL);
+       c = conversation_new( &pinfo->src, &pinfo->dst, PT_UDP, port,
+           pinfo->destport, 0);
        if (c) {
-               c->is_old_dissector = FALSE;
-               c->dissector.new = dissect_quake;
+               conversation_set_dissector(c, quake_handle);
        }
        if (tree) {
                proto_tree_add_uint(tree, hf_quake_CCREP_ACCEPT_port,
@@ -279,179 +234,122 @@ dissect_quake_CCREP_ACCEPT
 
 static void
 dissect_quake_CCREP_REJECT
-(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+(tvbuff_t *tvb, proto_tree *tree)
 {
-       gint maxbufsize;
-       char reason[QUAKE_MAXSTRING];
-       gint len;
-
-       maxbufsize = MIN(sizeof(reason), tvb_length(tvb));
-       len = tvb_get_stringz(tvb, 0, maxbufsize, reason);
-
        if (tree) {
-               proto_tree_add_string(tree, hf_quake_CCREP_REJECT_reason,
-                       tvb, 0, len + 1, reason);
+               proto_tree_add_item(tree, hf_quake_CCREP_REJECT_reason,
+                       tvb, 0, -1, TRUE);
        }
 }
 
 
 static void
 dissect_quake_CCREP_SERVER_INFO
-(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+(tvbuff_t *tvb, proto_tree *tree)
 {
        gint offset;
-       gint len;
-       gint maxbufsize;
-       char address[QUAKE_MAXSTRING];
-       char server[QUAKE_MAXSTRING];
-       char map[QUAKE_MAXSTRING];
-
-       guint8 num_player;
-       guint8 max_player;
-       guint8 version;
+       proto_item *ti;
 
        offset = 0;
 
-       maxbufsize = MIN(sizeof(address), tvb_length_remaining(tvb, offset));
-       len = tvb_get_stringz(tvb, offset, maxbufsize, address);
        if (tree) {
-               proto_tree_add_string(tree, hf_quake_CCREP_SERVER_INFO_address,
-                       tvb, offset, len + 1, address);
-       }
-       offset += len + 1;
-
-       maxbufsize = MIN(sizeof(server), tvb_length_remaining(tvb, offset));
-       len = tvb_get_stringz(tvb, offset, maxbufsize, server);
-       if (tree) {
-               proto_tree_add_string(tree, hf_quake_CCREP_SERVER_INFO_server,
-                       tvb, offset, len + 1, server);
-       }
-       offset += len + 1;
-       
-       maxbufsize = MIN(sizeof(map), tvb_length_remaining(tvb, offset));
-       len = tvb_get_stringz(tvb, offset, maxbufsize, map);
-       if (tree) {
-               proto_tree_add_string(tree, hf_quake_CCREP_SERVER_INFO_map,
-                       tvb, offset, len + 1, map);
-       }
-       offset += len + 1;
-
-       num_player = tvb_get_guint8(tvb, offset + 0);
-       max_player = tvb_get_guint8(tvb, offset + 1);
-       version    = tvb_get_guint8(tvb, offset + 2);
-
-       if (tree) {
-               proto_tree_add_uint(tree, hf_quake_CCREP_SERVER_INFO_num_player,
-                       tvb, offset + 0, 1, num_player);
-               proto_tree_add_uint(tree, hf_quake_CCREP_SERVER_INFO_max_player,
-                       tvb, offset + 1, 1, max_player);
-               proto_tree_add_uint(tree, hf_quake_CCREQ_SERVER_INFO_version,
-                       tvb, offset + 2, 1, version);
+               ti = proto_tree_add_item(tree,
+                       hf_quake_CCREP_SERVER_INFO_address, tvb, offset, -1,
+                       TRUE);
+               offset += proto_item_get_len(ti);
+
+               ti = proto_tree_add_item(tree,
+                       hf_quake_CCREP_SERVER_INFO_server, tvb, offset, -1,
+                       TRUE);
+               offset += proto_item_get_len(ti);
+
+               ti = proto_tree_add_item(tree, hf_quake_CCREP_SERVER_INFO_map,
+                       tvb, offset, -1, TRUE);
+               offset += proto_item_get_len(ti);
+
+               proto_tree_add_item(tree, hf_quake_CCREP_SERVER_INFO_num_player,
+                       tvb, offset, 1, TRUE);
+               offset += 1;
+               proto_tree_add_item(tree, hf_quake_CCREP_SERVER_INFO_max_player,
+                       tvb, offset, 1, TRUE);
+               offset += 1;
+               proto_tree_add_item(tree, hf_quake_CCREQ_SERVER_INFO_version,
+                       tvb, offset, 1, TRUE);
        }
 }
 
 
 static void
 dissect_quake_CCREP_PLAYER_INFO
-(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+(tvbuff_t *tvb, proto_tree *tree)
 {
        gint offset;
-       guint8 player;
-       gint len;
-       gint maxbufsize;
-       char name[QUAKE_MAXSTRING];
+       proto_item *ti;
        guint32 colors;
        guint32 color_shirt;
        guint32 color_pants;
-       guint32 frags;
-       guint32 connect_time;
-       char address[QUAKE_MAXSTRING];
+       proto_item *colors_item;
+       proto_tree *colors_tree;
 
        offset = 0;
 
-       player = tvb_get_guint8(tvb, offset);
        if (tree) {
-               proto_tree_add_uint(tree, hf_quake_CCREQ_PLAYER_INFO_player,
-                       tvb, offset, 1, player);
-       }
-       offset += 1;
-       
-       maxbufsize = MIN(sizeof(name), tvb_length_remaining(tvb, offset));
-       len = tvb_get_stringz(tvb, offset, maxbufsize, name);
-       if (tree) {
-               proto_tree_add_string(tree, hf_quake_CCREP_PLAYER_INFO_name,
-                       tvb, offset, len + 1, name);
-       }
-       offset += len + 1;
+               proto_tree_add_item(tree, hf_quake_CCREQ_PLAYER_INFO_player,
+                       tvb, offset, 1, TRUE);
+               offset += 1;
 
-       colors       = tvb_get_letohl(tvb, offset + 0);
-       color_shirt = (colors >> 4) & 0x0f;
-       color_pants = (colors     ) & 0x0f;
-       frags        = tvb_get_letohl(tvb, offset + 4);
-       connect_time = tvb_get_letohl(tvb, offset + 8);
-       if (tree) {
-               proto_item *colors_item;
-               proto_tree *colors_tree;
+               ti = proto_tree_add_item(tree, hf_quake_CCREP_PLAYER_INFO_name,
+                       tvb, offset, -1, TRUE);
+               offset += proto_item_get_len(ti);
+
+               colors       = tvb_get_letohl(tvb, offset + 0);
+               color_shirt = (colors >> 4) & 0x0f;
+               color_pants = (colors     ) & 0x0f;
 
                colors_item = proto_tree_add_uint(tree,
                        hf_quake_CCREP_PLAYER_INFO_colors,
-                       tvb, offset + 0, 4, colors);
-               if (colors_item) {
-                       colors_tree = proto_item_add_subtree(colors_item,
-                                       ett_quake_control_colors);
-                       proto_tree_add_uint(colors_tree,
-                               hf_quake_CCREP_PLAYER_INFO_colors_shirt,
-                               tvb, offset + 0, 1, color_shirt);
-                       proto_tree_add_uint(colors_tree,
-                               hf_quake_CCREP_PLAYER_INFO_colors_pants,
-                               tvb, offset + 0, 1, color_pants);
-               }
-               proto_tree_add_uint(tree, hf_quake_CCREP_PLAYER_INFO_frags,
-                       tvb, offset + 4, 4, frags);
-               proto_tree_add_uint(tree, hf_quake_CCREP_PLAYER_INFO_connect_time,
-                       tvb, offset + 8, 4, connect_time);
+                       tvb, offset, 4, colors);
+               colors_tree = proto_item_add_subtree(colors_item,
+                               ett_quake_control_colors);
+               proto_tree_add_uint(colors_tree,
+                       hf_quake_CCREP_PLAYER_INFO_colors_shirt,
+                       tvb, offset, 1, color_shirt);
+               proto_tree_add_uint(colors_tree,
+                       hf_quake_CCREP_PLAYER_INFO_colors_pants,
+                       tvb, offset, 1, color_pants);
+               offset += 4;
+               proto_tree_add_item(tree, hf_quake_CCREP_PLAYER_INFO_frags,
+                       tvb, offset, 4, TRUE);
+               offset += 4;
+               proto_tree_add_item(tree, hf_quake_CCREP_PLAYER_INFO_connect_time,
+                       tvb, offset, 4, TRUE);
+               offset += 4;
+
+               proto_tree_add_item(tree, hf_quake_CCREP_PLAYER_INFO_address,
+                       tvb, offset, -1, TRUE);
        }
-       offset += 3*4;
-
-       maxbufsize = MIN(sizeof(address), tvb_length_remaining(tvb, offset));
-       len = tvb_get_stringz(tvb, offset, maxbufsize, address);
-       if (tree) {
-               proto_tree_add_string(tree, hf_quake_CCREP_PLAYER_INFO_address,
-                       tvb, offset, len + 1, address);
-       }
-       offset += len + 1;
 }
 
 
 static void
 dissect_quake_CCREP_RULE_INFO
-(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+(tvbuff_t *tvb, proto_tree *tree)
 {
-       char rule[QUAKE_MAXSTRING];
-       char value[QUAKE_MAXSTRING];
-       gint maxbufsize;
-       gint len;
        gint offset;
+       proto_item *ti;
 
-       if (tvb_length(tvb) == 0) return;
+       if (tvb_reported_length(tvb) == 0) return;
 
        offset = 0;
 
-       maxbufsize = MIN(sizeof(rule), tvb_length_remaining(tvb, offset));
-       len = tvb_get_stringz(tvb, offset, maxbufsize, rule);
        if (tree) {
-               proto_tree_add_string(tree, hf_quake_CCREP_RULE_INFO_rule,
-                       tvb, offset, len + 1, rule);
-       }
-       offset += len + 1;
+               ti = proto_tree_add_item(tree, hf_quake_CCREP_RULE_INFO_rule,
+                       tvb, offset, -1, TRUE);
+               offset += proto_item_get_len(ti);
 
-       maxbufsize = MIN(sizeof(value), tvb_length_remaining(tvb, offset));
-       len = tvb_get_stringz(tvb, offset, maxbufsize, value);
-       if (tree) {
-               proto_tree_add_string(tree, hf_quake_CCREP_RULE_INFO_value,
-                       tvb, offset, len + 1, value);
+               proto_tree_add_item(tree, hf_quake_CCREP_RULE_INFO_value,
+                       tvb, offset, -1, TRUE);
        }
-       offset += len + 1;
 }
 
 
@@ -464,19 +362,19 @@ dissect_quake_control(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        proto_tree      *control_tree = NULL;
        guint           rest_length;
        tvbuff_t        *next_tvb;
-       
+
        command = tvb_get_guint8(tvb, 0);
        direction = (command & 0x80) ? CCREP : CCREQ;
 
-       if (check_col(pinfo->fd, COL_INFO)) {
-               col_add_fstr(pinfo->fd, COL_INFO, "%s %s",
+       if (check_col(pinfo->cinfo, COL_INFO)) {
+               col_add_fstr(pinfo->cinfo, COL_INFO, "%s %s",
                        val_to_str(command,names_control_command, "%u"),
                        val_to_str(direction,names_control_direction,"%u"));
        }
 
        if (tree) {
                control_item = proto_tree_add_text(tree, tvb,
-                               0, tvb_length(tvb), "Control %s: %s",
+                               0, -1, "Control %s: %s",
                                val_to_str(direction, names_control_direction, "%u"),
                                val_to_str(command, names_control_command, "%u"));
                if (control_item)
@@ -491,19 +389,19 @@ dissect_quake_control(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        switch (command) {
                case CCREQ_CONNECT:
                        dissect_quake_CCREQ_CONNECT
-                       (next_tvb, pinfo, control_tree);
+                       (next_tvb, control_tree);
                break;
                case CCREQ_SERVER_INFO:
                        dissect_quake_CCREQ_SERVER_INFO
-                       (next_tvb, pinfo, control_tree);
+                       (next_tvb, control_tree);
                break;
                case CCREQ_PLAYER_INFO:
                        dissect_quake_CCREQ_PLAYER_INFO
-                       (next_tvb, pinfo, control_tree);
+                       (next_tvb, control_tree);
                break;
                case CCREQ_RULE_INFO:
                        dissect_quake_CCREQ_RULE_INFO
-                       (next_tvb, pinfo, control_tree);
+                       (next_tvb, control_tree);
                break;
                case CCREP_ACCEPT:
                        dissect_quake_CCREP_ACCEPT
@@ -511,22 +409,22 @@ dissect_quake_control(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                break;
                case CCREP_REJECT:
                        dissect_quake_CCREP_REJECT
-                       (next_tvb, pinfo, control_tree);
+                       (next_tvb, control_tree);
                break;
                case CCREP_SERVER_INFO:
                        dissect_quake_CCREP_SERVER_INFO
-                       (next_tvb, pinfo, control_tree);
+                       (next_tvb, control_tree);
                break;
                case CCREP_PLAYER_INFO:
                        dissect_quake_CCREP_PLAYER_INFO
-                       (next_tvb, pinfo, control_tree);
+                       (next_tvb, control_tree);
                break;
                case CCREP_RULE_INFO:
                        dissect_quake_CCREP_RULE_INFO
-                       (next_tvb, pinfo, control_tree);
+                       (next_tvb, control_tree);
                break;
                default:
-                       dissect_data(next_tvb, pinfo, control_tree);
+                       call_dissector(data_handle,next_tvb, pinfo, control_tree);
                break;
        }
 }
@@ -543,20 +441,18 @@ dissect_quake(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        guint           rest_length;
        tvbuff_t        *next_tvb;
 
-       CHECK_DISPLAY_AS_DATA(proto_quake, tvb, pinfo, tree);
-
-       if (!tvb_bytes_exist(tvb, 0, 4)) return;
+       if (check_col(pinfo->cinfo, COL_PROTOCOL))
+               col_set_str(pinfo->cinfo, COL_PROTOCOL, "QUAKE");
+       if (check_col(pinfo->cinfo, COL_INFO))
+               col_clear(pinfo->cinfo, COL_INFO);
 
        length = tvb_get_ntohl(tvb, 0);
        flags = length & (~NETFLAG_LENGTH_MASK);
        length &= NETFLAG_LENGTH_MASK;
 
-       if (check_col(pinfo->fd, COL_PROTOCOL))
-               col_add_str(pinfo->fd, COL_PROTOCOL, "QUAKE");
-
        if (tree) {
                quake_item = proto_tree_add_item(tree, proto_quake,
-                               tvb, 0, tvb_length(tvb), FALSE);
+                               tvb, 0, -1, FALSE);
                if (quake_item)
                        quake_tree = proto_item_add_subtree(quake_item, ett_quake);
        }
@@ -603,8 +499,8 @@ dissect_quake(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        }
 
        sequence = tvb_get_ntohl(tvb, 4);
-       if (check_col(pinfo->fd, COL_INFO)) {
-               col_add_fstr(pinfo->fd, COL_INFO, "seq 0x%x", sequence);
+       if (check_col(pinfo->cinfo, COL_INFO)) {
+               col_add_fstr(pinfo->cinfo, COL_INFO, "seq 0x%x", sequence);
        }
        if (quake_tree) {
                proto_tree_add_uint(quake_tree, hf_quake_header_sequence,
@@ -613,134 +509,159 @@ dissect_quake(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
        rest_length = tvb_reported_length(tvb) - 8;
        next_tvb = tvb_new_subset(tvb, 8, rest_length , rest_length);
-       dissect_data(next_tvb, pinfo, quake_tree);
+       call_dissector(data_handle,next_tvb, pinfo, quake_tree);
 }
 
+
 void
-proto_register_quake(void)
+proto_reg_handoff_quake(void)
 {
+       static int Initialized=FALSE;
+       static int ServerPort=0;
+
+       if (Initialized) {
+               dissector_delete("udp.port", ServerPort, quake_handle);
+       } else {
+               Initialized=TRUE;
+       }
 
+       /* set port for future deletes */
+       ServerPort=gbl_quakeServerPort;
+
+       dissector_add("udp.port", gbl_quakeServerPort, quake_handle);
+       data_handle = find_dissector("data");
+}
+
+
+void
+proto_register_quake(void)
+{
   static hf_register_info hf[] = {
     { &hf_quake_header_flags,
       { "Flags", "quake.header.flags",
        FT_UINT16, BASE_HEX, NULL, 0x0,
-       "Flags" }},
+       "Flags", HFILL }},
     { &hf_quake_header_length,
       { "Length", "quake.header.length",
        FT_UINT16, BASE_DEC, NULL, 0x0,
-       "full data length" }},
+       "full data length", HFILL }},
     { &hf_quake_header_sequence,
       { "Sequence", "quake.header.sequence",
        FT_UINT32, BASE_HEX, NULL, 0x0,
-       "Sequence Number" }},
+       "Sequence Number", HFILL }},
     { &hf_quake_control_command,
       { "Command", "quake.control.command",
        FT_UINT8, BASE_HEX, VALS(names_control_command), 0x0,
-       "Control Command" }},
+       "Control Command", HFILL }},
     { &hf_quake_CCREQ_CONNECT_game,
       { "Game", "quake.control.connect.game",
-       FT_STRING, BASE_DEC, NULL, 0x0,
-       "Game Name" }},
+       FT_STRINGZ, BASE_NONE, NULL, 0x0,
+       "Game Name", HFILL }},
     { &hf_quake_CCREQ_CONNECT_version,
       { "Version", "quake.control.connect.version",
        FT_UINT8, BASE_DEC, NULL, 0x0,
-       "Game Protocol Version Number" }},
+       "Game Protocol Version Number", HFILL }},
     { &hf_quake_CCREQ_SERVER_INFO_game,
       { "Game", "quake.control.server_info.game",
-       FT_STRING, BASE_DEC, NULL, 0x0,
-       "Game Name" }},
+       FT_STRINGZ, BASE_NONE, NULL, 0x0,
+       "Game Name", HFILL }},
     { &hf_quake_CCREQ_SERVER_INFO_version,
       { "Version", "quake.control.server_info.version",
        FT_UINT8, BASE_DEC, NULL, 0x0,
-       "Game Protocol Version Number" }},
+       "Game Protocol Version Number", HFILL }},
     { &hf_quake_CCREQ_PLAYER_INFO_player,
       { "Player", "quake.control.player_info.player",
        FT_UINT8, BASE_DEC, NULL, 0x0,
-       "Player" }},
+       "Player", HFILL }},
     { &hf_quake_CCREQ_RULE_INFO_lastrule,
       { "Last Rule", "quake.control.rule_info.lastrule",
-       FT_STRING, BASE_DEC, NULL, 0x0,
-       "Last Rule Name" }},
+       FT_STRINGZ, BASE_NONE, NULL, 0x0,
+       "Last Rule Name", HFILL }},
     { &hf_quake_CCREP_ACCEPT_port,
       { "Port", "quake.control.accept.port",
        FT_UINT32, BASE_DEC, NULL, 0x0,
-       "Game Data Port" }},
+       "Game Data Port", HFILL }},
     { &hf_quake_CCREP_REJECT_reason,
       { "Reason", "quake.control.reject.reason",
-       FT_STRING, BASE_DEC, NULL, 0x0,
-       "Reject Reason" }},
+       FT_STRINGZ, BASE_NONE, NULL, 0x0,
+       "Reject Reason", HFILL }},
     { &hf_quake_CCREP_SERVER_INFO_address,
       { "Address", "quake.control.server_info.address",
-       FT_STRING, BASE_DEC, NULL, 0x0,
-       "Server Address" }},
+       FT_STRINGZ, BASE_NONE, NULL, 0x0,
+       "Server Address", HFILL }},
     { &hf_quake_CCREP_SERVER_INFO_server,
       { "Server", "quake.control.server_info.server",
-       FT_STRING, BASE_DEC, NULL, 0x0,
-       "Server Name" }},
+       FT_STRINGZ, BASE_NONE, NULL, 0x0,
+       "Server Name", HFILL }},
     { &hf_quake_CCREP_SERVER_INFO_map,
       { "Map", "quake.control.server_info.map",
-       FT_STRING, BASE_DEC, NULL, 0x0,
-       "Map Name" }},
+       FT_STRINGZ, BASE_NONE, NULL, 0x0,
+       "Map Name", HFILL }},
     { &hf_quake_CCREP_SERVER_INFO_num_player,
       { "Number of Players", "quake.control.server_info.num_player",
        FT_UINT8, BASE_DEC, NULL, 0x0,
-       "Current Number of Players" }},
+       "Current Number of Players", HFILL }},
     { &hf_quake_CCREP_SERVER_INFO_max_player,
       { "Maximal Number of Players", "quake.control.server_info.max_player",
        FT_UINT8, BASE_DEC, NULL, 0x0,
-       "Maximal Number of Players" }},
+       "Maximal Number of Players", HFILL }},
     { &hf_quake_CCREP_PLAYER_INFO_name,
       { "Name", "quake.control.player_info.name",
-       FT_STRING, BASE_DEC, NULL, 0x0,
-       "Player Name" }},
+       FT_STRINGZ, BASE_NONE, NULL, 0x0,
+       "Player Name", HFILL }},
     { &hf_quake_CCREP_PLAYER_INFO_colors,
       { "Colors", "quake.control.player_info.colors",
        FT_UINT32, BASE_HEX, NULL, 0x0,
-       "Player Colors" }},
+       "Player Colors", HFILL }},
     { &hf_quake_CCREP_PLAYER_INFO_colors_shirt,
       { "Shirt", "quake.control.player_info.colors.shirt",
        FT_UINT8, BASE_DEC, VALS(names_colors), 0x0,
-       "Shirt Color" }},
+       "Shirt Color", HFILL }},
     { &hf_quake_CCREP_PLAYER_INFO_colors_pants,
       { "Pants", "quake.control.player_info.colors.pants",
        FT_UINT8, BASE_DEC, VALS(names_colors), 0x0,
-       "Pants Color" }},
+       "Pants Color", HFILL }},
     { &hf_quake_CCREP_PLAYER_INFO_frags,
       { "Frags", "quake.control.player_info.frags",
        FT_UINT32, BASE_DEC, NULL, 0x0,
-       "Player Frags" }},
+       "Player Frags", HFILL }},
     { &hf_quake_CCREP_PLAYER_INFO_connect_time,
       { "Connect Time", "quake.control.player_info.connect_time",
        FT_UINT32, BASE_DEC, NULL, 0x0,
-       "Player Connect Time" }},
+       "Player Connect Time", HFILL }},
     { &hf_quake_CCREP_PLAYER_INFO_address,
       { "Address", "quake.control.player_info.address",
-       FT_STRING, BASE_DEC, NULL, 0x0,
-       "Player Address" }},
+       FT_STRINGZ, BASE_NONE, NULL, 0x0,
+       "Player Address", HFILL }},
     { &hf_quake_CCREP_RULE_INFO_rule,
       { "Rule", "quake.control.rule_info.rule",
-       FT_STRING, BASE_DEC, NULL, 0x0,
-       "Rule Name" }},
+       FT_STRINGZ, BASE_NONE, NULL, 0x0,
+       "Rule Name", HFILL }},
     { &hf_quake_CCREP_RULE_INFO_value,
       { "Value", "quake.control.rule_info.value",
-       FT_STRING, BASE_DEC, NULL, 0x0,
-       "Rule Value" }},
-  };
-  static gint *ett[] = {
-    &ett_quake,
-    &ett_quake_control,
-    &ett_quake_control_colors,
-    &ett_quake_flags,
+       FT_STRINGZ, BASE_NONE, NULL, 0x0,
+       "Rule Value", HFILL }},
   };
-
-  proto_quake = proto_register_protocol("Quake Network Protocol", "quake");
-  proto_register_field_array(proto_quake, hf, array_length(hf));
-  proto_register_subtree_array(ett, array_length(ett));
-}
-
-
-void
-proto_reg_handoff_quake(void)
-{
-       dissector_add("udp.port", DEFAULTnet_hostport, dissect_quake);
+       static gint *ett[] = {
+               &ett_quake,
+               &ett_quake_control,
+               &ett_quake_control_colors,
+               &ett_quake_flags,
+       };
+       module_t *quake_module;
+
+       proto_quake = proto_register_protocol("Quake Network Protocol",
+                                       "QUAKE", "quake");
+       proto_register_field_array(proto_quake, hf, array_length(hf));
+       proto_register_subtree_array(ett, array_length(ett));
+
+       quake_handle = create_dissector_handle(dissect_quake, proto_quake);
+
+       /* Register a configuration option for port */
+       quake_module = prefs_register_protocol(proto_quake,
+               proto_reg_handoff_quake);
+       prefs_register_uint_preference(quake_module, "udp.port",
+                                       "Quake Server UDP Port",
+                                       "Set the UDP port for the Quake Server",
+                                       10, &gbl_quakeServerPort);
 }