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 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "wsutil/nstime.h"
30 #include <epan/packet_info.h>
31 #include "ws_symbol_export.h"
32 #include "wmem/wmem.h"
34 #define GUID_STR_LEN 37
35 #define MAX_IP_STR_LEN 16
36 #define MAX_IP6_STR_LEN 40
37 #define MAX_ADDR_STR_LEN 256
38 #define VINES_ADDR_LEN 6
39 #define EUI64_STR_LEN 24
40 #define AX25_ADDR_LEN 7
41 #define FCWWN_ADDR_LEN 8
45 #endif /* __cplusplus */
48 * These are utility functions which convert various types to strings,
49 * but for which no more specific module applies.
54 WS_DLL_PUBLIC gchar* address_to_str(wmem_allocator_t *scope, const address *addr);
55 WS_DLL_PUBLIC gchar* address_with_resolution_to_str(wmem_allocator_t *scope, const address *addr);
56 WS_DLL_PUBLIC gchar* tvb_address_with_resolution_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, int type, const gint offset);
59 * address_to_name 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, it returns NULL.
67 const gchar *address_to_name(const address *addr);
70 * address_to_display takes as input an "address", as defined in address.h .
72 * If the address is of a type that can be translated into a name, and the
73 * user has activated name resolution, and the name can be resolved, it
74 * returns a string containing the translated name.
76 * Otherwise, if the address is of type AT_NONE, it returns "NONE".
78 * Otherwise, it returns a string containing the result of address_to_str
79 * on the argument, which should be a string representation for the address,
80 * e.g. "10.10.10.10" for IPv4 address 10.10.10.10.
83 const gchar *address_to_display(wmem_allocator_t *allocator, const address *addr);
85 WS_DLL_PUBLIC void address_to_str_buf(const address *addr, gchar *buf, int buf_len);
87 #define tvb_ether_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_ETHER, offset)
88 #define tvb_ip_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_IPv4, offset)
89 #define tvb_ip6_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_IPv6, offset)
90 #define tvb_fcwwn_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_FCWWN, offset)
91 #define tvb_fc_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_FC, offset)
92 #define tvb_eui64_to_str(tvb, opt_offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_EUI64, offset)
94 void ip_to_str_buf(const guint8 *ad, gchar *buf, const int buf_len);
96 void ip6_to_str_buf(const struct e_in6_addr *, gchar *);
97 extern gchar* ipxnet_to_str_punct(wmem_allocator_t *scope, const guint32 ad, const char punct);
98 WS_DLL_PUBLIC gchar* eui64_to_str(wmem_allocator_t *scope, const guint64 ad);
100 WS_DLL_PUBLIC gchar* time_secs_to_str(wmem_allocator_t *scope, const gint32 time_val);
101 gchar* time_secs_to_str_unsigned(wmem_allocator_t *scope, const guint32);
102 WS_DLL_PUBLIC gchar* time_msecs_to_str(wmem_allocator_t *scope, gint32 time_val);
103 WS_DLL_PUBLIC gchar* abs_time_to_str(wmem_allocator_t *scope, const nstime_t*, const absolute_time_display_e fmt,
105 WS_DLL_PUBLIC gchar* abs_time_secs_to_str(wmem_allocator_t *scope, const time_t, const absolute_time_display_e fmt,
107 WS_DLL_PUBLIC void display_signed_time(gchar *, int, const gint32, gint32, const to_str_time_res_t);
108 WS_DLL_PUBLIC void display_epoch_time(gchar *, int, const time_t, gint32, const to_str_time_res_t);
110 extern void guint32_to_str_buf(guint32 u, gchar *buf, int buf_len);
111 extern void guint64_to_str_buf(guint64 u, gchar *buf, int buf_len);
113 WS_DLL_PUBLIC gchar* rel_time_to_str(wmem_allocator_t *scope, const nstime_t*);
114 WS_DLL_PUBLIC gchar* rel_time_to_secs_str(wmem_allocator_t *scope, const nstime_t*);
115 WS_DLL_PUBLIC gchar* guid_to_str(wmem_allocator_t *scope, const e_guid_t*);
116 gchar* guid_to_str_buf(const e_guid_t*, gchar*, int);
118 WS_DLL_PUBLIC char *decode_bits_in_field(const guint bit_offset, const gint no_of_bits, const guint64 value);
120 WS_DLL_PUBLIC const gchar* port_type_to_str (port_type type);
122 /** Turn an address type retrieved from a tvb into a string.
124 * @param scope memory allocation scheme used
125 * @param tvb tvbuff to retrieve address
126 * @param type address type to retrieve
127 * @param offset offset into tvb to retrieve address
128 * @return A pointer to the formatted string
131 WS_DLL_PUBLIC gchar* tvb_address_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, int type, const gint offset);
133 /** Turn an address type retrieved from a tvb into a string.
135 * @param scope memory allocation scheme used
136 * @param tvb tvbuff to retrieve address
137 * @param type address type to retrieve
138 * @param offset offset into tvb to retrieve address
139 * @param length The length of the string
140 * @return A pointer to the formatted string
143 WS_DLL_PUBLIC gchar* tvb_address_var_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, address_type type, const gint offset, int length);
148 * Output guint16 hex represetation to 'out', and return pointer after last character (out + 4).
149 * It always output full representation (padded with 0).
151 * String is not NUL terminated by this routine.
152 * There needs to be at least 4 bytes in the buffer.
154 WS_DLL_PUBLIC char *word_to_hex(char *out, guint16 word);
159 * Output guint32 hex represetation to 'out', and return pointer after last character.
160 * It always output full representation (padded with 0).
162 * String is not NUL terminated by this routine.
163 * There needs to be at least 8 bytes in the buffer.
165 WS_DLL_PUBLIC char *dword_to_hex(char *out, guint32 dword);
167 /** Turn an array of bytes into a string showing the bytes in hex.
169 * @param scope memory allocation scheme used
170 * @param bd A pointer to the byte array
171 * @param bd_len The length of the byte array
172 * @return A pointer to the formatted string
174 WS_DLL_PUBLIC char *bytes_to_str(wmem_allocator_t *scope, const guint8 *bd, int bd_len);
176 /** Turn an array of bytes into a string showing the bytes in hex,
177 * separated by a punctuation character.
179 * @param scope memory allocation scheme used
180 * @param ad A pointer to the byte array
181 * @param len The length of the byte array
182 * @param punct The punctuation character
183 * @return A pointer to the formatted string
185 * @see bytes_to_str()
187 WS_DLL_PUBLIC const gchar *bytestring_to_str(wmem_allocator_t *scope, const guint8 *ad, const guint32 len, const char punct);
192 * Output hex represetation of guint8 ad array, and return pointer after last character.
193 * It always output full representation (padded with 0).
195 * String is not NUL terminated by this routine.
196 * There needs to be at least len * 2 bytes in the buffer.
198 WS_DLL_PUBLIC char *bytes_to_hexstr(char *out, const guint8 *ad, guint32 len);
203 * Output guint32 decimal representation backward (last character will be written on ptr - 1),
204 * and return pointer to first character.
206 * String is not NUL terminated by this routine.
207 * There needs to be at least 10 bytes in the buffer.
209 WS_DLL_PUBLIC char *uint_to_str_back(char *ptr, guint32 value);
213 #endif /* __cplusplus */
215 #endif /* __TO_STR_H__ */