Convert LAPD and V.120 dissector to use tvbuff. Convert xdlc dissector-helper,
[obnox/wireshark/wip.git] / packet-llc.c
index ae7c452414c1f0a93eaf8d2c3254c1840e740b14..b18544c68d9e5cc184034b8ee2ff046eee477988 100644 (file)
@@ -2,7 +2,7 @@
  * Routines for IEEE 802.2 LLC layer
  * Gilbert Ramirez <gram@xiexie.org>
  *
- * $Id: packet-llc.c,v 1.57 2000/05/11 22:04:16 gram Exp $
+ * $Id: packet-llc.c,v 1.64 2000/05/31 03:58:54 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -285,11 +285,6 @@ dissect_llc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        }
 
        dsap = tvb_get_guint8(tvb, 0);
-       ssap = tvb_get_guint8(tvb, 1);
-
-       is_snap = (dsap == SAP_SNAP) && (ssap == SAP_SNAP);
-       llc_header_len = 2;     /* DSAP + SSAP */
-
        if (tree) {
                ti = proto_tree_add_item(tree, proto_llc, tvb, 0, 0, NULL);
                llc_tree = proto_item_add_subtree(ti, ett_llc);
@@ -297,6 +292,11 @@ dissect_llc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                        1, dsap & SAP_MASK);
                proto_tree_add_item(llc_tree, hf_llc_dsap_ig, tvb, 0, 
                        1, dsap & DSAP_GI_BIT);
+       } else
+               llc_tree = NULL;
+
+       ssap = tvb_get_guint8(tvb, 1);
+       if (tree) {
                proto_tree_add_item(llc_tree, hf_llc_ssap, tvb, 1, 
                        1, ssap & SAP_MASK);
                proto_tree_add_item(llc_tree, hf_llc_ssap_cr, tvb, 1, 
@@ -304,16 +304,18 @@ dissect_llc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        } else
                llc_tree = NULL;
 
+       is_snap = (dsap == SAP_SNAP) && (ssap == SAP_SNAP);
+       llc_header_len = 2;     /* DSAP + SSAP */
+
        /*
         * XXX - the page referred to in the comment above about the
         * Command/Response bit also implies that LLC Type 2 always
         * uses extended operation, so we don't need to determine
         * whether it's basic or extended operation; is that the case?
         */
-       tvb_compat(tvb, &pd, &offset);
-       control = dissect_xdlc_control(pd, offset+2, pinfo->fd, llc_tree,
+       control = dissect_xdlc_control(tvb, 2, pinfo, llc_tree,
                                hf_llc_ctrl, ett_llc_ctrl,
-                               pd[offset+1] & SSAP_CR_BIT, TRUE);
+                               tvb_get_guint8(tvb, 1) & SSAP_CR_BIT, TRUE);
        llc_header_len += XDLC_CONTROL_LEN(control, TRUE);
        if (is_snap)
                llc_header_len += 5;    /* 3 bytes of OUI, 2 bytes of protocol ID */
@@ -327,9 +329,7 @@ dissect_llc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
         * than overwriting it?
         */
        if (is_snap) {
-               oui =   tvb_get_guint8(tvb, 3) << 16 |
-                       tvb_get_guint8(tvb, 4) << 8  |
-                       tvb_get_guint8(tvb, 5);
+               oui =   tvb_get_ntoh24(tvb, 3);
                etype = tvb_get_ntohs(tvb, 6);
 
                if (check_col(pinfo->fd, COL_INFO)) {
@@ -342,7 +342,7 @@ dissect_llc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                                oui);
                }
 
-               next_tvb = tvb_new_subset(tvb, 8, -1);
+               next_tvb = tvb_new_subset(tvb, 8, -1, -1);
                tvb_compat(next_tvb, &pd, &offset);
 
                switch (oui) {
@@ -357,8 +357,8 @@ dissect_llc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                           OUI_ENCAP_ETHER and an Ethernet
                           packet type for AARP packets. */
                        if (XDLC_IS_INFORMATION(control)) {
-                               ethertype(etype, offset+8, pd,
-                                   pinfo->fd, tree, llc_tree, hf_llc_type);
+                               ethertype(etype, tvb, 8,
+                                   pinfo, tree, llc_tree, hf_llc_type);
                        } else
                                dissect_data_tvb(next_tvb, pinfo, tree);
                        break;
@@ -378,28 +378,28 @@ dissect_llc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
 #if 0
                                case 0x0102:
-                                       dissect_drip(pd, offset+8, pinfo->fd, tree);
+                                       dissect_drip(pd, offset, pinfo->fd, tree);
                                        break;
 #endif
 
                                case 0x2000:
-                                       dissect_cdp(pd, offset+8, pinfo->fd, tree);
+                                       dissect_cdp(pd, offset, pinfo->fd, tree);
                                        break;
 
                                case 0x2001:
-                                       dissect_cgmp(pd, offset+8, pinfo->fd, tree);
+                                       dissect_cgmp(pd, offset, pinfo->fd, tree);
                                        break;
 
                                case 0x2003:
-                                       dissect_vtp(pd, offset+8, pinfo->fd, tree);
+                                       dissect_vtp(pd, offset, pinfo->fd, tree);
                                        break;
 
                                default:
-                                       dissect_data_tvb(tvb, pinfo, tree);
+                                       dissect_data_tvb(next_tvb, pinfo, tree);
                                        break;
                                }
                        } else
-                               dissect_data_tvb(tvb, pinfo, tree);
+                               dissect_data_tvb(next_tvb, pinfo, tree);
                        break;
 
                case OUI_CABLE_BPDU:    /* DOCSIS cable modem spanning tree BPDU */
@@ -407,7 +407,7 @@ dissect_llc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                                proto_tree_add_item(llc_tree,
                                hf_llc_pid, tvb, 6, 2, etype);
                        }
-                       dissect_bpdu(pd, offset+8, pinfo->fd, tree);
+                       dissect_bpdu(pd, offset, pinfo->fd, tree);
                        break;
 
                default:
@@ -415,7 +415,7 @@ dissect_llc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                                proto_tree_add_item(llc_tree,
                                    hf_llc_pid, tvb, 6, 2, etype);
                        }
-                       dissect_data_tvb(tvb, pinfo, tree);
+                       dissect_data_tvb(next_tvb, pinfo, tree);
                        break;
                }
        }
@@ -432,6 +432,7 @@ dissect_llc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                        );
                }
 
+               next_tvb = tvb_new_subset(tvb, llc_header_len, -1, -1);
                if (XDLC_IS_INFORMATION(control)) {
                        tvb_compat(tvb, &pd, &offset);
                        /* non-SNAP */
@@ -440,11 +441,10 @@ dissect_llc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                        /* do lookup with the subdissector table */
                        if (!dissector_try_port(subdissector_table, dsap,
                            pd, offset, pinfo->fd, tree)) {
-                               dissect_data_tvb(tvb, pinfo, tree);
+                               dissect_data_tvb(next_tvb, pinfo, tree);
                        }
                } else {
-                       next_tvb = tvb_new_subset(tvb, llc_header_len, -1);
-                       dissect_data_tvb(tvb, pinfo, tree);
+                       dissect_data_tvb(next_tvb, pinfo, tree);
                }
        }
 }