GTPv2: fix dissection of APN IE
[metze/wireshark/wip.git] / epan / dissectors / packet-ap1394.c
index 6c15804322b04f9c1c8568f71a987250dd19e376..2c7b73885646fab65af4506b16073c7036587ef9 100644 (file)
@@ -5,28 +5,16 @@
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
 #include "config.h"
 
 #include <epan/packet.h>
+#include <epan/capture_dissectors.h>
 #include <wsutil/pint.h>
 #include <epan/addr_resolv.h>
 
-#include "packet-ap1394.h"
 #include <epan/etypes.h>
 
 void proto_register_ap1394(void);
@@ -41,16 +29,13 @@ static gint ett_ap1394 = -1;
 
 static dissector_table_t ethertype_subdissector_table;
 
-static dissector_handle_t data_handle;
-
-void
-capture_ap1394(const guchar *pd, int offset, int len, packet_counts *ld)
+static gboolean
+capture_ap1394(const guchar *pd, int offset, int len, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header)
 {
   guint16    etype;
 
   if (!BYTES_ARE_IN_FRAME(offset, len, 18)) {
-    ld->other++;
-    return;
+    return FALSE;
   }
 
   /* Skip destination and source addresses */
@@ -58,32 +43,29 @@ capture_ap1394(const guchar *pd, int offset, int len, packet_counts *ld)
 
   etype = pntoh16(&pd[offset]);
   offset += 2;
-  capture_ethertype(etype, pd, offset, len, ld);
+  return try_capture_dissector("ethertype", etype, pd, offset, len, cpinfo, pseudo_header);
 }
 
-static void
-dissect_ap1394(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+static int
+dissect_ap1394(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
 {
   proto_item *ti;
   proto_tree *fh_tree = NULL;
-  const guint8 *src_addr, *dst_addr;
   guint16    etype;
   tvbuff_t *next_tvb;
 
   col_set_str(pinfo->cinfo, COL_PROTOCOL, "IP/IEEE1394");
   col_clear(pinfo->cinfo, COL_INFO);
 
-  src_addr=tvb_get_ptr(tvb, 8, 8);
-  TVB_SET_ADDRESS(&pinfo->dl_src,   AT_EUI64, tvb, 8, 8);
-  TVB_SET_ADDRESS(&pinfo->src,      AT_EUI64, tvb, 8, 8);
-  dst_addr=tvb_get_ptr(tvb, 0, 8);
-  TVB_SET_ADDRESS(&pinfo->dl_dst,   AT_EUI64, tvb, 0, 8);
-  TVB_SET_ADDRESS(&pinfo->dst,      AT_EUI64, tvb, 0, 8);
+  set_address_tvb(&pinfo->dl_src,   AT_EUI64, 8, tvb, 8);
+  copy_address_shallow(&pinfo->src, &pinfo->dl_src);
+  set_address_tvb(&pinfo->dl_dst,   AT_EUI64, 8, tvb, 0);
+  copy_address_shallow(&pinfo->dst, &pinfo->dl_dst);
 
   if (tree) {
     ti = proto_tree_add_protocol_format(tree, proto_ap1394, tvb, 0, 18,
                 "Apple IP-over-IEEE 1394, Src: %s, Dst: %s",
-                bytes_to_ep_str(src_addr, 8), bytes_to_ep_str(dst_addr, 8));
+                address_to_str(wmem_packet_scope(), &pinfo->src), address_to_str(wmem_packet_scope(), &pinfo->dst));
     fh_tree = proto_item_add_subtree(ti, ett_ap1394);
     proto_tree_add_item(fh_tree, hf_ap1394_dst, tvb, 0, 8, ENC_NA);
     proto_tree_add_item(fh_tree, hf_ap1394_src, tvb, 8, 8, ENC_NA);
@@ -93,7 +75,10 @@ dissect_ap1394(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
   next_tvb = tvb_new_subset_remaining(tvb, 18);
   if (!dissector_try_uint(ethertype_subdissector_table, etype, next_tvb,
                 pinfo, tree))
-    call_dissector(data_handle, next_tvb, pinfo, tree);
+  {
+      call_data_dissector(next_tvb, pinfo, tree);
+  }
+  return tvb_captured_length(tvb);
 }
 
 void
@@ -124,13 +109,15 @@ void
 proto_reg_handoff_ap1394(void)
 {
   dissector_handle_t ap1394_handle;
-
-  data_handle = find_dissector("data");
+  capture_dissector_handle_t ap1394_cap_handle;
 
   ethertype_subdissector_table = find_dissector_table("ethertype");
 
   ap1394_handle = create_dissector_handle(dissect_ap1394, proto_ap1394);
   dissector_add_uint("wtap_encap", WTAP_ENCAP_APPLE_IP_OVER_IEEE1394, ap1394_handle);
+
+  ap1394_cap_handle = create_capture_dissector_handle(capture_ap1394, proto_ap1394);
+  capture_dissector_add_uint("wtap_encap", WTAP_ENCAP_APPLE_IP_OVER_IEEE1394, ap1394_cap_handle);
 }
 
 /*