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 <epan/ipv6.h>
32 #include "ws_symbol_export.h"
33 #include "wmem/wmem.h"
35 #define GUID_STR_LEN 37
36 #define MAX_IP_STR_LEN 16
37 #define MAX_IP6_STR_LEN 40
38 #define MAX_ADDR_STR_LEN 256
39 #define VINES_ADDR_LEN 6
40 #define EUI64_STR_LEN 24
41 #define AX25_ADDR_LEN 7
42 #define FCWWN_ADDR_LEN 8
46 #endif /* __cplusplus */
49 * These are utility functions which convert various types to strings,
50 * but for which no more specific module applies.
53 WS_DLL_PUBLIC gchar* address_to_str(wmem_allocator_t *scope, const address *addr);
54 WS_DLL_PUBLIC gchar* address_with_resolution_to_str(wmem_allocator_t *scope, const address *addr);
55 WS_DLL_PUBLIC gchar* tvb_address_with_resolution_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, int type, const gint offset);
58 * address_to_name takes as input an "address", as defined in address.h.
60 * If the address is of a type that can be translated into a name, and the
61 * user has activated name resolution, and the name can be resolved, it
62 * returns a string containing the translated name.
64 * Otherwise, it returns NULL.
66 WS_DLL_PUBLIC const gchar *address_to_name(const address *addr);
69 * address_to_display takes as input an "address", as defined in address.h .
71 * If the address is of a type that can be translated into a name, and the
72 * user has activated name resolution, and the name can be resolved, it
73 * returns a string containing the translated name.
75 * Otherwise, if the address is of type AT_NONE, it returns "NONE".
77 * Otherwise, it returns a string containing the result of address_to_str
78 * on the argument, which should be a string representation for the address,
79 * e.g. "10.10.10.10" for IPv4 address 10.10.10.10.
82 gchar *address_to_display(wmem_allocator_t *allocator, const address *addr);
84 WS_DLL_PUBLIC void address_to_str_buf(const address *addr, gchar *buf, int buf_len);
86 #define tvb_ether_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_ETHER, offset)
87 #define tvb_ip_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_IPv4, offset)
88 #define tvb_ip6_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_IPv6, offset)
89 #define tvb_fcwwn_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_FCWWN, offset)
90 #define tvb_fc_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_FC, offset)
91 #define tvb_eui64_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_EUI64, offset)
93 void ip_to_str_buf(const guint8 *ad, gchar *buf, const int buf_len);
95 void ip6_to_str_buf(const struct e_in6_addr *, gchar *);
96 extern gchar* ipxnet_to_str_punct(wmem_allocator_t *scope, const guint32 ad, const char punct);
97 WS_DLL_PUBLIC gchar* eui64_to_str(wmem_allocator_t *scope, const guint64 ad);
99 WS_DLL_PUBLIC gchar* time_secs_to_str(wmem_allocator_t *scope, const gint32 time_val);
100 gchar* time_secs_to_str_unsigned(wmem_allocator_t *scope, const guint32);
101 WS_DLL_PUBLIC gchar* time_msecs_to_str(wmem_allocator_t *scope, gint32 time_val);
102 WS_DLL_PUBLIC gchar* abs_time_to_str(wmem_allocator_t *scope, const nstime_t*, const absolute_time_display_e fmt,
104 WS_DLL_PUBLIC gchar* abs_time_secs_to_str(wmem_allocator_t *scope, const time_t, const absolute_time_display_e fmt,
106 WS_DLL_PUBLIC void display_signed_time(gchar *, int, const gint32, gint32, const to_str_time_res_t);
107 WS_DLL_PUBLIC void display_epoch_time(gchar *, int, const time_t, gint32, const to_str_time_res_t);
109 extern void guint32_to_str_buf(guint32 u, gchar *buf, int buf_len);
110 extern void guint64_to_str_buf(guint64 u, gchar *buf, int buf_len);
112 WS_DLL_PUBLIC gchar* rel_time_to_str(wmem_allocator_t *scope, const nstime_t*);
113 WS_DLL_PUBLIC gchar* rel_time_to_secs_str(wmem_allocator_t *scope, const nstime_t*);
114 WS_DLL_PUBLIC gchar* guid_to_str(wmem_allocator_t *scope, const e_guid_t*);
115 gchar* guid_to_str_buf(const e_guid_t*, gchar*, int);
117 WS_DLL_PUBLIC char *decode_bits_in_field(const guint bit_offset, const gint no_of_bits, const guint64 value);
119 WS_DLL_PUBLIC const gchar* port_type_to_str (port_type type);
121 /** Turn an address type retrieved from a tvb into a string.
123 * @param scope memory allocation scheme used
124 * @param tvb tvbuff to retrieve address
125 * @param type address type to retrieve
126 * @param offset offset into tvb to retrieve address
127 * @return A pointer to the formatted string
130 WS_DLL_PUBLIC gchar* tvb_address_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, int type, const gint offset);
132 /** Turn an address type retrieved from a tvb into a string.
134 * @param scope memory allocation scheme used
135 * @param tvb tvbuff to retrieve address
136 * @param type address type to retrieve
137 * @param offset offset into tvb to retrieve address
138 * @param length The length of the string
139 * @return A pointer to the formatted string
142 WS_DLL_PUBLIC gchar* tvb_address_var_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, address_type type, const gint offset, int length);
147 * Output guint16 hex represetation to 'out', and return pointer after last character (out + 4).
148 * It always output full representation (padded with 0).
150 * String is not NUL terminated by this routine.
151 * There needs to be at least 4 bytes in the buffer.
153 WS_DLL_PUBLIC char *word_to_hex(char *out, guint16 word);
158 * Output guint32 hex represetation to 'out', and return pointer after last character.
159 * It always output full representation (padded with 0).
161 * String is not NUL terminated by this routine.
162 * There needs to be at least 8 bytes in the buffer.
164 WS_DLL_PUBLIC char *dword_to_hex(char *out, guint32 dword);
166 /** Turn an array of bytes into a string showing the bytes in hex.
168 * @param scope memory allocation scheme used
169 * @param bd A pointer to the byte array
170 * @param bd_len The length of the byte array
171 * @return A pointer to the formatted string
173 WS_DLL_PUBLIC char *bytes_to_str(wmem_allocator_t *scope, const guint8 *bd, int bd_len);
175 /** Turn an array of bytes into a string showing the bytes in hex,
176 * separated by a punctuation character.
178 * @param scope memory allocation scheme used
179 * @param ad A pointer to the byte array
180 * @param len The length of the byte array
181 * @param punct The punctuation character
182 * @return A pointer to the formatted string
184 * @see bytes_to_str()
186 WS_DLL_PUBLIC gchar *bytestring_to_str(wmem_allocator_t *scope, const guint8 *ad, const guint32 len, const char punct);
191 * Output hex represetation of guint8 ad array, and return pointer after last character.
192 * It always output full representation (padded with 0).
194 * String is not NUL terminated by this routine.
195 * There needs to be at least len * 2 bytes in the buffer.
197 WS_DLL_PUBLIC char *bytes_to_hexstr(char *out, const guint8 *ad, guint32 len);
202 * Output guint32 decimal representation backward (last character will be written on ptr - 1),
203 * and return pointer to first character.
205 * String is not NUL terminated by this routine.
206 * There needs to be at least 10 bytes in the buffer.
208 WS_DLL_PUBLIC char *uint_to_str_back(char *ptr, guint32 value);
212 #endif /* __cplusplus */
214 #endif /* __TO_STR_H__ */