diff options
author | guy <guy@f5534014-38df-0310-8fa8-9805f1628bb7> | 1999-08-18 00:57:54 +0000 |
---|---|---|
committer | guy <guy@f5534014-38df-0310-8fa8-9805f1628bb7> | 1999-08-18 00:57:54 +0000 |
commit | 973eb23d6688f6f75caa89958d847c5e9bd0beea (patch) | |
tree | e9e831bb1b3b77de445b70cbeb126f919f01bce2 /packet-eth.c | |
parent | 3104122f7df1c1e0814136c22de0f0487d01968f (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".)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@506 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'packet-eth.c')
-rw-r--r-- | packet-eth.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/packet-eth.c b/packet-eth.c index 34ff78081b..1cde4f4ff4 100644 --- a/packet-eth.c +++ b/packet-eth.c @@ -1,7 +1,7 @@ /* packet-eth.c * Routines for ethernet packet disassembly * - * $Id: packet-eth.c,v 1.14 1999/08/01 04:28:08 gram Exp $ + * $Id: packet-eth.c,v 1.15 1999/08/18 00:57:50 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -47,6 +47,8 @@ static int hf_eth_type = -1; #define IEEE_802_3_MAX_LEN 1500 +#define ETH_HEADER_SIZE 14 + /* These are the Netware-ish names for the different Ethernet frame types. EthernetII: The ethernet with a Type field instead of a length field Ethernet802.2: An 802.3 header followed by an 802.3 header @@ -64,8 +66,8 @@ static int hf_eth_type = -1; void capture_eth(const u_char *pd, guint32 cap_len, packet_counts *ld) { guint16 etype; - int offset = 14; - int ethhdr_type; /* the type of ethernet frame */ + int offset = ETH_HEADER_SIZE; + int ethhdr_type; /* the type of ethernet frame */ etype = (pd[12] << 8) | pd[13]; @@ -104,10 +106,10 @@ capture_eth(const u_char *pd, guint32 cap_len, packet_counts *ld) { void dissect_eth(const u_char *pd, frame_data *fd, proto_tree *tree) { guint16 etype, length; - int offset = 14; + int offset = ETH_HEADER_SIZE; proto_tree *fh_tree = NULL; proto_item *ti; - int ethhdr_type; /* the type of ethernet frame */ + int ethhdr_type; /* the type of ethernet frame */ if (check_col(fd, COL_RES_DL_DST)) col_add_str(fd, COL_RES_DL_DST, get_ether_name((u_char *)&pd[0])); @@ -145,7 +147,7 @@ dissect_eth(const u_char *pd, frame_data *fd, proto_tree *tree) { col_add_str(fd, COL_INFO, "802.3"); if (tree) { - ti = proto_tree_add_item_format(tree, proto_eth, 0, offset, + ti = proto_tree_add_item_format(tree, proto_eth, 0, ETH_HEADER_SIZE, NULL, "IEEE 802.3 %s", (ethhdr_type == ETHERNET_802_3 ? "Raw " : "")); fh_tree = proto_item_add_subtree(ti, ETT_IEEE8023); @@ -153,14 +155,24 @@ dissect_eth(const u_char *pd, frame_data *fd, proto_tree *tree) { proto_tree_add_item(fh_tree, hf_eth_dst, 0, 6, &pd[0]); proto_tree_add_item(fh_tree, hf_eth_src, 6, 6, &pd[6]); proto_tree_add_item(fh_tree, hf_eth_len, 12, 2, length); + + /* Convert the LLC length from the 802.3 header to a total + length, by adding in the Ethernet header size, and set + the payload and captured-payload lengths to the minima + of the total length and the frame lengths. */ + length += ETH_HEADER_SIZE; + if (pi.len > length) + pi.len = length; + if (pi.captured_len > length) + pi.captured_len = length; } } else { ethhdr_type = ETHERNET_II; if (tree) { - ti = proto_tree_add_item_format(tree, proto_eth, 0, 14, NULL, - "Ethernet II"); + ti = proto_tree_add_item_format(tree, proto_eth, 0, ETH_HEADER_SIZE, + NULL, "Ethernet II"); fh_tree = proto_item_add_subtree(ti, ETT_ETHER2); @@ -171,7 +183,6 @@ dissect_eth(const u_char *pd, frame_data *fd, proto_tree *tree) { proto_tree_add_item_format(fh_tree, hf_eth_src, 6, 6, &pd[6], "Source: %s (%s)", ether_to_str((guint8 *) &pd[6]), get_ether_name((u_char *) &pd[6])); - } } |