diff options
author | Gilbert Ramirez <gram@alumni.rice.edu> | 2000-05-31 03:58:56 +0000 |
---|---|---|
committer | Gilbert Ramirez <gram@alumni.rice.edu> | 2000-05-31 03:58:56 +0000 |
commit | aa553f63ecc7b9e310a05b743502c50f6dffb800 (patch) | |
tree | 51fbaf8816a6c74cd38581bc4c2eda79a91f9246 /packet-v120.c | |
parent | fa8b1d4e8b3882975514518232e429eaa5e41659 (diff) | |
download | wireshark-aa553f63ecc7b9e310a05b743502c50f6dffb800.tar.gz wireshark-aa553f63ecc7b9e310a05b743502c50f6dffb800.tar.bz2 wireshark-aa553f63ecc7b9e310a05b743502c50f6dffb800.zip |
Convert LAPD and V.120 dissector to use tvbuff. Convert xdlc dissector-helper,
too.
svn path=/trunk/; revision=2030
Diffstat (limited to 'packet-v120.c')
-rw-r--r-- | packet-v120.c | 139 |
1 files changed, 75 insertions, 64 deletions
diff --git a/packet-v120.c b/packet-v120.c index bc802d06ad..e8a8940125 100644 --- a/packet-v120.c +++ b/packet-v120.c @@ -2,7 +2,7 @@ * Routines for v120 frame disassembly * Bert Driehuis <driehuis@playbeing.org> * - * $Id: packet-v120.c,v 1.8 2000/05/19 23:06:09 gram Exp $ + * $Id: packet-v120.c,v 1.9 2000/05/31 03:58:54 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -51,75 +51,83 @@ static gint ett_v120_address = -1; static gint ett_v120_control = -1; static gint ett_v120_header = -1; -static int dissect_v120_header(const u_char *pd, int offset, frame_data *fd, proto_tree *tree); +static int dissect_v120_header(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree); void -dissect_v120(const union wtap_pseudo_header *pseudo_header, const u_char *pd, - frame_data *fd, proto_tree *tree) +dissect_v120(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { - proto_tree *v120_tree, *ti, *tc, *address_tree; - int is_response; - int addr; - char info[80]; - int v120len; - guint16 control; - - if (check_col(fd, COL_PROTOCOL)) - col_add_str(fd, COL_PROTOCOL, "V.120"); - - if(check_col(fd, COL_RES_DL_SRC)) - col_add_fstr(fd, COL_RES_DL_SRC, "0x%02X", pd[0]); - if ((pd[0] & 0x01) != 0x00 && (pd[1] && 0x01) != 0x01) + proto_tree *v120_tree, *tc, *address_tree; + proto_item *ti; + int is_response; + int addr; + char info[80]; + int v120len; + guint8 byte0, byte1; + guint16 control; + tvbuff_t *next_tvb; + + pinfo->current_proto = "V.120"; + + if (check_col(pinfo->fd, COL_PROTOCOL)) + col_add_str(pinfo->fd, COL_PROTOCOL, "V.120"); + + byte0 = tvb_get_guint8(tvb, 0); + + if(check_col(pinfo->fd, COL_RES_DL_SRC)) + col_add_fstr(pinfo->fd, COL_RES_DL_SRC, "0x%02X", byte0); + + byte1 = tvb_get_guint8(tvb, 1); + + if ((byte0 & 0x01) != 0x00 && (byte1 && 0x01) != 0x01) { - if (check_col(fd, COL_INFO)) - col_add_str(fd, COL_INFO, "Invalid V.120 frame"); + if (check_col(pinfo->fd, COL_INFO)) + col_add_str(pinfo->fd, COL_INFO, "Invalid V.120 frame"); if (tree) - ti = proto_tree_add_protocol_format(tree, proto_v120, NullTVB, 0, fd->cap_len, + ti = proto_tree_add_protocol_format(tree, proto_v120, tvb, 0, pinfo->fd->cap_len, "Invalid V.120 frame"); return; } - if (pseudo_header->x25.flags & FROM_DCE) { - if(check_col(fd, COL_RES_DL_DST)) - col_add_str(fd, COL_RES_DL_DST, "DTE"); - if(check_col(fd, COL_RES_DL_SRC)) - col_add_str(fd, COL_RES_DL_SRC, "DCE"); + if (pinfo->pseudo_header->x25.flags & FROM_DCE) { + if(check_col(pinfo->fd, COL_RES_DL_DST)) + col_add_str(pinfo->fd, COL_RES_DL_DST, "DTE"); + if(check_col(pinfo->fd, COL_RES_DL_SRC)) + col_add_str(pinfo->fd, COL_RES_DL_SRC, "DCE"); } else { - if(check_col(fd, COL_RES_DL_DST)) - col_add_str(fd, COL_RES_DL_DST, "DCE"); - if(check_col(fd, COL_RES_DL_SRC)) - col_add_str(fd, COL_RES_DL_SRC, "DTE"); + if(check_col(pinfo->fd, COL_RES_DL_DST)) + col_add_str(pinfo->fd, COL_RES_DL_DST, "DCE"); + if(check_col(pinfo->fd, COL_RES_DL_SRC)) + col_add_str(pinfo->fd, COL_RES_DL_SRC, "DTE"); } - if (((pseudo_header->x25.flags & FROM_DCE) && pd[0] & 0x02) || - (!(pseudo_header->x25.flags & FROM_DCE) && !(pd[0] & 0x02))) + if (((pinfo->pseudo_header->x25.flags & FROM_DCE) && byte0 & 0x02) || + (!(pinfo->pseudo_header->x25.flags & FROM_DCE) && !(byte0 & 0x02))) is_response = TRUE; else is_response = FALSE; if (tree) { - ti = proto_tree_add_protocol_format(tree, proto_v120, NullTVB, 0, 0, - "V.120"); + ti = proto_tree_add_protocol_format(tree, proto_v120, tvb, 0, 0, "V.120"); v120_tree = proto_item_add_subtree(ti, ett_v120); - addr = pd[1] << 8 | pd[0]; + addr = byte1 << 8 | byte0; sprintf(info, "LLI: %d C/R: %s", - ((pd[0] & 0xfc) << 5) | ((pd[1] & 0xfe) >> 1), - pd[0] & 0x02 ? "R" : "C"); - tc = proto_tree_add_text(v120_tree, NullTVB, + ((byte0 & 0xfc) << 5) | ((byte1 & 0xfe) >> 1), + byte0 & 0x02 ? "R" : "C"); + tc = proto_tree_add_text(v120_tree, tvb, 0, 2, "Address field: %s", info); address_tree = proto_item_add_subtree(tc, ett_v120_address); - proto_tree_add_text(address_tree, NullTVB, 0, 2, + proto_tree_add_text(address_tree, tvb, 0, 2, decode_boolean_bitfield(addr, 0x0002, 2*8, "Response", "Command"), NULL); - sprintf(info, "LLI: %d", ((pd[0] & 0xfc) << 5) | ((pd[1] & 0xfe) >> 1)); - proto_tree_add_text(address_tree, NullTVB, 0, 2, + sprintf(info, "LLI: %d", ((byte0 & 0xfc) << 5) | ((byte1 & 0xfe) >> 1)); + proto_tree_add_text(address_tree, tvb, 0, 2, decode_numeric_bitfield(addr, 0xfefc, 2*8, info)); - proto_tree_add_text(address_tree, NullTVB, 0, 2, + proto_tree_add_text(address_tree, tvb, 0, 2, decode_boolean_bitfield(addr, 0x0001, 2*8, "EA0 = 1 (Error)", "EA0 = 0"), NULL); - proto_tree_add_text(address_tree, NullTVB, 0, 2, + proto_tree_add_text(address_tree, tvb, 0, 2, decode_boolean_bitfield(addr, 0x0100, 2*8, "EA1 = 1", "EA1 = 0 (Error)"), NULL); } @@ -127,66 +135,69 @@ dissect_v120(const union wtap_pseudo_header *pseudo_header, const u_char *pd, v120_tree = NULL; ti = NULL; } - control = dissect_xdlc_control(pd, 2, fd, v120_tree, hf_v120_control, + control = dissect_xdlc_control(tvb, 2, pinfo, v120_tree, hf_v120_control, ett_v120_control, is_response, TRUE); if (tree) { v120len = 2 + XDLC_CONTROL_LEN(control, TRUE); - if (BYTES_ARE_IN_FRAME(v120len, 1)) - v120len += dissect_v120_header(pd, v120len, fd, v120_tree); + if (tvb_bytes_exist(tvb, v120len, 1)) + v120len += dissect_v120_header(tvb, v120len, pinfo, v120_tree); proto_item_set_len(ti, v120len); - if (IS_DATA_IN_FRAME(v120len)) - dissect_data(&pd[v120len], v120len, fd, v120_tree); + next_tvb = tvb_new_subset(tvb, v120len, -1, -1); + dissect_data_tvb(next_tvb, pinfo, v120_tree); } } static int -dissect_v120_header(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) +dissect_v120_header(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) { char info[80]; int header_len, nbits; int header; proto_tree *h_tree, *tc; + guint8 byte0; + + byte0 = tvb_get_guint8(tvb, offset); - if (pd[offset] & 0x80) { + if (byte0 & 0x80) { header_len = 1; - header = pd[offset]; + header = byte0; } else { header_len = 2; - header = pd[offset] | pd[offset + 1] << 8; + header = byte0 | tvb_get_guint8(tvb, offset + 1) << 8; } nbits = header_len * 8; - sprintf(info, "Header: B: %d F: %d", pd[offset] & 0x02 ? 1:0, - pd[offset] & 0x01 ? 1:0); - tc = proto_tree_add_text(tree, NullTVB, + sprintf(info, "Header: B: %d F: %d", byte0 & 0x02 ? 1:0, + byte0 & 0x01 ? 1:0); + tc = proto_tree_add_text(tree, tvb, offset, header_len, - "Header octet: %s (0x%02X)", info, pd[offset]); + "Header octet: %s (0x%02X)", info, byte0); h_tree = proto_item_add_subtree(tc, ett_v120_header); - proto_tree_add_text(h_tree, NullTVB, offset, header_len, + proto_tree_add_text(h_tree, tvb, offset, header_len, decode_boolean_bitfield(header, 0x80, nbits, "No extension octet", "Extension octet follows"), NULL); - proto_tree_add_text(h_tree, NullTVB, offset, header_len, + proto_tree_add_text(h_tree, tvb, offset, header_len, decode_boolean_bitfield(header, 0x40, nbits, "Break condition", "No break condition"), NULL); sprintf(info, "Error control C1/C2: %d", (header & 0x0c) >> 2); - proto_tree_add_text(h_tree, NullTVB, offset, header_len, + proto_tree_add_text(h_tree, tvb, offset, header_len, decode_numeric_bitfield(header, 0x0c, nbits, info)); - proto_tree_add_text(h_tree, NullTVB, offset, header_len, + proto_tree_add_text(h_tree, tvb, offset, header_len, decode_boolean_bitfield(header, 0x02, nbits, "Segmentation bit B", "No segmentation bit B"), NULL); - proto_tree_add_text(h_tree, NullTVB, offset, header_len, + proto_tree_add_text(h_tree, tvb, offset, header_len, decode_boolean_bitfield(header, 0x01, nbits, "Segmentation bit F", "No segmentation bit F"), NULL); if (header_len == 2) { - proto_tree_add_text(h_tree, NullTVB, offset, header_len, + proto_tree_add_text(h_tree, tvb, offset, header_len, decode_boolean_bitfield(header, 0x8000, nbits, "E", "E bit not set (Error)"), NULL); - proto_tree_add_text(h_tree, NullTVB, offset, header_len, + proto_tree_add_text(h_tree, tvb, offset, header_len, decode_boolean_bitfield(header, 0x4000, nbits, "DR", "No DR"), NULL); - proto_tree_add_text(h_tree, NullTVB, offset, header_len, + proto_tree_add_text(h_tree, tvb, offset, header_len, decode_boolean_bitfield(header, 0x2000, nbits, "SR", "No SR"), NULL); - proto_tree_add_text(h_tree, NullTVB, offset, header_len, + proto_tree_add_text(h_tree, tvb, offset, header_len, decode_boolean_bitfield(header, 0x1000, nbits, "RR", "No RR"), NULL); } |