Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
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  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10 
11 #ifndef __TO_STR_H__
12 #define __TO_STR_H__
13 
14 #include <glib.h>
15 
16 #include "wsutil/nstime.h"
17 #include <wsutil/inet_addr.h>
18 #include "time_fmt.h"
19 #include <epan/packet_info.h>
20 #include <epan/ipv6.h>
21 #include "ws_symbol_export.h"
22 #include "wmem/wmem.h"
23 
24 #define GUID_STR_LEN 37
25 #define MAX_ADDR_STR_LEN 256
26 #define VINES_ADDR_LEN 6
27 #define EUI64_STR_LEN 24
28 #define AX25_ADDR_LEN 7
29 #define FCWWN_ADDR_LEN 8
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif /* __cplusplus */
34 
35 /*
36  * These are utility functions which convert various types to strings,
37  * but for which no more specific module applies.
38  */
39 
40 WS_DLL_PUBLIC gchar* address_to_str(wmem_allocator_t *scope, const address *addr);
41 WS_DLL_PUBLIC gchar* address_with_resolution_to_str(wmem_allocator_t *scope, const address *addr);
42 WS_DLL_PUBLIC gchar* tvb_address_with_resolution_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, int type, const gint offset);
43 
44 /*
45  * address_to_name takes as input an "address", as defined in address.h.
46  *
47  * If the address is of a type that can be translated into a name, and the
48  * user has activated name resolution, and the name can be resolved, it
49  * returns a string containing the translated name.
50  *
51  * Otherwise, it returns NULL.
52  */
53 WS_DLL_PUBLIC const gchar *address_to_name(const address *addr);
54 
55 /*
56  * address_to_display takes as input an "address", as defined in address.h .
57  *
58  * If the address is of a type that can be translated into a name, and the
59  * user has activated name resolution, and the name can be resolved, it
60  * returns a string containing the translated name.
61  *
62  * Otherwise, if the address is of type AT_NONE, it returns "NONE".
63  *
64  * Otherwise, it returns a string containing the result of address_to_str
65  * on the argument, which should be a string representation for the address,
66  * e.g. "10.10.10.10" for IPv4 address 10.10.10.10.
67  */
68 WS_DLL_PUBLIC
69 gchar *address_to_display(wmem_allocator_t *allocator, const address *addr);
70 
71 WS_DLL_PUBLIC void address_to_str_buf(const address *addr, gchar *buf, int buf_len);
72 
73 #define tvb_ether_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_ETHER, offset)
74 #define tvb_ip_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_IPv4, offset)
75 #define tvb_ip6_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_IPv6, offset)
76 #define tvb_fcwwn_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_FCWWN, offset)
77 #define tvb_fc_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_FC, offset)
78 #define tvb_eui64_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_EUI64, offset)
79 
80 void ip_to_str_buf(const guint8 *ad, gchar *buf, const int buf_len);
81 
82 /* Returns length of the result. */
83 int ip6_to_str_buf(const ws_in6_addr *ad, gchar *buf, int buf_size);
84 
85 /* Returns length of the result. Takes a prefix to be inserted before the address. */
86 int ip6_to_str_buf_with_pfx(const ws_in6_addr *ad, gchar *buf, int buf_size, const char *prefix);
87 
88 extern gchar* ipxnet_to_str_punct(wmem_allocator_t *scope, const guint32 ad, const char punct);
89 WS_DLL_PUBLIC gchar* eui64_to_str(wmem_allocator_t *scope, const guint64 ad);
90 
91 WS_DLL_PUBLIC gchar* abs_time_to_str(wmem_allocator_t *scope, const nstime_t*, const absolute_time_display_e fmt,
92  gboolean show_zone);
93 WS_DLL_PUBLIC gchar* abs_time_secs_to_str(wmem_allocator_t *scope, const time_t, const absolute_time_display_e fmt,
94  gboolean show_zone);
95 WS_DLL_PUBLIC void display_epoch_time(gchar *, int, const time_t, gint32, const to_str_time_res_t);
96 
97 WS_DLL_PUBLIC void display_signed_time(gchar *, int, const gint32, gint32, const to_str_time_res_t);
98 
99 WS_DLL_PUBLIC gchar* signed_time_secs_to_str(wmem_allocator_t *scope, const gint32 time_val);
100 WS_DLL_PUBLIC gchar* unsigned_time_secs_to_str(wmem_allocator_t *scope, const guint32);
101 WS_DLL_PUBLIC gchar* signed_time_msecs_to_str(wmem_allocator_t *scope, gint32 time_val);
102 
103 WS_DLL_PUBLIC void guint32_to_str_buf(guint32 u, gchar *buf, int buf_len);
104 WS_DLL_PUBLIC void guint64_to_str_buf(guint64 u, gchar *buf, int buf_len);
105 
106 WS_DLL_PUBLIC gchar* rel_time_to_str(wmem_allocator_t *scope, const nstime_t*);
107 WS_DLL_PUBLIC gchar* rel_time_to_secs_str(wmem_allocator_t *scope, const nstime_t*);
108 WS_DLL_PUBLIC gchar* guid_to_str(wmem_allocator_t *scope, const e_guid_t*);
109 gchar* guid_to_str_buf(const e_guid_t*, gchar*, int);
110 
111 WS_DLL_PUBLIC char *decode_bits_in_field(const guint bit_offset, const gint no_of_bits, const guint64 value);
112 
113 WS_DLL_PUBLIC const gchar* port_type_to_str (port_type type);
114 
124 WS_DLL_PUBLIC gchar* tvb_address_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, int type, const gint offset);
125 
136 WS_DLL_PUBLIC gchar* tvb_address_var_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, address_type type, const gint offset, int length);
137 
147 WS_DLL_PUBLIC char *guint8_to_hex(char *out, guint8 val);
148 
158 WS_DLL_PUBLIC char *word_to_hex(char *out, guint16 word);
159 
169 WS_DLL_PUBLIC char *dword_to_hex(char *out, guint32 dword);
170 
178 WS_DLL_PUBLIC char *bytes_to_str(wmem_allocator_t *scope, const guint8 *bd, int bd_len);
179 
191 WS_DLL_PUBLIC gchar *bytestring_to_str(wmem_allocator_t *scope, const guint8 *ad, const guint32 len, const char punct);
192 
202 WS_DLL_PUBLIC char *bytes_to_hexstr(char *out, const guint8 *ad, guint32 len);
203 
213 WS_DLL_PUBLIC char *uint_to_str_back(char *ptr, guint32 value);
214 
215 #ifdef __cplusplus
216 }
217 #endif /* __cplusplus */
218 
219 #endif /* __TO_STR_H__ */
Definition: inet_ipv6.h:20
Definition: tvbuff-int.h:35
Definition: nstime.h:27
Definition: guid-utils.h:21
Definition: wmem_allocator.h:26
Definition: address.h:47