Add support for SDLC encapsulation in DOS Sniffer captures; that
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 3 Jan 2003 22:31:26 +0000 (22:31 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 3 Jan 2003 22:31:26 +0000 (22:31 +0000)
includes adding an SDLC dissector.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@6848 f5534014-38df-0310-8fa8-9805f1628bb7

Makefile.am
Makefile.nmake
packet-sdlc.c [new file with mode: 0644]
wiretap/ngsniffer.c
wiretap/wtap.c
wiretap/wtap.h

index 83ba7b6f255c08e916a7d8169989011b0573a922..f268d0875380dfc8ed0ef425f7c02779df1075fe 100644 (file)
@@ -1,7 +1,7 @@
 # Makefile.am
 # Automake file for Ethereal
 #
-# $Id: Makefile.am,v 1.532 2003/01/02 20:44:31 guy Exp $
+# $Id: Makefile.am,v 1.533 2003/01/03 22:31:23 guy Exp $
 #
 # Ethereal - Network traffic analyzer
 # By Gerald Combs <gerald@ethereal.com>
@@ -323,6 +323,7 @@ DISSECTOR_SRC = \
        packet-sccpmg.c  \
        packet-scsi.c  \
        packet-sctp.c  \
+       packet-sdlc.c  \
        packet-sdp.c   \
        packet-sip.c   \
        packet-skinny.c   \
index fb9ceb9f2798581c254124f00ce441630918030d..cf84db74794eff79e9c5a4a33bd5d7d67c8bbc5e 100644 (file)
@@ -1,7 +1,7 @@
 ## Makefile for building ethereal.exe with Microsoft C and nmake
 ## Use: $(MAKE) /$(MAKEFLAGS) -f makefile.nmake
 #
-# $Id: Makefile.nmake,v 1.266 2003/01/02 20:44:32 guy Exp $
+# $Id: Makefile.nmake,v 1.267 2003/01/03 22:31:24 guy Exp $
 
 include config.nmake
 include <win32.mak>
@@ -266,6 +266,7 @@ DISSECTOR_SRC = \
        packet-sccpmg.c  \
        packet-scsi.c  \
        packet-sctp.c  \
+       packet-sdlc.c  \
        packet-sdp.c   \
        packet-sip.c   \
        packet-skinny.c   \
diff --git a/packet-sdlc.c b/packet-sdlc.c
new file mode 100644 (file)
index 0000000..b485f97
--- /dev/null
@@ -0,0 +1,164 @@
+/* packet-sdlc.c
+ * Routines for SDLC frame disassembly
+ *
+ * $Id: packet-sdlc.c,v 1.1 2003/01/03 22:31:24 guy Exp $
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@ethereal.com>
+ * Copyright 1998
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <glib.h>
+#include <string.h>
+#include <epan/packet.h>
+#include "xdlc.h"
+
+/*
+ * See
+ *
+ *     http://www.protocols.com/pbook/sna.htm
+ */
+
+static int proto_sdlc = -1;
+static int hf_sdlc_address = -1;
+static int hf_sdlc_control = -1;
+
+static gint ett_sdlc = -1;
+static gint ett_sdlc_control = -1;
+
+static dissector_handle_t sna_handle;
+static dissector_handle_t data_handle;
+
+static void
+dissect_sdlc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+{
+       proto_tree      *sdlc_tree;
+       proto_item      *sdlc_ti;
+       guint8          address;
+       guint16         control;
+       int             sdlc_header_len;
+       gboolean        is_response;
+       tvbuff_t        *next_tvb;
+
+       if (check_col(pinfo->cinfo, COL_PROTOCOL))
+               col_set_str(pinfo->cinfo, COL_PROTOCOL, "SDLC");
+       if (check_col(pinfo->cinfo, COL_INFO))
+               col_clear(pinfo->cinfo, COL_INFO);
+
+       address = tvb_get_guint8(tvb, 0);
+       sdlc_header_len = 1;    /* address */
+
+       /*
+        * XXX - is there something in the SDLC header that indicates
+        * how to interpret "command vs. response" based on the
+        * direction?
+        */
+       if (pinfo->p2p_dir == P2P_DIR_SENT) {
+               is_response = FALSE;
+               if (check_col(pinfo->cinfo, COL_RES_DL_DST))
+                       col_set_str(pinfo->cinfo, COL_RES_DL_DST, "DCE");
+               if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
+                       col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "DTE");
+       }
+       else {
+               /* XXX - what if the direction is unknown? */
+               is_response = TRUE;
+               if (check_col(pinfo->cinfo, COL_RES_DL_DST))
+                   col_set_str(pinfo->cinfo, COL_RES_DL_DST, "DTE");
+               if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
+                   col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "DCE");
+       }
+
+       if (tree) {
+               sdlc_ti = proto_tree_add_item(tree, proto_sdlc, tvb, 0, -1,
+                   FALSE);
+               sdlc_tree = proto_item_add_subtree(sdlc_ti, ett_sdlc);
+
+               proto_tree_add_uint(sdlc_tree, hf_sdlc_address, tvb, 0, 1,
+                   address);
+       } else {
+               sdlc_ti = NULL;
+               sdlc_tree = NULL;
+       }
+
+       /*
+        * XXX - SDLC has a mod-128 mode as well as a mod-7 mode.
+        * We can infer the mode from an SNRM/SRME frame, but if
+        * we don't see one of them, we may have to have a preference
+        * to control what to use.
+        */
+       control = dissect_xdlc_control(tvb, 1, pinfo, sdlc_tree, hf_sdlc_control,
+           ett_sdlc_control, is_response, FALSE);
+       sdlc_header_len += XDLC_CONTROL_LEN(control, FALSE);
+
+       if (tree)
+               proto_item_set_len(sdlc_ti, sdlc_header_len);
+
+       /*
+        * XXX - is there an FCS at the end, at least in Sniffer
+        * captures?  (There doesn't appear to be.)
+        */
+       next_tvb = tvb_new_subset(tvb, sdlc_header_len, -1, -1);
+       if (XDLC_IS_INFORMATION(control)) {
+               /* call the SNA dissector */
+               call_dissector(sna_handle, next_tvb, pinfo, tree);
+       } else
+               call_dissector(data_handle, next_tvb, pinfo, tree);
+}
+
+void
+proto_register_sdlc(void)
+{
+       static hf_register_info hf[] = {
+               { &hf_sdlc_address,
+                 { "Address Field", "sdlc.address", FT_UINT8, BASE_HEX,
+                    NULL, 0x0, "Address", HFILL }},
+
+               { &hf_sdlc_control,
+                 { "Control Field", "sdlc.control", FT_UINT16, BASE_HEX,
+                   NULL, 0x0, "Control field", HFILL }},
+       };
+       static gint *ett[] = {
+               &ett_sdlc,
+               &ett_sdlc_control,
+       };
+
+       proto_sdlc = proto_register_protocol(
+           "Synchronous Data Link Control (SDLC)", "SDLC", "sdlc");
+       proto_register_field_array(proto_sdlc, hf, array_length(hf));
+       proto_register_subtree_array(ett, array_length(ett));
+}
+
+void
+proto_reg_handoff_sdlc(void)
+{
+       dissector_handle_t sdlc_handle;
+
+       /*
+        * Get handle for the SNA dissector.
+        */
+       sna_handle = find_dissector("sna");
+       data_handle = find_dissector("data");
+
+       sdlc_handle = create_dissector_handle(dissect_sdlc, proto_sdlc);
+       dissector_add("wtap_encap", WTAP_ENCAP_SDLC, sdlc_handle);
+}
index 08aa22c151d9accec01ee15647a4f8ca3b334458..8aaf5e0950cc3da1002a9a1637460c669d038c31 100644 (file)
@@ -1,6 +1,6 @@
 /* ngsniffer.c
  *
- * $Id: ngsniffer.c,v 1.98 2003/01/03 20:42:52 guy Exp $
+ * $Id: ngsniffer.c,v 1.99 2003/01/03 22:31:26 guy Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@@ -775,6 +775,10 @@ process_rec_header2_v45(wtap *wth, unsigned char *buffer, guint16 length,
         */
        switch (buffer[4]) {
 
+       case NET_SDLC:
+               wth->file_encap = WTAP_ENCAP_SDLC;
+               break;
+
        case NET_HDLC:
                wth->file_encap = WTAP_ENCAP_LAPB;
                break;
index 0c5351ab6531d2b4391a7a0b9a0d9fddb36a7fc8..f4f4f3c746436edcdcae78feb6078ced92d29e15 100644 (file)
@@ -1,6 +1,6 @@
 /* wtap.c
  *
- * $Id: wtap.c,v 1.76 2003/01/03 06:45:45 guy Exp $
+ * $Id: wtap.c,v 1.77 2003/01/03 22:31:26 guy Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@@ -157,6 +157,9 @@ static const struct encap_type_info {
 
        /* WTAP_ENCAP_WFLEET_HDLC */
        { "Wellfleet HDLC", "whdlc" },
+
+       /* WTAP_ENCAP_SDLC */
+       { "SDLC", "sdlc" },
 };
 
 /* Name that should be somewhat descriptive. */
index 8dc1b1f9235e9fc7d1c530b2b4761163a6bd37b1..edb1589da535af36510abe8230cd0ab49bf5e0c3 100644 (file)
@@ -1,6 +1,6 @@
 /* wtap.h
  *
- * $Id: wtap.h,v 1.128 2003/01/03 06:45:45 guy Exp $
+ * $Id: wtap.h,v 1.129 2003/01/03 22:31:26 guy Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
 #define WTAP_ENCAP_DOCSIS                      29
 #define WTAP_ENCAP_COSINE                      30
 #define WTAP_ENCAP_WLAN_HEADER                 31
-#define WTAP_ENCAP_WFLEET_HDLC                  32
+#define WTAP_ENCAP_WFLEET_HDLC                 32
+#define WTAP_ENCAP_SDLC                                33
 
 /* last WTAP_ENCAP_ value + 1 */
-#define WTAP_NUM_ENCAP_TYPES                   33
+#define WTAP_NUM_ENCAP_TYPES                   34
 
 /* File types that can be read by wiretap.
    We support writing some many of these file types, too, so we