aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-udt.c
diff options
context:
space:
mode:
authorBill Meier <wmeier@newsguy.com>2014-03-17 11:58:22 -0400
committerBill Meier <wmeier@newsguy.com>2014-03-17 16:45:58 +0000
commit386ebf50fef43a75d70d4c0085948c13cdd4e930 (patch)
tree04ea1f42f41afe9bd12120311817211c1a922e32 /epan/dissectors/packet-udt.c
parentd426802162a3b77898a75802167c0b6e898cf087 (diff)
Heuristics length check must use captured_length; Do other misc changes:
- Use tvb_reported_length() iso tvb_length() in various places; - Add some 'if(tree) {...}'; - Remove an unneeded length-check; - Use a consistent formatting style for hf[]array entries; - Do some minor whitespace changes; - Add editor modelines. Change-Id: Iac0a74142c5a5944e69fc911e54b0fbdfd1f5bab Reviewed-on: https://code.wireshark.org/review/717 Reviewed-by: Bill Meier <wmeier@newsguy.com> Tested-by: Bill Meier <wmeier@newsguy.com>
Diffstat (limited to 'epan/dissectors/packet-udt.c')
-rw-r--r--epan/dissectors/packet-udt.c349
1 files changed, 185 insertions, 164 deletions
diff --git a/epan/dissectors/packet-udt.c b/epan/dissectors/packet-udt.c
index 5c95f5556c..8f0dbd290b 100644
--- a/epan/dissectors/packet-udt.c
+++ b/epan/dissectors/packet-udt.c
@@ -55,21 +55,21 @@ void proto_reg_handoff_udt(void);
static const value_string udt_packet_types[] = {
{UDT_PACKET_TYPE_HANDSHAKE, "handshake"},
{UDT_PACKET_TYPE_KEEPALIVE, "keepalive"},
- {UDT_PACKET_TYPE_ACK, "ack"},
- {UDT_PACKET_TYPE_NAK, "nak"},
- {UDT_PACKET_TYPE_SHUTDOWN, "shutdown"},
- {UDT_PACKET_TYPE_ACK2, "ack2"},
+ {UDT_PACKET_TYPE_ACK, "ack"},
+ {UDT_PACKET_TYPE_NAK, "nak"},
+ {UDT_PACKET_TYPE_SHUTDOWN, "shutdown"},
+ {UDT_PACKET_TYPE_ACK2, "ack2"},
{0, NULL},
};
static const value_string udt_handshake_types[] = {
{UDT_HANDSHAKE_TYPE_STREAM, "STREAM"},
- {UDT_HANDSHAKE_TYPE_DGRAM, "DGRAM"},
+ {UDT_HANDSHAKE_TYPE_DGRAM, "DGRAM"},
{0, NULL},
};
static const value_string udt_types[] = {
- {UDT_TYPE_DATA, "DATA"},
+ {UDT_TYPE_DATA, "DATA"},
{UDT_TYPE_CONTROL, "CONTROL"},
{0, NULL},
};
@@ -110,17 +110,13 @@ static dissector_handle_t udt_handle;
static dissector_handle_t data_handle;
static int
-dissect_udt(tvbuff_t * tvb, packet_info * pinfo, proto_tree * parent_tree,
+dissect_udt(tvbuff_t *tvb, packet_info* pinfo, proto_tree *parent_tree,
void *data _U_)
{
proto_tree *tree;
proto_item *udt_item;
- int is_control, type;
- guint i;
-
- /* Ensure we have enough data */
- if (tvb_length(tvb) < 16)
- return 0;
+ int is_control, type;
+ guint i;
col_set_str(pinfo->cinfo, COL_PROTOCOL, "UDT");
col_clear(pinfo->cinfo, COL_INFO);
@@ -146,74 +142,80 @@ dissect_udt(tvbuff_t * tvb, packet_info * pinfo, proto_tree * parent_tree,
proto_tree_add_item(tree, hf_udt_iscontrol, tvb, 0, 4, ENC_BIG_ENDIAN);
if (is_control) {
- proto_tree_add_item(tree, hf_udt_type, tvb, 0, 2,
- ENC_BIG_ENDIAN);
- switch (type) {
- case UDT_PACKET_TYPE_ACK:
- proto_tree_add_item(tree, hf_udt_ackno, tvb, 4, 4,
+ if (tree) {
+ proto_tree_add_item(tree, hf_udt_type, tvb, 0, 2,
ENC_BIG_ENDIAN);
- break;
- case UDT_PACKET_TYPE_ACK2:
- proto_tree_add_item(tree, hf_udt_ackno, tvb, 4, 4,
+ switch (type) {
+ case UDT_PACKET_TYPE_ACK:
+ proto_tree_add_item(tree, hf_udt_ackno, tvb, 4, 4,
+ ENC_BIG_ENDIAN);
+ break;
+ case UDT_PACKET_TYPE_ACK2:
+ proto_tree_add_item(tree, hf_udt_ackno, tvb, 4, 4,
+ ENC_BIG_ENDIAN);
+ break;
+ default:
+ proto_tree_add_item(tree, hf_udt_addinfo, tvb, 4, 4,
+ ENC_BIG_ENDIAN);
+ }
+ proto_tree_add_item(tree, hf_udt_timestamp, tvb, 8, 4,
ENC_BIG_ENDIAN);
- break;
- default:
- proto_tree_add_item(tree, hf_udt_addinfo, tvb, 4, 4,
+ proto_tree_add_item(tree, hf_udt_id, tvb, 12, 4,
ENC_BIG_ENDIAN);
}
- proto_tree_add_item(tree, hf_udt_timestamp, tvb, 8, 4,
- ENC_BIG_ENDIAN);
- proto_tree_add_item(tree, hf_udt_id, tvb, 12, 4,
- ENC_BIG_ENDIAN);
switch (type) {
case UDT_PACKET_TYPE_HANDSHAKE:
- proto_tree_add_item(tree, hf_udt_handshake_version, tvb,
- 16, 4, ENC_BIG_ENDIAN);
- proto_tree_add_item(tree, hf_udt_handshake_type, tvb,
- 20, 4, ENC_BIG_ENDIAN);
- proto_tree_add_item(tree, hf_udt_handshake_isn, tvb, 24,
- 4, ENC_BIG_ENDIAN);
- proto_tree_add_item(tree, hf_udt_handshake_mtu, tvb, 28,
- 4, ENC_BIG_ENDIAN);
- proto_tree_add_item(tree, hf_udt_handshake_flow_window,
- tvb, 32, 4, ENC_BIG_ENDIAN);
- proto_tree_add_item(tree, hf_udt_handshake_reqtype, tvb,
- 36, 4, ENC_BIG_ENDIAN);
- proto_tree_add_item(tree, hf_udt_handshake_id, tvb, 40,
- 4, ENC_BIG_ENDIAN);
- proto_tree_add_item(tree, hf_udt_handshake_cookie, tvb,
- 44, 4, ENC_BIG_ENDIAN);
- proto_tree_add_item(tree, hf_udt_handshake_peerip, tvb,
- 48, 16, ENC_NA);
- proto_item_set_len(udt_item, 64);
+ if (tree) {
+ proto_tree_add_item(tree, hf_udt_handshake_version, tvb,
+ 16, 4, ENC_BIG_ENDIAN);
+ proto_tree_add_item(tree, hf_udt_handshake_type, tvb,
+ 20, 4, ENC_BIG_ENDIAN);
+ proto_tree_add_item(tree, hf_udt_handshake_isn, tvb,
+ 24, 4, ENC_BIG_ENDIAN);
+ proto_tree_add_item(tree, hf_udt_handshake_mtu, tvb,
+ 28, 4, ENC_BIG_ENDIAN);
+ proto_tree_add_item(tree, hf_udt_handshake_flow_window, tvb,
+ 32, 4, ENC_BIG_ENDIAN);
+ proto_tree_add_item(tree, hf_udt_handshake_reqtype, tvb,
+ 36, 4, ENC_BIG_ENDIAN);
+ proto_tree_add_item(tree, hf_udt_handshake_id, tvb,
+ 40, 4, ENC_BIG_ENDIAN);
+ proto_tree_add_item(tree, hf_udt_handshake_cookie, tvb,
+ 44, 4, ENC_BIG_ENDIAN);
+ proto_tree_add_item(tree, hf_udt_handshake_peerip, tvb,
+ 48, 16, ENC_NA);
+ proto_item_set_len(udt_item, 64);
+ }
break;
case UDT_PACKET_TYPE_ACK:
- proto_tree_add_item(tree, hf_udt_ack_seqno, tvb, 16, 4,
- ENC_BIG_ENDIAN);
- proto_tree_add_item(tree, hf_udt_rtt, tvb, 20, 4,
- ENC_BIG_ENDIAN);
- proto_tree_add_item(tree, hf_udt_rttvar, tvb, 24, 4,
- ENC_BIG_ENDIAN);
- proto_tree_add_item(tree, hf_udt_bufavail, tvb, 28, 4,
- ENC_BIG_ENDIAN);
- /* if not a light ack, decode the rate and link capacity */
- if (tvb_length(tvb) == 40) {
- proto_tree_add_item(tree, hf_udt_rate, tvb, 32,
- 4, ENC_BIG_ENDIAN);
- proto_tree_add_item(tree, hf_udt_linkcap, tvb,
- 36, 4, ENC_BIG_ENDIAN);
- proto_item_set_len(udt_item, 40);
- }
- else
- {
- proto_item_set_len(udt_item, 32);
+ if (tree) {
+ proto_tree_add_item(tree, hf_udt_ack_seqno, tvb, 16, 4,
+ ENC_BIG_ENDIAN);
+ proto_tree_add_item(tree, hf_udt_rtt, tvb, 20, 4,
+ ENC_BIG_ENDIAN);
+ proto_tree_add_item(tree, hf_udt_rttvar, tvb, 24, 4,
+ ENC_BIG_ENDIAN);
+ proto_tree_add_item(tree, hf_udt_bufavail, tvb, 28, 4,
+ ENC_BIG_ENDIAN);
+ /* if not a light ack, decode the rate and link capacity */
+ if (tvb_reported_length(tvb) == 40) {
+ proto_tree_add_item(tree, hf_udt_rate, tvb,
+ 32, 4, ENC_BIG_ENDIAN);
+ proto_tree_add_item(tree, hf_udt_linkcap, tvb,
+ 36, 4, ENC_BIG_ENDIAN);
+ proto_item_set_len(udt_item, 40);
+ }
+ else
+ {
+ proto_item_set_len(udt_item, 32);
+ }
}
break;
case UDT_PACKET_TYPE_NAK:
- for (i = 16; i < tvb_length(tvb); i = i + 4) {
+ for (i = 16; i < tvb_reported_length(tvb); i = i + 4) {
guint32 start, finish;
- int is_range;
+ int is_range;
is_range = tvb_get_ntohl(tvb, i) & 0x80000000;
start = tvb_get_ntohl(tvb, i) & 0x7fffffff;
@@ -232,33 +234,35 @@ dissect_udt(tvbuff_t * tvb, packet_info * pinfo, proto_tree * parent_tree,
}
}
- proto_item_set_len(udt_item, tvb_length(tvb));
+ proto_item_set_len(udt_item, tvb_reported_length(tvb));
break;
}
} else {
/* otherwise, a data packet */
tvbuff_t *next_tvb;
- proto_tree_add_item(tree, hf_udt_seqno, tvb, 0, 4,
- ENC_BIG_ENDIAN);
- proto_tree_add_item(tree, hf_udt_msgno_first, tvb, 4, 4,
- ENC_BIG_ENDIAN);
- proto_tree_add_item(tree, hf_udt_msgno_last, tvb, 4, 4,
- ENC_BIG_ENDIAN);
- proto_tree_add_item(tree, hf_udt_msgno_inorder, tvb, 4, 4,
- ENC_BIG_ENDIAN);
- proto_tree_add_item(tree, hf_udt_msgno, tvb, 4, 4,
- ENC_BIG_ENDIAN);
- proto_tree_add_item(tree, hf_udt_timestamp, tvb, 8, 4,
- ENC_BIG_ENDIAN);
- proto_tree_add_item(tree, hf_udt_id, tvb, 12, 4,
- ENC_BIG_ENDIAN);
+ if (tree) {
+ proto_tree_add_item(tree, hf_udt_seqno, tvb, 0, 4,
+ ENC_BIG_ENDIAN);
+ proto_tree_add_item(tree, hf_udt_msgno_first, tvb, 4, 4,
+ ENC_BIG_ENDIAN);
+ proto_tree_add_item(tree, hf_udt_msgno_last, tvb, 4, 4,
+ ENC_BIG_ENDIAN);
+ proto_tree_add_item(tree, hf_udt_msgno_inorder, tvb, 4, 4,
+ ENC_BIG_ENDIAN);
+ proto_tree_add_item(tree, hf_udt_msgno, tvb, 4, 4,
+ ENC_BIG_ENDIAN);
+ proto_tree_add_item(tree, hf_udt_timestamp, tvb, 8, 4,
+ ENC_BIG_ENDIAN);
+ proto_tree_add_item(tree, hf_udt_id, tvb, 12, 4,
+ ENC_BIG_ENDIAN);
+ }
next_tvb = tvb_new_subset_remaining(tvb, 16);
- call_dissector(data_handle, next_tvb, pinfo, parent_tree);
+ call_dissector(data_handle, next_tvb, pinfo, tree);
}
- return tvb_length(tvb);
+ return tvb_reported_length(tvb);
}
static gboolean
@@ -266,9 +270,9 @@ dissect_udt_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data
{
conversation_t *conv;
- /* Must have at least 20 bytes */
- if (tvb_reported_length(tvb) < 20)
- return 0;
+ /* Must have at least 24 captured bytes for heuristic check */
+ if (tvb_captured_length(tvb) < 24)
+ return FALSE;
/* detect handshake control packet */
if (tvb_get_ntohl(tvb, 0) != (0x80000000 | UDT_PACKET_TYPE_HANDSHAKE))
@@ -296,132 +300,135 @@ void proto_register_udt(void)
static hf_register_info hf[] = {
{&hf_udt_iscontrol, {
- "Type", "udt.iscontrol", FT_UINT32,
- BASE_DEC,
- VALS(udt_types), 0x80000000, NULL, HFILL}},
+ "Type", "udt.iscontrol",
+ FT_UINT32, BASE_DEC,
+ VALS(udt_types), 0x80000000, NULL, HFILL}},
{&hf_udt_type, {
- "Type", "udt.type", FT_UINT16, BASE_HEX,
+ "Type", "udt.type",
+ FT_UINT16, BASE_HEX,
VALS(udt_packet_types), 0x7fff, NULL, HFILL}},
{&hf_udt_seqno, {
- "Sequence Number", "udt.seqno", FT_UINT32,
- BASE_DEC,
- NULL, 0x7fffffff, NULL, HFILL}},
+ "Sequence Number", "udt.seqno",
+ FT_UINT32, BASE_DEC,
+ NULL, 0x7fffffff, NULL, HFILL}},
{&hf_udt_addinfo, {
- "Additional Info", "udt.addinfo", FT_UINT32,
- BASE_DEC,
- NULL, 0, NULL, HFILL}},
+ "Additional Info", "udt.addinfo",
+ FT_UINT32, BASE_DEC,
+ NULL, 0, NULL, HFILL}},
{&hf_udt_msgno, {
- "Message Number", "udt.msgno", FT_UINT32,
- BASE_DEC,
- NULL, 0x1fffffff, NULL, HFILL}},
+ "Message Number", "udt.msgno",
+ FT_UINT32, BASE_DEC,
+ NULL, 0x1fffffff, NULL, HFILL}},
{&hf_udt_msgno_first, {
- "First Indicator", "udt.msg.first",
- FT_UINT32, BASE_DEC,
- NULL, 0x80000000, NULL, HFILL}},
+ "First Indicator", "udt.msg.first",
+ FT_UINT32, BASE_DEC,
+ NULL, 0x80000000, NULL, HFILL}},
{&hf_udt_msgno_last, {
- "Last Indicator", "udt.msg.last",
- FT_UINT32, BASE_DEC,
- NULL, 0x40000000, NULL, HFILL}},
+ "Last Indicator", "udt.msg.last",
+ FT_UINT32, BASE_DEC,
+ NULL, 0x40000000, NULL, HFILL}},
{&hf_udt_msgno_inorder, {
- "In-Order Indicator", "udt.msg.order",
- FT_UINT32, BASE_DEC,
- NULL, 0x20000000, NULL, HFILL}},
+ "In-Order Indicator", "udt.msg.order",
+ FT_UINT32, BASE_DEC,
+ NULL, 0x20000000, NULL, HFILL}},
{&hf_udt_timestamp, {
- "Timestamp", "udt.timestamp", FT_UINT32,
- BASE_DEC,
- NULL, 0, NULL, HFILL}},
+ "Timestamp", "udt.timestamp",
+ FT_UINT32, BASE_DEC,
+ NULL, 0, NULL, HFILL}},
{&hf_udt_id, {
- "ID", "udt.id", FT_UINT32, BASE_HEX,
- NULL, 0, NULL, HFILL}},
+ "ID", "udt.id",
+ FT_UINT32, BASE_HEX,
+ NULL, 0, NULL, HFILL}},
{&hf_udt_ack_seqno, {
- "Ack Sequence Number", "udt.ack_seqno",
- FT_UINT32, BASE_DEC,
- NULL, 0, NULL, HFILL}},
+ "Ack Sequence Number", "udt.ack_seqno",
+ FT_UINT32, BASE_DEC,
+ NULL, 0, NULL, HFILL}},
{&hf_udt_ackno, {
- "Ack Number", "udt.ackno", FT_UINT32, BASE_DEC,
- NULL, 0, NULL, HFILL}},
+ "Ack Number", "udt.ackno",
+ FT_UINT32, BASE_DEC,
+ NULL, 0, NULL, HFILL}},
{&hf_udt_rtt, {
- "RTT (microseconds)", "udt.rtt", FT_UINT32,
- BASE_DEC,
- NULL, 0, NULL, HFILL}},
+ "RTT (microseconds)", "udt.rtt",
+ FT_UINT32, BASE_DEC,
+ NULL, 0, NULL, HFILL}},
{&hf_udt_rttvar, {
- "RTT Variance (microseconds)", "udt.rttvar",
- FT_UINT32, BASE_DEC,
- NULL, 0, NULL, HFILL}},
+ "RTT Variance (microseconds)", "udt.rttvar",
+ FT_UINT32, BASE_DEC,
+ NULL, 0, NULL, HFILL}},
{&hf_udt_bufavail, {
- "Buffer Available (packets)", "udt.rttvar",
- FT_UINT32, BASE_DEC,
- NULL, 0, NULL, HFILL}},
+ "Buffer Available (packets)", "udt.rttvar",
+ FT_UINT32, BASE_DEC,
+ NULL, 0, NULL, HFILL}},
{&hf_udt_rate, {
- "Rate (packets/second)", "udt.rate", FT_UINT32,
- BASE_DEC,
+ "Rate (packets/second)", "udt.rate",
+ FT_UINT32, BASE_DEC,
NULL, 0, NULL, HFILL}},
{&hf_udt_linkcap, {
- "Link Capacity (packets/second)",
- "udt.linkcap", FT_UINT32, BASE_DEC,
- NULL, 0, NULL, HFILL}},
+ "Link Capacity (packets/second)", "udt.linkcap",
+ FT_UINT32, BASE_DEC,
+ NULL, 0, NULL, HFILL}},
{&hf_udt_handshake_version, {
- "Version", "udt.hs.version",
- FT_UINT32, BASE_DEC,
- NULL, 0, NULL, HFILL}},
+ "Version", "udt.hs.version",
+ FT_UINT32, BASE_DEC,
+ NULL, 0, NULL, HFILL}},
{&hf_udt_handshake_type, {
- "Type", "udt.hs.type", FT_UINT32,
- BASE_DEC,
- VALS(udt_handshake_types), 0, NULL,
- HFILL}},
+ "Type", "udt.hs.type",
+ FT_UINT32, BASE_DEC,
+ VALS(udt_handshake_types), 0, NULL,
+ HFILL}},
{&hf_udt_handshake_isn, {
- "Initial Sequence Number",
- "udt.hs.isn", FT_UINT32, BASE_DEC,
- NULL, 0, NULL, HFILL}},
+ "Initial Sequence Number", "udt.hs.isn",
+ FT_UINT32, BASE_DEC,
+ NULL, 0, NULL, HFILL}},
{&hf_udt_handshake_mtu, {
- "MTU", "udt.hs.mtu", FT_UINT32,
- BASE_DEC,
- NULL, 0, NULL, HFILL}},
+ "MTU", "udt.hs.mtu",
+ FT_UINT32, BASE_DEC,
+ NULL, 0, NULL, HFILL}},
{&hf_udt_handshake_flow_window, {
- "Flow Window",
- "udt.hs.flow_window",
- FT_UINT32, BASE_DEC,
- NULL, 0, NULL, HFILL}},
+ "Flow Window", "udt.hs.flow_window",
+ FT_UINT32, BASE_DEC,
+ NULL, 0, NULL, HFILL}},
{&hf_udt_handshake_reqtype, {
- "Requested Type", "udt.hs.reqtype",
- FT_INT32, BASE_DEC,
- NULL, 0, NULL, HFILL}},
+ "Requested Type", "udt.hs.reqtype",
+ FT_INT32, BASE_DEC,
+ NULL, 0, NULL, HFILL}},
{&hf_udt_handshake_id, {
- "ID", "udt.hs.id", FT_UINT32, BASE_DEC,
- NULL, 0, NULL, HFILL}},
+ "ID", "udt.hs.id",
+ FT_UINT32, BASE_DEC,
+ NULL, 0, NULL, HFILL}},
{&hf_udt_handshake_cookie, {
- "SYN Cookie", "udt.hs.cookie",
- FT_UINT32, BASE_HEX,
- NULL, 0, NULL, HFILL}},
+ "SYN Cookie", "udt.hs.cookie",
+ FT_UINT32, BASE_HEX,
+ NULL, 0, NULL, HFILL}},
{&hf_udt_handshake_peerip, {
- "Peer IP Address", "udt.hs.peerip",
- FT_BYTES, BASE_NONE,
- NULL, 0, NULL, HFILL}},
+ "Peer IP Address", "udt.hs.peerip",
+ FT_BYTES, BASE_NONE,
+ NULL, 0, NULL, HFILL}},
};
static gint *ett[] = {
@@ -432,7 +439,7 @@ void proto_register_udt(void)
{ &ei_udt_nak_seqno,
{ "udt.nak_seqno", PI_SEQUENCE, PI_NOTE,
"Missing Sequence Number(s)", EXPFILL }},
- };
+ };
proto_udt = proto_register_protocol("UDT Protocol", "UDT", "udt");
proto_register_field_array(proto_udt, hf, array_length(hf));
@@ -445,8 +452,22 @@ void proto_register_udt(void)
void proto_reg_handoff_udt(void)
{
data_handle = find_dissector("data");
- udt_handle = new_create_dissector_handle(dissect_udt, proto_udt);
+ udt_handle = new_create_dissector_handle(dissect_udt, proto_udt);
heur_dissector_add("udp", dissect_udt_heur, proto_udt);
dissector_add_handle("udp.port", udt_handle);
}
+
+
+/*
+ * Editor modelines - http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 8
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * End:
+ *
+ * vi: set shiftwidth=8 tabstop=8 noexpandtab:
+ * :indentSize=8:tabSize=8:noTabs=false:
+ */