Cite the source of frequency allocation information.
[obnox/wireshark/wip.git] / epan / proto.c
index e0317e33defa5888bbd112e939969f372c3fd811..4197b5c1a948e16e95c5739d18d88d3cebd0e0b6 100644 (file)
@@ -144,9 +144,11 @@ static void fill_label_enumerated_int(field_info *fi, gchar *label_str);
 int hfinfo_bitwidth(header_field_info *hfinfo);
 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 proto_item*
@@ -1469,6 +1471,8 @@ proto_tree_set_bytes(field_info *fi, const guint8* start_ptr, gint length)
        if (length > 0) {
                g_byte_array_append(bytes, start_ptr, length);
        }
+       col_custom_set_fstr(fi->hfinfo, "%s", bytes_to_str(bytes->data,
+                                                                  length));
        fvalue_set(&fi->value, bytes, TRUE);
 }
 
@@ -1559,7 +1563,16 @@ proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint st
 static void
 proto_tree_set_time(field_info *fi, nstime_t *value_ptr)
 {
+       header_field_info       *hfinfo;
+
        DISSECTOR_ASSERT(value_ptr != NULL);
+       hfinfo = fi->hfinfo;
+
+       if (hfinfo->type == FT_ABSOLUTE_TIME) {
+               col_custom_set_fstr(fi->hfinfo, "%s", abs_time_to_str(value_ptr));
+       } else if (hfinfo->type == FT_RELATIVE_TIME) {
+               col_custom_set_fstr(fi->hfinfo, "%s", rel_time_to_secs_str(value_ptr));
+       }
        fvalue_set(&fi->value, value_ptr, FALSE);
 }
 
@@ -1641,7 +1654,6 @@ proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint
 static void
 proto_tree_set_ipxnet(field_info *fi, guint32 value)
 {
-       col_custom_set_fstr(fi->hfinfo->abbrev, "%u", value);
        fvalue_set_uinteger(&fi->value, value);
 }
 
@@ -1723,6 +1735,8 @@ proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint st
 static void
 proto_tree_set_ipv4(field_info *fi, guint32 value)
 {
+       col_custom_set_fstr(fi->hfinfo, "%s",
+                           ip_to_str((guint8 *)&value));
        fvalue_set_uinteger(&fi->value, value);
 }
 
@@ -1895,6 +1909,8 @@ static void
 proto_tree_set_guid(field_info *fi, const e_guid_t *value_ptr)
 {
        DISSECTOR_ASSERT(value_ptr != NULL);
+       col_custom_set_fstr(fi->hfinfo, "%s",
+                           guid_to_str(value_ptr));
        fvalue_set(&fi->value, (gpointer) value_ptr, FALSE);
 }
 
@@ -1994,6 +2010,8 @@ proto_tree_set_oid(field_info *fi, const guint8* value_ptr, gint length)
        if (length > 0) {
                g_byte_array_append(bytes, value_ptr, length);
        }
+       col_custom_set_fstr(fi->hfinfo, "%s",
+                           oid_resolved_from_encoded(value_ptr, length));
        fvalue_set(&fi->value, bytes, TRUE);
 }
 
@@ -2006,6 +2024,8 @@ proto_tree_set_oid_tvb(field_info *fi, tvbuff_t *tvb, gint start, gint length)
 static void
 proto_tree_set_uint64(field_info *fi, guint64 value)
 {
+       col_custom_set_fstr(fi->hfinfo, "%" G_GINT64_MODIFIER "u",
+                           value);
        fvalue_set_integer64(&fi->value, value);
 }
 
@@ -2169,10 +2189,11 @@ static void
 proto_tree_set_string(field_info *fi, const char* value)
 {
        if (value) {
-               col_custom_set_fstr(fi->hfinfo->abbrev, "%s", value);
+               col_custom_set_fstr(fi->hfinfo, "%s",
+                                   format_text(value, strlen(value)));
                fvalue_set(&fi->value, (gpointer) value, FALSE);
        } else {
-               col_custom_set_fstr(fi->hfinfo->abbrev, "[ Null ]");
+               col_custom_set_fstr(fi->hfinfo, "[ Null ]");
                fvalue_set(&fi->value, (gpointer) "[ Null ]", FALSE);
        }
 }
