aboutsummaryrefslogtreecommitdiffstats
path: root/packet-eth.c
diff options
context:
space:
mode:
authorGilbert Ramirez <gram@alumni.rice.edu>2000-05-16 06:21:33 +0000
committerGilbert Ramirez <gram@alumni.rice.edu>2000-05-16 06:21:33 +0000
commit9f45a0b0f5d45d8d84e0abd2854d34693d6f3b06 (patch)
tree0e341c3c817a573ed46ce6c07a32a4874ce55060 /packet-eth.c
parent0a2817cebacb5352ff348434db2571e218a21bdb (diff)
Convert Ethernet and Lucent/Ascend dissectors to use tvbuff.
Note in AUTHORS file that we use the exception module from kazlib. svn path=/trunk/; revision=1966
Diffstat (limited to 'packet-eth.c')
-rw-r--r--packet-eth.c101
1 files changed, 55 insertions, 46 deletions
diff --git a/packet-eth.c b/packet-eth.c
index fbe02aa878..8b9e8adbb5 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.37 2000/05/16 04:44:11 gram Exp $
+ * $Id: packet-eth.c,v 1.38 2000/05/16 06:21:32 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -56,7 +56,7 @@ static gint ett_ether2 = -1;
/* 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
+ Ethernet802.2: An 802.3 header followed by an 802.2 header
Ethernet802.3: A raw 802.3 packet. IPX/SPX can be the only payload.
There's not 802.2 hdr in this.
EthernetSNAP: Basically 802.2, just with 802.2SNAP. For our purposes,
@@ -137,38 +137,39 @@ capture_eth(const u_char *pd, int offset, packet_counts *ld)
}
void
-dissect_eth(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
+dissect_eth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
int orig_captured_len;
- guint16 length;
- volatile guint16 etype;
proto_item *ti;
+ guint8 *dst, *src;
+ const guint8 *pd;
+ volatile guint16 etype;
volatile int ethhdr_type; /* the type of ethernet frame */
+
/* These are static because I need to modify them before the TRY block,
* and gcc says that they might get clobbered otherwise. */
static tvbuff_t *next_tvb = NULL;
static int eth_offset;
static proto_tree *fh_tree = NULL;
+ static guint16 length;
- eth_offset = offset;
+ tvb_compat(tvb, &pd, &eth_offset);
- if (!BYTES_ARE_IN_FRAME(eth_offset, ETH_HEADER_SIZE)) {
- dissect_data(pd, eth_offset, fd, tree);
- return;
- }
- pi.current_proto = "Ethernet";
- orig_captured_len = pi.captured_len;
+ pinfo->current_proto = "Ethernet";
+ orig_captured_len = pinfo->captured_len;
- SET_ADDRESS(&pi.dl_src, AT_ETHER, 6, &pd[eth_offset+6]);
- SET_ADDRESS(&pi.src, AT_ETHER, 6, &pd[eth_offset+6]);
- SET_ADDRESS(&pi.dl_dst, AT_ETHER, 6, &pd[eth_offset+0]);
- SET_ADDRESS(&pi.dst, AT_ETHER, 6, &pd[eth_offset+0]);
+ if (check_col(pinfo->fd, COL_PROTOCOL))
+ col_add_str(pinfo->fd, COL_PROTOCOL, "Ethernet");
- if (check_col(fd, COL_PROTOCOL))
- col_add_str(fd, COL_PROTOCOL, "Ethernet");
+ src = tvb_get_ptr(tvb, 6, 6);
+ dst = tvb_get_ptr(tvb, 0, 6);
+ SET_ADDRESS(&pi.dl_src, AT_ETHER, 6, src);
+ SET_ADDRESS(&pi.src, AT_ETHER, 6, src);
+ SET_ADDRESS(&pi.dl_dst, AT_ETHER, 6, dst);
+ SET_ADDRESS(&pi.dst, AT_ETHER, 6, dst);
- etype = pntohs(&pd[eth_offset+12]);
+ etype = tvb_get_ntohs(tvb, 12);
/* either ethernet802.3 or ethernet802.2 */
if (etype <= IEEE_802_3_MAX_LEN) {
@@ -180,42 +181,50 @@ dissect_eth(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
(IPX/SPX is they only thing that can be contained inside a
straight 802.3 packet). A non-0xffff value means that there's an
802.2 layer inside the 802.3 layer */
- if (pd[eth_offset+14] == 0xff && pd[eth_offset+15] == 0xff) {
- ethhdr_type = ETHERNET_802_3;
+ ethhdr_type = ETHERNET_802_2;
+ TRY {
+ if (tvb_get_ntohs(tvb, 14) == 0xffff) {
+ ethhdr_type = ETHERNET_802_3;
+ }
}
- else {
- ethhdr_type = ETHERNET_802_2;
+ CATCH2(BoundsError, ReportedBoundsError) {
+ ; /* do nothing */
+
}
+ ENDTRY;
/* Oh, yuck. Cisco ISL frames require special interpretation of the
destination address field; fortunately, they can be recognized by
checking the first 5 octets of the destination address, which are
01-00-0C-00-00 for ISL frames. */
- if (pd[eth_offset] == 0x01 && pd[eth_offset+1] == 0x00 && pd[eth_offset+2] == 0x0C
- && pd[eth_offset+3] == 0x00 && pd[eth_offset+4] == 0x00) {
- dissect_isl(pd, eth_offset, fd, tree);
+ if ( tvb_get_guint8(tvb, 0) == 0x01 &&
+ tvb_get_guint8(tvb, 1) == 0x00 &&
+ tvb_get_guint8(tvb, 2) == 0x0C &&
+ tvb_get_guint8(tvb, 3) == 0x00 &&
+ tvb_get_guint8(tvb, 4) == 0x00 ) {
+ dissect_isl(pd, eth_offset, pinfo->fd, tree);
return;
}
- if (check_col(fd, COL_INFO)) {
- col_add_fstr(fd, COL_INFO, "IEEE 802.3 %s",
+ if (check_col(pinfo->fd, COL_INFO)) {
+ col_add_fstr(pinfo->fd, COL_INFO, "IEEE 802.3 %s",
(ethhdr_type == ETHERNET_802_3 ? "Raw " : ""));
}
if (tree) {
- ti = proto_tree_add_protocol_format(tree, proto_eth, NullTVB, eth_offset, ETH_HEADER_SIZE,
+ ti = proto_tree_add_protocol_format(tree, proto_eth, tvb, 0, ETH_HEADER_SIZE,
"IEEE 802.3 %s", (ethhdr_type == ETHERNET_802_3 ? "Raw " : ""));
fh_tree = proto_item_add_subtree(ti, ett_ieee8023);
- proto_tree_add_item(fh_tree, hf_eth_dst, NullTVB, eth_offset+0, 6, &pd[eth_offset+0]);
- proto_tree_add_item(fh_tree, hf_eth_src, NullTVB, eth_offset+6, 6, &pd[eth_offset+6]);
+ proto_tree_add_item(fh_tree, hf_eth_dst, tvb, 0, 6, dst);
+ proto_tree_add_item(fh_tree, hf_eth_src, tvb, 6, 6, src);
/* add items for eth.addr filter */
- proto_tree_add_item_hidden(fh_tree, hf_eth_addr, NullTVB, eth_offset + 0, 6, &pd[eth_offset+0]);
- proto_tree_add_item_hidden(fh_tree, hf_eth_addr, NullTVB, eth_offset + 6, 6, &pd[eth_offset+6]);
+ proto_tree_add_item_hidden(fh_tree, hf_eth_addr, tvb, 0, 6, dst);
+ proto_tree_add_item_hidden(fh_tree, hf_eth_addr, tvb, 6, 6, src);
- proto_tree_add_item(fh_tree, hf_eth_len, NullTVB, eth_offset+12, 2, length);
+ proto_tree_add_item(fh_tree, hf_eth_len, tvb, 12, 2, length);
}
/* Convert the LLC length from the 802.3 header to a total
@@ -230,20 +239,20 @@ dissect_eth(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
pi.captured_len = length;
} else {
ethhdr_type = ETHERNET_II;
- if (check_col(fd, COL_INFO))
- col_add_str(fd, COL_INFO, "Ethernet II");
+ if (check_col(pinfo->fd, COL_INFO))
+ col_add_str(pinfo->fd, COL_INFO, "Ethernet II");
if (tree) {
- ti = proto_tree_add_protocol_format(tree, proto_eth, NullTVB, eth_offset, ETH_HEADER_SIZE,
+ ti = proto_tree_add_protocol_format(tree, proto_eth, tvb, 0, ETH_HEADER_SIZE,
"Ethernet II");
fh_tree = proto_item_add_subtree(ti, ett_ether2);
- proto_tree_add_item(fh_tree, hf_eth_dst, NullTVB, eth_offset+0, 6, &pd[eth_offset+0]);
- proto_tree_add_item(fh_tree, hf_eth_src, NullTVB, eth_offset+6, 6, &pd[eth_offset+6]);
+ proto_tree_add_item(fh_tree, hf_eth_dst, tvb, 0, 6, dst);
+ proto_tree_add_item(fh_tree, hf_eth_src, tvb, 6, 6, src);
/* add items for eth.addr filter */
- proto_tree_add_item_hidden(fh_tree, hf_eth_addr, NullTVB, eth_offset + 0, 6, &pd[eth_offset+0]);
- proto_tree_add_item_hidden(fh_tree, hf_eth_addr, NullTVB, eth_offset + 6, 6, &pd[eth_offset+6]);
+ proto_tree_add_item_hidden(fh_tree, hf_eth_addr, tvb, 0, 6, dst);
+ proto_tree_add_item_hidden(fh_tree, hf_eth_addr, tvb, 6, 6, src);
}
}
eth_offset += ETH_HEADER_SIZE;
@@ -251,26 +260,26 @@ dissect_eth(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
/* Give the next dissector only 'length' number of bytes */
if (etype <= IEEE_802_3_MAX_LEN) {
TRY {
- next_tvb = tvb_new_subset(pi.compat_top_tvb, eth_offset, etype, etype);
+ next_tvb = tvb_new_subset(tvb, ETH_HEADER_SIZE, etype, etype);
}
CATCH2(BoundsError, ReportedBoundsError) {
- next_tvb = tvb_new_subset(pi.compat_top_tvb, eth_offset, -1, etype);
+ next_tvb = tvb_new_subset(tvb, ETH_HEADER_SIZE, -1, etype);
}
ENDTRY;
}
else {
- next_tvb = tvb_new_subset(pi.compat_top_tvb, eth_offset, -1, -1);
+ next_tvb = tvb_new_subset(tvb, ETH_HEADER_SIZE, -1, -1);
}
switch (ethhdr_type) {
case ETHERNET_802_3:
- dissect_ipx(pd, eth_offset, fd, tree);
+ dissect_ipx(pd, eth_offset, pinfo->fd, tree);
break;
case ETHERNET_802_2:
dissect_llc(next_tvb, &pi, tree);
break;
case ETHERNET_II:
- ethertype(etype, eth_offset, pd, fd, tree, fh_tree, hf_eth_type);
+ ethertype(etype, eth_offset, pd, pinfo->fd, tree, fh_tree, hf_eth_type);
break;
}