(Temporarily) Allow DCE/RPC dissector table to have duplicates.
[metze/wireshark/wip.git] / epan / to_str.h
1 /* to_str.h
2  * Definitions for utilities to convert various other types to strings.
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
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.
12  *
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.
17  *
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.
21  */
22
23 #ifndef __TO_STR_H__
24 #define __TO_STR_H__
25
26 #include <glib.h>
27
28 #include "wsutil/nstime.h"
29 #include "time_fmt.h"
30 #include <epan/packet_info.h>
31 #include "ws_symbol_export.h"
32 #include "wmem/wmem.h"
33
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
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif /* __cplusplus */
46
47 /*
48  * These are utility functions which convert various types to strings,
49  * but for which no more specific module applies.
50  */
51
52 struct     e_in6_addr;
53
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);
57
58 /*
59  * address_to_name takes as input an "address", as defined in address.h.
60  *
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.
64  *
65  * Otherwise, it returns NULL.
66  */
67 const gchar *address_to_name(const address *addr);
68
69 /*
70  * address_to_display takes as input an "address", as defined in address.h .
71  *
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.
75  *
76  * Otherwise, if the address is of type AT_NONE, it returns "NONE".
77  *
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.
81  */
82 WS_DLL_PUBLIC
83 const gchar *address_to_display(wmem_allocator_t *allocator, const address *addr);
84
85 WS_DLL_PUBLIC void     address_to_str_buf(const address *addr, gchar *buf, int buf_len);
86
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)
93
94 void    ip_to_str_buf(const guint8 *ad, gchar *buf, const int buf_len);
95
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);
99
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,
104     gboolean show_zone);
105 WS_DLL_PUBLIC gchar*    abs_time_secs_to_str(wmem_allocator_t *scope, const time_t, const absolute_time_display_e fmt,
106     gboolean show_zone);
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);
109
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);
112
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);
117
118 WS_DLL_PUBLIC char *decode_bits_in_field(const guint bit_offset, const gint no_of_bits, const guint64 value);
119
120 WS_DLL_PUBLIC const gchar* port_type_to_str (port_type type);
121
122 /** Turn an address type retrieved from a tvb into a string.
123  *
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
129  *
130  */
131 WS_DLL_PUBLIC gchar* tvb_address_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, int type, const gint offset);
132
133 /** Turn an address type retrieved from a tvb into a string.
134  *
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
141  *
142  */
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);
144
145 /**
146  * word_to_hex()
147  *
148  * Output guint16 hex represetation to 'out', and return pointer after last character (out + 4).
149  * It always output full representation (padded with 0).
150  *
151  * String is not NUL terminated by this routine.
152  * There needs to be at least 4 bytes in the buffer.
153  */
154 WS_DLL_PUBLIC char *word_to_hex(char *out, guint16 word);
155
156 /**
157  * dword_to_hex()
158  *
159  * Output guint32 hex represetation to 'out', and return pointer after last character.
160  * It always output full representation (padded with 0).
161  *
162  * String is not NUL terminated by this routine.
163  * There needs to be at least 8 bytes in the buffer.
164  */
165 WS_DLL_PUBLIC char *dword_to_hex(char *out, guint32 dword);
166
167 /** Turn an array of bytes into a string showing the bytes in hex.
168  *
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
173  */
174 WS_DLL_PUBLIC char *bytes_to_str(wmem_allocator_t *scope, const guint8 *bd, int bd_len);
175
176 /** Turn an array of bytes into a string showing the bytes in hex,
177  *  separated by a punctuation character.
178  *
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
184  *
185  * @see bytes_to_str()
186  */
187 WS_DLL_PUBLIC const gchar *bytestring_to_str(wmem_allocator_t *scope, const guint8 *ad, const guint32 len, const char punct);
188
189 /**
190  * bytes_to_hexstr()
191  *
192  * Output hex represetation of guint8 ad array, and return pointer after last character.
193  * It always output full representation (padded with 0).
194  *
195  * String is not NUL terminated by this routine.
196  * There needs to be at least len * 2 bytes in the buffer.
197  */
198 WS_DLL_PUBLIC char *bytes_to_hexstr(char *out, const guint8 *ad, guint32 len);
199
200 /**
201  * uint_to_str_back()
202  *
203  * Output guint32 decimal representation backward (last character will be written on ptr - 1),
204  * and return pointer to first character.
205  *
206  * String is not NUL terminated by this routine.
207  * There needs to be at least 10 bytes in the buffer.
208  */
209 WS_DLL_PUBLIC char *uint_to_str_back(char *ptr, guint32 value);
210
211 #ifdef __cplusplus
212 }
213 #endif /* __cplusplus */
214
215 #endif /* __TO_STR_H__  */