From Yaniv Kaul: constify parameters
[obnox/wireshark/wip.git] / epan / proto.c
index 96cbdbcb19ae62348900cb0e1c8d5deeb05eccb9..287bf7383511cfd1863cfe313098b1522c8e8a98 100644 (file)
@@ -46,6 +46,7 @@
 #include "charsets.h"
 #include "asm_utils.h"
 #include "column-utils.h"
+#include "to_str.h"
 
 #include "wspython/wspy_register.h"
 
@@ -73,7 +74,7 @@ struct ptvcursor {
 
 /* Candidates for assembler */
 static int
-wrs_count_bitshift(guint32 bitmask)
+wrs_count_bitshift(const guint32 bitmask)
 {
        int bitshift = 0;
 
@@ -143,29 +144,29 @@ static void fill_label_bitfield(field_info *fi, gchar *label_str);
 static void fill_label_int(field_info *fi, gchar *label_str);
 static void fill_label_int64(field_info *fi, gchar *label_str);
 
-static const char* hfinfo_uint_vals_format(header_field_info *hfinfo);
-static const char* hfinfo_uint_format(header_field_info *hfinfo);
-static const char* hfinfo_uint_value_format(header_field_info *hfinfo);
-static const char* hfinfo_uint64_format(header_field_info *hfinfo);
-static const char* hfinfo_int_vals_format(header_field_info *hfinfo);
-static const char* hfinfo_int_format(header_field_info *hfinfo);
-static const char* hfinfo_int_value_format(header_field_info *hfinfo);
-static const char* hfinfo_int64_format(header_field_info *hfinfo);
+static const char* hfinfo_uint_vals_format(const header_field_info *hfinfo);
+static const char* hfinfo_uint_format(const header_field_info *hfinfo);
+static const char* hfinfo_uint_value_format(const header_field_info *hfinfo);
+static const char* hfinfo_uint64_format(const header_field_info *hfinfo);
+static const char* hfinfo_int_vals_format(const header_field_info *hfinfo);
+static const char* hfinfo_int_format(const header_field_info *hfinfo);
+static const char* hfinfo_int_value_format(const header_field_info *hfinfo);
+static const char* hfinfo_int64_format(const header_field_info *hfinfo);
 
 static proto_item*
 proto_tree_add_node(proto_tree *tree, field_info *fi);
 
 static header_field_info *
-get_hfi_and_length(int hfindex, tvbuff_t *tvb, gint start, gint *length,
+get_hfi_and_length(int hfindex, tvbuff_t *tvb, const gint start, gint *length,
        gint *item_length);
 
 static field_info *
 new_field_info(proto_tree *tree, header_field_info *hfinfo, tvbuff_t *tvb,
-       gint start, gint item_length);
+       const gint start, const gint item_length);
 
 static field_info *
 alloc_field_info(proto_tree *tree, int hfindex, tvbuff_t *tvb,
-               gint start, gint *length);
+               const gint start, gint *length);
 
 static proto_item *
 proto_tree_add_pi(proto_tree *tree, int hfindex, tvbuff_t *tvb,
@@ -225,10 +226,10 @@ proto_tree_set_uint64(field_info *fi, guint64 value);
 static void
 proto_tree_set_uint64_tvb(field_info *fi, tvbuff_t *tvb, gint start, guint length, gboolean little_endian);
 static gboolean
-proto_item_add_bitmask_tree(proto_item *item, tvbuff_t *tvb, int offset, int len, gint ett,
-       const gint **fields, gboolean little_endian, int flags, gboolean first);
+proto_item_add_bitmask_tree(proto_item *item, tvbuff_t *tvb, const int offset, const int len, const gint ett,
+       const gint **fields, const gboolean little_endian, const int flags, gboolean first);
 
-static int proto_register_field_init(header_field_info *hfinfo, int parent);
+static int proto_register_field_init(header_field_info *hfinfo, const int parent);
 
 /* special-case header field used within proto.c */
 int hf_text_only = -1;
@@ -1470,8 +1471,8 @@ ptvcursor_add(ptvcursor_t *ptvc, int hfindex, gint length,
 /* Add an item to a proto_tree, using the text label registered to that item;
    the item is extracted from the tvbuff handed to it. */
 proto_item *
-proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
-       gint start, gint length, gboolean little_endian)
+proto_tree_add_item(proto_tree *tree, const int hfindex, tvbuff_t *tvb,
+       const gint start, gint length, const gboolean little_endian)
 {
        field_info      *new_fi;
        header_field_info       *hfinfo;
@@ -1489,7 +1490,7 @@ proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
 
 /* Add a FT_NONE to a proto_tree */
 proto_item *
-proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
+proto_tree_add_none_format(proto_tree *tree, const int hfindex, tvbuff_t *tvb, const gint start,
                gint length, const char *format, ...)
 {
        proto_item              *pi;
@@ -1557,7 +1558,7 @@ proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gin
 
        pi = proto_tree_add_pi(tree, hfindex, tvb, start, &length, &new_fi);
 
-       proto_tree_set_protocol_tvb(new_fi, (start == 0 ? tvb : NULL));
+       proto_tree_set_protocol_tvb(new_fi, (start == 0 ? tvb : tvb_new_subset(tvb, start, length, length)));
 
        TRY_TO_FAKE_THIS_REPR(tree, pi);
 
@@ -3014,7 +3015,7 @@ proto_tree_add_pi(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
 
 
 static header_field_info *
-get_hfi_and_length(int hfindex, tvbuff_t *tvb, gint start, gint *length,
+get_hfi_and_length(int hfindex, tvbuff_t *tvb, const gint start, gint *length,
        gint *item_length)
 {
        header_field_info       *hfinfo;
@@ -3149,7 +3150,7 @@ get_hfi_and_length(int hfindex, tvbuff_t *tvb, gint start, gint *length,
 
 static field_info *
 new_field_info(proto_tree *tree, header_field_info *hfinfo, tvbuff_t *tvb,
-       gint start, gint item_length)
+       const gint start, const gint item_length)
 {
        field_info              *fi;
 
@@ -3176,7 +3177,7 @@ new_field_info(proto_tree *tree, header_field_info *hfinfo, tvbuff_t *tvb,
 }
 
 static field_info *
-alloc_field_info(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
+alloc_field_info(proto_tree *tree, int hfindex, tvbuff_t *tvb, const gint start,
        gint *length)
 {
        header_field_info       *hfinfo;
@@ -3281,9 +3282,9 @@ proto_tree_set_representation(proto_item *pi, const char *format, va_list ap)
 
 /* -------------------------- */
 const gchar *
-proto_custom_set(proto_tree* tree, int field_id,
+proto_custom_set(proto_tree* tree, const int field_id,
                                                         gchar *result,
-                                                        gchar *expr, int size )
+                                                        gchar *expr, const int size )
 {
        guint32         u_integer;
        gint32          integer;
@@ -3335,7 +3336,7 @@ proto_custom_set(proto_tree* tree, int field_id,
 
                case FT_ABSOLUTE_TIME:
                        g_strlcpy(result,
-                               abs_time_to_str(fvalue_get(&finfo->value), (hfinfo->display == ABSOLUTE_TIME_UTC)),
+                               abs_time_to_str(fvalue_get(&finfo->value), hfinfo->display),
                                size);
                        break;
 
@@ -3525,7 +3526,7 @@ proto_item_append_text(proto_item *pi, const char *format, ...)
 }
 
 void
-proto_item_set_len(proto_item *pi, gint length)
+proto_item_set_len(proto_item *pi, const gint length)
 {
        field_info *fi;
 
@@ -3568,7 +3569,7 @@ proto_item_set_end(proto_item *pi, tvbuff_t *tvb, gint end)
 }
 
 int
-proto_item_get_len(proto_item *pi)
+proto_item_get_len(const proto_item *pi)
 {
        field_info *fi = PITEM_FINFO(pi);
        return fi ? fi->length : -1;
@@ -3582,7 +3583,7 @@ proto_item_get_len(proto_item *pi)
 }
 
 gboolean
-proto_item_set_expert_flags(proto_item *pi, int group, guint severity)
+proto_item_set_expert_flags(proto_item *pi, const int group, const guint severity)
 {
        if(pi == NULL || PITEM_FINFO(pi) == NULL)
                return FALSE;
@@ -3631,7 +3632,7 @@ proto_tree_create_root(void)
 /* "prime" a proto_tree with a single hfid that a dfilter
  * is interested in. */
 void
-proto_tree_prime_hfid(proto_tree *tree _U_, gint hfid)
+proto_tree_prime_hfid(proto_tree *tree _U_, const gint hfid)
 {
        header_field_info *hfinfo;
 
@@ -3657,7 +3658,7 @@ proto_tree_prime_hfid(proto_tree *tree _U_, gint hfid)
 }
 
 proto_tree*
-proto_item_add_subtree(proto_item *pi, gint idx) {
+proto_item_add_subtree(proto_item *pi, const gint idx) {
        field_info *fi;
 
        if (!pi)
@@ -3675,7 +3676,7 @@ proto_item_add_subtree(proto_item *pi,    gint idx) {
 }
 
 proto_tree*
-proto_item_get_subtree(proto_item *pi) {
+proto_item_get_subtree(const proto_item *pi) {
        field_info *fi;
 
        if (!pi)
@@ -3687,7 +3688,7 @@ proto_item_get_subtree(proto_item *pi) {
 }
 
 proto_item*
-proto_item_get_parent(proto_item *ti) {
+proto_item_get_parent(const proto_item *ti) {
        if (!ti)
                return (NULL);
        return ti->parent;
@@ -3707,7 +3708,7 @@ proto_item_get_parent_nth(proto_item *ti, int gen) {
 
 
 proto_item*
-proto_tree_get_parent(proto_tree *tree) {
+proto_tree_get_parent(const proto_tree *tree) {
        if (!tree)
                return (NULL);
        return (proto_item*) tree;
@@ -3770,7 +3771,7 @@ proto_tree_move_item(proto_tree *tree, proto_item *fixed_item, proto_item *item_
 }
 
 void
-proto_tree_set_appendix(proto_tree *tree, tvbuff_t *tvb, gint start, gint length)
+proto_tree_set_appendix(proto_tree *tree, tvbuff_t *tvb, gint start, const gint length)
 {
        field_info *fi;
 
@@ -3889,7 +3890,7 @@ proto_register_protocol(const char *name, const char *short_name, const char *fi
 }
 
 void
-proto_mark_private(int proto_id)
+proto_mark_private(const int proto_id)
 {
        protocol_t *protocol = find_protocol_by_id(proto_id);
        if (protocol)
@@ -3897,7 +3898,7 @@ proto_mark_private(int proto_id)
 }
 
 gboolean
-proto_is_private(int proto_id)
+proto_is_private(const int proto_id)
 {
        protocol_t *protocol = find_protocol_by_id(proto_id);
        if (protocol)
@@ -3940,7 +3941,7 @@ proto_get_next_protocol(void **cookie)
 }
 
 header_field_info *
-proto_get_first_protocol_field(int proto_id, void **cookie)
+proto_get_first_protocol_field(const int proto_id, void **cookie)
 {
        protocol_t *protocol = find_protocol_by_id(proto_id);
        hf_register_info *ptr;
@@ -3969,7 +3970,7 @@ proto_get_next_protocol_field(void **cookie)
 }
 
 protocol_t *
-find_protocol_by_id(int proto_id)
+find_protocol_by_id(const int proto_id)
 {
        header_field_info *hfinfo;
 
@@ -3991,7 +3992,7 @@ static gint compare_filter_name(gconstpointer proto_arg,
 }
 
 int
-proto_get_id(protocol_t *protocol)
+proto_get_id(const protocol_t *protocol)
 {
        return protocol->proto_id;
 }
@@ -4011,7 +4012,7 @@ int proto_get_id_by_filter_name(const gchar* filter_name)
 }
 
 const char *
-proto_get_protocol_name(int proto_id)
+proto_get_protocol_name(const int proto_id)
 {
        protocol_t *protocol;
 
@@ -4020,7 +4021,7 @@ proto_get_protocol_name(int proto_id)
 }
 
 const char *
-proto_get_protocol_short_name(protocol_t *protocol)
+proto_get_protocol_short_name(const protocol_t *protocol)
 {
        if (protocol == NULL)
                return "(none)";
@@ -4028,7 +4029,7 @@ proto_get_protocol_short_name(protocol_t *protocol)
 }
 
 const char *
-proto_get_protocol_long_name(protocol_t *protocol)
+proto_get_protocol_long_name(const protocol_t *protocol)
 {
        if (protocol == NULL)
                return "(none)";
@@ -4036,7 +4037,7 @@ proto_get_protocol_long_name(protocol_t *protocol)
 }
 
 const char *
-proto_get_protocol_filter_name(int proto_id)
+proto_get_protocol_filter_name(const int proto_id)
 {
        protocol_t *protocol;
 
@@ -4047,13 +4048,13 @@ proto_get_protocol_filter_name(int proto_id)
 }
 
 gboolean
-proto_is_protocol_enabled(protocol_t *protocol)
+proto_is_protocol_enabled(const protocol_t *protocol)
 {
        return protocol->is_enabled;
 }
 
 gboolean
-proto_can_toggle_protocol(int proto_id)
+proto_can_toggle_protocol(const int proto_id)
 {
        protocol_t *protocol;
 
@@ -4062,7 +4063,7 @@ proto_can_toggle_protocol(int proto_id)
 }
 
 void
-proto_set_decoding(int proto_id, gboolean enabled)
+proto_set_decoding(const int proto_id, const gboolean enabled)
 {
        protocol_t *protocol;
 
@@ -4089,7 +4090,7 @@ proto_enable_all(void)
 }
 
 void
-proto_set_cant_toggle(int proto_id)
+proto_set_cant_toggle(const int proto_id)
 {
        protocol_t *protocol;
 
@@ -4100,7 +4101,7 @@ proto_set_cant_toggle(int proto_id)
 /* for use with static arrays only, since we don't allocate our own copies
 of the header_field_info struct contained within the hf_register_info struct */
 void
-proto_register_field_array(int parent, hf_register_info *hf, int num_records)
+proto_register_field_array(const int parent, hf_register_info *hf, const int num_records)
 {
        int                     field_id, i;
        hf_register_info        *ptr = hf;
@@ -4228,7 +4229,8 @@ static void tmp_fld_check_assert(header_field_info *hfinfo) {
 
        case FT_ABSOLUTE_TIME:
                DISSECTOR_ASSERT(hfinfo->display == ABSOLUTE_TIME_LOCAL ||
-                   hfinfo->display == ABSOLUTE_TIME_UTC);
+                   hfinfo->display == ABSOLUTE_TIME_UTC ||
+                   hfinfo->display == ABSOLUTE_TIME_DOY_UTC);
                DISSECTOR_ASSERT(hfinfo->bitmask == 0);
                DISSECTOR_ASSERT(hfinfo->strings == NULL);
                break;
@@ -4242,7 +4244,7 @@ static void tmp_fld_check_assert(header_field_info *hfinfo) {
 }
 
 static int
-proto_register_field_init(header_field_info *hfinfo, int parent)
+proto_register_field_init(header_field_info *hfinfo, const int parent)
 {
 
        tmp_fld_check_assert(hfinfo);
@@ -4322,7 +4324,7 @@ proto_register_field_init(header_field_info *hfinfo, int parent)
 }
 
 void
-proto_register_subtree_array(gint *const *indices, int num_indices)
+proto_register_subtree_array(gint *const *indices, const int num_indices)
 {
        int     i;
        gint    *const *ptr = indices;
@@ -4470,7 +4472,7 @@ proto_item_fill_label(field_info *fi, gchar *label_str)
                case FT_ABSOLUTE_TIME:
                        g_snprintf(label_str, ITEM_LABEL_LENGTH,
                                "%s: %s", hfinfo->name,
-                               abs_time_to_str(fvalue_get(&fi->value), (hfinfo->display == ABSOLUTE_TIME_UTC)));
+                               abs_time_to_str(fvalue_get(&fi->value), hfinfo->display));
                        break;
 
                case FT_RELATIVE_TIME:
@@ -4784,7 +4786,7 @@ fill_label_int64(field_info *fi, gchar *label_str)
 }
 
 int
-hfinfo_bitwidth(header_field_info *hfinfo)
+hfinfo_bitwidth(const header_field_info *hfinfo)
 {
        int bitwidth = 0;
 
@@ -4820,7 +4822,7 @@ hfinfo_bitwidth(header_field_info *hfinfo)
 }
 
 static const char*
-hfinfo_uint_vals_format(header_field_info *hfinfo)
+hfinfo_uint_vals_format(const header_field_info *hfinfo)
 {
        const char *format = NULL;
 
@@ -4834,7 +4836,7 @@ hfinfo_uint_vals_format(header_field_info *hfinfo)
                        format = "%s: %s (%u)";
                        break;
                case BASE_OCT: /* I'm lazy */
-                       format = "%s: %s (%o)";
+                       format = "%s: %s (%#o)";
                        break;
                case BASE_HEX:
                case BASE_HEX_DEC:
@@ -4864,7 +4866,7 @@ hfinfo_uint_vals_format(header_field_info *hfinfo)
 }
 
 static const char*
-hfinfo_uint_format(header_field_info *hfinfo)
+hfinfo_uint_format(const header_field_info *hfinfo)
 {
        const char *format = NULL;
 
@@ -4899,7 +4901,7 @@ hfinfo_uint_format(header_field_info *hfinfo)
                                }
                                break;
                        case BASE_OCT: /* I'm lazy */
-                               format = "%s: %o";
+                               format = "%s: %#o";
                                break;
                        case BASE_HEX:
                                switch(hfinfo->type) {
@@ -4948,7 +4950,7 @@ hfinfo_uint_format(header_field_info *hfinfo)
 }
 
 static const char*
-hfinfo_uint_value_format(header_field_info *hfinfo)
+hfinfo_uint_value_format(const header_field_info *hfinfo)
 {
        const char *format = NULL;
 
@@ -4983,7 +4985,7 @@ hfinfo_uint_value_format(header_field_info *hfinfo)
                                }
                                break;
                        case BASE_OCT:
-                               format = "%o";
+                               format = "%#o";
                                break;
                        case BASE_HEX:
                                switch(hfinfo->type) {
@@ -5032,7 +5034,7 @@ hfinfo_uint_value_format(header_field_info *hfinfo)
 }
 
 static const char*
-hfinfo_int_vals_format(header_field_info *hfinfo)
+hfinfo_int_vals_format(const header_field_info *hfinfo)
 {
        const char *format = NULL;
 
@@ -5046,7 +5048,7 @@ hfinfo_int_vals_format(header_field_info *hfinfo)
                        format = "%s: %s (%d)";
                        break;
                case BASE_OCT: /* I'm lazy */
-                       format = "%s: %s (%o)";
+                       format = "%s: %s (%#o)";
                        break;
                case BASE_HEX:
                case BASE_HEX_DEC:
@@ -5076,7 +5078,7 @@ hfinfo_int_vals_format(header_field_info *hfinfo)
 }
 
 static const char*
-hfinfo_uint64_format(header_field_info *hfinfo)
+hfinfo_uint64_format(const header_field_info *hfinfo)
 {
        const char *format = NULL;
 
@@ -5089,7 +5091,7 @@ hfinfo_uint64_format(header_field_info *hfinfo)
                        format = "%s: %" G_GINT64_MODIFIER "u (%" G_GINT64_MODIFIER "x)";
                        break;
                case BASE_OCT: /* I'm lazy */
-                       format = "%s: %" G_GINT64_MODIFIER "o";
+                       format = "%s: %#" G_GINT64_MODIFIER "o";
                        break;
                case BASE_HEX:
                        format = "%s: 0x%016" G_GINT64_MODIFIER "x";
@@ -5105,7 +5107,7 @@ hfinfo_uint64_format(header_field_info *hfinfo)
 }
 
 static const char*
-hfinfo_int_format(header_field_info *hfinfo)
+hfinfo_int_format(const header_field_info *hfinfo)
 {
        const char *format = NULL;
 
@@ -5134,7 +5136,7 @@ hfinfo_int_format(header_field_info *hfinfo)
                        }
                        break;
                case BASE_OCT: /* I'm lazy */
-                       format = "%s: %o";
+                       format = "%s: %#o";
                        break;
                case BASE_HEX:
                        switch(hfinfo->type) {
@@ -5182,7 +5184,7 @@ hfinfo_int_format(header_field_info *hfinfo)
 }
 
 static const char*
-hfinfo_int_value_format(header_field_info *hfinfo)
+hfinfo_int_value_format(const header_field_info *hfinfo)
 {
        const char *format = NULL;
 
@@ -5211,7 +5213,7 @@ hfinfo_int_value_format(header_field_info *hfinfo)
                        }
                        break;
                case BASE_OCT:
-                       format = "%o";
+                       format = "%#o";
                        break;
                case BASE_HEX:
                        switch(hfinfo->type) {
@@ -5259,7 +5261,7 @@ hfinfo_int_value_format(header_field_info *hfinfo)
 }
 
 static const char*
-hfinfo_int64_format(header_field_info *hfinfo)
+hfinfo_int64_format(const header_field_info *hfinfo)
 {
        const char *format = NULL;
 
@@ -5272,7 +5274,7 @@ hfinfo_int64_format(header_field_info *hfinfo)
                        format = "%s: %" G_GINT64_MODIFIER "d (%" G_GINT64_MODIFIER "x)";
                        break;
                case BASE_OCT: /* I'm lazy */
-                       format = "%s: %" G_GINT64_MODIFIER "o";
+                       format = "%s: %#" G_GINT64_MODIFIER "o";
                        break;
                case BASE_HEX:
                        format = "%s: 0x%016" G_GINT64_MODIFIER "x";
@@ -5294,7 +5296,7 @@ proto_registrar_n(void)
 }
 
 const char*
-proto_registrar_get_name(int n)
+proto_registrar_get_name(const int n)
 {
        header_field_info *hfinfo;
 
@@ -5303,7 +5305,7 @@ proto_registrar_get_name(int n)
 }
 
 const char*
-proto_registrar_get_abbrev(int n)
+proto_registrar_get_abbrev(const int n)
 {
        header_field_info *hfinfo;
 
@@ -5312,7 +5314,7 @@ proto_registrar_get_abbrev(int n)
 }
 
 int
-proto_registrar_get_ftype(int n)
+proto_registrar_get_ftype(const int n)
 {
        header_field_info *hfinfo;
 
@@ -5321,7 +5323,7 @@ proto_registrar_get_ftype(int n)
 }
 
 int
-proto_registrar_get_parent(int n)
+proto_registrar_get_parent(const int n)
 {
        header_field_info *hfinfo;
 
@@ -5330,7 +5332,7 @@ proto_registrar_get_parent(int n)
 }
 
 gboolean
-proto_registrar_is_protocol(int n)
+proto_registrar_is_protocol(const int n)
 {
        header_field_info *hfinfo;
 
@@ -5343,7 +5345,7 @@ proto_registrar_is_protocol(int n)
  * 0 means undeterminable at time of registration
  * -1 means the field is not registered. */
 gint
-proto_registrar_get_length(int n)
+proto_registrar_get_length(const int n)
 {
        header_field_info *hfinfo;
 
@@ -5354,7 +5356,7 @@ proto_registrar_get_length(int n)
 /* Looks for a protocol or a field in a proto_tree. Returns TRUE if
  * it exists anywhere, or FALSE if it exists nowhere. */
 gboolean
-proto_check_for_protocol_or_field(proto_tree* tree, int id)
+proto_check_for_protocol_or_field(const proto_tree* tree, const int id)
 {
        GPtrArray *ptrs = proto_get_finfo_ptr_array(tree, id);
 
@@ -5375,7 +5377,7 @@ proto_check_for_protocol_or_field(proto_tree* tree, int id)
  * The caller should *not* free the GPtrArray*; proto_tree_free_node()
  * handles that. */
 GPtrArray*
-proto_get_finfo_ptr_array(proto_tree *tree, int id)
+proto_get_finfo_ptr_array(const proto_tree *tree, const int id)
 {
        if (!tree)
                return NULL;
@@ -5388,7 +5390,7 @@ proto_get_finfo_ptr_array(proto_tree *tree, int id)
 }
 
 gboolean
-proto_tracking_interesting_fields(proto_tree *tree)
+proto_tracking_interesting_fields(const proto_tree *tree)
 {
        if (!tree)
                return FALSE;
@@ -5424,7 +5426,7 @@ find_finfo(proto_node *node, gpointer data)
 * g_ptr_array_free(<array>, TRUE).
 */
 GPtrArray*
-proto_find_finfo(proto_tree *tree, int id)
+proto_find_finfo(proto_tree *tree, const int id)
 {
        ffdata_t        ffdata;
 
@@ -5471,7 +5473,7 @@ typedef struct {
 } offset_search_t;
 
 static gboolean
-check_for_offset(proto_node *node, gpointer data)
+check_for_offset(proto_node *node, const gpointer data)
 {
        field_info                      *fi = PNODE_FINFO(node);
        offset_search_t         *offsearch = data;
@@ -5726,7 +5728,7 @@ proto_registrar_dump_values(void)
  * Field 8 = bitmask: format: hex: 0x....
  */
 void
-proto_registrar_dump_fields(int format)
+proto_registrar_dump_fields(const int format)
 {
        header_field_info       *hfinfo, *parent_hfinfo;
        int                     i, len;
@@ -5846,7 +5848,7 @@ proto_registrar_dump_fields(int format)
 }
 
 static const char*
-hfinfo_numeric_format(header_field_info *hfinfo)
+hfinfo_numeric_format(const header_field_info *hfinfo)
 {
        const char *format = NULL;
 
@@ -6186,8 +6188,8 @@ proto_construct_match_selected_string(field_info *finfo, epan_dissect_t *edt)
  *     proto_tree_add_bitmask_text() functions.
  */
 static gboolean
-proto_item_add_bitmask_tree(proto_item *item, tvbuff_t *tvb, int offset, int len, gint ett,
-       const int **fields, gboolean little_endian, int flags, gboolean first)
+proto_item_add_bitmask_tree(proto_item *item, tvbuff_t *tvb, const int offset, const int len, const gint ett,
+       const int **fields, const gboolean little_endian, const int flags, gboolean first)
 {
        guint32 value = 0, tmpval;
        proto_tree *tree = NULL;
@@ -6322,8 +6324,8 @@ proto_item_add_bitmask_tree(proto_item *item, tvbuff_t *tvb, int offset, int len
  * matched string displayed on the expansion line.
  */
 proto_item *
-proto_tree_add_bitmask(proto_tree *parent_tree, tvbuff_t *tvb, guint offset, int hf_hdr,
-               gint ett, const int **fields, gboolean little_endian)
+proto_tree_add_bitmask(proto_tree *parent_tree, tvbuff_t *tvb, const guint offset, const int hf_hdr,
+               const gint ett, const int **fields, const gboolean little_endian)
 {
        proto_item *item = NULL;
        header_field_info *hf;
@@ -6344,9 +6346,9 @@ proto_tree_add_bitmask(proto_tree *parent_tree, tvbuff_t *tvb, guint offset, int
 
 /* The same as proto_tree_add_bitmask(), but using an arbitrary text as a top-level item */
 proto_item *
-proto_tree_add_bitmask_text(proto_tree *parent_tree, tvbuff_t *tvb, guint offset, guint len,
+proto_tree_add_bitmask_text(proto_tree *parent_tree, tvbuff_t *tvb, const guint offset, const guint len,
                const char *name, const char *fallback,
-               gint ett, const int **fields, gboolean little_endian, int flags)
+               const gint ett, const int **fields, const gboolean little_endian, const int flags)
 {
        proto_item *item = NULL;
 
@@ -6363,7 +6365,7 @@ proto_tree_add_bitmask_text(proto_tree *parent_tree, tvbuff_t *tvb, guint offset
 }
 
 proto_item *
-proto_tree_add_bits_item(proto_tree *tree, int hf_index, tvbuff_t *tvb, gint bit_offset, gint no_of_bits, gboolean little_endian)
+proto_tree_add_bits_item(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const gint bit_offset, const gint no_of_bits, const gboolean little_endian)
 {
        header_field_info       *hfinfo;
 
@@ -6372,58 +6374,6 @@ proto_tree_add_bits_item(proto_tree *tree, int hf_index, tvbuff_t *tvb, gint bit
        return proto_tree_add_bits_ret_val(tree, hf_index, tvb, bit_offset, no_of_bits, NULL, little_endian);
 }
 
-/*
- * This function will prepare a string showing how a certain value is broken down
- * in bits and also which parts of an octet are used. E.g. '..11 100.'
- */
-gchar *
-prepare_bits_string(guint64 value, gint bit_offset, gint no_of_bits)
-{
-       guint64 mask, tmp;
-       gchar *str;
-       gint bit, i;
-
-       mask = 1;
-       mask = mask << (no_of_bits-1);
-
-       /* prepare the string */
-       str=ep_alloc(256);
-       str[0]='\0';
-       for(bit=0;bit<((int)(bit_offset&0x07));bit++){
-               if(bit&&(!(bit%4))){
-                       strcat(str, " ");
-               }
-               strcat(str,".");
-       }
-
-       /* read the bits for the int */
-       for(i=0;i<no_of_bits;i++){
-               if(bit&&(!(bit%4))){
-                       strcat(str, " ");
-               }
-               if(bit&&(!(bit%8))){
-                       strcat(str, " ");
-               }
-               bit++;
-               tmp = value & mask;
-               if(tmp != 0){
-                       strcat(str, "1");
-               } else {
-                       strcat(str, "0");
-               }
-               mask = mask>>1;
-       }
-
-       for(;bit%8;bit++){
-               if(bit&&(!(bit%4))){
-                       strcat(str, " ");
-               }
-               strcat(str,".");
-       }
-
-       return str;
-}
-
 /*
  * This function will dissect a sequence of bits that does not need to be byte aligned; the bits
  * set will be shown in the tree as ..10 10.. and the integer value returned if return_value is set.
@@ -6431,7 +6381,7 @@ prepare_bits_string(guint64 value, gint bit_offset, gint no_of_bits)
  */
 
 proto_item *
-proto_tree_add_bits_ret_val(proto_tree *tree, int hf_index, tvbuff_t *tvb, gint bit_offset, gint no_of_bits, guint64 *return_value, gboolean little_endian)
+proto_tree_add_bits_ret_val(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const gint bit_offset, const gint no_of_bits, guint64 *return_value, const gboolean little_endian)
 {
        const char *format = NULL;
        gint    offset;
@@ -6485,7 +6435,7 @@ proto_tree_add_bits_ret_val(proto_tree *tree, int hf_index, tvbuff_t *tvb, gint
        /* Coast clear. Try and fake it */
        TRY_TO_FAKE_THIS_ITEM(tree, hf_index, hf_field);
 
-       str = prepare_bits_string(value, bit_offset, no_of_bits);
+       str = decode_bits_in_field(bit_offset, no_of_bits, value);
 
        strcat(str," = ");
        strcat(str,hf_field->name);
@@ -6547,7 +6497,7 @@ proto_tree_add_bits_ret_val(proto_tree *tree, int hf_index, tvbuff_t *tvb, gint
 }
 
 proto_item *
-proto_tree_add_bits_format_value(proto_tree *tree, int hf_index, tvbuff_t *tvb, gint bit_offset, gint no_of_bits, void *value_ptr, gchar *value_str)
+proto_tree_add_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const gint bit_offset, const gint no_of_bits, void *value_ptr, gchar *value_str)
 {
        gint    offset;
        guint   length;
@@ -6592,7 +6542,7 @@ proto_tree_add_bits_format_value(proto_tree *tree, int hf_index, tvbuff_t *tvb,
                return NULL;
        }
 
-       str = prepare_bits_string(value, bit_offset, no_of_bits);
+       str = decode_bits_in_field(bit_offset, no_of_bits, value);
 
        strcat(str," = ");
        strcat(str,hf_field->name);
@@ -6649,7 +6599,7 @@ proto_tree_add_bits_format_value(proto_tree *tree, int hf_index, tvbuff_t *tvb,
        va_end(ap);
 
 proto_item *
-proto_tree_add_uint_bits_format_value(proto_tree *tree, int hf_index, tvbuff_t *tvb, gint bit_offset, gint no_of_bits,
+proto_tree_add_uint_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const gint bit_offset, const gint no_of_bits,
        guint32 value, const char *format, ...)
 {
        va_list ap;
@@ -6677,7 +6627,7 @@ proto_tree_add_uint_bits_format_value(proto_tree *tree, int hf_index, tvbuff_t *
 }
 
 proto_item *
-proto_tree_add_float_bits_format_value(proto_tree *tree, int hf_index, tvbuff_t *tvb, gint bit_offset, gint no_of_bits,
+proto_tree_add_float_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const gint bit_offset, const gint no_of_bits,
        float value, const char *format, ...)
 {
        va_list ap;
@@ -6694,7 +6644,7 @@ proto_tree_add_float_bits_format_value(proto_tree *tree, int hf_index, tvbuff_t
 }
 
 proto_item *
-proto_tree_add_int_bits_format_value(proto_tree *tree, int hf_index, tvbuff_t *tvb, gint bit_offset, gint no_of_bits,
+proto_tree_add_int_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const gint bit_offset, const gint no_of_bits,
        gint32 value, const char *format, ...)
 {
        va_list ap;
@@ -6722,7 +6672,7 @@ proto_tree_add_int_bits_format_value(proto_tree *tree, int hf_index, tvbuff_t *t
 }
 
 proto_item *
-proto_tree_add_boolean_bits_format_value(proto_tree *tree, int hf_index, tvbuff_t *tvb, gint bit_offset, gint no_of_bits,
+proto_tree_add_boolean_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const gint bit_offset, const gint no_of_bits,
        guint32 value, const char *format, ...)
 {
        va_list ap;