diff options
-rw-r--r-- | epan/packet.c | 46 | ||||
-rw-r--r-- | epan/packet.h | 10 | ||||
-rw-r--r-- | packet-ip.c | 30 | ||||
-rw-r--r-- | packet-ipv6.c | 8 | ||||
-rw-r--r-- | packet-ipx.c | 25 |
5 files changed, 66 insertions, 53 deletions
diff --git a/epan/packet.c b/epan/packet.c index e44fe8e33b..6b53e6fe8c 100644 --- a/epan/packet.c +++ b/epan/packet.c @@ -1,7 +1,7 @@ /* packet.c * Routines for packet disassembly * - * $Id: packet.c,v 1.35 2001/06/02 08:23:10 guy Exp $ + * $Id: packet.c,v 1.36 2001/06/29 09:46:54 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -96,6 +96,50 @@ packet_cleanup(void) /* nothing */ } +/* + * Given a tvbuff, a packet_info *, and a length from a packet header, + * adjust the length of the tvbuff, and the "len" and "captured_len" + * members of the "packet_info" structure, to reflect the specified + * length. + */ +void +set_actual_length(tvbuff_t *tvb, packet_info *pinfo, guint specified_len) +{ + guint payload_len, reported_payload_len; + int padding; + + /* Length of payload handed to us. */ + reported_payload_len = tvb_reported_length(tvb); + payload_len = tvb_length(tvb); + + if (specified_len < reported_payload_len) { + /* Adjust the length of this tvbuff to include only the specified + payload length. + + The dissector above the one calling us (the dissector above is + probably us) may use that to determine how much of its packet + was padding. */ + tvb_set_reported_length(tvb, specified_len); + + /* XXX - can we get rid of "pinfo->len" and "pinfo->captured_len" + when the last dissector is tvbuffified? */ + + /* Shrink the total payload by the amount of padding. */ + padding = reported_payload_len - specified_len; + if (pinfo->len >= padding) + pinfo->len -= padding; + + /* Shrink the captured payload by the amount of padding in the + captured payload (which may be less than the amount of padding, + as the padding may not have been captured). */ + if (specified_len < payload_len) { + padding = payload_len - specified_len; + if (pinfo->captured_len >= padding) + pinfo->captured_len -= padding; + } + } +} + /* Allow protocols to register "init" routines, which are called before we make a pass through a capture file and dissect all its packets (e.g., when we read in a new capture file, or run a "filter packets" diff --git a/epan/packet.h b/epan/packet.h index b3b02cb4d6..31e0dd0eb5 100644 --- a/epan/packet.h +++ b/epan/packet.h @@ -1,7 +1,7 @@ /* packet.h * Definitions for packet disassembly structures and routines * - * $Id: packet.h,v 1.34 2001/06/02 08:23:10 guy Exp $ + * $Id: packet.h,v 1.35 2001/06/29 09:46:54 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -206,6 +206,14 @@ void dissect_init(void); void dissect_cleanup(void); +/* + * Given a tvbuff, a packet_info *, and a length from a packet header, + * adjust the length of the tvbuff, and the "len" and "captured_len" + * members of the "packet_info" structure, to reflect the specified + * length. + */ +void set_actual_length(tvbuff_t *tvb, packet_info *pinfo, guint specified_len); + /* Allow protocols to register "init" routines, which are called before we make a pass through a capture file and dissect all its packets (e.g., when we read in a new capture file, or run a "filter packets" diff --git a/packet-ip.c b/packet-ip.c index 38a453df1e..91a01d5be7 100644 --- a/packet-ip.c +++ b/packet-ip.c @@ -1,7 +1,7 @@ /* packet-ip.c * Routines for IP and miscellaneous IP protocol packet disassembly * - * $Id: packet-ip.c,v 1.138 2001/06/19 23:08:55 guy Exp $ + * $Id: packet-ip.c,v 1.139 2001/06/29 09:46:52 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -792,7 +792,7 @@ dissect_ip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) proto_tree *ip_tree = NULL, *field_tree; proto_item *ti, *tf; int offset = 0; - guint hlen, optlen, len, payload_len, reported_payload_len; + guint hlen, optlen, len; int padding; guint16 flags; guint8 nxt; @@ -815,33 +815,11 @@ dissect_ip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) iph.ip_off = ntohs(iph.ip_off); iph.ip_sum = ntohs(iph.ip_sum); - /* Length of payload handed to us. */ - reported_payload_len = tvb_reported_length(tvb); - payload_len = tvb_length(tvb); - /* Length of IP datagram. */ len = iph.ip_len; - if (len < reported_payload_len) { - /* Adjust the length of this tvbuff to include only the IP datagram. - Our caller may use that to determine how much of its packet - was padding. */ - tvb_set_reported_length(tvb, len); - - /* Shrink the total payload by the amount of padding. */ - padding = reported_payload_len - len; - if (pinfo->len >= padding) - pinfo->len -= padding; - - /* Shrink the captured payload by the amount of padding in the - captured payload (which may be less than the amount of padding, - as the padding may not have been captured). */ - if (len < payload_len) { - padding = payload_len - len; - if (pinfo->captured_len >= padding) - pinfo->captured_len -= padding; - } - } + /* Adjust the length of this tvbuff to include only the IP datagram. */ + set_actual_length(tvb, pinfo, len); hlen = lo_nibble(iph.ip_v_hl) * 4; /* IP header length, in bytes */ diff --git a/packet-ipv6.c b/packet-ipv6.c index 8b2c8e49db..d5a6e7de0e 100644 --- a/packet-ipv6.c +++ b/packet-ipv6.c @@ -1,11 +1,10 @@ /* packet-ipv6.c * Routines for IPv6 packet disassembly * - * $Id: packet-ipv6.c,v 1.60 2001/06/26 17:31:36 itojun Exp $ + * $Id: packet-ipv6.c,v 1.61 2001/06/29 09:46:52 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> - * * Copyright 1998 Gerald Combs * * MobileIPv6 support added by Tomislav Borosa <tomislav.borosa@siemens.hr> @@ -675,9 +674,8 @@ dissect_ipv6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* Get the payload length */ plen = ntohs(ipv6.ip6_plen); - /* Check for trailer (not part of IPv6 packet) */ - if (plen + sizeof (struct ip6_hdr) < tvb_reported_length(tvb)) - tvb_set_reported_length(tvb, plen + sizeof (struct ip6_hdr)); + /* Adjust the length of this tvbuff to include only the IPv6 datagram. */ + set_actual_length(tvb, pinfo, plen + sizeof (struct ip6_hdr)); SET_ADDRESS(&pinfo->net_src, AT_IPv6, 16, tvb_get_ptr(tvb, offset + IP6H_SRC, 16)); SET_ADDRESS(&pinfo->src, AT_IPv6, 16, tvb_get_ptr(tvb, offset + IP6H_SRC, 16)); diff --git a/packet-ipx.c b/packet-ipx.c index ce24ff9320..3b7a786cf2 100644 --- a/packet-ipx.c +++ b/packet-ipx.c @@ -2,12 +2,11 @@ * Routines for NetWare's IPX * Gilbert Ramirez <gram@xiexie.org> * - * $Id: packet-ipx.c,v 1.86 2001/06/18 02:17:47 guy Exp $ + * $Id: packet-ipx.c,v 1.87 2001/06/29 09:46:52 guy Exp $ * * Ethereal - Network traffic analyzer - * By Gerald Combs <gerald@zing.org> + * By Gerald Combs <gerald@ethereal.com> * Copyright 1998 Gerald Combs - * * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -202,8 +201,6 @@ static void dissect_ipx(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { tvbuff_t *next_tvb; - const guint8 *this_pd; - int this_offset, len; proto_tree *ipx_tree; proto_item *ti; @@ -212,7 +209,6 @@ dissect_ipx(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) guint8 ipx_type, ipx_hops; guint16 ipx_length; - int reported_length, available_length; guint16 ipx_dsocket, ipx_ssocket; @@ -227,15 +223,8 @@ dissect_ipx(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) ipx_type = tvb_get_guint8(tvb, 5); ipx_length = tvb_get_ntohs(tvb, 2); - /* Set the payload and captured-payload lengths to the minima of - (the IPX length plus the length of the headers above it) and - the frame lengths. XXX - remove once all dissectors use tvbuffs */ - tvb_compat(tvb, &this_pd, &this_offset); - len = ipx_length + this_offset; - if (pi.len > len) - pi.len = len; - if (pi.captured_len > len) - pi.captured_len = len; + /* Adjust the tvbuff length to include only the IPX datagram. */ + set_actual_length(tvb, pinfo, ipx_length); src_net_node = tvb_get_ptr(tvb, 18, 10); dst_net_node = tvb_get_ptr(tvb, 6, 10); @@ -278,11 +267,7 @@ dissect_ipx(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) } /* Make the next tvbuff */ - reported_length = ipx_length - IPX_HEADER_LEN; - available_length = tvb_length(tvb) - IPX_HEADER_LEN; - next_tvb = tvb_new_subset(tvb, IPX_HEADER_LEN, - MIN(available_length, reported_length), - reported_length); + next_tvb = tvb_new_subset(tvb, IPX_HEADER_LEN, -1, -1); if (dissector_try_port(ipx_type_dissector_table, ipx_type, next_tvb, pinfo, tree)) |