- fix potential buffer overflow problems.
[obnox/wireshark/wip.git] / packet-quake.c
1 /* packet-quake.c
2  * Routines for quake packet dissection
3  *
4  * Uwe Girlich <uwe@planetquake.com>
5  *      http://www.idsoftware.com/q1source/q1source.zip
6  *
7  * $Id: packet-quake.c,v 1.4 2000/08/13 14:08:36 deniel Exp $
8  *
9  * Ethereal - Network traffic analyzer
10  * By Gerald Combs <gerald@zing.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * Copied from packet-tftp.c
14  * 
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  * 
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  * 
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28  */
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
36 #endif
37
38 #ifdef HAVE_NETINET_IN_H
39 # include <netinet/in.h>
40 #endif
41
42 #include <glib.h>
43 #include "packet.h"
44 #include "conversation.h"
45
46 static int proto_quake = -1;
47 static int hf_quake_header_flags = -1; 
48 static int hf_quake_header_length = -1; 
49 static int hf_quake_header_sequence = -1; 
50 static int hf_quake_control_command = -1;
51
52 static int hf_quake_CCREQ_CONNECT_game = -1;
53 static int hf_quake_CCREQ_CONNECT_version = -1;
54 static int hf_quake_CCREQ_SERVER_INFO_game = -1;
55 static int hf_quake_CCREQ_SERVER_INFO_version = -1;
56 static int hf_quake_CCREQ_PLAYER_INFO_player = -1;
57 static int hf_quake_CCREQ_RULE_INFO_lastrule = -1;
58
59 static int hf_quake_CCREP_ACCEPT_port = -1;
60 static int hf_quake_CCREP_REJECT_reason = -1;
61 static int hf_quake_CCREP_SERVER_INFO_address = -1;
62 static int hf_quake_CCREP_SERVER_INFO_server = -1;
63 static int hf_quake_CCREP_SERVER_INFO_map = -1;
64 static int hf_quake_CCREP_SERVER_INFO_num_player = -1;
65 static int hf_quake_CCREP_SERVER_INFO_max_player = -1;
66 static int hf_quake_CCREP_PLAYER_INFO_name = -1;
67 static int hf_quake_CCREP_PLAYER_INFO_colors = -1;
68 static int hf_quake_CCREP_PLAYER_INFO_colors_shirt = -1;
69 static int hf_quake_CCREP_PLAYER_INFO_colors_pants = -1;
70 static int hf_quake_CCREP_PLAYER_INFO_frags = -1;
71 static int hf_quake_CCREP_PLAYER_INFO_connect_time = -1;
72 static int hf_quake_CCREP_PLAYER_INFO_address = -1;
73 static int hf_quake_CCREP_RULE_INFO_rule = -1;
74 static int hf_quake_CCREP_RULE_INFO_value = -1;
75
76
77 static gint ett_quake = -1;
78 static gint ett_quake_control = -1;
79 static gint ett_quake_control_colors = -1;
80 static gint ett_quake_flags = -1;
81
82
83 /* I took these names directly out of the Q1 source. */
84 #define NETFLAG_LENGTH_MASK 0x0000ffff
85 #define NET_HEADERSIZE 8
86 #define DEFAULTnet_hostport 26000
87
88 #define NETFLAG_LENGTH_MASK     0x0000ffff
89 #define NETFLAG_DATA            0x00010000
90 #define NETFLAG_ACK                     0x00020000
91 #define NETFLAG_NAK                     0x00040000
92 #define NETFLAG_EOM                     0x00080000
93 #define NETFLAG_UNRELIABLE      0x00100000
94 #define NETFLAG_CTL                     0x80000000                              
95
96
97 #define CCREQ_CONNECT           0x01
98 #define CCREQ_SERVER_INFO       0x02
99 #define CCREQ_PLAYER_INFO       0x03
100 #define CCREQ_RULE_INFO         0x04
101  
102 #define CCREP_ACCEPT            0x81
103 #define CCREP_REJECT            0x82
104 #define CCREP_SERVER_INFO       0x83
105 #define CCREP_PLAYER_INFO       0x84
106 #define CCREP_RULE_INFO         0x85
107
108 static const value_string names_control_command[] = {
109         {       CCREQ_CONNECT, "connect" },
110         {       CCREQ_SERVER_INFO, "server_info" },
111         {       CCREQ_PLAYER_INFO, "player_info" },
112         {       CCREQ_RULE_INFO, "rule_info" },
113         {       CCREP_ACCEPT, "accept" },
114         {       CCREP_REJECT, "reject" },
115         {       CCREP_SERVER_INFO, "server_info" },
116         {       CCREP_PLAYER_INFO, "player_info" },
117         {       CCREP_RULE_INFO, "rule_info" },
118         { 0, NULL }
119 };
120
121 #define CCREQ 0x00
122 #define CCREP 0x80
123
124 #define QUAKE_MAXSTRING 0x800
125
126 static const value_string names_control_direction[] = {
127         { CCREQ, "Request" },
128         { CCREP, "Reply" },
129         { 0, NULL }
130 };
131
132
133 static const value_string names_colors[] = {
134         {  0, "White" },
135         {  1, "Brown" },
136         {  2, "Lavender" },
137         {  3, "Khaki" },
138         {  4, "Red" },
139         {  5, "Lt Brown" },
140         {  6, "Peach" },
141         {  7, "Lt Peach" },
142         {  8, "Purple" },
143         {  9, "Dk Purple" },
144         { 10, "Tan" },
145         { 11, "Green" },
146         { 12, "Yellow" },
147         { 13, "Blue" },
148         { 14, "Blue" },
149         { 15, "Blue" },
150         {  0, NULL }
151 };
152
153
154 static void dissect_quake(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
155
156
157 static gint
158 tvb_get_stringz(tvbuff_t *tvb, gint offset, gint maxlength, guint8* buffer)
159 {
160         int i;
161         char* zeropos = NULL;
162         gint stringlen = 0;
163
164         if (maxlength == 0) {
165                 buffer[0] = 0;
166                 return 0;
167         }
168
169         tvb_memcpy(tvb, buffer, offset, maxlength);
170         for (i=0 ; i<maxlength ; i++) {
171                 if (buffer[i] == 0) {
172                         stringlen = i;
173                         zeropos = buffer+i;
174                         break;
175                 }
176         }
177         if (zeropos == NULL) {
178                 buffer[maxlength-1] = 0;
179                 return maxlength-1;
180         }
181         return stringlen;
182 }
183
184
185 static void
186 dissect_quake_CCREQ_CONNECT
187 (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
188 {
189         gint maxbufsize;
190         char game[QUAKE_MAXSTRING];
191         guint8 version;
192         gint len;
193
194         maxbufsize = MIN(sizeof(game), tvb_length(tvb));
195         len = tvb_get_stringz(tvb, 0, maxbufsize, game);
196         version = tvb_get_guint8(tvb, len + 1);
197
198         if (tree) {
199                 proto_tree_add_string(tree, hf_quake_CCREQ_CONNECT_game,
200                         tvb, 0, len + 1, game);
201                 proto_tree_add_uint(tree, hf_quake_CCREQ_CONNECT_version,
202                         tvb, len + 1, 1, version);
203         }
204 }
205
206
207 static void
208 dissect_quake_CCREQ_SERVER_INFO
209 (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
210 {
211         gint maxbufsize;
212         char game[QUAKE_MAXSTRING];
213         guint8 version;
214         gint len;
215
216         maxbufsize = MIN(sizeof(game), tvb_length(tvb));
217         len = tvb_get_stringz(tvb, 0, maxbufsize, game);
218         version = tvb_get_guint8(tvb, len + 1);
219
220         if (tree) {
221                 proto_tree_add_string(tree, hf_quake_CCREQ_SERVER_INFO_game,
222                         tvb, 0, len + 1, game);
223                 proto_tree_add_uint(tree, hf_quake_CCREQ_SERVER_INFO_version,
224                         tvb, len + 1, 1, version);
225         }
226 }
227
228
229 static void
230 dissect_quake_CCREQ_PLAYER_INFO
231 (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
232 {
233         guint8 player;
234
235         player = tvb_get_guint8(tvb, 0);
236         if (tree) {
237                  proto_tree_add_uint(tree, hf_quake_CCREQ_PLAYER_INFO_player,
238                         tvb, 0, 1, player);
239         }
240 }
241
242
243 static void
244 dissect_quake_CCREQ_RULE_INFO
245 (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
246 {
247         char rule[QUAKE_MAXSTRING];
248         gint maxbufsize;
249         gint len;
250
251         maxbufsize = MIN(sizeof(rule), tvb_length(tvb));
252         len = tvb_get_stringz(tvb, 0, maxbufsize, rule);
253         if (tree) {
254                 proto_tree_add_string(tree, hf_quake_CCREQ_RULE_INFO_lastrule,
255                         tvb, 0, len + 1, rule);
256         }
257 }
258
259
260 static void
261 dissect_quake_CCREP_ACCEPT
262 (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
263 {
264         guint32 port;
265         conversation_t *c;
266
267         port = tvb_get_letohl(tvb, 0);
268         c = conversation_new( &pi.src, &pi.dst, PT_UDP, port, pi.destport, NULL);
269         if (c) {
270                 c->is_old_dissector = FALSE;
271                 c->dissector.new = dissect_quake;
272         }
273         if (tree) {
274                 proto_tree_add_uint(tree, hf_quake_CCREP_ACCEPT_port,
275                         tvb, 0, 4, port);
276         }
277 }
278
279
280 static void
281 dissect_quake_CCREP_REJECT
282 (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
283 {
284         gint maxbufsize;
285         char reason[QUAKE_MAXSTRING];
286         gint len;
287
288         maxbufsize = MIN(sizeof(reason), tvb_length(tvb));
289         len = tvb_get_stringz(tvb, 0, maxbufsize, reason);
290
291         if (tree) {
292                 proto_tree_add_string(tree, hf_quake_CCREP_REJECT_reason,
293                         tvb, 0, len + 1, reason);
294         }
295 }
296
297
298 static void
299 dissect_quake_CCREP_SERVER_INFO
300 (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
301 {
302         gint offset;
303         gint len;
304         gint maxbufsize;
305         char address[QUAKE_MAXSTRING];
306         char server[QUAKE_MAXSTRING];
307         char map[QUAKE_MAXSTRING];
308
309         guint8 num_player;
310         guint8 max_player;
311         guint8 version;
312
313         offset = 0;
314
315         maxbufsize = MIN(sizeof(address), tvb_length_remaining(tvb, offset));
316         len = tvb_get_stringz(tvb, offset, maxbufsize, address);
317         if (tree) {
318                 proto_tree_add_string(tree, hf_quake_CCREP_SERVER_INFO_address,
319                         tvb, offset, len + 1, address);
320         }
321         offset += len + 1;
322
323         maxbufsize = MIN(sizeof(server), tvb_length_remaining(tvb, offset));
324         len = tvb_get_stringz(tvb, offset, maxbufsize, server);
325         if (tree) {
326                 proto_tree_add_string(tree, hf_quake_CCREP_SERVER_INFO_server,
327                         tvb, offset, len + 1, server);
328         }
329         offset += len + 1;
330         
331         maxbufsize = MIN(sizeof(map), tvb_length_remaining(tvb, offset));
332         len = tvb_get_stringz(tvb, offset, maxbufsize, map);
333         if (tree) {
334                 proto_tree_add_string(tree, hf_quake_CCREP_SERVER_INFO_map,
335                         tvb, offset, len + 1, map);
336         }
337         offset += len + 1;
338
339         num_player = tvb_get_guint8(tvb, offset + 0);
340         max_player = tvb_get_guint8(tvb, offset + 1);
341         version    = tvb_get_guint8(tvb, offset + 2);
342
343         if (tree) {
344                 proto_tree_add_uint(tree, hf_quake_CCREP_SERVER_INFO_num_player,
345                         tvb, offset + 0, 1, num_player);
346                 proto_tree_add_uint(tree, hf_quake_CCREP_SERVER_INFO_max_player,
347                         tvb, offset + 1, 1, max_player);
348                 proto_tree_add_uint(tree, hf_quake_CCREQ_SERVER_INFO_version,
349                         tvb, offset + 2, 1, version);
350         }
351 }
352
353
354 static void
355 dissect_quake_CCREP_PLAYER_INFO
356 (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
357 {
358         gint offset;
359         guint8 player;
360         gint len;
361         gint maxbufsize;
362         char name[QUAKE_MAXSTRING];
363         guint32 colors;
364         guint32 color_shirt;
365         guint32 color_pants;
366         guint32 frags;
367         guint32 connect_time;
368         char address[QUAKE_MAXSTRING];
369
370         offset = 0;
371
372         player = tvb_get_guint8(tvb, offset);
373         if (tree) {
374                 proto_tree_add_uint(tree, hf_quake_CCREQ_PLAYER_INFO_player,
375                         tvb, offset, 1, player);
376         }
377         offset += 1;
378         
379         maxbufsize = MIN(sizeof(name), tvb_length_remaining(tvb, offset));
380         len = tvb_get_stringz(tvb, offset, maxbufsize, name);
381         if (tree) {
382                 proto_tree_add_string(tree, hf_quake_CCREP_PLAYER_INFO_name,
383                         tvb, offset, len + 1, name);
384         }
385         offset += len + 1;
386
387         colors       = tvb_get_letohl(tvb, offset + 0);
388         color_shirt = (colors >> 4) & 0x0f;
389         color_pants = (colors     ) & 0x0f;
390         frags        = tvb_get_letohl(tvb, offset + 4);
391         connect_time = tvb_get_letohl(tvb, offset + 8);
392         if (tree) {
393                 proto_item *colors_item;
394                 proto_tree *colors_tree;
395
396                 colors_item = proto_tree_add_uint(tree,
397                         hf_quake_CCREP_PLAYER_INFO_colors,
398                         tvb, offset + 0, 4, colors);
399                 if (colors_item) {
400                         colors_tree = proto_item_add_subtree(colors_item,
401                                         ett_quake_control_colors);
402                         proto_tree_add_uint(colors_tree,
403                                 hf_quake_CCREP_PLAYER_INFO_colors_shirt,
404                                 tvb, offset + 0, 1, color_shirt);
405                         proto_tree_add_uint(colors_tree,
406                                 hf_quake_CCREP_PLAYER_INFO_colors_pants,
407                                 tvb, offset + 0, 1, color_pants);
408                 }
409                 proto_tree_add_uint(tree, hf_quake_CCREP_PLAYER_INFO_frags,
410                         tvb, offset + 4, 4, frags);
411                 proto_tree_add_uint(tree, hf_quake_CCREP_PLAYER_INFO_connect_time,
412                         tvb, offset + 8, 4, connect_time);
413         }
414         offset += 3*4;
415
416         maxbufsize = MIN(sizeof(address), tvb_length_remaining(tvb, offset));
417         len = tvb_get_stringz(tvb, offset, maxbufsize, address);
418         if (tree) {
419                 proto_tree_add_string(tree, hf_quake_CCREP_PLAYER_INFO_address,
420                         tvb, offset, len + 1, address);
421         }
422         offset += len + 1;
423 }
424
425
426 static void
427 dissect_quake_CCREP_RULE_INFO
428 (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
429 {
430         char rule[QUAKE_MAXSTRING];
431         char value[QUAKE_MAXSTRING];
432         gint maxbufsize;
433         gint len;
434         gint offset;
435
436         if (tvb_length(tvb) == 0) return;
437
438         offset = 0;
439
440         maxbufsize = MIN(sizeof(rule), tvb_length_remaining(tvb, offset));
441         len = tvb_get_stringz(tvb, offset, maxbufsize, rule);
442         if (tree) {
443                 proto_tree_add_string(tree, hf_quake_CCREP_RULE_INFO_rule,
444                         tvb, offset, len + 1, rule);
445         }
446         offset += len + 1;
447
448         maxbufsize = MIN(sizeof(value), tvb_length_remaining(tvb, offset));
449         len = tvb_get_stringz(tvb, offset, maxbufsize, value);
450         if (tree) {
451                 proto_tree_add_string(tree, hf_quake_CCREP_RULE_INFO_value,
452                         tvb, offset, len + 1, value);
453         }
454         offset += len + 1;
455 }
456
457
458 static void
459 dissect_quake_control(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
460 {
461         guint8          command;
462         int             direction;
463         proto_item      *control_item = NULL;
464         proto_tree      *control_tree = NULL;
465         guint           rest_length;
466         tvbuff_t        *next_tvb;
467         
468         command = tvb_get_guint8(tvb, 0);
469         direction = (command & 0x80) ? CCREP : CCREQ;
470
471         if (check_col(pinfo->fd, COL_INFO)) {
472                 col_add_fstr(pinfo->fd, COL_INFO, "%s %s",
473                         val_to_str(command,names_control_command, "%u"),
474                         val_to_str(direction,names_control_direction,"%u"));
475         }
476
477         if (tree) {
478                 control_item = proto_tree_add_text(tree, tvb,
479                                 0, tvb_length(tvb), "Control %s: %s",
480                                 val_to_str(direction, names_control_direction, "%u"),
481                                 val_to_str(command, names_control_command, "%u"));
482                 if (control_item)
483                         control_tree = proto_item_add_subtree(control_item,
484                                                 ett_quake_control);
485                 proto_tree_add_uint(control_tree, hf_quake_control_command,
486                                         tvb, 0, 1, command);
487         }
488
489         rest_length = tvb_reported_length(tvb) - 1;
490         next_tvb = tvb_new_subset(tvb, 1, rest_length , rest_length);
491         switch (command) {
492                 case CCREQ_CONNECT:
493                         dissect_quake_CCREQ_CONNECT
494                         (next_tvb, pinfo, control_tree);
495                 break;
496                 case CCREQ_SERVER_INFO:
497                         dissect_quake_CCREQ_SERVER_INFO
498                         (next_tvb, pinfo, control_tree);
499                 break;
500                 case CCREQ_PLAYER_INFO:
501                         dissect_quake_CCREQ_PLAYER_INFO
502                         (next_tvb, pinfo, control_tree);
503                 break;
504                 case CCREQ_RULE_INFO:
505                         dissect_quake_CCREQ_RULE_INFO
506                         (next_tvb, pinfo, control_tree);
507                 break;
508                 case CCREP_ACCEPT:
509                         dissect_quake_CCREP_ACCEPT
510                         (next_tvb, pinfo, control_tree);
511                 break;
512                 case CCREP_REJECT:
513                         dissect_quake_CCREP_REJECT
514                         (next_tvb, pinfo, control_tree);
515                 break;
516                 case CCREP_SERVER_INFO:
517                         dissect_quake_CCREP_SERVER_INFO
518                         (next_tvb, pinfo, control_tree);
519                 break;
520                 case CCREP_PLAYER_INFO:
521                         dissect_quake_CCREP_PLAYER_INFO
522                         (next_tvb, pinfo, control_tree);
523                 break;
524                 case CCREP_RULE_INFO:
525                         dissect_quake_CCREP_RULE_INFO
526                         (next_tvb, pinfo, control_tree);
527                 break;
528                 default:
529                         dissect_data(next_tvb, pinfo, control_tree);
530                 break;
531         }
532 }
533
534
535 static void
536 dissect_quake(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
537 {
538         proto_tree      *quake_tree = NULL;
539         proto_item      *quake_item = NULL;
540         guint32         length;
541         guint32         flags;
542         guint32         sequence = 0;
543         guint           rest_length;
544         tvbuff_t        *next_tvb;
545
546         CHECK_DISPLAY_AS_DATA(proto_quake, tvb, pinfo, tree);
547
548         if (!tvb_bytes_exist(tvb, 0, 4)) return;
549
550         length = tvb_get_ntohl(tvb, 0);
551         flags = length & (~NETFLAG_LENGTH_MASK);
552         length &= NETFLAG_LENGTH_MASK;
553
554         if (check_col(pinfo->fd, COL_PROTOCOL))
555                 col_add_str(pinfo->fd, COL_PROTOCOL, "QUAKE");
556
557         if (tree) {
558                 quake_item = proto_tree_add_item(tree, proto_quake,
559                                 tvb, 0, tvb_length(tvb), FALSE);
560                 if (quake_item)
561                         quake_tree = proto_item_add_subtree(quake_item, ett_quake);
562         }
563
564         if (quake_tree) {
565                 proto_item* flags_item = NULL;
566                 proto_tree* flags_tree = NULL;
567
568                 flags_item = proto_tree_add_uint(quake_tree, hf_quake_header_flags,
569                         tvb, 0, 2, flags);
570                 if (flags_item) {
571                         flags_tree = proto_item_add_subtree(flags_item, ett_quake_flags);
572                 }
573
574                 if (flags_tree) {
575                         proto_tree_add_text(flags_tree, tvb, 0, 2,
576                                 decode_boolean_bitfield(flags, NETFLAG_DATA, 32,
577                                 "Data","-"));
578                         proto_tree_add_text(flags_tree, tvb, 0, 2,
579                                 decode_boolean_bitfield(flags, NETFLAG_ACK, 32,
580                                 "Acknowledgment","-"));
581                         proto_tree_add_text(flags_tree, tvb, 0, 2,
582                                 decode_boolean_bitfield(flags, NETFLAG_NAK, 32,
583                                 "No Acknowledgment","-"));
584                         proto_tree_add_text(flags_tree, tvb, 0, 2,
585                                 decode_boolean_bitfield(flags, NETFLAG_EOM, 32,
586                                 "End Of Message","-"));
587                         proto_tree_add_text(flags_tree, tvb, 0, 2,
588                                 decode_boolean_bitfield(flags, NETFLAG_UNRELIABLE, 32,
589                                 "Unreliable","-"));
590                         proto_tree_add_text(flags_tree, tvb, 0, 2,
591                                 decode_boolean_bitfield(flags, NETFLAG_CTL, 32,
592                                 "Control","-"));
593                 }
594                 proto_tree_add_uint(quake_tree, hf_quake_header_length,
595                         tvb, 2, 2, length);
596         }
597
598         if (flags == NETFLAG_CTL) {
599                 rest_length = tvb_reported_length(tvb) - 4;
600                 next_tvb = tvb_new_subset(tvb, 4, rest_length , rest_length);
601                 dissect_quake_control(next_tvb, pinfo, quake_tree);
602                 return;
603         }
604
605         sequence = tvb_get_ntohl(tvb, 4);
606         if (check_col(pinfo->fd, COL_INFO)) {
607                 col_add_fstr(pinfo->fd, COL_INFO, "seq 0x%x", sequence);
608         }
609         if (quake_tree) {
610                 proto_tree_add_uint(quake_tree, hf_quake_header_sequence,
611                         tvb, 4, 4, sequence);
612         }
613
614         rest_length = tvb_reported_length(tvb) - 8;
615         next_tvb = tvb_new_subset(tvb, 8, rest_length , rest_length);
616         dissect_data(next_tvb, pinfo, quake_tree);
617 }
618
619 void
620 proto_register_quake(void)
621 {
622
623   static hf_register_info hf[] = {
624     { &hf_quake_header_flags,
625       { "Flags", "quake.header.flags",
626         FT_UINT16, BASE_HEX, NULL, 0x0,
627         "Flags" }},
628     { &hf_quake_header_length,
629       { "Length", "quake.header.length",
630         FT_UINT16, BASE_DEC, NULL, 0x0,
631         "full data length" }},
632     { &hf_quake_header_sequence,
633       { "Sequence", "quake.header.sequence",
634         FT_UINT32, BASE_HEX, NULL, 0x0,
635         "Sequence Number" }},
636     { &hf_quake_control_command,
637       { "Command", "quake.control.command",
638         FT_UINT8, BASE_HEX, VALS(names_control_command), 0x0,
639         "Control Command" }},
640     { &hf_quake_CCREQ_CONNECT_game,
641       { "Game", "quake.control.connect.game",
642         FT_STRING, BASE_DEC, NULL, 0x0,
643         "Game Name" }},
644     { &hf_quake_CCREQ_CONNECT_version,
645       { "Version", "quake.control.connect.version",
646         FT_UINT8, BASE_DEC, NULL, 0x0,
647         "Game Protocol Version Number" }},
648     { &hf_quake_CCREQ_SERVER_INFO_game,
649       { "Game", "quake.control.server_info.game",
650         FT_STRING, BASE_DEC, NULL, 0x0,
651         "Game Name" }},
652     { &hf_quake_CCREQ_SERVER_INFO_version,
653       { "Version", "quake.control.server_info.version",
654         FT_UINT8, BASE_DEC, NULL, 0x0,
655         "Game Protocol Version Number" }},
656     { &hf_quake_CCREQ_PLAYER_INFO_player,
657       { "Player", "quake.control.player_info.player",
658         FT_UINT8, BASE_DEC, NULL, 0x0,
659         "Player" }},
660     { &hf_quake_CCREQ_RULE_INFO_lastrule,
661       { "Last Rule", "quake.control.rule_info.lastrule",
662         FT_STRING, BASE_DEC, NULL, 0x0,
663         "Last Rule Name" }},
664     { &hf_quake_CCREP_ACCEPT_port,
665       { "Port", "quake.control.accept.port",
666         FT_UINT32, BASE_DEC, NULL, 0x0,
667         "Game Data Port" }},
668     { &hf_quake_CCREP_REJECT_reason,
669       { "Reason", "quake.control.reject.reason",
670         FT_STRING, BASE_DEC, NULL, 0x0,
671         "Reject Reason" }},
672     { &hf_quake_CCREP_SERVER_INFO_address,
673       { "Address", "quake.control.server_info.address",
674         FT_STRING, BASE_DEC, NULL, 0x0,
675         "Server Address" }},
676     { &hf_quake_CCREP_SERVER_INFO_server,
677       { "Server", "quake.control.server_info.server",
678         FT_STRING, BASE_DEC, NULL, 0x0,
679         "Server Name" }},
680     { &hf_quake_CCREP_SERVER_INFO_map,
681       { "Map", "quake.control.server_info.map",
682         FT_STRING, BASE_DEC, NULL, 0x0,
683         "Map Name" }},
684     { &hf_quake_CCREP_SERVER_INFO_num_player,
685       { "Number of Players", "quake.control.server_info.num_player",
686         FT_UINT8, BASE_DEC, NULL, 0x0,
687         "Current Number of Players" }},
688     { &hf_quake_CCREP_SERVER_INFO_max_player,
689       { "Maximal Number of Players", "quake.control.server_info.max_player",
690         FT_UINT8, BASE_DEC, NULL, 0x0,
691         "Maximal Number of Players" }},
692     { &hf_quake_CCREP_PLAYER_INFO_name,
693       { "Name", "quake.control.player_info.name",
694         FT_STRING, BASE_DEC, NULL, 0x0,
695         "Player Name" }},
696     { &hf_quake_CCREP_PLAYER_INFO_colors,
697       { "Colors", "quake.control.player_info.colors",
698         FT_UINT32, BASE_HEX, NULL, 0x0,
699         "Player Colors" }},
700     { &hf_quake_CCREP_PLAYER_INFO_colors_shirt,
701       { "Shirt", "quake.control.player_info.colors.shirt",
702         FT_UINT8, BASE_DEC, VALS(names_colors), 0x0,
703         "Shirt Color" }},
704     { &hf_quake_CCREP_PLAYER_INFO_colors_pants,
705       { "Pants", "quake.control.player_info.colors.pants",
706         FT_UINT8, BASE_DEC, VALS(names_colors), 0x0,
707         "Pants Color" }},
708     { &hf_quake_CCREP_PLAYER_INFO_frags,
709       { "Frags", "quake.control.player_info.frags",
710         FT_UINT32, BASE_DEC, NULL, 0x0,
711         "Player Frags" }},
712     { &hf_quake_CCREP_PLAYER_INFO_connect_time,
713       { "Connect Time", "quake.control.player_info.connect_time",
714         FT_UINT32, BASE_DEC, NULL, 0x0,
715         "Player Connect Time" }},
716     { &hf_quake_CCREP_PLAYER_INFO_address,
717       { "Address", "quake.control.player_info.address",
718         FT_STRING, BASE_DEC, NULL, 0x0,
719         "Player Address" }},
720     { &hf_quake_CCREP_RULE_INFO_rule,
721       { "Rule", "quake.control.rule_info.rule",
722         FT_STRING, BASE_DEC, NULL, 0x0,
723         "Rule Name" }},
724     { &hf_quake_CCREP_RULE_INFO_value,
725       { "Value", "quake.control.rule_info.value",
726         FT_STRING, BASE_DEC, NULL, 0x0,
727         "Rule Value" }},
728   };
729   static gint *ett[] = {
730     &ett_quake,
731     &ett_quake_control,
732     &ett_quake_control_colors,
733     &ett_quake_flags,
734   };
735
736   proto_quake = proto_register_protocol("Quake Network Protocol", "quake");
737   proto_register_field_array(proto_quake, hf, array_length(hf));
738   proto_register_subtree_array(ett, array_length(ett));
739 }
740
741
742 void
743 proto_reg_handoff_quake(void)
744 {
745         dissector_add("udp.port", DEFAULTnet_hostport, dissect_quake);
746 }