quakeworld: use ws_strtou function.

Change-Id: I2d4d97229ee4fee37b26a2dabab9d373a0401e13
Reviewed-on: https://code.wireshark.org/review/18149
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Dario Lombardo <lomato@gmail.com>
This commit is contained in:
Dario Lombardo 2016-10-11 13:58:27 +02:00
parent 5546400b55
commit 913225b5d4
1 changed files with 31 additions and 8 deletions

View File

@ -31,6 +31,9 @@
#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/prefs-int.h>
#include <epan/expert.h>
#include <wsutil/strtoi.h>
void proto_register_quakeworld(void);
void proto_reg_handoff_quakeworld(void);
@ -72,6 +75,8 @@ static gint ett_quakeworld_game_seq2 = -1;
static gint ett_quakeworld_game_clc = -1;
static gint ett_quakeworld_game_svc = -1;
static expert_field ei_quakeworld_connectionless_command_invalid = EI_INIT;
/*
helper functions, they may ave to go somewhere else
they are mostly copied without change from
@ -345,6 +350,7 @@ dissect_quakeworld_ConnectionlessPacket(tvbuff_t *tvb, packet_info *pinfo,
{
proto_tree *cl_tree;
proto_tree *text_tree = NULL;
proto_item *pi;
guint8 *text;
int len;
int offset;
@ -390,16 +396,19 @@ dissect_quakeworld_ConnectionlessPacket(tvbuff_t *tvb, packet_info *pinfo,
command = "Log";
command_len = 3;
} else if (strcmp(c,"connect") == 0) {
int version;
int qport;
int challenge;
guint32 version = 0;
guint16 qport = 0;
guint32 challenge = 0;
gboolean version_valid = TRUE;
gboolean qport_valid = TRUE;
gboolean challenge_valid = TRUE;
const char *infostring;
proto_tree *argument_tree = NULL;
command = "Connect";
command_len = Cmd_Argv_length(0);
if (text_tree) {
proto_item *argument_item;
proto_tree_add_string(text_tree, hf_quakeworld_connectionless_command,
pi = proto_tree_add_string(text_tree, hf_quakeworld_connectionless_command,
tvb, offset, command_len, command);
argument_item = proto_tree_add_string(text_tree,
hf_quakeworld_connectionless_arguments,
@ -409,10 +418,14 @@ dissect_quakeworld_ConnectionlessPacket(tvbuff_t *tvb, packet_info *pinfo,
ett_quakeworld_connectionless_arguments);
command_finished=TRUE;
}
version = atoi(Cmd_Argv(1));
qport = atoi(Cmd_Argv(2));
challenge = atoi(Cmd_Argv(3));
version_valid = ws_strtou32(Cmd_Argv(1), NULL, &version);
qport_valid = ws_strtou16(Cmd_Argv(2), NULL, &qport);
challenge_valid = ws_strtou32(Cmd_Argv(3), NULL, &challenge);
infostring = Cmd_Argv(4);
if (text_tree && (!version_valid || !qport_valid || !challenge_valid))
expert_add_info(pinfo, pi, &ei_quakeworld_connectionless_command_invalid);
if (argument_tree) {
proto_item *info_item;
proto_tree *info_tree;
@ -518,7 +531,7 @@ dissect_quakeworld_ConnectionlessPacket(tvbuff_t *tvb, packet_info *pinfo,
} else if (text[0] == S2C_CHALLENGE) {
command = "Challenge";
command_len = 1;
/* string, atoi */
/* string, conversion */
} else {
command = "Unknown";
command_len = len - 1;
@ -699,6 +712,8 @@ apply_quakeworld_prefs(void)
void
proto_register_quakeworld(void)
{
expert_module_t* expert_quakeworld;
static hf_register_info hf[] = {
{ &hf_quakeworld_c2s,
{ "Client to Server", "quakeworld.c2s",
@ -803,12 +818,20 @@ proto_register_quakeworld(void)
&ett_quakeworld_game_svc
};
static ei_register_info ei[] = {
{ &ei_quakeworld_connectionless_command_invalid, { "quakeworld.connectionless.command.invalid",
PI_MALFORMED, PI_ERROR, "Invalid connectionless command", EXPFILL }}
};
proto_quakeworld = proto_register_protocol("QuakeWorld Network Protocol", "QUAKEWORLD", "quakeworld");
proto_register_field_array(proto_quakeworld, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
/* Register a configuration option for port */
prefs_register_protocol(proto_quakeworld, apply_quakeworld_prefs);
expert_quakeworld = expert_register_protocol(proto_quakeworld);
expert_register_field_array(expert_quakeworld, ei, array_length(ei));
}