diff options
author | gram <gram@f5534014-38df-0310-8fa8-9805f1628bb7> | 2000-05-16 06:21:33 +0000 |
---|---|---|
committer | gram <gram@f5534014-38df-0310-8fa8-9805f1628bb7> | 2000-05-16 06:21:33 +0000 |
commit | d519a3ab2aec3ce7cbcdeec88b108bf084e496f1 (patch) | |
tree | 0e341c3c817a573ed46ce6c07a32a4874ce55060 | |
parent | e6db724c140f18bc79f378cbd5337fa734b0d374 (diff) |
Convert Ethernet and Lucent/Ascend dissectors to use tvbuff.
Note in AUTHORS file that we use the exception module from kazlib.
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@1966 f5534014-38df-0310-8fa8-9805f1628bb7
-rw-r--r-- | AUTHORS | 6 | ||||
-rw-r--r-- | packet-ascend.c | 62 | ||||
-rw-r--r-- | packet-atm.c | 13 | ||||
-rw-r--r-- | packet-eth.c | 101 | ||||
-rw-r--r-- | packet-eth.h | 4 | ||||
-rw-r--r-- | packet-isl.c | 8 | ||||
-rw-r--r-- | packet-vlan.c | 4 | ||||
-rw-r--r-- | packet.c | 7 |
8 files changed, 114 insertions, 91 deletions
@@ -314,3 +314,9 @@ routine to be used. Mattia Cazzola <mattiac@alinet.it> provided a patch to the hex dump display routine. + +We use the exception module from Kazlib, a C library written by +Kaz Kylheku <kaz@ashi.footprints.net>. Thanks goes to him for his +well-written library. The Kazlib home page can be found at +http://users.footprint.net/~kaz/kazlib.html + diff --git a/packet-ascend.c b/packet-ascend.c index cee11ab9f0..c53c3da26c 100644 --- a/packet-ascend.c +++ b/packet-ascend.c @@ -1,7 +1,7 @@ /* packet-ascend.c * Routines for decoding Lucent/Ascend packet traces * - * $Id: packet-ascend.c,v 1.11 2000/05/11 08:14:54 gram Exp $ + * $Id: packet-ascend.c,v 1.12 2000/05/16 06:21:31 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -52,51 +52,57 @@ static const value_string encaps_vals[] = { {0, NULL } }; void -dissect_ascend( const u_char *pd, frame_data *fd, proto_tree *tree ) { +dissect_ascend( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) +{ proto_tree *fh_tree; proto_item *ti; + const guint8 *pd; + int offset; + + pinfo->current_proto = "Lucent/Ascend"; /* load the top pane info. This should be overwritten by the next protocol in the stack */ - if(check_col(fd, COL_RES_DL_SRC)) - col_add_str(fd, COL_RES_DL_SRC, "N/A" ); - if(check_col(fd, COL_RES_DL_DST)) - col_add_str(fd, COL_RES_DL_DST, "N/A" ); - if(check_col(fd, COL_PROTOCOL)) - col_add_str(fd, COL_PROTOCOL, "N/A" ); - if(check_col(fd, COL_INFO)) - col_add_str(fd, COL_INFO, "Lucent/Ascend packet trace" ); + if(check_col(pinfo->fd, COL_RES_DL_SRC)) + col_add_str(pinfo->fd, COL_RES_DL_SRC, "N/A" ); + if(check_col(pinfo->fd, COL_RES_DL_DST)) + col_add_str(pinfo->fd, COL_RES_DL_DST, "N/A" ); + if(check_col(pinfo->fd, COL_PROTOCOL)) + col_add_str(pinfo->fd, COL_PROTOCOL, "N/A" ); + if(check_col(pinfo->fd, COL_INFO)) + col_add_str(pinfo->fd, COL_INFO, "Lucent/Ascend packet trace" ); /* populate a tree in the second pane with the status of the link layer (ie none) */ if(tree) { - ti = proto_tree_add_text(tree, NullTVB, 0, 0, "Lucent/Ascend packet trace" ); + ti = proto_tree_add_text(tree, tvb, 0, 0, "Lucent/Ascend packet trace" ); fh_tree = proto_item_add_subtree(ti, ett_raw); - proto_tree_add_item(fh_tree, hf_link_type, NullTVB, 0, 0, - fd->pseudo_header.ascend.type); - if (fd->pseudo_header.ascend.type == ASCEND_PFX_WDD) { - proto_tree_add_item(fh_tree, hf_called_number, NullTVB, 0, 0, - fd->pseudo_header.ascend.call_num); - proto_tree_add_item(fh_tree, hf_chunk, NullTVB, 0, 0, - fd->pseudo_header.ascend.chunk); - proto_tree_add_item_hidden(fh_tree, hf_session_id, NullTVB, 0, 0, 0); + proto_tree_add_item(fh_tree, hf_link_type, tvb, 0, 0, + pinfo->fd->pseudo_header.ascend.type); + if (pinfo->fd->pseudo_header.ascend.type == ASCEND_PFX_WDD) { + proto_tree_add_item(fh_tree, hf_called_number, tvb, 0, 0, + pinfo->fd->pseudo_header.ascend.call_num); + proto_tree_add_item(fh_tree, hf_chunk, tvb, 0, 0, + pinfo->fd->pseudo_header.ascend.chunk); + proto_tree_add_item_hidden(fh_tree, hf_session_id, tvb, 0, 0, 0); } else { /* It's wandsession data */ - proto_tree_add_item(fh_tree, hf_user_name, NullTVB, 0, 0, - fd->pseudo_header.ascend.user); - proto_tree_add_item(fh_tree, hf_session_id, NullTVB, 0, 0, - fd->pseudo_header.ascend.sess); - proto_tree_add_item_hidden(fh_tree, hf_chunk, NullTVB, 0, 0, 0); + proto_tree_add_item(fh_tree, hf_user_name, tvb, 0, 0, + pinfo->fd->pseudo_header.ascend.user); + proto_tree_add_item(fh_tree, hf_session_id, tvb, 0, 0, + pinfo->fd->pseudo_header.ascend.sess); + proto_tree_add_item_hidden(fh_tree, hf_chunk, tvb, 0, 0, 0); } - proto_tree_add_item(fh_tree, hf_task, NullTVB, 0, 0, fd->pseudo_header.ascend.task); + proto_tree_add_item(fh_tree, hf_task, tvb, 0, 0, pinfo->fd->pseudo_header.ascend.task); } - switch (fd->pseudo_header.ascend.type) { + switch (pinfo->fd->pseudo_header.ascend.type) { case ASCEND_PFX_WDS_X: case ASCEND_PFX_WDS_R: - dissect_ppp(pd, 0, fd, tree); + tvb_compat(tvb, &pd, &offset); + dissect_ppp(pd, offset, pinfo->fd, tree); break; case ASCEND_PFX_WDD: - dissect_eth(pd, 0, fd, tree); + dissect_eth(tvb, pinfo, tree); break; default: break; diff --git a/packet-atm.c b/packet-atm.c index 52faabfa6b..5244ee14a2 100644 --- a/packet-atm.c +++ b/packet-atm.c @@ -1,7 +1,7 @@ /* packet-atm.c * Routines for ATM packet disassembly * - * $Id: packet-atm.c,v 1.17 2000/05/16 04:44:10 gram Exp $ + * $Id: packet-atm.c,v 1.18 2000/05/16 06:21:31 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -374,8 +374,8 @@ static void dissect_lane(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) { tvbuff_t *next_tvb; + tvbuff_t *next_tvb_le_client; - next_tvb = tvb_new_subset(pi.compat_top_tvb, offset, -1, -1); if (check_col(fd, COL_PROTOCOL)) col_add_str(fd, COL_PROTOCOL, "ATM LANE"); @@ -392,23 +392,24 @@ dissect_lane(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) case AHLT_LANE_802_3: case AHLT_LANE_802_3_MC: dissect_le_client(pd, offset, fd, tree); - offset += 2; /* Dissect as Ethernet */ - dissect_eth(pd, offset, fd, tree); + next_tvb_le_client = tvb_new_subset(pi.compat_top_tvb, offset+2, -1, -1); + dissect_eth(next_tvb_le_client, &pi, tree); break; case AHLT_LANE_802_5: case AHLT_LANE_802_5_MC: dissect_le_client(pd, offset, fd, tree); - offset += 2; /* Dissect as Token-Ring */ - dissect_tr(next_tvb, &pi, tree); + next_tvb_le_client = tvb_new_subset(pi.compat_top_tvb, offset+2, -1, -1); + dissect_tr(next_tvb_le_client, &pi, tree); break; default: /* Dump it as raw data. */ + next_tvb = tvb_new_subset(pi.compat_top_tvb, offset, -1, -1); dissect_data_tvb(next_tvb, &pi, tree); break; } 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, ð_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; } diff --git a/packet-eth.h b/packet-eth.h index 8d17b83ea9..9f9ee660cf 100644 --- a/packet-eth.h +++ b/packet-eth.h @@ -1,6 +1,6 @@ /* packet-eth.h * - * $Id: packet-eth.h,v 1.1 2000/02/15 21:02:08 gram Exp $ + * $Id: packet-eth.h,v 1.2 2000/05/16 06:21:32 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -23,4 +23,4 @@ */ void capture_eth(const u_char *, int, packet_counts *); -void dissect_eth(const u_char *, int, frame_data *, proto_tree *); +void dissect_eth(tvbuff_t *, packet_info *, proto_tree *); diff --git a/packet-isl.c b/packet-isl.c index 55c679e0e5..a466f346ad 100644 --- a/packet-isl.c +++ b/packet-isl.c @@ -1,7 +1,7 @@ /* packet-isl.c * Routines for Cisco ISL Ethernet header disassembly * - * $Id: packet-isl.c,v 1.10 2000/05/16 04:44:11 gram Exp $ + * $Id: packet-isl.c,v 1.11 2000/05/16 06:21:32 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -209,7 +209,8 @@ dissect_isl(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) switch (type) { case TYPE_ETHER: - dissect_eth(pd, offset+26, fd, tree); + next_tvb = tvb_new_subset(pi.compat_top_tvb, offset+26, -1, -1); + dissect_eth(next_tvb, &pi, tree); break; case TYPE_TR: @@ -230,7 +231,8 @@ dissect_isl(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) break; default: - dissect_data(pd, offset+26, fd, tree); + next_tvb = tvb_new_subset(pi.compat_top_tvb, offset+26, -1, -1); + dissect_data_tvb(next_tvb, &pi, tree); break; } } diff --git a/packet-vlan.c b/packet-vlan.c index 67a4692f4b..1517e36b52 100644 --- a/packet-vlan.c +++ b/packet-vlan.c @@ -1,7 +1,7 @@ /* packet-vlan.c * Routines for VLAN 802.1Q ethernet header disassembly * - * $Id: packet-vlan.c,v 1.13 2000/05/16 04:44:13 gram Exp $ + * $Id: packet-vlan.c,v 1.14 2000/05/16 06:21:33 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -98,7 +98,7 @@ dissect_vlan(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) { proto_tree_add_item(vlan_tree, hf_vlan_id, NullTVB, offset, 2, tci); } - next_tvb = tvb_new_subset(pi.compat_top_tvb, offset+4, -1, -1); /* XXX - like dissect_eth() */ + next_tvb = tvb_new_subset(pi.compat_top_tvb, offset+4, -1, -1); /* XXX - should TRY() like dissect_eth() */ if ( encap_proto <= IEEE_802_3_MAX_LEN) { if ( pd[offset+4] == 0xff && pd[offset+5] == 0xff ) { dissect_ipx(pd,offset+4,fd,tree); @@ -1,7 +1,7 @@ /* packet.c * Routines for packet disassembly * - * $Id: packet.c,v 1.83 2000/05/16 04:44:13 gram Exp $ + * $Id: packet.c,v 1.84 2000/05/16 06:21:33 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -1174,8 +1174,7 @@ dissect_packet(const u_char *pd, frame_data *fd, proto_tree *tree) TRY { switch (fd->lnk_t) { case WTAP_ENCAP_ETHERNET : - /*dissect_eth(tvb, &pi, tree);*/ - dissect_eth(pd, 0, fd, tree); + dissect_eth(tvb, &pi, tree); break; case WTAP_ENCAP_FDDI : dissect_fddi(tvb, &pi, tree, FALSE); @@ -1205,7 +1204,7 @@ dissect_packet(const u_char *pd, frame_data *fd, proto_tree *tree) dissect_atm(pd, fd, tree); break; case WTAP_ENCAP_ASCEND : - dissect_ascend(pd, fd, tree); + dissect_ascend(tvb, &pi, tree); break; case WTAP_ENCAP_LAPD : dissect_lapd(pd, fd, tree); |