diff options
author | Guy Harris <guy@alum.mit.edu> | 1999-08-18 00:57:54 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 1999-08-18 00:57:54 +0000 |
commit | ac4f87218d7bf56558225bc0f78a5a0af25687e6 (patch) | |
tree | e9e831bb1b3b77de445b70cbeb126f919f01bce2 /packet-ip.c | |
parent | d4331d432915144e57271b70a9bf6b867087c0a0 (diff) |
Declare the "packet_info" structure "pi" in "packet.h", rather than in a
bunch of source files.
Replace the "payload" field of a "packet_info" structure with "len" and
"captured_len" fields, which contain the total packet length and total
captured packet length (including all headers) at the current protocol
layer (i.e., if a given layer has a length field, and that length field
says its shorter than the length we got from the capture, reduce the
"pi.len" and "pi.captured_len" values appropriately). Those fields can
be used in the future if we add checks to make sure a field we're
extracting from a packet doesn't go past the end of the packet, or past
the captured part of the packet.
Get rid of the additional payload argument to some dissection functions;
use "pi.captured_len - offset" instead.
Have the END_OF_FRAME macro use "pi.captured_len" rather than
"fd->cap_len", so that "dissect the rest of the frame" becomes "dissect
the rest of the packet", and doesn't dissect end-of-frame padding such
as padding added to make an Ethernet frame 60 or more octets long. (We
might want to rename it END_OF_PACKET; if we ever want to label the
end-of-frame padding for the benefit of people curious what that extra
gunk is, we could have a separate END_OF_FRAME macro that uses
"fd->cap_len".)
svn path=/trunk/; revision=506
Diffstat (limited to 'packet-ip.c')
-rw-r--r-- | packet-ip.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/packet-ip.c b/packet-ip.c index 5d23b671e9..518ccaa617 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.37 1999/08/17 03:09:39 gram Exp $ + * $Id: packet-ip.c,v 1.38 1999/08/18 00:57:50 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -46,8 +46,6 @@ #include "packet-ip.h" #endif -extern packet_info pi; - static int proto_ip = -1; static int hf_ip_version = -1; static int hf_ip_hdr_len = -1; @@ -627,10 +625,10 @@ dissect_ip(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) { proto_tree *ip_tree, *field_tree; proto_item *ti, *tf; gchar tos_str[32]; - guint hlen, optlen; + guint hlen, optlen, len; guint16 flags; - int advance; - guint8 nxt; + int advance; + guint8 nxt; /* To do: check for runts, errs, etc. */ /* Avoids alignment problems on many architectures. */ @@ -640,6 +638,17 @@ dissect_ip(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) { iph.ip_off = ntohs(iph.ip_off); iph.ip_sum = ntohs(iph.ip_sum); + /* Length of IP datagram plus headers above it. */ + len = iph.ip_len + offset; + + /* Set the payload and captured-payload lengths to the minima of (the + IP length plus the length of the headers above it) and the frame + lengths. */ + if (pi.len > len) + pi.len = len; + if (pi.captured_len > len) + pi.captured_len = len; + hlen = lo_nibble(iph.ip_v_hl) * 4; /* IP header length, in bytes */ switch (iph.ip_p) { @@ -768,8 +777,8 @@ dissect_ip(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) { pi.iphdrlen = lo_nibble(iph.ip_v_hl); pi.ip_src = iph.ip_src; pi.ip_dst = iph.ip_dst; - pi.payload = pi.iplen - hlen; + /* Skip over header + options */ offset += hlen; nxt = iph.ip_p; if (iph.ip_off & IP_OFFSET) { |