@@ -2283,7 +2304,7 @@ proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint s
 static void
 proto_tree_set_ether(field_info *fi, const guint8* value)
 {
-       col_custom_set_fstr(fi->hfinfo->abbrev, "%s", value);
+       col_custom_set_fstr(fi->hfinfo, "%s", bytes_to_str_punct(value, 6, ':'));
        fvalue_set(&fi->value, (gpointer) value, FALSE);
 }
 
@@ -2453,6 +2474,8 @@ proto_tree_add_float_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint s
 static void
 proto_tree_set_float(field_info *fi, float value)
 {
+       col_custom_set_fstr(fi->hfinfo, "%." STRINGIFY(FLT_DIG) "f",
+                           value);
        fvalue_set_floating(&fi->value, value);
 }
 
@@ -2534,6 +2557,8 @@ proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint
 static void
 proto_tree_set_double(field_info *fi, double value)
 {
+       col_custom_set_fstr(fi->hfinfo, "%." STRINGIFY(DBL_DIG) "g",
+                           value);
        fvalue_set_floating(&fi->value, value);
 }
 
@@ -2640,7 +2665,20 @@ proto_tree_set_uint(field_info *fi, guint32 value)
                        integer >>= hfinfo->bitshift;
                }
        }
-       col_custom_set_fstr(hfinfo->abbrev, "%u", value);
+
+       if (hfinfo->type == FT_BOOLEAN) {
+               const true_false_string  *tfstring = &tfs_true_false;
+               if (hfinfo->strings) {
+                       tfstring = (const struct true_false_string*) hfinfo->strings;
+               }
+               col_custom_set_fstr(fi->hfinfo, "%s", value ? tfstring->true_string : tfstring->false_string);
+       } else if (hfinfo->strings) {
+               col_custom_set_fstr(fi->hfinfo, "%s", val_to_str(integer, cVALS(hfinfo->strings), "%d"));
+       } else if (IS_BASE_DUAL(hfinfo->display)) {
+               col_custom_set_fstr(fi->hfinfo, hfinfo_uint_value_format(hfinfo), integer, integer);
+       } else {
+               col_custom_set_fstr(fi->hfinfo, hfinfo_uint_value_format(hfinfo), integer);
+       }
        fvalue_set_uinteger(&fi->value, integer);
 }
 
@@ -2806,7 +2844,13 @@ proto_tree_set_int(field_info *fi, gint32 value)
                }
        }
 
-       col_custom_set_fstr(hfinfo->abbrev, "%u", value);
+       if (hfinfo->strings) {
+               col_custom_set_fstr(fi->hfinfo, "%s", val_to_str(integer, cVALS(hfinfo->strings), "%d"));
+       } else if (IS_BASE_DUAL(hfinfo->display)) {
+               col_custom_set_fstr(fi->hfinfo, hfinfo_int_value_format(hfinfo), integer, integer);
+       } else {
+               col_custom_set_fstr(fi->hfinfo, hfinfo_int_value_format(hfinfo), integer);
+       }
        fvalue_set_sinteger(&fi->value, integer);
 }
 
@@ -4640,6 +4684,90 @@ hfinfo_uint_format(header_field_info *hfinfo)
        return format;
 }
 
