Move some headers for stuff defined by a dissector into epan/dissectors
[obnox/wireshark/wip.git] / epan / dissectors / packet-cops.c
index 683d20bf8a086606fd25be82513c32f8d1b6eed6..8c3861a5e22643c3b0ee74515c0c7fbe79d2bf3b 100644 (file)
 #endif /* HAVE_NET_SNMP */
 #endif /* HAVE_SOME_SNMP */
 
-#include "asn1.h"
-#include "format-oid.h"
+#include <epan/asn1.h>
+#include <epan/dissectors/format-oid.h>
 #include <epan/prefs.h>
+#include <epan/emem.h>
 
 /* XXX - The "plain" COPS port (3288) can be overridden in the prefs.
    The PacketCable port cannot - should this be the case? */
@@ -156,7 +157,7 @@ struct _COPS_CNV
   guint class;
   guint tag;
   gint  syntax;
-  gchar *name;
+  const gchar *name;
 };
 
 static COPS_CNV CopsCnv [] =
@@ -174,7 +175,7 @@ static COPS_CNV CopsCnv [] =
   {0,       0,         -1,                  NULL}
 };
 
-static gchar *
+static const gchar *
 cops_tag_cls2syntax ( guint tag, guint cls, gushort *syntax)
 {
   COPS_CNV *cnv;
@@ -456,7 +457,7 @@ static const value_string table_cops_dqos_transaction_id[] =
   { 0xc,  "Gate Delete Err" },
   { 0xd,  "Gate Open" },
   { 0xe,  "Gate Close" },
-  { 0xFF, NULL },
+  { 0, NULL },
 };
 
 /* Direction */
@@ -464,7 +465,7 @@ static const value_string table_cops_direction[] =
 {
   { 0x0,  "Downstream gate" },
   { 0x1,  "Upstream gate" },
-  { 0xFF, NULL },
+  { 0, NULL },
 };
 
 /* Session Class */
@@ -474,7 +475,7 @@ static const value_string table_cops_session_class[] =
   { 0x1,  "Normal priority VoIP session" },
   { 0x2,  "High priority VoIP session" },
   { 0x3,  "Reserved" },
-  { 0xFF, NULL },
+  { 0, NULL },
 };
 
 /* Reason Code */
@@ -482,7 +483,7 @@ static const value_string table_cops_reason_code[] =
 {
   { 0x0,  "Gate Delete Operation" },
   { 0x1,  "Gate Close Operation" },
-  { 0xFF, NULL },
+  { 0, NULL },
 };
 
 /* Reason Sub Code - Delete */
@@ -495,7 +496,7 @@ static const value_string table_cops_reason_subcode_delete[] =
   { 0x4,  "Unexpected Gate-Open" },
   { 0x5,  "Local Gate-Close failure" },
   { 0x127,"Unspecified error" },
-  { 0xFF, NULL },
+  { 0, NULL },
 };
 
 /* Reason Sub Code - Close */
@@ -510,7 +511,7 @@ static const value_string table_cops_reason_subcode_close[] =
   { 0x6,  "Timer T7 expiration; Service Flow reservation timeout" },
   { 0x7,  "Timer T8 expiration; Service Flow inactivity in the upstream direction" },
   { 0x127,"Unspecified error" },
-  { 0xFF, NULL },
+  { 0, NULL },
 };
 
 /* PacketCable Error */
@@ -524,7 +525,7 @@ static const value_string table_cops_packetcable_error[] =
   { 0x6,  "Missing Required Object" },
   { 0x7,  "Invalid Object" },
   { 0x127,"Unspecified error" },
-  { 0xFF, NULL },
+  { 0, NULL },
 };
 
 
@@ -789,15 +790,15 @@ static void dissect_cops_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
 
 static int dissect_cops_object(tvbuff_t *tvb, packet_info *pinfo, guint8 op_code, guint32 offset, proto_tree *tree, guint16 client_type);
 static void dissect_cops_object_data(tvbuff_t *tvb, packet_info *pinfo, guint32 offset, proto_tree *tree,
-                                     guint8 op_code, guint16 client_type, guint8 c_num, guint8 c_type, guint16 len);
+                                     guint8 op_code, guint16 client_type, guint8 c_num, guint8 c_type, int len);
 
-static void dissect_cops_pr_objects(tvbuff_t *tvb, guint32 offset, proto_tree *tree, guint16 pr_len);
+static void dissect_cops_pr_objects(tvbuff_t *tvb, guint32 offset, proto_tree *tree, int pr_len);
 static int dissect_cops_pr_object_data(tvbuff_t *tvb, guint32 offset, proto_tree *tree,
-                                       guint8 s_num, guint8 s_type, guint16 len);
+                                       guint8 s_num, guint8 s_type, int len);
 
 /* Added for PacketCable */
-static proto_tree *info_to_cops_subtree(tvbuff_t *, proto_tree *, int, int, char *);
-static proto_item *info_to_display(tvbuff_t *, proto_item *, int, int, char *, const value_string *, int, gint *);
+static proto_tree *info_to_cops_subtree(tvbuff_t *, proto_tree *, int, int, const char *);
+static proto_item *info_to_display(tvbuff_t *, proto_item *, int, int, const char *, const value_string *, int, gint *);
 
 static void cops_transaction_id(tvbuff_t *, packet_info *, proto_tree *, guint8, guint, guint32);
 static void cops_subscriber_id_v4(tvbuff_t *, proto_tree *, guint, guint32);
