aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-dcc.c
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2014-09-26 19:28:01 -0400
committerMichael Mann <mmann78@netscape.net>2014-09-27 15:44:53 +0000
commit6fad7d19e73be54c5426a6a5e97245c782e53b6c (patch)
tree41436d398cc6a6b73fc47050f0478ab7bb461173 /epan/dissectors/packet-dcc.c
parent65437a7c526c0f11d164ecd32b99c13a4f9ec5e6 (diff)
Eliminate proto_tree_add_text from some dissectors.
Some other related cleanup. Change-Id: I45f54032aa8318858f4ee784945b6f2ed163b6ea Reviewed-on: https://code.wireshark.org/review/4328 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/dissectors/packet-dcc.c')
-rw-r--r--epan/dissectors/packet-dcc.c108
1 files changed, 76 insertions, 32 deletions
diff --git a/epan/dissectors/packet-dcc.c b/epan/dissectors/packet-dcc.c
index ca6a7f8212..866092ca62 100644
--- a/epan/dissectors/packet-dcc.c
+++ b/epan/dissectors/packet-dcc.c
@@ -29,6 +29,7 @@
#include <glib.h>
#include <epan/packet.h>
+#include <epan/expert.h>
#include <packet-dcc.h>
@@ -57,6 +58,7 @@ static int hf_dcc_ck_sum = -1;
static int hf_dcc_date = -1;
static int hf_dcc_target = -1;
+static int hf_dcc_response_text = -1;
static int hf_dcc_adminop = -1;
static int hf_dcc_adminval = -1;
@@ -70,31 +72,39 @@ static int hf_dcc_trace_query = -1;
static int hf_dcc_trace_ridc = -1;
static int hf_dcc_trace_flood = -1;
+static int hf_dcc_addr = -1;
+static int hf_dcc_id = -1;
+static int hf_dcc_last_used = -1;
+static int hf_dcc_requests = -1;
+static int hf_dcc_pad = -1;
+static int hf_dcc_unused = -1;
+
static gint ett_dcc = -1;
static gint ett_dcc_opnums = -1;
static gint ett_dcc_op = -1;
static gint ett_dcc_ck = -1;
static gint ett_dcc_trace = -1;
+static expert_field ei_dcc_len = EI_INIT;
+
/* Utility macros */
#define D_SIGNATURE() \
proto_tree_add_item(dcc_optree, hf_dcc_signature, tvb, \
offset, (int)sizeof(DCC_SIGNATURE), ENC_NA); \
offset += (int)sizeof(DCC_SIGNATURE);
-#define D_LABEL(label,len) \
- proto_tree_add_text(dcc_optree, tvb, offset, len, label); \
+#define D_LABEL(hf_label, len, encoding) \
+ proto_tree_add_item(dcc_optree, hf_label, tvb, offset, len, encoding); \
offset += len;
-#define D_TEXT(label, endpad) { \
+#define D_TEXT(hf_label, endpad) { \
int next_offset,left; \
while (tvb_offset_exists(tvb, offset+endpad)) { \
left = tvb_length_remaining(tvb,offset) - endpad; \
tvb_find_line_end(tvb, offset, left, &next_offset, \
FALSE); \
- proto_tree_add_text(dcc_optree, tvb, offset, \
- next_offset - offset, "%s: %s", \
- label, tvb_format_text(tvb, offset, next_offset - offset)); \
+ proto_tree_add_item(dcc_optree, hf_label, tvb, offset, \
+ next_offset - offset, ENC_ASCII|ENC_NA); \
offset = next_offset; \
} \
}
@@ -201,8 +211,9 @@ static const value_string dcc_floodop_vals[] = {
static gboolean
dissect_dcc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
- proto_tree *dcc_tree, *dcc_optree, *dcc_opnumtree, *ti;
+ proto_tree *dcc_tree, *dcc_optree, *dcc_opnumtree, *ti;
proto_tree *dcc_tracetree;
+ proto_item *len_item;
int offset = 0;
int client_is_le = 0;
int op = 0;
@@ -214,7 +225,7 @@ dissect_dcc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
}
/* get at least a full packet structure */
- if ( tvb_length(tvb) < sizeof(DCC_HDR) ) {
+ if ( tvb_reported_length(tvb) < sizeof(DCC_HDR) ) {
/* Doesn't have enough bytes to contain packet header. */
return FALSE;
}
@@ -228,23 +239,22 @@ dissect_dcc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
"%s: %s",
is_response ? "Response" : "Request",
val_to_str(tvb_get_guint8(tvb, offset+3),
- dcc_op_vals, "Unknown Op: %u")
- );
+ dcc_op_vals, "Unknown Op: %u"));
- if (tree) {
- ti = proto_tree_add_item(tree, proto_dcc, tvb, offset, -1,
- ENC_NA);
- dcc_tree = proto_item_add_subtree(ti, ett_dcc);
+ ti = proto_tree_add_item(tree, proto_dcc, tvb, offset, -1,
+ ENC_NA);
+ dcc_tree = proto_item_add_subtree(ti, ett_dcc);
- proto_tree_add_item(dcc_tree, hf_dcc_len, tvb,
- offset, 2, ENC_BIG_ENDIAN);
+ len_item = proto_tree_add_item(dcc_tree, hf_dcc_len, tvb,
+ offset, 2, ENC_BIG_ENDIAN);
- if ( tvb_length(tvb) < tvb_get_ntohs(tvb, offset)) {
- /* Doesn't have number of bytes that header claims. */
- proto_tree_add_text(dcc_tree, tvb, offset, 2, "Error - packet is shorter than header claims!");
- }
- offset += 2;
+ if ( tvb_reported_length(tvb) < tvb_get_ntohs(tvb, offset)) {
+ /* Doesn't have number of bytes that header claims. */
+ expert_add_info(pinfo, len_item, &ei_dcc_len);
+ }
+ offset += 2;
+ if (tree) {
proto_tree_add_item(dcc_tree, hf_dcc_pkt_vers, tvb,
offset, 1, ENC_BIG_ENDIAN);
offset += 1;
@@ -321,14 +331,14 @@ dissect_dcc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
(int)sizeof(DCC_SIGNATURE);
if ( left_local == sizeof(DCC_ADMN_RESP_CLIENTS) )
{
- D_LABEL("Addr", 16);
- D_LABEL("Id", (int)sizeof(DCC_CLNT_ID));
- D_LABEL("Last Used", 4);
- D_LABEL("Requests", 4);
+ D_LABEL(hf_dcc_addr, 16, ENC_NA);
+ D_LABEL(hf_dcc_id, (int)sizeof(DCC_CLNT_ID), ENC_BIG_ENDIAN);
+ D_LABEL(hf_dcc_last_used, 4, ENC_BIG_ENDIAN);
+ D_LABEL(hf_dcc_requests, 4, ENC_BIG_ENDIAN);
}
else
{
- D_TEXT("Response Text", (int)sizeof(DCC_SIGNATURE));
+ D_TEXT(hf_dcc_response_text, (int)sizeof(DCC_SIGNATURE));
}
D_SIGNATURE();
}
@@ -374,7 +384,7 @@ dissect_dcc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
offset += 4;
offset += 1; /* admin op we did in reverse order */
- D_LABEL("Pad", 3);
+ D_LABEL(hf_dcc_pad, 3, ENC_NA);
D_SIGNATURE();
}
break;
@@ -384,7 +394,7 @@ dissect_dcc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
offset, 1, ENC_BIG_ENDIAN);
offset += 1;
- D_LABEL("Unused", 1);
+ D_LABEL(hf_dcc_unused, 1, ENC_NA);
proto_tree_add_item(dcc_optree, hf_dcc_qdelay_ms, tvb,
offset, 2, ENC_BIG_ENDIAN);
@@ -474,6 +484,10 @@ proto_register_dcc(void)
"Target", "dcc.target", FT_UINT32, BASE_HEX,
VALS(dcc_target_vals), 0, NULL, HFILL }},
+ { &hf_dcc_response_text, {
+ "Response Text", "dcc.response_text", FT_BYTES, BASE_NONE,
+ NULL, 0, NULL, HFILL }},
+
{ &hf_dcc_date, {
"Date", "dcc.date", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL,
NULL, 0, NULL, HFILL }},
@@ -522,7 +536,31 @@ proto_register_dcc(void)
"Flood Control Operation", "dcc.floodop", FT_UINT32, BASE_DEC,
VALS(dcc_floodop_vals), 0, NULL, HFILL }},
- };
+ { &hf_dcc_id, {
+ "Id", "dcc.id", FT_UINT32, BASE_DEC,
+ NULL, 0, NULL, HFILL }},
+
+ { &hf_dcc_last_used, {
+ "Last Used", "dcc.last_used", FT_UINT32, BASE_DEC,
+ NULL, 0, NULL, HFILL }},
+
+ { &hf_dcc_requests, {
+ "Requests", "dcc.requests", FT_UINT32, BASE_DEC,
+ NULL, 0, NULL, HFILL }},
+
+ { &hf_dcc_addr, {
+ "Addr", "dcc.addr", FT_BYTES, BASE_NONE,
+ NULL, 0, NULL, HFILL }},
+
+ { &hf_dcc_pad, {
+ "Pad", "dcc.pad", FT_BYTES, BASE_NONE,
+ NULL, 0, NULL, HFILL }},
+
+ { &hf_dcc_unused, {
+ "Unused", "dcc.unused", FT_BYTES, BASE_NONE,
+ NULL, 0, NULL, HFILL }},
+ };
+
static gint *ett[] = {
&ett_dcc,
&ett_dcc_op,
@@ -531,12 +569,18 @@ proto_register_dcc(void)
&ett_dcc_trace,
};
- proto_dcc = proto_register_protocol("Distributed Checksum Clearinghouse protocol",
- "DCC", "dcc");
+ static ei_register_info ei[] = {
+ { &ei_dcc_len, { "dcc.len.short", PI_MALFORMED, PI_ERROR, "Error - packet is shorter than header claims!", EXPFILL }},
+ };
+
+ expert_module_t* expert_dcc;
- proto_register_field_array(proto_dcc, hf, array_length(hf));
+ proto_dcc = proto_register_protocol("Distributed Checksum Clearinghouse protocol", "DCC", "dcc");
+ proto_register_field_array(proto_dcc, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
+ expert_dcc = expert_register_protocol(proto_dcc);
+ expert_register_field_array(expert_dcc, ei, array_length(ei));
}
void