checkAPIs.pl: support for new-style dissectors in check_hf_entries
[metze/wireshark/wip.git] / epan / dissectors / packet-cmpp.c
index 59d2b7830c8069fce3865815bb1bd390b3eb9fd8..ca68869eecab6edc76ac2be8d2133aed834907fe 100644 (file)
@@ -2,41 +2,23 @@
  * Routines for China Mobile Point to Point dissection
  * Copyright 2007, Andy Chu <chu.dev@gmail.com>
  *
- * $Id$
- *
  * Wireshark - Network traffic analyzer
  * 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/wmem/wmem.h>
-#include <epan/dissectors/packet-tcp.h>
+#include "packet-tcp.h"
 
 #define CMPP_FIX_HEADER_LENGTH  12
 #define CMPP_DELIVER_REPORT_LEN 71
 
 /* These are not registered with IANA */
-#define CMPP_SP_LONG_PORT    7890
-#define CMPP_SP_SHORT_PORT   7900
-#define CMPP_ISMG_LONG_PORT  7930
-#define CMPP_ISMG_SHORT_PORT 9168
+#define CMPP_PORT_RANGE "7890,7900,7930,9168"
 
 void proto_register_cmpp(void);
 void proto_reg_handoff_cmpp(void);
@@ -151,6 +133,7 @@ static gboolean cmpp_desegment = TRUE;
 #define CMPP_PUSH_MT_ROUTE_UPDATE_RESP 0x80000015
 #define CMPP_PUSH_MO_ROUTE_UPDATE_RESP 0x80000016
 #define CMPP_GET_MO_ROUTE_RESP         0x80000017
+
 static const value_string vals_command_Id[] = {                /* Operation    */
        { CMPP_CONNECT,                   "CMPP_CONNECT" },
        { CMPP_CONNECT_RESP,              "CMPP_CONNECT_RESP" },
@@ -253,13 +236,12 @@ static gint ett_deliver_report = -1;
 
 /* Helper functions */
 
-static char*
+static const guint8*
 cmpp_octet_string(proto_tree *tree, tvbuff_t *tvb, gint field, gint offset, gint length)
 {
-       char *display;
+       const guint8 *display;
 
-       display = (char *)tvb_get_string(wmem_packet_scope(), tvb, offset, length);
-       proto_tree_add_string(tree, field, tvb, offset, length, display);
+       proto_tree_add_item_ret_string(tree, field, tvb, offset, length, ENC_ASCII, wmem_packet_scope(), &display);
        return display;
 }
 
@@ -549,7 +531,7 @@ dissect_cmpp_tcp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *
        const gchar *command_str; /* Header command string */
 
        /* Get the length of the PDU */
-       tvb_len = tvb_length(tvb);
+       tvb_len = tvb_captured_length(tvb);
        /* if the length of the tvb is shorder then the cmpp header length exit */
        if (tvb_len < CMPP_FIX_HEADER_LENGTH)
                return 0;
@@ -619,13 +601,13 @@ dissect_cmpp_tcp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *
                }
        }
 
-       return tvb_length(tvb);
+       return tvb_reported_length(tvb);
 }
 
 
 /* Get the CMPP PDU Length */
 static guint
-get_cmpp_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, gint offset)
+get_cmpp_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *data _U_)
 {
        return tvb_get_ntohl(tvb, offset);
 }
@@ -636,7 +618,7 @@ dissect_cmpp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
 {
        guint total_length, command_id, tvb_len;
        /* Check that there's enough data */
-       tvb_len = tvb_length(tvb);
+       tvb_len = tvb_captured_length(tvb);
        if (tvb_len < CMPP_FIX_HEADER_LENGTH)
                return 0;
 
@@ -660,7 +642,7 @@ dissect_cmpp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
                         get_cmpp_pdu_len, dissect_cmpp_tcp_pdu, data);
 
        /* Return the amount of data this dissector was able to dissect */
-       return tvb_length(tvb);
+       return tvb_reported_length(tvb);
 
 }
 
@@ -979,9 +961,19 @@ proto_reg_handoff_cmpp(void)
 {
        dissector_handle_t cmpp_handle;
 
-       cmpp_handle = new_create_dissector_handle(dissect_cmpp, proto_cmpp);
-       dissector_add_uint("tcp.port", CMPP_SP_LONG_PORT, cmpp_handle);
-       dissector_add_uint("tcp.port", CMPP_SP_SHORT_PORT, cmpp_handle);
-       dissector_add_uint("tcp.port", CMPP_ISMG_LONG_PORT, cmpp_handle);
-       dissector_add_uint("tcp.port", CMPP_ISMG_SHORT_PORT, cmpp_handle);
+       cmpp_handle = create_dissector_handle(dissect_cmpp, proto_cmpp);
+       dissector_add_uint_range_with_preference("tcp.port", CMPP_PORT_RANGE, cmpp_handle);
 }
+
+/*
+ * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 8
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * End:
+ *
+ * vi: set shiftwidth=8 tabstop=8 noexpandtab:
+ * :indentSize=8:tabSize=8:noTabs=false:
+ */