attr_dissector_fn_t
[wireshark-sm.git] / epan / to_str.h
blobb26c1a9eccaef8a78929e89997614cb85ef7adf1
1 /** @file
2 * Definitions for utilities to convert various other types to strings.
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
11 #ifndef __TO_STR_H__
12 #define __TO_STR_H__
14 #include "wsutil/nstime.h"
15 #include <wsutil/inet_cidr.h>
16 #include <epan/proto.h>
17 #include <epan/packet_info.h>
18 #include "ws_symbol_export.h"
19 #include <epan/wmem_scopes.h>
20 #include <wsutil/to_str.h>
22 #define GUID_STR_LEN 37
23 #define MAX_ADDR_STR_LEN 256
24 #define VINES_ADDR_LEN 6
25 #define EUI64_STR_LEN 24
26 #define AX25_ADDR_LEN 7
27 #define FCWWN_ADDR_LEN 8
30 #ifdef __cplusplus
31 extern "C" {
32 #endif /* __cplusplus */
35 * These are utility functions which convert various types to strings,
36 * but for which no more specific module applies.
40 ************** Address
43 WS_DLL_PUBLIC char *address_to_str(wmem_allocator_t *scope, const address *addr);
45 WS_DLL_PUBLIC char *address_with_resolution_to_str(wmem_allocator_t *scope, const address *addr);
48 * address_to_name takes as input an "address", as defined in address.h.
50 * If the address is of a type that can be translated into a name, and the
51 * user has activated name resolution, and the name can be resolved, it
52 * returns a string containing the translated name.
54 * Otherwise, it returns NULL.
56 WS_DLL_PUBLIC const char *address_to_name(const address *addr);
59 * address_to_display takes as input an "address", as defined in address.h .
61 * If the address is of a type that can be translated into a name, and the
62 * user has activated name resolution, and the name can be resolved, it
63 * returns a string containing the translated name.
65 * Otherwise, if the address is of type AT_NONE, it returns "NONE".
67 * Otherwise, it returns a string containing the result of address_to_str
68 * on the argument, which should be a string representation for the address,
69 * e.g. "10.10.10.10" for IPv4 address 10.10.10.10.
71 WS_DLL_PUBLIC char *address_to_display(wmem_allocator_t *allocator, const address *addr);
73 WS_DLL_PUBLIC void address_to_str_buf(const address *addr, char *buf, int buf_len);
75 WS_DLL_PUBLIC const char *port_type_to_str (port_type type);
78 ************** TVB
81 WS_DLL_PUBLIC char* tvb_address_with_resolution_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, int type, const int offset);
83 #define tvb_ether_to_str(scope, tvb, offset) tvb_address_to_str(scope, tvb, AT_ETHER, offset)
85 #define tvb_ip_to_str(scope, tvb, offset) tvb_address_to_str(scope, tvb, AT_IPv4, offset)
87 #define tvb_ip6_to_str(scope, tvb, offset) tvb_address_to_str(scope, tvb, AT_IPv6, offset)
89 #define tvb_fcwwn_to_str(scope, tvb, offset) tvb_address_to_str(scope, tvb, AT_FCWWN, offset)
91 #define tvb_fc_to_str(scope, tvb, offset) tvb_address_to_str(scope, tvb, AT_FC, offset)
93 #define tvb_eui64_to_str(scope, tvb, offset) tvb_address_to_str(scope, tvb, AT_EUI64, offset)
95 /** Turn an address type retrieved from a tvb into a string.
97 * @param scope memory allocation scheme used
98 * @param tvb tvbuff to retrieve address
99 * @param type address type to retrieve
100 * @param offset offset into tvb to retrieve address
101 * @return A pointer to the formatted string
104 WS_DLL_PUBLIC char* tvb_address_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, int type, const int offset);
106 /** Turn an address type retrieved from a tvb into a string.
108 * @param scope memory allocation scheme used
109 * @param tvb tvbuff to retrieve address
110 * @param type address type to retrieve
111 * @param offset offset into tvb to retrieve address
112 * @param length The length of the string
113 * @return A pointer to the formatted string
116 WS_DLL_PUBLIC char* tvb_address_var_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, address_type type, const int offset, int length);
119 ************** Time
122 #define ABS_TIME_TO_STR_SHOW_ZONE (1U << 0)
123 #define ABS_TIME_TO_STR_ADD_DQUOTES (1U << 1)
124 #define ABS_TIME_TO_STR_SHOW_UTC_ONLY (1U << 2)
125 #define ABS_TIME_TO_STR_ISO8601 (1U << 3)
127 WS_DLL_PUBLIC char *abs_time_to_str_ex(wmem_allocator_t *scope,
128 const nstime_t *, field_display_e fmt,
129 int flags);
131 #define abs_time_to_str(scope, nst, fmt, show_zone) \
132 abs_time_to_str_ex(scope, nst, fmt, (show_zone) ? ABS_TIME_TO_STR_SHOW_ZONE : 0)
134 char *
135 abs_time_to_unix_str(wmem_allocator_t *scope, const nstime_t *rel_time);
137 WS_DLL_PUBLIC char *abs_time_secs_to_str_ex(wmem_allocator_t *scope,
138 const time_t, field_display_e fmt,
139 int flags);
141 #define abs_time_secs_to_str(scope, nst, fmt, show_zone) \
142 abs_time_secs_to_str_ex(scope, nst, fmt, (show_zone) ? ABS_TIME_TO_STR_SHOW_ZONE : 0)
144 WS_DLL_PUBLIC char *signed_time_secs_to_str(wmem_allocator_t *scope, const int32_t time_val);
146 WS_DLL_PUBLIC char *unsigned_time_secs_to_str(wmem_allocator_t *scope, const uint32_t);
148 WS_DLL_PUBLIC char *signed_time_msecs_to_str(wmem_allocator_t *scope, int32_t time_val);
150 WS_DLL_PUBLIC char *rel_time_to_str(wmem_allocator_t *scope, const nstime_t *);
152 WS_DLL_PUBLIC char *rel_time_to_secs_str(wmem_allocator_t *scope, const nstime_t *);
155 ************** Misc
158 WS_DLL_PUBLIC char *guid_to_str_buf(const e_guid_t *, char *, int);
160 WS_DLL_PUBLIC char *guid_to_str(wmem_allocator_t *scope, const e_guid_t *);
162 WS_DLL_PUBLIC char *decode_bits_in_field(wmem_allocator_t *scope, const unsigned bit_offset, const int no_of_bits, const uint64_t value, const unsigned encoding);
164 #ifdef __cplusplus
166 #endif /* __cplusplus */
168 #endif /* __TO_STR_H__ */