diff options
author | Guy Harris <guy@alum.mit.edu> | 2002-01-20 22:12:39 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2002-01-20 22:12:39 +0000 |
commit | 92915713d33924bf25041255e5f2fe8b0c2cd2f6 (patch) | |
tree | ab76e260eae8b60be6c48d592bd36f74a00f3601 /packet-sctp.c | |
parent | a0d7e9051920dea67c6558c65b9529f7d8609b85 (diff) | |
download | wireshark-92915713d33924bf25041255e5f2fe8b0c2cd2f6.tar.gz wireshark-92915713d33924bf25041255e5f2fe8b0c2cd2f6.tar.bz2 wireshark-92915713d33924bf25041255e5f2fe8b0c2cd2f6.zip |
Allow a length of -1 to be specified when adding FT_NONE and FT_PROTOCOL
items to the protocol tree; it's interpreted as "the rest of the data in
the tvbuff". This can be used if
1) the item covers the entire packet or the remaining payload in
the packet
or
2) the item's length won't be known until it's dissected, and
will be then set with "proto_item_set_len()" - if an
exception is thrown in the dissection, it means the item ran
*past* the end of the tvbuff, so saying it runs to the end of
the tvbuff is reasonable.
Convert a number of "proto_tree_add_XXX()" calls using
"tvb_length_remaining()", values derived from the result of
"tvb_length()", or 0 (in the case of items whose length is unknown) to
use -1 instead (using 0 means that if an exception is thrown, selecting
the item highlights nothing; using -1 means it highlights all the data
for that item that's available).
In some places where "tvb_length()" or "tvb_length_remaining()" was used
to determine how large a packet is, use "tvb_reported_length()" or
"tvb_reported_length_remaining()", instead - the first two calls
indicate how much captured data was in the packet, the latter two calls
indicate how large the packet actually was (and the fact that using the
latter could cause BoundsError exceptions to be thrown is a feature - if
such an exception is thrown, the frame really *was* short, and it should
be tagged as such).
Replace some "proto_tree_add_XXX()" calls with equivalent
"proto_tree_add_item()" calls.
Fix some indentation.
svn path=/trunk/; revision=4578
Diffstat (limited to 'packet-sctp.c')
-rw-r--r-- | packet-sctp.c | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/packet-sctp.c b/packet-sctp.c index 5de7432f45..2b7d44a7f6 100644 --- a/packet-sctp.c +++ b/packet-sctp.c @@ -10,7 +10,7 @@ * - support for reassembly * - code cleanup * - * $Id: packet-sctp.c,v 1.27 2002/01/15 23:05:36 guy Exp $ + * $Id: packet-sctp.c,v 1.28 2002/01/20 22:12:27 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -652,7 +652,7 @@ dissect_tlv_parameter_list(tvbuff_t *parameter_list_tvb, packet_info *pinfo, pro tvbuff_t *parameter_tvb; offset = 0; - while(tvb_length_remaining(parameter_list_tvb, offset)) { + while(tvb_reported_length_remaining(parameter_list_tvb, offset)) { length = tvb_get_ntohs(parameter_list_tvb, offset + PARAMETER_LENGTH_OFFSET); padding_length = nr_of_padding_bytes(length); total_length = length + padding_length; @@ -874,7 +874,7 @@ dissect_error_cause_indication_parameter(tvbuff_t *parameter_tvb, packet_info *p tvbuff_t *error_cause_tvb; offset = PARAMETER_VALUE_OFFSET; - while(tvb_length_remaining(parameter_tvb, offset)) { + while(tvb_reported_length_remaining(parameter_tvb, offset)) { length = tvb_get_ntohs(parameter_tvb, offset + CAUSE_LENGTH_OFFSET); padding_length = nr_of_padding_bytes(length); total_length = length + padding_length; @@ -1592,16 +1592,16 @@ dissect_abort_chunk(tvbuff_t *chunk_tvb, packet_info *pinfo, proto_tree *tree, if (chunk_tree) { number_of_causes = 0; offset = ABORT_CHUNK_FIRST_ERROR_CAUSE_OFFSET; - while(tvb_length_remaining(chunk_tvb, offset)) { - length = tvb_get_ntohs(chunk_tvb, offset + CAUSE_LENGTH_OFFSET); - padding_length = nr_of_padding_bytes(length); - total_length = length + padding_length; - /* create a tvb for the chunk including the padding bytes */ - cause_tvb = tvb_new_subset(chunk_tvb, offset, total_length, total_length); - dissect_error_cause(cause_tvb, pinfo, chunk_tree); - /* get rid of the handled parameter */ - offset += total_length; - number_of_causes++; + while(tvb_reported_length_remaining(chunk_tvb, offset)) { + length = tvb_get_ntohs(chunk_tvb, offset + CAUSE_LENGTH_OFFSET); + padding_length = nr_of_padding_bytes(length); + total_length = length + padding_length; + /* create a tvb for the chunk including the padding bytes */ + cause_tvb = tvb_new_subset(chunk_tvb, offset, total_length, total_length); + dissect_error_cause(cause_tvb, pinfo, chunk_tree); + /* get rid of the handled parameter */ + offset += total_length; + number_of_causes++; }; proto_item_set_text(chunk_item, "Abort chunk with %u cause%s", @@ -1667,7 +1667,7 @@ dissect_error_chunk(tvbuff_t *chunk_tvb, packet_info *pinfo, proto_tree *tree, /* get rid of the handled parameter */ offset += total_length; number_of_causes++; - } while(tvb_length_remaining(chunk_tvb, offset)); + } while(tvb_reported_length_remaining(chunk_tvb, offset)); proto_item_set_text(chunk_item, "Error chunk with %u cause%s", number_of_causes, plurality(number_of_causes, "", "s")); @@ -1848,7 +1848,7 @@ dissect_asconf_chunk(tvbuff_t *chunk_tvb, packet_info *pinfo, proto_tree *tree, offset += ASCONF_ADDR_LENGTH; proto_item_set_text(chunk_item, "ASCONF chunk"); - while(tvb_length_remaining(chunk_tvb, offset)) { + while(tvb_reported_length_remaining(chunk_tvb, offset)) { correlation_id = tvb_get_ntohl(chunk_tvb, offset); proto_tree_add_uint(chunk_tree, hf_sctp_asconf_correlation_id, chunk_tvb, offset, CORRELATION_ID_LENGTH, correlation_id); offset += CORRELATION_ID_LENGTH; @@ -1880,7 +1880,7 @@ dissect_asconf_ack_chunk(tvbuff_t *chunk_tvb, packet_info *pinfo, proto_tree *tr proto_item_set_text(chunk_item, "ASCONF-ACK chunk"); offset = SERIAL_NUMBER_OFFSET + SERIAL_NUMBER_LENGTH; - while(tvb_length_remaining(chunk_tvb, offset)) { + while(tvb_reported_length_remaining(chunk_tvb, offset)) { correlation_id = tvb_get_ntohl(chunk_tvb, offset); proto_tree_add_uint(chunk_tree, hf_sctp_asconf_ack_correlation_id, chunk_tvb, offset, CORRELATION_ID_LENGTH, correlation_id); offset += CORRELATION_ID_LENGTH; @@ -1947,7 +1947,7 @@ dissect_sctp_chunk(tvbuff_t *chunk_tvb, packet_info *pinfo, proto_tree *tree, pr if (tree) { /* create proto_tree stuff */ - chunk_item = proto_tree_add_text(sctp_tree, chunk_tvb, CHUNK_HEADER_OFFSET, tvb_length(chunk_tvb), "Incomplete chunk"); + chunk_item = proto_tree_add_text(sctp_tree, chunk_tvb, CHUNK_HEADER_OFFSET, -1, "Incomplete chunk"); chunk_tree = proto_item_add_subtree(chunk_item, ett_sctp_chunk); /* then insert the chunk header components into the protocol tree */ @@ -2037,7 +2037,7 @@ dissect_sctp_chunks(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_i offset = COMMON_HEADER_LENGTH; sctp_item_length_set = FALSE; - while(tvb_length_remaining(tvb, offset) > 0) { + while(tvb_reported_length_remaining(tvb, offset) > 0) { /* extract the chunk length and compute number of padding bytes */ length = tvb_get_ntohs(tvb, offset + CHUNK_LENGTH_OFFSET); padding_length = nr_of_padding_bytes(length); @@ -2050,8 +2050,8 @@ dissect_sctp_chunks(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_i sctp_item_length_set = TRUE; offset += total_length; last_offset = offset; - if (tvb_length_remaining(tvb, offset) > 0) { - sctp_item = proto_tree_add_item(tree, proto_sctp, tvb, offset, 0, FALSE); + if (tvb_reported_length_remaining(tvb, offset) > 0) { + sctp_item = proto_tree_add_item(tree, proto_sctp, tvb, offset, -1, FALSE); sctp_tree = proto_item_add_subtree(sctp_item, ett_sctp); sctp_item_length_set = FALSE; } @@ -2102,7 +2102,7 @@ dissect_sctp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) necessary to generate protocol tree items. */ if (tree) { /* create the sctp protocol tree */ - sctp_item = proto_tree_add_item(tree, proto_sctp, tvb, 0, 0, FALSE); + sctp_item = proto_tree_add_item(tree, proto_sctp, tvb, 0, -1, FALSE); sctp_tree = proto_item_add_subtree(sctp_item, ett_sctp); /* add the components of the common header to the protocol tree */ |