Removed trailing whitespaces from .h and .c files using the
[obnox/wireshark/wip.git] / packet-null.c
index 654eb72d2fcb7f801b46e543007fdb2633e7fa8f..851e5e79d22a263cc5c87413d3da7e7e2cdcbdf2 100644 (file)
@@ -1,12 +1,12 @@
 /* packet-null.c
  * Routines for null packet disassembly
  *
- * $Id: packet-null.c,v 1.43 2001/03/30 06:15:47 guy Exp $
+ * $Id: packet-null.c,v 1.55 2002/08/03 19:49:30 guy Exp $
  *
  * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * By Gerald Combs <gerald@ethereal.com>
  *
- * This file created and by Mike Hall <mlh@io.com>
+ * This file created by Mike Hall <mlh@io.com>
  * Copyright 1998
  * 
  * This program is free software; you can redistribute it and/or
 # include "config.h"
 #endif
 
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
 #include <glib.h>
 
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
 #include <string.h>
-#include "packet.h"
+#include <epan/packet.h>
 #include "packet-null.h"
-#include "atalk-utils.h"
+#include <epan/atalk-utils.h>
 #include "packet-ip.h"
-#include "packet-ipv6.h"
 #include "packet-ipx.h"
 #include "packet-osi.h"
 #include "packet-ppp.h"
@@ -52,8 +43,6 @@
 
 static dissector_table_t null_dissector_table;
 
-extern const value_string etype_vals[];
-
 /* protocols and header fields */
 static int proto_null = -1;
 static int hf_null_etype = -1;
@@ -71,13 +60,14 @@ static const value_string family_vals[] = {
     {BSD_AF_IPX,           "Netware IPX/SPX"},
     {BSD_AF_INET6_BSD,     "IPv6"           },
     {BSD_AF_INET6_FREEBSD, "IPv6"           },
+    {BSD_AF_INET6_DARWIN,  "IPv6"           }, 
     {0,                    NULL             }
 };
 
 static dissector_handle_t ppp_hdlc_handle;
-
+static dissector_handle_t data_handle;
 void
-capture_null( const u_char *pd, packet_counts *ld )
+capture_null( const guchar *pd, int len, packet_counts *ld )
 {
   guint32 null_header;
 
@@ -166,15 +156,23 @@ capture_null( const u_char *pd, packet_counts *ld )
    * given that the effect of inserting the two 0 bytes depends only
    * on the byte order of the machine reading the file.)
    */
+  if (!BYTES_ARE_IN_FRAME(0, len, 2)) {
+    ld->other++;
+    return;
+  }
   if (pd[0] == 0xFF && pd[1] == 0x03) {
     /*
      * Hand it to PPP.
      */
-    capture_ppp_hdlc(pd, 0, ld);
+    capture_ppp_hdlc(pd, 0, len, ld);
   } else {
     /*
      * Treat it as a normal DLT_NULL header.
      */
+    if (!BYTES_ARE_IN_FRAME(0, len, (int)sizeof(null_header))) {
+      ld->other++;
+      return;
+    }
     memcpy((char *)&null_header, (char *)&pd[0], sizeof(null_header));
 
     if ((null_header & 0xFFFF0000) != 0) {
@@ -193,12 +191,12 @@ capture_null( const u_char *pd, packet_counts *ld )
      * BSD derivatives have different values?).
      */
     if (null_header > IEEE_802_3_MAX_LEN)
-      capture_ethertype(null_header, 4, pd, ld);
+      capture_ethertype(null_header, pd, 4, len, ld);
     else {
       switch (null_header) {
 
       case BSD_AF_INET:
-        capture_ip(pd, 4, ld);
+        capture_ip(pd, 4, len, ld);
         break;
 
       default:
@@ -230,14 +228,14 @@ dissect_null(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
     /* load the top pane info. This should be overwritten by
        the next protocol in the stack */
-    if(check_col(pinfo->fd, COL_RES_DL_SRC))
-      col_set_str(pinfo->fd, COL_RES_DL_SRC, "N/A" );
-    if(check_col(pinfo->fd, COL_RES_DL_DST))
-      col_set_str(pinfo->fd, COL_RES_DL_DST, "N/A" );
-    if(check_col(pinfo->fd, COL_PROTOCOL))
-      col_set_str(pinfo->fd, COL_PROTOCOL, "N/A" );
-    if(check_col(pinfo->fd, COL_INFO))
-      col_set_str(pinfo->fd, COL_INFO, "Null/Loopback" );
+    if(check_col(pinfo->cinfo, COL_RES_DL_SRC))
+      col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "N/A" );
+    if(check_col(pinfo->cinfo, COL_RES_DL_DST))
+      col_set_str(pinfo->cinfo, COL_RES_DL_DST, "N/A" );
+    if(check_col(pinfo->cinfo, COL_PROTOCOL))
+      col_set_str(pinfo->cinfo, COL_PROTOCOL, "N/A" );
+    if(check_col(pinfo->cinfo, COL_INFO))
+      col_set_str(pinfo->cinfo, COL_INFO, "Null/Loopback" );
 
     /*
      * Treat it as a normal DLT_NULL header.
@@ -279,7 +277,7 @@ dissect_null(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
       if (!dissector_try_port(null_dissector_table, null_header,
            next_tvb, pinfo, tree)) {
         /* No sub-dissector found.  Label rest of packet as "Data" */
-        dissect_data(next_tvb, 0, pinfo, tree);
+        call_dissector(data_handle,next_tvb, pinfo, tree);
       }
     }
   }
@@ -293,11 +291,11 @@ proto_register_null(void)
                /* registered here but handled in ethertype.c */
                { &hf_null_etype,
                { "Type",               "null.type", FT_UINT16, BASE_HEX, VALS(etype_vals), 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_null_family,
                { "Family",             "null.family",  FT_UINT32, BASE_HEX, VALS(family_vals), 0x0,
-                       "" }}
+                       "", HFILL }}
        };
        static gint *ett[] = {
                &ett_null,
@@ -308,15 +306,20 @@ proto_register_null(void)
        proto_register_subtree_array(ett, array_length(ett));
 
        /* subdissector code */
-       null_dissector_table = register_dissector_table("null.type");
+       null_dissector_table = register_dissector_table("null.type",
+          "BSD AF_ type", FT_UINT32, BASE_DEC);
 }
 
 void
 proto_reg_handoff_null(void)
 {
+       dissector_handle_t null_handle;
+
        /*
         * Get a handle for the PPP-in-HDLC-like-framing dissector.
         */
        ppp_hdlc_handle = find_dissector("ppp_hdlc");
-       dissector_add("wtap_encap", WTAP_ENCAP_NULL, dissect_null, proto_null);
+       data_handle = find_dissector("data");
+       null_handle = create_dissector_handle(dissect_null, proto_null);
+       dissector_add("wtap_encap", WTAP_ENCAP_NULL, null_handle);
 }