aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-catapult-dct2000.c
diff options
context:
space:
mode:
authorJeff Morriss <jeff.morriss@ulticom.com>2011-01-12 02:25:08 +0000
committerJeff Morriss <jeff.morriss@ulticom.com>2011-01-12 02:25:08 +0000
commit0c4e881911efcf0ddc1278a0ed2bd100d8d06c43 (patch)
treeccf27b3ad65b72ef7318a4bcd3f1d78bb663b019 /epan/dissectors/packet-catapult-dct2000.c
parent1c5d75288c8f5b83659f4f5969ca0ef4a2cde2f9 (diff)
downloadwireshark-0c4e881911efcf0ddc1278a0ed2bd100d8d06c43.tar.gz
wireshark-0c4e881911efcf0ddc1278a0ed2bd100d8d06c43.tar.bz2
wireshark-0c4e881911efcf0ddc1278a0ed2bd100d8d06c43.zip
Introduce, and start using, tvb_get_const_stringz(). This function returns a
pointer to a NULL-terminated string in the TVB. It is no safer than dissectors which call tvb_get_strsize() and then tvb_get_ptr() but it makes it clear that this usage of tvb_get_ptr() is safe. This function is slightly more efficient than tvb_get_ephemeral_stringz()--but only as long as we're not using composite TVBs. svn path=/trunk/; revision=35493
Diffstat (limited to 'epan/dissectors/packet-catapult-dct2000.c')
-rw-r--r--epan/dissectors/packet-catapult-dct2000.c60
1 files changed, 27 insertions, 33 deletions
diff --git a/epan/dissectors/packet-catapult-dct2000.c b/epan/dissectors/packet-catapult-dct2000.c
index b442ed81a8..df20f0e398 100644
--- a/epan/dissectors/packet-catapult-dct2000.c
+++ b/epan/dissectors/packet-catapult-dct2000.c
@@ -206,7 +206,7 @@ static dissector_handle_t pdcp_lte_handle;
void proto_register_catapult_dct2000(void);
-static dissector_handle_t look_for_dissector(char *protocol_name);
+static dissector_handle_t look_for_dissector(const char *protocol_name);
static void parse_outhdr_string(const guchar *outhdr_string);
static void attach_fp_info(packet_info *pinfo, gboolean received,
const char *protocol_name, int variant);
@@ -1082,7 +1082,7 @@ static void dissect_pdcp_lte(tvbuff_t *tvb, gint offset,
/* Look up dissector by protocol name. Fix up known name mis-matches.
This includes exact matches and prefixes (e.g. "diameter_rx" -> "diameter") */
-static dissector_handle_t look_for_dissector(char *protocol_name)
+static dissector_handle_t look_for_dissector(const char *protocol_name)
{
/* Use known aliases and protocol name prefixes */
if (strcmp(protocol_name, "tbcp") == 0) {
@@ -1714,22 +1714,22 @@ dissect_catapult_dct2000(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_item *ti = NULL;
gint offset = 0;
gint context_length;
+ const char *context_name;
guint8 port_number;
- gint protocol_start;
gint protocol_length;
- gint timestamp_start;
gint timestamp_length;
- gint variant_start;
+ const char *timestamp_string;
gint variant_length;
- gint outhdr_start;
+ const char *variant_string;
gint outhdr_length;
+ const char *outhdr_string;
guint8 direction;
tvbuff_t *next_tvb;
int encap;
dissector_handle_t protocol_handle = 0;
dissector_handle_t heur_protocol_handle = 0;
int sub_dissector_result = 0;
- char *protocol_name;
+ const char *protocol_name;
gboolean is_comment;
/* Set Protocol */
@@ -1749,7 +1749,7 @@ dissect_catapult_dct2000(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
/* by the wiretap module */
/* Context Name */
- context_length = tvb_strsize(tvb, offset);
+ context_name = tvb_get_const_stringz(tvb, offset, &context_length);
if (dct2000_tree) {
proto_tree_add_item(dct2000_tree, hf_catapult_dct2000_context, tvb,
offset, context_length, FALSE);
@@ -1765,33 +1765,29 @@ dissect_catapult_dct2000(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
offset++;
/* Timestamp in file */
- timestamp_start = offset;
- timestamp_length = tvb_strsize(tvb, offset);
+ timestamp_string = tvb_get_const_stringz(tvb, offset, &timestamp_length);
if (dct2000_tree) {
/* TODO: this is *very* slow, but float version adds trailing digits when
displayed as a custom column... */
proto_tree_add_double(dct2000_tree, hf_catapult_dct2000_timestamp, tvb,
offset, timestamp_length,
- atof(tvb_get_ptr(tvb, offset, timestamp_length)));
+ atof(timestamp_string));
}
offset += timestamp_length;
/* DCT2000 protocol name */
- protocol_start = offset;
- protocol_length = tvb_strsize(tvb, offset);
+ protocol_name = tvb_get_const_stringz(tvb, offset, &protocol_length);
if (dct2000_tree) {
proto_tree_add_item(dct2000_tree, hf_catapult_dct2000_protocol, tvb,
offset, protocol_length, FALSE);
}
- protocol_name = (char*)tvb_get_ptr(tvb, protocol_start, protocol_length);
is_comment = (strcmp(protocol_name, "comment") == 0);
offset += protocol_length;
/* Protocol Variant */
- variant_start = offset;
- variant_length = tvb_strsize(tvb, offset);
+ variant_string = tvb_get_const_stringz(tvb, offset, &variant_length);
if (!is_comment) {
proto_tree_add_item(dct2000_tree, hf_catapult_dct2000_variant, tvb,
offset, variant_length, FALSE);
@@ -1799,8 +1795,7 @@ dissect_catapult_dct2000(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
offset += variant_length;
/* Outhdr (shown as string) */
- outhdr_start = offset;
- outhdr_length = tvb_strsize(tvb, offset);
+ outhdr_string = tvb_get_const_stringz(tvb, offset, &outhdr_length);
if (!is_comment && (outhdr_length > 1)) {
proto_tree_add_item(dct2000_tree, hf_catapult_dct2000_outhdr, tvb,
offset, outhdr_length, FALSE);
@@ -1825,12 +1820,12 @@ dissect_catapult_dct2000(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
/* Add useful details to protocol tree label */
proto_item_append_text(ti, " context=%s.%u t=%s %c prot=%s (v=%s)",
- tvb_get_ptr(tvb, 0, context_length),
+ context_name,
port_number,
- tvb_get_ptr(tvb, timestamp_start, timestamp_length),
+ timestamp_string,
(direction == 0) ? 'S' : 'R',
protocol_name,
- tvb_get_ptr(tvb, variant_start, variant_length));
+ variant_string);
@@ -1843,26 +1838,25 @@ dissect_catapult_dct2000(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
(strcmp(protocol_name, "fp_r8") == 0) ||
(strcmp(protocol_name, "fpiur_r5") == 0)) {
- parse_outhdr_string(tvb_get_ptr(tvb, outhdr_start, outhdr_length));
- attach_fp_info(pinfo, direction, protocol_name,
- atoi((char*)tvb_get_ptr(tvb, variant_start, variant_length)));
+ parse_outhdr_string(outhdr_string);
+ attach_fp_info(pinfo, direction, protocol_name, atoi(variant_string));
}
/* LTE MAC needs info attached */
else if (strcmp(protocol_name, "mac_r8_lte") == 0) {
- parse_outhdr_string(tvb_get_ptr(tvb, outhdr_start, outhdr_length));
+ parse_outhdr_string(outhdr_string);
attach_mac_lte_info(pinfo);
}
/* LTE RLC needs info attached */
else if (strcmp(protocol_name, "rlc_r8_lte") == 0) {
- parse_outhdr_string(tvb_get_ptr(tvb, outhdr_start, outhdr_length));
+ parse_outhdr_string(outhdr_string);
attach_rlc_lte_info(pinfo);
}
/* LTE PDCP needs info attached */
else if (strcmp(protocol_name, "pdcp_r8_lte") == 0) {
- parse_outhdr_string(tvb_get_ptr(tvb, outhdr_start, outhdr_length));
+ parse_outhdr_string(outhdr_string);
attach_pdcp_lte_info(pinfo);
}
@@ -1922,14 +1916,14 @@ dissect_catapult_dct2000(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
if (direction == 0) {
col_add_fstr(pinfo->cinfo, COL_DEF_SRC,
"%s.%u",
- tvb_get_ptr(tvb, 0, context_length),
+ context_name,
port_number);
}
else
if (direction == 1) {
col_add_fstr(pinfo->cinfo, COL_DEF_DST,
"%s.%u",
- tvb_get_ptr(tvb, 0, context_length),
+ context_name,
port_number);
}
@@ -2336,12 +2330,12 @@ dissect_catapult_dct2000(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
col_add_fstr(pinfo->cinfo, COL_INFO,
"Not dissected (context=%s.%u t=%s %c prot=%s (v=%s))",
- tvb_get_ptr(tvb, 0, context_length),
+ context_name,
port_number,
- tvb_get_ptr(tvb, timestamp_start, timestamp_length),
+ timestamp_string,
(direction == 0) ? 'S' : 'R',
- tvb_get_ptr(tvb, protocol_start, protocol_length),
- tvb_get_ptr(tvb, variant_start, variant_length));
+ protocol_name,
+ variant_string);
}
else {
/* Show number of dissected bytes */