Removed trailing whitespaces from .h and .c files using the
[obnox/wireshark/wip.git] / packet-llc.c
index e6f10670d37723579700245e980c56de03426316..a8dcd82f0818dcb110e12bc036048179a6e1df88 100644 (file)
@@ -2,7 +2,7 @@
  * Routines for IEEE 802.2 LLC layer
  * Gilbert Ramirez <gram@alumni.rice.edu>
  *
- * $Id: packet-llc.c,v 1.95 2002/01/21 07:36:37 guy Exp $
+ * $Id: packet-llc.c,v 1.99 2002/08/02 23:35:53 jmayer Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
 # include "config.h"
 #endif
 
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
 #include <glib.h>
 #include <epan/packet.h>
 #include "oui.h"
@@ -38,6 +34,7 @@
 #include "etypes.h"
 #include "llcsaps.h"
 #include "bridged_pids.h"
+#include "ppptypes.h"
 #include "packet-ip.h"
 #include "packet-ipx.h"
 #include "packet-netbios.h"
 
 #include "packet-llc.h"
 
+#define UDP_PORT_LLC1   12000
+#define UDP_PORT_LLC2   12001
+#define UDP_PORT_LLC3   12002
+#define UDP_PORT_LLC4   12003
+#define UDP_PORT_LLC5   12004
+
 static int proto_llc = -1;
 static int hf_llc_dsap = -1;
 static int hf_llc_ssap = -1;
@@ -67,17 +70,6 @@ static dissector_handle_t fddi_handle;
 static dissector_handle_t tr_handle;
 static dissector_handle_t data_handle;
 
-typedef void (capture_func_t)(const u_char *, int, int, packet_counts *);
-
-/* The SAP info is split into two tables, one value_string table and one
- * table of sap_info. This is so that the value_string can be used in the
- * header field registration.
- */
-struct sap_info {
-       guint8  sap;
-       capture_func_t *capture_func;
-};
-
 /*
  * Group/Individual bit, in the DSAP.
  */
@@ -145,13 +137,6 @@ static const value_string sap_vals[] = {
        { 0x00,               NULL }
 };
 
-static struct sap_info saps[] = {
-       { SAP_IP,                       capture_ip },
-       { SAP_NETWARE,                  capture_ipx },
-       { SAP_NETBIOS,                  capture_netbios },
-       { 0x00,                         NULL}
-};
-
 /*
  * See
  *
@@ -174,31 +159,14 @@ http://www.cisco.com/univercd/cc/td/doc/product/software/ios113ed/113ed_cr/ibm_r
        { 0,               NULL }
 };
 
-static capture_func_t *
-sap_capture_func(u_char sap) {
-       int i=0;
-
-       /* look for the second record where sap == 0, which should
-        * be the last record
-        */
-       while (saps[i].sap > 0 || i == 0) {
-               if (saps[i].sap == sap) {
-                       return saps[i].capture_func;
-               }
-               i++;
-       }
-       return NULL;
-}
-
 void
-capture_llc(const u_char *pd, int offset, int len, packet_counts *ld) {
+capture_llc(const guchar *pd, int offset, int len, packet_counts *ld) {
 
        int             is_snap;
        guint16         control;
        int             llc_header_len;
        guint32         oui;
        guint16         etype;
-       capture_func_t  *capture;
 
        if (!BYTES_ARE_IN_FRAME(offset, len, 2)) {
                ld->other++;
@@ -213,8 +181,7 @@ capture_llc(const u_char *pd, int offset, int len, packet_counts *ld) {
         * uses extended operation, so we don't need to determine
         * whether it's basic or extended operation; is that the case?
         */
-       control = get_xdlc_control(pd, offset+2, pd[offset+1] & SSAP_CR_BIT,
-           TRUE);
+       control = get_xdlc_control(pd, offset+2, pd[offset+1] & SSAP_CR_BIT);
        llc_header_len += XDLC_CONTROL_LEN(control, TRUE);
        if (is_snap)
                llc_header_len += 5;    /* 3 bytes of OUI, 2 bytes of protocol ID */
@@ -253,17 +220,26 @@ capture_llc(const u_char *pd, int offset, int len, packet_counts *ld) {
                }
        }               
        else {
+               /* non-SNAP */
                if (XDLC_IS_INFORMATION(control)) {
-                       capture = sap_capture_func(pd[offset]);
+                       switch (pd[offset]) {
 
-                       /* non-SNAP */
-                       offset += llc_header_len;
+                       case SAP_IP:
+                               capture_ip(pd, offset + llc_header_len, len,
+                                   ld);
+                               break;
 
-                       if (capture) {
-                               capture(pd, offset, len, ld);
-                       }
-                       else {
+                       case SAP_NETWARE:
+                               capture_ipx(ld);
+                               break;
+
+                       case SAP_NETBIOS:
+                               capture_netbios(ld);
+                               break;
+
+                       default:
                                ld->other++;
+                               break;
                        }
                }
        }
@@ -575,4 +551,12 @@ proto_reg_handoff_llc(void)
 
        llc_handle = find_dissector("llc");
        dissector_add("wtap_encap", WTAP_ENCAP_ATM_RFC1483, llc_handle);
+       /* RFC 2043 */
+       dissector_add("ppp.protocol", PPP_LLC, llc_handle);
+       /* RFC 2353 */
+       dissector_add("udp.port", UDP_PORT_LLC1, llc_handle);
+       dissector_add("udp.port", UDP_PORT_LLC2, llc_handle);
+       dissector_add("udp.port", UDP_PORT_LLC3, llc_handle);
+       dissector_add("udp.port", UDP_PORT_LLC4, llc_handle);
+       dissector_add("udp.port", UDP_PORT_LLC5, llc_handle);
 }