@@ -906,7 +907,7 @@ dissect_cops_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
   }
 }
 
-static char *cops_c_type_to_str(guint8 c_num, guint8 c_type)
+static const char *cops_c_type_to_str(guint8 c_num, guint8 c_type)
 {
   switch (c_num) {
   case COPS_OBJ_HANDLE:
@@ -965,11 +966,11 @@ static char *cops_c_type_to_str(guint8 c_num, guint8 c_type)
 
 static int dissect_cops_object(tvbuff_t *tvb, packet_info *pinfo, guint8 op_code, guint32 offset, proto_tree *tree, guint16 client_type)
 {
-  guint16 object_len, contents_len;
+  int object_len, contents_len;
   guint8 c_num, c_type;
   proto_item *ti;
   proto_tree *obj_tree;
-  char *type_str;
+  const char *type_str;
 
   object_len = tvb_get_ntohs(tvb, offset);
   if (object_len < COPS_OBJECT_HDR_SIZE) {
@@ -1011,11 +1012,11 @@ static int dissect_cops_object(tvbuff_t *tvb, packet_info *pinfo, guint8 op_code
   return object_len;
 }
 
-static void dissect_cops_pr_objects(tvbuff_t *tvb, guint32 offset, proto_tree *tree, guint16 pr_len)
+static void dissect_cops_pr_objects(tvbuff_t *tvb, guint32 offset, proto_tree *tree, int pr_len)
 {
-  guint16 object_len, contents_len;
+  int object_len, contents_len;
   guint8 s_num, s_type;
-  char *type_str;
+  const char *type_str;
   int ret;
   proto_tree *cops_pr_tree, *obj_tree;
   proto_item *ti;
@@ -1070,7 +1071,7 @@ static void dissect_cops_pr_objects(tvbuff_t *tvb, guint32 offset, proto_tree *t
 }
 
 static void dissect_cops_object_data(tvbuff_t *tvb, packet_info *pinfo, guint32 offset, proto_tree *tree,
-                                     guint8 op_code, guint16 client_type, guint8 c_num, guint8 c_type, guint16 len)
+                                     guint8 op_code, guint16 client_type, guint8 c_num, guint8 c_type, int len)
 {
   proto_item *ti;
   proto_tree *r_type_tree, *itf_tree, *reason_tree, *dec_tree, *error_tree, *clientsi_tree, *pdp_tree;
@@ -1095,7 +1096,7 @@ static void dissect_cops_object_data(tvbuff_t *tvb, packet_info *pinfo, guint32
   case COPS_OBJ_IN_INT:
   case COPS_OBJ_OUT_INT:
     if (c_type == 1) {          /* IPv4 */
-      tvb_memcpy(tvb, (guint8 *)&ipv4addr, offset, 4);
+      ipv4addr = tvb_get_ipv4(tvb, offset);
       ifindex = tvb_get_ntohl(tvb, offset + 4);
       ti = proto_tree_add_text(tree, tvb, offset, 8, "Contents: IPv4 address %s, ifIndex: %u",
                                ip_to_str((guint8 *)&ipv4addr), ifindex);
@@ -1105,7 +1106,7 @@ static void dissect_cops_object_data(tvbuff_t *tvb, packet_info *pinfo, guint32
                           tvb, offset, 4, ipv4addr);
       offset += 4;
     } else if (c_type == 2) {   /* IPv6 */
-      tvb_memcpy(tvb, (guint8 *)&ipv6addr, offset, sizeof ipv6addr);
+      tvb_get_ipv6(tvb, offset, &ipv6addr);
       ifindex = tvb_get_ntohl(tvb, offset + sizeof ipv6addr);
       ti = proto_tree_add_text(tree, tvb, offset, 20, "Contents: IPv6 address %s, ifIndex: %u",
                                ip6_to_str(&ipv6addr), ifindex);
@@ -1149,7 +1150,7 @@ static void dissect_cops_object_data(tvbuff_t *tvb, packet_info *pinfo, guint32
       offset += 2;
       proto_tree_add_uint(dec_tree, hf_cops_dec_flags, tvb, offset, 2, cmd_flags);
     } else if (c_type == 5) { /*COPS-PR Data*/
-      ti = proto_tree_add_text(tree, tvb, offset, 4, "Contents: %u bytes", len);
+      ti = proto_tree_add_text(tree, tvb, offset, 4, "Contents: %d bytes", len);
       dec_tree = proto_item_add_subtree(ti, ett_cops_decision);
       dissect_cops_pr_objects(tvb, offset, dec_tree, len);
     }
@@ -1195,7 +1196,7 @@ static void dissect_cops_object_data(tvbuff_t *tvb, packet_info *pinfo, guint32
     if (c_type != 2) /*Not COPS-PR data*/
       break;
 
-    ti = proto_tree_add_text(tree, tvb, offset, 4, "Contents: %u bytes", len);
+    ti = proto_tree_add_text(tree, tvb, offset, 4, "Contents: %d bytes", len);
     clientsi_tree = proto_item_add_subtree(ti, ett_cops_clientsi);
 
     dissect_cops_pr_objects(tvb, offset, clientsi_tree, len);
@@ -1231,7 +1232,7 @@ static void dissect_cops_object_data(tvbuff_t *tvb, packet_info *pinfo, guint32
   case COPS_OBJ_PDPREDIRADDR:
   case COPS_OBJ_LASTPDPADDR:
     if (c_type == 1) {          /* IPv4 */
-      tvb_memcpy(tvb, (guint8 *)&ipv4addr, offset, 4);
+      ipv4addr = tvb_get_ipv4(tvb, offset);
       tcp_port = tvb_get_ntohs(tvb, offset + 4 + 2);
       ti = proto_tree_add_text(tree, tvb, offset, 8, "Contents: IPv4 address %s, TCP Port Number: %u",
                                ip_to_str((guint8 *)&ipv4addr), tcp_port);
@@ -1241,7 +1242,7 @@ static void dissect_cops_object_data(tvbuff_t *tvb, packet_info *pinfo, guint32
                           tvb, offset, 4, ipv4addr);
       offset += 4;
     } else if (c_type == 2) {   /* IPv6 */
-      tvb_memcpy(tvb, (guint8 *)&ipv6addr, offset, sizeof ipv6addr);
+      tvb_get_ipv6(tvb, offset, &ipv6addr);
       tcp_port = tvb_get_ntohs(tvb, offset + sizeof ipv6addr + 2);
       ti = proto_tree_add_text(tree, tvb, offset, 20, "Contents: IPv6 address %s, TCP Port Number: %u",
                                ip6_to_str(&ipv6addr), tcp_port);
@@ -1277,7 +1278,7 @@ static void dissect_cops_object_data(tvbuff_t *tvb, packet_info *pinfo, guint32
 
     break;
   default:
-    proto_tree_add_text(tree, tvb, offset, len, "Contents: %u bytes", len);
+    proto_tree_add_text(tree, tvb, offset, len, "Contents: %d bytes", len);
 
     break;
   }
@@ -1300,7 +1301,7 @@ static guchar*format_asn_value (struct variable_list *variable, subid_t *variabl
     variable->type= type_from_packet;
 
   buf_len = SPRINT_MAX_LEN; /*defined in NET-SNMP's snmp-impl.h*/
-  buf = g_malloc(buf_len);
+  buf = ep_alloc(buf_len);
   *buf = '\0';
   out_len = 0;
 
@@ -1309,7 +1310,7 @@ static guchar*format_asn_value (struct variable_list *variable, subid_t *variabl
     variable->type=mib_to_asn_type(subtree->type);
 
   if (!sprint_realloc_by_type(&buf, &buf_len, &out_len, TRUE, variable, subtree->enums, subtree->hint, NULL))
-    sprintf(buf,"%s","sprint_realloc_by_type failed");
+    g_snprintf(buf,SPRINT_MAX_LEN,"%s","sprint_realloc_by_type failed");
 
   return buf;
 }
@@ -1329,7 +1330,7 @@ static int decode_cops_pr_asn1_data(tvbuff_t *tvb, guint32 offset,
 
   guint vb_length;
   gushort vb_type;
-  gchar *vb_type_name;
+  const gchar *vb_type_name;
 
   int ret;
   guint cls, con, tag;
@@ -1353,7 +1354,6 @@ static int decode_cops_pr_asn1_data(tvbuff_t *tvb, guint32 offset,
 
   unsigned int i;
   gchar *buf;
-  int len;
 
   while (asnlen > 0) { /*while there is ASN stuff to be decoded*/
 
@@ -1406,7 +1406,6 @@ static int decode_cops_pr_asn1_data(tvbuff_t *tvb, guint32 offset,
 
           proto_tree_add_text(tree, asn1.tvb, offset, length,
                               "Value: %s", vb_display_string);
-          g_free(vb_display_string);
         }
         else
 #endif /* HAVE_NET_SNMP */
@@ -1436,7 +1435,6 @@ static int decode_cops_pr_asn1_data(tvbuff_t *tvb, guint32 offset,
 
           proto_tree_add_text(tree, asn1.tvb, offset, length, "Value %s: %s",vb_type_name, vb_display_string);
 
-          g_free(vb_display_string);
         }
         else
 #endif /* HAVE_NET_SNMP */
@@ -1467,7 +1465,6 @@ static int decode_cops_pr_asn1_data(tvbuff_t *tvb, guint32 offset,
           proto_tree_add_text(tree, asn1.tvb, offset, length,
                               "Value: %s (ASN.1 type from packet: %s)", vb_display_string, vb_type_name);
 
-          g_free(vb_display_string);
         }
         else
         {
@@ -1485,17 +1482,14 @@ static int decode_cops_pr_asn1_data(tvbuff_t *tvb, guint32 offset,
              * We stopped, due to a non-printable character, before we got
              * to the end of the string.
              */
-            vb_display_string = g_malloc(4*vb_length);
-            buf = &vb_display_string[0];
-            len = sprintf(buf, "%03u", vb_octet_string[0]);
-            buf += len;
+            vb_display_string = ep_alloc(4*vb_length);
+            buf = vb_display_string;
+            buf += g_snprintf(buf, 4*vb_length, "%03u", vb_octet_string[0]);
             for (i = 1; i < vb_length; i++) {
-              len = sprintf(buf, ".%03u", vb_octet_string[i]);
-              buf += len;
+              buf += g_snprintf(buf, 4*vb_length-(buf-vb_display_string), ".%03u", vb_octet_string[i]);
             }
             proto_tree_add_text(tree, asn1.tvb, offset, length,
                                 "Value: %s: %s", vb_type_name, vb_display_string);
-            g_free(vb_display_string);
           } else {
             proto_tree_add_text(tree, asn1.tvb, offset, length,
                                 "Value: %s: %.*s", vb_type_name, (int)vb_length,
@@ -1564,16 +1558,12 @@ static int decode_cops_pr_asn1_data(tvbuff_t *tvb, guint32 offset,
           last_decoded_prid_oid_length=vb_oid_length;
         }
 #endif /* HAVE_NET_SNMP */
-
-      g_free(vb_display_string);
-      if(vb_display_string2)
-        g_free(vb_display_string2);
       }
       g_free(vb_oid);
       break;
 
     default:
-      g_assert_not_reached();
+      DISSECTOR_ASSERT_NOT_REACHED();
       return ASN1_ERR_WRONG_TYPE;
     }
 
@@ -1586,7 +1576,7 @@ static int decode_cops_pr_asn1_data(tvbuff_t *tvb, guint32 offset,
 }
 
 static int dissect_cops_pr_object_data(tvbuff_t *tvb, guint32 offset, proto_tree *tree,
-                                       guint8 s_num, guint8 s_type, guint16 len)
+                                       guint8 s_num, guint8 s_type, int len)
 {
   proto_item *ti;
   proto_tree *asn1_object_tree, *gperror_tree, *cperror_tree;
@@ -1674,7 +1664,7 @@ static int dissect_cops_pr_object_data(tvbuff_t *tvb, guint32 offset, proto_tree
 
     break;
   default:
-    proto_tree_add_text(tree, tvb, offset, len, "Contents: %u bytes", len);
+    proto_tree_add_text(tree, tvb, offset, len, "Contents: %d bytes", len);
     break;
   }
 
@@ -1756,22 +1746,22 @@ void proto_register_cops(void)
     },
     { &hf_cops_in_int_ipv4,
       { "IPv4 address",           "cops.in-int.ipv4",
-      FT_IPv4, 0, NULL, 0xFFFF,
+      FT_IPv4, 0, NULL, 0,
       "IPv4 address in COPS IN-Int object", HFILL }
     },
     { &hf_cops_in_int_ipv6,
       { "IPv6 address",           "cops.in-int.ipv6",
-      FT_IPv6, 0, NULL, 0xFFFF,
+      FT_IPv6, 0, NULL, 0,
       "IPv6 address in COPS IN-Int object", HFILL }
     },
     { &hf_cops_out_int_ipv4,
       { "IPv4 address",           "cops.out-int.ipv4",
-      FT_IPv4, 0, NULL, 0xFFFF,
+      FT_IPv4, 0, NULL, 0,
       "IPv4 address in COPS OUT-Int object", HFILL }
     },
     { &hf_cops_out_int_ipv6,
       { "IPv6 address",           "cops.out-int.ipv6",
-      FT_IPv6, 0, NULL, 0xFFFF,
+      FT_IPv6, 0, NULL, 0,
       "IPv6 address in COPS OUT-Int", HFILL }
     },
     { &hf_cops_int_ifindex,
@@ -1826,22 +1816,22 @@ void proto_register_cops(void)
     },
     { &hf_cops_pdprediraddr_ipv4,
       { "IPv4 address",           "cops.pdprediraddr.ipv4",
-      FT_IPv4, 0, NULL, 0xFFFF,
+      FT_IPv4, 0, NULL, 0,
       "IPv4 address in COPS PDPRedirAddr object", HFILL }
     },
     { &hf_cops_pdprediraddr_ipv6,
       { "IPv6 address",           "cops.pdprediraddr.ipv6",
-      FT_IPv6, 0, NULL, 0xFFFF,
+      FT_IPv6, 0, NULL, 0,
       "IPv6 address in COPS PDPRedirAddr object", HFILL }
     },
     { &hf_cops_lastpdpaddr_ipv4,
       { "IPv4 address",           "cops.lastpdpaddr.ipv4",
-      FT_IPv4, 0, NULL, 0xFFFF,
+      FT_IPv4, 0, NULL, 0,
       "IPv4 address in COPS LastPDPAddr object", HFILL }
     },
     { &hf_cops_lastpdpaddr_ipv6,
       { "IPv6 address",           "cops.lastpdpaddr.ipv6",
-      FT_IPv6, 0, NULL, 0xFFFF,
+      FT_IPv6, 0, NULL, 0,
       "IPv6 address in COPS LastPDPAddr object", HFILL }
     },
     { &hf_cops_pdp_tcp_port,
@@ -2217,12 +2207,12 @@ void proto_register_cops(void)
     },
     { &hf_cops_pcmm_classifier_src_addr,
            { "Source address", "cops.pc_mm_classifier_src_addr",
-           FT_IPv4, 0, NULL, 0xFFFF,
+           FT_IPv4, 0, NULL, 0,
            "PacketCable Multimedia Classifier Source IP Address", HFILL }
     },
     { &hf_cops_pcmm_classifier_dst_addr,
            { "Destination address", "cops.pc_mm_classifier_dst_addr",
-           FT_IPv4, 0, NULL, 0xFFFF,
+           FT_IPv4, 0, NULL, 0,
            "PacketCable Multimedia Classifier Destination IP Address", HFILL }
     },
     { &hf_cops_pcmm_classifier_src_port,
@@ -2498,11 +2488,12 @@ void proto_reg_handoff_cops(void)
  */
 
 static proto_item *
-info_to_display(tvbuff_t *tvb, proto_item *stt, int offset, int octets, char *str, const value_string *vsp, int mode,gint *hf_proto_parameter)
+info_to_display(tvbuff_t *tvb, proto_item *stt, int offset, int octets, const char *str, const value_string *vsp, int mode,gint *hf_proto_parameter)
 {
      proto_item *pi = NULL;
      guint8   code8  = 0;
      guint16  code16 = 0;
+     guint32  codeipv4 = 0;
      guint32  code32 = 0;
      float    codefl = 0.0;
 
@@ -2568,7 +2559,7 @@ info_to_display(tvbuff_t *tvb, proto_item *stt, int offset, int octets, char *st
              switch (mode) {
                case FMT_FLT:  codefl  = tvb_get_ntohieee_float(tvb,offset);
                               break;
-               case FMT_IPv4: tvb_memcpy(tvb, (guint8 *)&code32, offset, 4);
+               case FMT_IPv4: codeipv4 = tvb_get_ipv4(tvb, offset);
                               break;
                default:       code32  = tvb_get_ntohl(tvb,offset);
             }
@@ -2582,7 +2573,7 @@ info_to_display(tvbuff_t *tvb, proto_item *stt, int offset, int octets, char *st
                 }
                 /* Ip address format*/
                 if (mode==FMT_IPv4) {
-                   pi = proto_tree_add_ipv4(stt, *hf_proto_parameter,tvb, offset, octets, code32);
+                   pi = proto_tree_add_ipv4(stt, *hf_proto_parameter,tvb, offset, octets, codeipv4);
                    break;
                 }
                 /* Ieee float format */
@@ -2627,7 +2618,7 @@ info_to_display(tvbuff_t *tvb, proto_item *stt, int offset, int octets, char *st
 
 /* Print the subtree information for cops */
 static proto_tree *
-info_to_cops_subtree(tvbuff_t *tvb, proto_tree *st, int n, int offset, char *str) {
+info_to_cops_subtree(tvbuff_t *tvb, proto_tree *st, int n, int offset, const char *str) {
      proto_item *tv;
 
      tv  = proto_tree_add_uint_format( st, hf_cops_subtree, tvb, offset, n, (guint)NULL, str);
@@ -2644,6 +2635,7 @@ cops_transaction_id(tvbuff_t *tvb, packet_info *pinfo, proto_tree *st, guint8 op
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"D-QoS Transaction ID");
+     offset += 4;
 
      /* Transaction Identifier */
      info_to_display(tvb,stt,offset,2,"D-QoS Transaction Identifier", NULL,FMT_DEC,&hf_cops_pc_transaction_id);
@@ -2656,7 +2648,7 @@ cops_transaction_id(tvbuff_t *tvb, packet_info *pinfo, proto_tree *st, guint8 op
             val_to_str(code16,table_cops_dqos_transaction_id, "Unknown (0x%04x)"),code16);
 
      /* Write the right data into the 'info field' on the Gui */
-     sprintf(info,"COPS %-20s - ",val_to_str(op_code,cops_op_code_vals, "Unknown"));
+     g_snprintf(info,sizeof(info),"COPS %-20s - ",val_to_str(op_code,cops_op_code_vals, "Unknown"));
      strcat(info,val_to_str(code16,table_cops_dqos_transaction_id, "Unknown"));
 
      if (check_col(pinfo->cinfo, COL_INFO)) {
@@ -2674,6 +2666,7 @@ cops_subscriber_id_v4(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offset) {
 
      /* Create a subtree */
      tv = info_to_cops_subtree(tvb,st,n,offset,"Subscriber ID (IPv4)");
+     offset += 4;
 
      /* Subscriber Identifier */
      info_to_display(tvb,tv,offset,4,"Subscriber Identifier (IPv4)", NULL,FMT_IPv4,&hf_cops_pc_subscriber_id_ipv4);
@@ -2687,6 +2680,7 @@ cops_subscriber_id_v6(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offset) {
 
      /* Create a subtree */
      tv = info_to_cops_subtree(tvb,st,n,offset,"Subscriber ID (IPv6)");
+     offset += 4;
 
      /* Subscriber Identifier */
      info_to_display(tvb,tv,offset,16,"Subscriber Identifier (IPv6)", NULL,FMT_IPv6,&hf_cops_pc_subscriber_id_ipv6);
@@ -2700,6 +2694,7 @@ cops_gate_id(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offset) {
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Gate ID");
+     offset += 4;
 
      /* Gate Identifier */
      info_to_display(tvb,stt,offset,4,"Gate Identifier", NULL,FMT_HEX,&hf_cops_pc_gate_id);
@@ -2713,6 +2708,7 @@ cops_activity_count(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offset) {
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Activity Count");
+     offset += 4;
 
      /* Activity Count */
      info_to_display(tvb,stt,offset,4,"Count", NULL,FMT_DEC,&hf_cops_pc_activity_count);
@@ -2726,6 +2722,7 @@ cops_gate_specs(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offset) {
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Gate Specifications");
+     offset += 4;
 
      /* Direction */
      info_to_display(tvb,stt,offset,1,"Direction",table_cops_direction,FMT_DEC,&hf_cops_pc_direction);
@@ -2819,6 +2816,7 @@ cops_surveillance_parameters(tvbuff_t *tvb, proto_tree *st, guint n, guint32 off
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Electronic Surveillance Parameters");
+     offset += 4;
 
      /* DF IP Address for CDC */
      info_to_display(tvb,stt,offset,4,"DF IP Address for CDC", NULL,FMT_IPv4,&hf_cops_pc_dfcdc_ip);
@@ -2853,12 +2851,12 @@ cops_surveillance_parameters(tvbuff_t *tvb, proto_tree *st, guint n, guint32 off
      offset += 4;
 
      /* BCID Element ID */
-     bcid_str = tvb_get_string(tvb, offset, 8);
+     bcid_str = tvb_format_text(tvb, offset, 8);
      proto_tree_add_text(stt, tvb, offset, 8,"%-28s : '%s'","BCID - Element ID",bcid_str);
      offset += 8;
 
      /* BCID Time Zone */
-     bcid_str = tvb_get_string(tvb, offset, 8);
+     bcid_str = tvb_format_text(tvb, offset, 8);
      proto_tree_add_text(stt, tvb, offset, 8,"%-28s : '%s'","BCID - Time Zone",bcid_str);
      offset += 8;
 
@@ -2875,6 +2873,7 @@ cops_event_generation_info(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offse
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Event Generation Info");
+     offset += 4;
 
      /* Primary Record Keeping Server IP Address */
      info_to_display(tvb,stt,offset,4,"PRKS IP Address", NULL,FMT_IPv4,&hf_cops_pc_prks_ip);
@@ -2913,12 +2912,12 @@ cops_event_generation_info(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offse
      offset += 4;
 
      /* BCID Element ID */
-     bcid_str = tvb_get_string(tvb, offset, 8);
+     bcid_str = tvb_format_text(tvb, offset, 8);
      proto_tree_add_text(stt, tvb, offset, 8,"%-28s : '%s'","BCID - Element ID",bcid_str);
      offset += 8;
 
      /* BCID Time Zone */
-     bcid_str = tvb_get_string(tvb, offset, 8);
+     bcid_str = tvb_format_text(tvb, offset, 8);
      proto_tree_add_text(stt, tvb, offset, 8,"%-28s : '%s'","BCID - Time Zone",bcid_str);
      offset += 8;
 
@@ -2934,6 +2933,7 @@ cops_remote_gate_info(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offset) {
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Remote Gate Info");
+     offset += 4;
 
      /* CMTS IP Address */
      info_to_display(tvb,stt,offset,4,"CMTS IP Address", NULL,FMT_IPv4,&hf_cops_pc_cmts_ip);
@@ -2984,6 +2984,7 @@ cops_packetcable_reason(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offset)
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"PacketCable Reason");
+     offset += 4;
 
      /* Reason Code */
      code16 = tvb_get_ntohs(tvb,offset);
@@ -3009,6 +3010,7 @@ cops_packetcable_error(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offset) {
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"PacketCable Error");
+     offset += 4;
 
      /* Error Code */
      info_to_display(tvb,stt,offset,2,"Error Code",table_cops_packetcable_error,FMT_DEC,&hf_cops_pc_packetcable_err_code);
@@ -3029,6 +3031,7 @@ cops_mm_transaction_id(tvbuff_t *tvb, packet_info *pinfo, proto_tree *st, guint8
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"MM Transaction ID");
+     offset += 4;
 
      /* Transaction Identifier */
      info_to_display(tvb,stt,offset,2,"Multimedia Transaction Identifier", NULL,FMT_DEC,&hf_cops_pc_transaction_id);
@@ -3041,7 +3044,7 @@ cops_mm_transaction_id(tvbuff_t *tvb, packet_info *pinfo, proto_tree *st, guint8
             val_to_str(code16,table_cops_mm_transaction_id, "Unknown (0x%04x)"),code16);
 
      /* Write the right data into the 'info field' on the Gui */
-     sprintf(info,"COPS %-20s - ",val_to_str(op_code,cops_op_code_vals, "Unknown"));
+     g_snprintf(info,sizeof(info),"COPS %-20s - ",val_to_str(op_code,cops_op_code_vals, "Unknown"));
      strcat(info,val_to_str(code16,table_cops_mm_transaction_id, "Unknown"));
 
      if (check_col(pinfo->cinfo, COL_INFO)) {
@@ -3059,6 +3062,7 @@ cops_amid(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offset) {
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"AMID");
+     offset += 4;
 
      /* Gate Identifier */
      info_to_display(tvb,stt,offset,4,"Application Manager ID", NULL,FMT_DEC,&hf_cops_pcmm_amid);
@@ -3074,6 +3078,7 @@ cops_mm_gate_spec(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offset) {
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Gate Spec");
+     offset += 4;
 
      /* Flags */
      gs_flags = tvb_get_guint8(tvb, offset);
@@ -3128,6 +3133,7 @@ cops_classifier(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offset) {
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Classifier");
+     offset += 4;
 
      /* Protocol ID */
      info_to_display(tvb,stt,offset,2,"Protocol ID",NULL,FMT_DEC,&hf_cops_pcmm_classifier_protocol_id);
@@ -3173,6 +3179,7 @@ cops_flow_spec(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offset) {
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Flow Spec");
+     offset += 4;
 
      /* Envelope */
      info_to_display(tvb,stt,offset,1,"Envelope",NULL,FMT_DEC,&hf_cops_pcmm_flow_spec_envelope);
@@ -3294,6 +3301,7 @@ cops_docsis_service_class_name(tvbuff_t *tvb, proto_tree *st, guint object_len,
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,object_len,offset,"DOCSIS Service Class Name");
+     offset += 4;
 
      /* Envelope */
      info_to_display(tvb,stt,offset,1,"Envelope",NULL,FMT_DEC,&hf_cops_pcmm_envelope);
@@ -3318,6 +3326,7 @@ cops_best_effort_service(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offset)
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Best Effort Service");
+     offset += 4;
 
      /* Envelope */
      info_to_display(tvb,stt,offset,1,"Envelope",NULL,FMT_DEC,&hf_cops_pcmm_envelope);
@@ -3444,6 +3453,7 @@ cops_non_real_time_polling_service(tvbuff_t *tvb, proto_tree *st, guint n, guint
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Non-Real-Time Polling Service");
+     offset += 4;
 
      /* Envelope */
      info_to_display(tvb,stt,offset,1,"Envelope",NULL,FMT_DEC,&hf_cops_pcmm_envelope);
@@ -3582,6 +3592,7 @@ cops_real_time_polling_service(tvbuff_t *tvb, proto_tree *st, guint n, guint32 o
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Real-Time Polling Service");
+     offset += 4;
 
      /* Envelope */
      info_to_display(tvb,stt,offset,1,"Envelope",NULL,FMT_DEC,&hf_cops_pcmm_envelope);
@@ -3711,6 +3722,7 @@ cops_unsolicited_grant_service(tvbuff_t *tvb, proto_tree *st, guint n, guint32 o
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Unsolicited Grant Service");
+     offset += 4;
 
      /* Envelope */
      info_to_display(tvb,stt,offset,1,"Envelope",NULL,FMT_DEC,&hf_cops_pcmm_envelope);
@@ -3813,6 +3825,7 @@ cops_ugs_with_activity_detection(tvbuff_t *tvb, proto_tree *st, guint n, guint32
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Unsolicited Grant Service with Activity Detection");
+     offset += 4;
 
      /* Envelope */
      info_to_display(tvb,stt,offset,1,"Envelope",NULL,FMT_DEC,&hf_cops_pcmm_envelope);
@@ -3939,6 +3952,7 @@ cops_downstream_service(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offset)
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Downstream Service");
+     offset += 4;
 
      /* Envelope */
      info_to_display(tvb,stt,offset,1,"Envelope",NULL,FMT_DEC,&hf_cops_pcmm_envelope);
@@ -4066,6 +4080,7 @@ cops_mm_event_generation_info(tvbuff_t *tvb, proto_tree *st, guint n, guint32 of
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Event Generation Info");
+     offset += 4;
 
      /* Primary Record Keeping Server IP Address */
      info_to_display(tvb,stt,offset,4,"PRKS IP Address", NULL,FMT_IPv4,&hf_cops_pc_prks_ip);
@@ -4096,12 +4111,12 @@ cops_mm_event_generation_info(tvbuff_t *tvb, proto_tree *st, guint n, guint32 of
      offset += 4;
 
      /* BCID Element ID */
-     bcid_str = tvb_get_string(tvb, offset, 8);
+     bcid_str = tvb_format_text(tvb, offset, 8);
      proto_tree_add_text(stt, tvb, offset, 8,"%-28s : '%s'","BCID - Element ID",bcid_str);
      offset += 8;
 
      /* BCID Time Zone */
-     bcid_str = tvb_get_string(tvb, offset, 8);
+     bcid_str = tvb_format_text(tvb, offset, 8);
      proto_tree_add_text(stt, tvb, offset, 8,"%-28s : '%s'","BCID - Time Zone",bcid_str);
      offset += 8;
 
@@ -4117,6 +4132,7 @@ cops_volume_based_usage_limit(tvbuff_t *tvb, proto_tree *st, guint object_len, g
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,object_len,offset,"Volume-Based Usage Limit");
+     offset += 4;
 
      /* Usage Limit */
      proto_tree_add_item(stt, hf_cops_pcmm_volume_based_usage_limit, tvb, offset, 8,
@@ -4131,6 +4147,7 @@ cops_time_based_usage_limit(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offs
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Time-Based Usage Limit");
+     offset += 4;
 
      /* Time Limit */
      info_to_display(tvb,stt,offset,4,"Time Limit", NULL,FMT_DEC,&hf_cops_pcmm_time_based_usage_limit);
@@ -4145,6 +4162,7 @@ cops_opaque_data(tvbuff_t *tvb, proto_tree *st, guint object_len, guint32 offset
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,object_len,offset,"Opaque Data");
+     offset += 4;
 
      /* Opaque Data */
      proto_tree_add_text(stt, tvb, offset, 8,"Opaque Data");
@@ -4158,6 +4176,7 @@ cops_gate_time_info(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offset) {
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Gate Time Info");
+     offset += 4;
 
      /* Gate Time Info */
      info_to_display(tvb,stt,offset,4,"Time Committed", NULL,FMT_DEC,&hf_cops_pcmm_gate_time_info);
@@ -4172,6 +4191,7 @@ cops_gate_usage_info(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offset) {
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Gate Usage Info");
+     offset += 4;
 
      /* Gate Time Info */
      info_to_display(tvb,stt,offset,4,"Octet Count", NULL,FMT_DEC,&hf_cops_pcmm_gate_usage_info);
@@ -4187,6 +4207,7 @@ cops_packetcable_mm_error(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offset
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"PacketCable Error");
+     offset += 4;
 
      code = tvb_get_ntohs(tvb, offset);
      proto_tree_add_uint_format(stt, hf_cops_pcmm_packetcable_error_code, tvb, offset, 2, code,
@@ -4213,6 +4234,7 @@ cops_gate_state(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offset) {
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Gate State");
+     offset += 4;
 
      /* State */
      info_to_display(tvb,stt,offset,2,"State",pcmm_gate_state,FMT_DEC,&hf_cops_pcmm_packetcable_gate_state);
@@ -4231,6 +4253,7 @@ cops_version_info(tvbuff_t *tvb, proto_tree *st, guint n, guint32 offset) {
 
      /* Create a subtree */
      stt = info_to_cops_subtree(tvb,st,n,offset,"Version Info");
+     offset += 4;
 
      /* State */
      info_to_display(tvb,stt,offset,2,"Major Version Number",NULL,FMT_DEC,&hf_cops_pcmm_packetcable_version_info_major);
@@ -4290,9 +4313,6 @@ cops_analyze_packetcable_dqos_obj(tvbuff_t *tvb, packet_info *pinfo, proto_tree
        /* Glom the s_num and s_type together to make switching easier */
        num_type_glob = s_num << 8 | s_type;
 
-       /* Tune offset */
-       offset += 4;
-
        /* Perform the appropriate functions */
        switch (num_type_glob){
         case PCDQ_TRANSACTION_ID:
@@ -4331,7 +4351,7 @@ cops_analyze_packetcable_dqos_obj(tvbuff_t *tvb, packet_info *pinfo, proto_tree
        }
 
        /* Tune offset */
-       offset += object_len-4;
+       offset += object_len;
 
        /* See what we can still get from the buffer */
        remdata = tvb_length_remaining(tvb, offset);
@@ -4399,7 +4419,6 @@ decode_docsis_request_transmission_policy(tvbuff_t *tvb, guint32 offset, proto_t
 static void
 cops_analyze_packetcable_mm_obj(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint8 op_code, guint32 offset) {
 
-    gint remdata;
     guint16 object_len;
     guint8 s_num, s_type;
     guint16 num_type_glob;
@@ -4410,8 +4429,7 @@ cops_analyze_packetcable_mm_obj(tvbuff_t *tvb, packet_info *pinfo, proto_tree *t
     }
 
     /* Do the remaining client specific objects */
-    remdata = tvb_length_remaining(tvb, offset);
-    while (remdata > 4) {
+    while (tvb_reported_length_remaining(tvb, offset) > 4) {
 
        /* In case we have remaining data, then lets try to get this analyzed */
        object_len   = tvb_get_ntohs(tvb, offset);
@@ -4427,9 +4445,6 @@ cops_analyze_packetcable_mm_obj(tvbuff_t *tvb, packet_info *pinfo, proto_tree *t
        /* Glom the s_num and s_type together to make switching easier */
        num_type_glob = s_num << 8 | s_type;
 
-       /* Tune offset */
-       offset += 4;
-
        /* Perform the appropriate functions */
        switch (num_type_glob){
         case PCMM_TRANSACTION_ID:
@@ -4504,10 +4519,7 @@ cops_analyze_packetcable_mm_obj(tvbuff_t *tvb, packet_info *pinfo, proto_tree *t
        }
 
        /* Tune offset */
-       offset += object_len-4;
-
-       /* See what we can still get from the buffer */
-       remdata = tvb_length_remaining(tvb, offset);
+       offset += object_len;
     }
 }