#include "charsets.h"
#include "asm_utils.h"
#include "column-utils.h"
+#include "to_str.h"
#include "wspython/wspy_register.h"
/* Candidates for assembler */
static int
-wrs_count_bitshift(guint32 bitmask)
+wrs_count_bitshift(const guint32 bitmask)
{
int bitshift = 0;
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,
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;
/* 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;
/* 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;
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);
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;
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;
}
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;
/* -------------------------- */
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;
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;
}
void
-proto_item_set_len(proto_item *pi, gint length)
+proto_item_set_len(proto_item *pi, const gint length)
{
field_info *fi;
}
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;
}
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;
/* "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;
}
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)
}
proto_tree*
-proto_item_get_subtree(proto_item *pi) {
+proto_item_get_subtree(const proto_item *pi) {
field_info *fi;
if (!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;
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;
}
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;
}
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)
}
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)
}
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;
}
protocol_t *
-find_protocol_by_id(int proto_id)
+find_protocol_by_id(const int proto_id)
{
header_field_info *hfinfo;
}
int
-proto_get_id(protocol_t *protocol)
+proto_get_id(const protocol_t *protocol)
{
return protocol->proto_id;
}
}
const char *
-proto_get_protocol_name(int proto_id)
+proto_get_protocol_name(const int proto_id)
{
protocol_t *protocol;
}
const char *
-proto_get_protocol_short_name(protocol_t *protocol)
+proto_get_protocol_short_name(const protocol_t *protocol)
{
if (protocol == NULL)
return "(none)";
}
const char *
-proto_get_protocol_long_name(protocol_t *protocol)
+proto_get_protocol_long_name(const protocol_t *protocol)
{
if (protocol == NULL)
return "(none)";
}
const char *
-proto_get_protocol_filter_name(int proto_id)
+proto_get_protocol_filter_name(const int proto_id)
{
protocol_t *protocol;
}
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;
}
void
-proto_set_decoding(int proto_id, gboolean enabled)
+proto_set_decoding(const int proto_id, const gboolean enabled)
{
protocol_t *protocol;
}
void
-proto_set_cant_toggle(int proto_id)
+proto_set_cant_toggle(const int proto_id)
{
protocol_t *protocol;
/* 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;
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;
}
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);
}
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;
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:
}
int
-hfinfo_bitwidth(header_field_info *hfinfo)
+hfinfo_bitwidth(const header_field_info *hfinfo)
{
int bitwidth = 0;
}
static const char*
-hfinfo_uint_vals_format(header_field_info *hfinfo)
+hfinfo_uint_vals_format(const header_field_info *hfinfo)
{
const char *format = NULL;
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:
}
static const char*
-hfinfo_uint_format(header_field_info *hfinfo)
+hfinfo_uint_format(const header_field_info *hfinfo)
{
const char *format = NULL;
}
break;
case BASE_OCT: /* I'm lazy */
- format = "%s: %o";
+ format = "%s: %#o";
break;
case BASE_HEX:
switch(hfinfo->type) {
}
static const char*
-hfinfo_uint_value_format(header_field_info *hfinfo)
+hfinfo_uint_value_format(const header_field_info *hfinfo)
{
const char *format = NULL;
}
break;
case BASE_OCT:
- format = "%o";
+ format = "%#o";
break;
case BASE_HEX:
switch(hfinfo->type) {
}
static const char*
-hfinfo_int_vals_format(header_field_info *hfinfo)
+hfinfo_int_vals_format(const header_field_info *hfinfo)
{
const char *format = NULL;
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:
}
static const char*
-hfinfo_uint64_format(header_field_info *hfinfo)
+hfinfo_uint64_format(const header_field_info *hfinfo)
{
const char *format = NULL;
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";
}
static const char*
-hfinfo_int_format(header_field_info *hfinfo)
+hfinfo_int_format(const header_field_info *hfinfo)
{
const char *format = NULL;
}
break;
case BASE_OCT: /* I'm lazy */
- format = "%s: %o";
+ format = "%s: %#o";
break;
case BASE_HEX:
switch(hfinfo->type) {
}
static const char*
-hfinfo_int_value_format(header_field_info *hfinfo)
+hfinfo_int_value_format(const header_field_info *hfinfo)
{
const char *format = NULL;
}
break;
case BASE_OCT:
- format = "%o";
+ format = "%#o";
break;
case BASE_HEX:
switch(hfinfo->type) {
}
static const char*
-hfinfo_int64_format(header_field_info *hfinfo)
+hfinfo_int64_format(const header_field_info *hfinfo)
{
const char *format = NULL;
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";
}
const char*
-proto_registrar_get_name(int n)
+proto_registrar_get_name(const int n)
{
header_field_info *hfinfo;
}
const char*
-proto_registrar_get_abbrev(int n)
+proto_registrar_get_abbrev(const int n)
{
header_field_info *hfinfo;
}
int
-proto_registrar_get_ftype(int n)
+proto_registrar_get_ftype(const int n)
{
header_field_info *hfinfo;
}
int
-proto_registrar_get_parent(int n)
+proto_registrar_get_parent(const int n)
{
header_field_info *hfinfo;
}
gboolean
-proto_registrar_is_protocol(int n)
+proto_registrar_is_protocol(const int n)
{
header_field_info *hfinfo;
* 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;
/* 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);
* 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;
}
gboolean
-proto_tracking_interesting_fields(proto_tree *tree)
+proto_tracking_interesting_fields(const proto_tree *tree)
{
if (!tree)
return FALSE;
* 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;
} 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;
* 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;
}
static const char*
-hfinfo_numeric_format(header_field_info *hfinfo)
+hfinfo_numeric_format(const header_field_info *hfinfo)
{
const char *format = NULL;
* 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;
* 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;
/* 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;
}
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;
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.
*/
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;
/* 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);
}
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;
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);
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;
}
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;
}
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;
}
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;