+static const char*
+hfinfo_uint_value_format(header_field_info *hfinfo)
+{
+       const char *format = NULL;
+
+       /* Pick the proper format string */
+       if (hfinfo->type == FT_FRAMENUM) {
+               /*
+                * Frame numbers are always displayed in decimal.
+                */
+               format = "%u";
+       } else {
+               switch(hfinfo->display) {
+                       case BASE_DEC:
+                               format = "%u";
+                               break;
+                       case BASE_DEC_HEX:
+                               switch(hfinfo->type) {
+                                       case FT_UINT8:
+                                               format = "%u (0x%02x)";
+                                               break;
+                                       case FT_UINT16:
+                                               format = "%u (0x%04x)";
+                                               break;
+                                       case FT_UINT24:
+                                               format = "%u (0x%06x)";
+                                               break;
+                                       case FT_UINT32:
+                                               format = "%u (0x%08x)";
+                                               break;
+                                       default:
+                                               DISSECTOR_ASSERT_NOT_REACHED();
+                                               ;
+                               }
+                               break;
+                       case BASE_OCT:
+                               format = "%o";
+                               break;
+                       case BASE_HEX:
+                               switch(hfinfo->type) {
+                                       case FT_UINT8:
+                                               format = "0x%02x";
+                                               break;
+                                       case FT_UINT16:
+                                               format = "0x%04x";
+                                               break;
+                                       case FT_UINT24:
+                                               format = "0x%06x";
+                                               break;
+                                       case FT_UINT32:
+                                               format = "0x%08x";
+                                               break;
+                                       default:
+                                               DISSECTOR_ASSERT_NOT_REACHED();
+                                               ;
+                               }
+                               break;
+                       case BASE_HEX_DEC:
+                               switch(hfinfo->type) {
+                                       case FT_UINT8:
+                                               format = "0x%02x (%u)";
+                                               break;
+                                       case FT_UINT16:
+                                               format = "0x%04x (%u)";
+                                               break;
+                                       case FT_UINT24:
+                                               format = "0x%06x (%u)";
+                                               break;
+                                       case FT_UINT32:
+                                               format = "0x%08x (%u)";
+                                               break;
+                                       default:
+                                               DISSECTOR_ASSERT_NOT_REACHED();
+                                               ;
+                               }
+                               break;
+                       default:
+                               DISSECTOR_ASSERT_NOT_REACHED();
+                               ;
+               }
+       }
+       return format;
+}
+
 static const char*
 hfinfo_int_vals_format(header_field_info *hfinfo)
 {
@@ -4788,6 +4916,83 @@ hfinfo_int_format(header_field_info *hfinfo)
        return format;
 }
 
+static const char*
+hfinfo_int_value_format(header_field_info *hfinfo)
+{
+       const char *format = NULL;
+
+       /* Pick the proper format string */
+       switch(hfinfo->display) {
+               case BASE_DEC:
+                       format = "%d";
+                       break;
+               case BASE_DEC_HEX:
+                       switch(hfinfo->type) {
+                               case FT_INT8:
+                                       format = "%d (0x%02x)";
+                                       break;
+                               case FT_INT16:
+                                       format = "%d (0x%04x)";
+                                       break;
+                               case FT_INT24:
+                                       format = "%d (0x%06x)";
+                                       break;
+                               case FT_INT32:
+                                       format = "%d (0x%08x)";
+                                       break;
+                               default:
+                                       DISSECTOR_ASSERT_NOT_REACHED();
+                                       ;
+                       }
+                       break;
+               case BASE_OCT:
+                       format = "%o";
+                       break;
+               case BASE_HEX:
+                       switch(hfinfo->type) {
+                               case FT_INT8:
+                                       format = "0x%02x";
+                                       break;
+                               case FT_INT16:
+                                       format = "0x%04x";
+                                       break;
+                               case FT_INT24:
+                                       format = "0x%06x";
+                                       break;
+                               case FT_INT32:
+                                       format = "0x%08x";
+                                       break;
+                               default:
+                                       DISSECTOR_ASSERT_NOT_REACHED();
+                                       ;
+                       }
+                       break;
+               case BASE_HEX_DEC:
+                       switch(hfinfo->type) {
+                               case FT_INT8:
+                                       format = "0x%02x (%d)";
+                                       break;
+                               case FT_INT16:
+                                       format = "0x%04x (%d)";
+                                       break;
+                               case FT_INT24:
+                                       format = "0x%06x (%d)";
+                                       break;
+                               case FT_INT32:
+                                       format = "0x%08x (%d)";
+                                       break;
+                               default:
+                                       DISSECTOR_ASSERT_NOT_REACHED();
+                                       ;
+                       }
+                       break;
+               default:
+                       DISSECTOR_ASSERT_NOT_REACHED();
+                       ;
+       }
+       return format;
+}
+
 static const char*
 hfinfo_int64_format(header_field_info *hfinfo)
 {