diff options
author | Guy Harris <guy@alum.mit.edu> | 2016-01-17 12:30:36 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2016-01-17 20:33:32 +0000 |
commit | 59e6c9ed5ebce3e49eed268393495ac1f632aa5b (patch) | |
tree | ce4350b25c2a991b91cb5913188763019eac59e9 /epan | |
parent | 278b21329b012ae1081911f95b3d7342444a75da (diff) |
Fix construction of subset tvbuff.
We should use both the captured length and original length, and we
should use them as the captured length and original length of the
tvbuff.
Clean up indentation and returning process while we're at it.
Change-Id: If7538268cd6ae557d9d5b85eefd57cf3e2e34a9e
Reviewed-on: https://code.wireshark.org/review/13366
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan')
-rw-r--r-- | epan/dissectors/packet-e100.c | 108 |
1 files changed, 57 insertions, 51 deletions
diff --git a/epan/dissectors/packet-e100.c b/epan/dissectors/packet-e100.c index dc471e0675..7c7d5d5c75 100644 --- a/epan/dissectors/packet-e100.c +++ b/epan/dissectors/packet-e100.c @@ -66,61 +66,67 @@ static guint e100_encap_len = 28; static int dissect_e100(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) { - int ret_val = 0; tvbuff_t *next_tvb = NULL; - /* heuristic testing: - * (1) tvb packet is larger than e100 packet - * (2) e100 header is 1 - * (3) e100 capture size matches tvb packet size - */ - if (tvb_captured_length(tvb) >= e100_encap_len && - tvb_get_guint8(tvb, e100_header_ver.offset) == 1 && - tvb_get_ntohl(tvb, e100_bytes_cap.offset) == tvb_reported_length(tvb)-e100_encap_len) + /* heuristic testing: + * (1) tvb packet is larger than e100 packet + * (2) e100 header is 1 + * (3) e100 capture size matches tvb packet size + */ + if (tvb_captured_length(tvb) >= e100_encap_len && + tvb_get_guint8(tvb, e100_header_ver.offset) == 1 && + tvb_get_ntohl(tvb, e100_bytes_cap.offset) == tvb_reported_length(tvb)-e100_encap_len) + { + /* This looks like one of our packets. */ + guint32 bytes_captured; + guint32 bytes_original; + + col_set_str(pinfo->cinfo, COL_PROTOCOL, "e100"); + col_set_str(pinfo->cinfo, COL_INFO, "E100 Encapsulated Packet"); + if (tree) { - guint32 bytes_captured=0; - col_set_str(pinfo->cinfo, COL_PROTOCOL, "e100"); - col_set_str(pinfo->cinfo, COL_INFO, "E100 Encapsulated Packet"); - if (tree) + /* pick apart protocol for display */ + proto_item *ti = NULL; + proto_tree *e100_tree = NULL; + + ti = proto_tree_add_item(tree, proto_e100, tvb, 0, e100_encap_len, ENC_NA); + e100_tree = proto_item_add_subtree(ti, ett_e100); + + proto_tree_add_item(e100_tree, hf_e100_header, tvb, + e100_header_ver.offset, e100_header_ver.len, ENC_BIG_ENDIAN); + proto_tree_add_item(e100_tree, hf_e100_port, tvb, + e100_port_recv.offset, e100_port_recv.len, ENC_BIG_ENDIAN); + proto_tree_add_item(e100_tree, hf_e100_seq, tvb, + e100_seq.offset, e100_seq.len, ENC_BIG_ENDIAN); + proto_tree_add_item(e100_tree, hf_e100_ip, tvb, + e100_ip.offset, e100_ip.len, ENC_BIG_ENDIAN); + proto_tree_add_item(e100_tree, hf_e100_mon_pkt_id, tvb, + e100_mon_pkt_id.offset, e100_mon_pkt_id.len, ENC_BIG_ENDIAN); { - /* pick apart protocol for display */ - proto_item *ti = NULL; - proto_tree *e100_tree = NULL; - - ti = proto_tree_add_item(tree, proto_e100, tvb, 0, e100_encap_len, ENC_NA); - e100_tree = proto_item_add_subtree(ti, ett_e100); - - proto_tree_add_item(e100_tree, hf_e100_header, tvb, - e100_header_ver.offset, e100_header_ver.len, ENC_BIG_ENDIAN); - proto_tree_add_item(e100_tree, hf_e100_port, tvb, - e100_port_recv.offset, e100_port_recv.len, ENC_BIG_ENDIAN); - proto_tree_add_item(e100_tree, hf_e100_seq, tvb, - e100_seq.offset, e100_seq.len, ENC_BIG_ENDIAN); - proto_tree_add_item(e100_tree, hf_e100_ip, tvb, - e100_ip.offset, e100_ip.len, ENC_BIG_ENDIAN); - proto_tree_add_item(e100_tree, hf_e100_mon_pkt_id, tvb, - e100_mon_pkt_id.offset, e100_mon_pkt_id.len, ENC_BIG_ENDIAN); - { - nstime_t ts; - ts.secs = tvb_get_ntohl(tvb, e100_ts.offset); - ts.nsecs = tvb_get_ntohl(tvb, e100_ts.offset+4)*1000; - proto_tree_add_time(e100_tree, hf_e100_pkt_ts, tvb, - e100_ts.offset, e100_ts.len, &ts); - } - proto_tree_add_item(e100_tree, hf_e100_bytes_cap, tvb, - e100_bytes_cap.offset, e100_bytes_cap.len, ENC_BIG_ENDIAN); - proto_tree_add_item(e100_tree, hf_e100_bytes_orig, tvb, - e100_bytes_orig.offset, e100_bytes_orig.len, ENC_BIG_ENDIAN); - - } /* if(tree) */ - bytes_captured = tvb_get_ntohl(tvb, e100_bytes_cap.offset); - next_tvb = tvb_new_subset(tvb, e100_encap_len, -1, bytes_captured); - call_dissector(eth_handle, next_tvb, pinfo, tree); - - ret_val = tvb_captured_length(tvb); - } /* heuristic testing */ - - return ret_val; + nstime_t ts; + ts.secs = tvb_get_ntohl(tvb, e100_ts.offset); + ts.nsecs = tvb_get_ntohl(tvb, e100_ts.offset+4)*1000; + proto_tree_add_time(e100_tree, hf_e100_pkt_ts, tvb, + e100_ts.offset, e100_ts.len, &ts); + } + proto_tree_add_item(e100_tree, hf_e100_bytes_cap, tvb, + e100_bytes_cap.offset, e100_bytes_cap.len, ENC_BIG_ENDIAN); + proto_tree_add_item(e100_tree, hf_e100_bytes_orig, tvb, + e100_bytes_orig.offset, e100_bytes_orig.len, ENC_BIG_ENDIAN); + + } /* if(tree) */ + bytes_captured = tvb_get_ntohl(tvb, e100_bytes_cap.offset); + bytes_original = tvb_get_ntohl(tvb, e100_bytes_orig.offset); + next_tvb = tvb_new_subset(tvb, e100_encap_len, bytes_captured, bytes_original); + call_dissector(eth_handle, next_tvb, pinfo, tree); + + return tvb_captured_length(tvb); + } + else + { + /* Not one of our packets. */ + return 0; + } } void |