EPL: Fix segmented transfer complete detection
[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 <epan/ipv6.h>
32 #include "ws_symbol_export.h"
33 #include "wmem/wmem.h"
34
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
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif /* __cplusplus */
47
48 /*
49  * These are utility functions which convert various types to strings,
50  * but for which no more specific module applies.
51  */
52
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);
56
57 /*
58  * address_to_name takes as input an "address", as defined in address.h.
59  *
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.
63  *
64  * Otherwise, it returns NULL.
65  */
66 WS_DLL_PUBLIC const gchar *address_to_name(const address *addr);
67
68 /*
69  * address_to_display takes as input an "address", as defined in address.h .
70  *
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.
74  *
75  * Otherwise, if the address is of type AT_NONE, it returns "NONE".
76  *
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.
80  */
81 WS_DLL_PUBLIC
82 gchar *address_to_display(wmem_allocator_t *allocator, const address *addr);
83
84 WS_DLL_PUBLIC void     address_to_str_buf(const address *addr, gchar *buf, int buf_len);
85
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)
92
93 void    ip_to_str_buf(const guint8 *ad, gchar *buf, const int buf_len);
94
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);
98
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,
103     gboolean show_zone);
104 WS_DLL_PUBLIC gchar*    abs_time_secs_to_str(wmem_allocator_t *scope, const time_t, const absolute_time_display_e fmt,
105     gboolean show_zone);
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);
108
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);
111
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);
116
117 WS_DLL_PUBLIC char *decode_bits_in_field(const guint bit_offset, const gint no_of_bits, const guint64 value);
118
119 WS_DLL_PUBLIC const gchar* port_type_to_str (port_type type);
120
121 /** Turn an address type retrieved from a tvb into a string.
122  *
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
128  *
129  */
130 WS_DLL_PUBLIC gchar* tvb_address_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, int type, const gint offset);
131
132 /** Turn an address type retrieved from a tvb into a string.
133  *
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
140  *
141  */
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);
143
144 /**
145  * word_to_hex()
146  *
147  * Output guint16 hex represetation to 'out', and return pointer after last character (out + 4).
148  * It always output full representation (padded with 0).
149  *
150  * String is not NUL terminated by this routine.
151  * There needs to be at least 4 bytes in the buffer.
152  */
153 WS_DLL_PUBLIC char *word_to_hex(char *out, guint16 word);
154
155 /**
156  * dword_to_hex()
157  *
158  * Output guint32 hex represetation to 'out', and return pointer after last character.
159  * It always output full representation (padded with 0).
160  *
161  * String is not NUL terminated by this routine.
162  * There needs to be at least 8 bytes in the buffer.
163  */
164 WS_DLL_PUBLIC char *dword_to_hex(char *out, guint32 dword);
165
166 /** Turn an array of bytes into a string showing the bytes in hex.
167  *
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
172  */
173 WS_DLL_PUBLIC char *bytes_to_str(wmem_allocator_t *scope, const guint8 *bd, int bd_len);
174
175 /** Turn an array of bytes into a string showing the bytes in hex,
176  *  separated by a punctuation character.
177  *
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
183  *
184  * @see bytes_to_str()
185  */
186 WS_DLL_PUBLIC gchar *bytestring_to_str(wmem_allocator_t *scope, const guint8 *ad, const guint32 len, const char punct);
187
188 /**
189  * bytes_to_hexstr()
190  *
191  * Output hex represetation of guint8 ad array, and return pointer after last character.
192  * It always output full representation (padded with 0).
193  *
194  * String is not NUL terminated by this routine.
195  * There needs to be at least len * 2 bytes in the buffer.
196  */
197 WS_DLL_PUBLIC char *bytes_to_hexstr(char *out, const guint8 *ad, guint32 len);
198
199 /**
200  * uint_to_str_back()
201  *
202  * Output guint32 decimal representation backward (last character will be written on ptr - 1),
203  * and return pointer to first character.
204  *
205  * String is not NUL terminated by this routine.
206  * There needs to be at least 10 bytes in the buffer.
207  */
208 WS_DLL_PUBLIC char *uint_to_str_back(char *ptr, guint32 value);
209
210 #ifdef __cplusplus
211 }
212 #endif /* __cplusplus */
213
214 #endif /* __TO_STR_H__  */