/* to_str.h
* Definitions for utilities to convert various other types to strings.
*
- * $Id$
- *
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef __TO_STR_H__
#include <glib.h>
-#include "nstime.h"
+#include "wsutil/nstime.h"
+#include <wsutil/inet_addr.h>
+#include "time_fmt.h"
#include <epan/packet_info.h>
+#include <epan/ipv6.h>
+#include "ws_symbol_export.h"
+#include "wmem/wmem.h"
-#define GUID_STR_LEN 37
-#define MAX_IP_STR_LEN 16
+#define GUID_STR_LEN 37
#define MAX_ADDR_STR_LEN 256
+#define VINES_ADDR_LEN 6
+#define EUI64_STR_LEN 24
+#define AX25_ADDR_LEN 7
+#define FCWWN_ADDR_LEN 8
-/*
- * Resolution of a time stamp.
- */
-typedef enum {
- TO_STR_TIME_RES_T_SECS, /* seconds */
- TO_STR_TIME_RES_T_DSECS, /* deciseconds */
- TO_STR_TIME_RES_T_CSECS, /* centiseconds */
- TO_STR_TIME_RES_T_MSECS, /* milliseconds */
- TO_STR_TIME_RES_T_USECS, /* microseconds */
- TO_STR_TIME_RES_T_NSECS /* nanoseconds */
-} to_str_time_res_t;
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
/*
* These are utility functions which convert various types to strings,
* but for which no more specific module applies.
*/
-struct e_in6_addr;
-
-/* !!Deprecated!! - use ep_address_to_str() */
-#define address_to_str ep_address_to_str
-extern gchar* ep_address_to_str(const address *);
-extern gchar* se_address_to_str(const address *);
-extern void address_to_str_buf(const address *addr, gchar *buf, int buf_len);
-extern gchar* bytestring_to_str(const guint8 *, guint32, char);
-extern gchar* ether_to_str(const guint8 *);
-extern const gchar* ip_to_str(const guint8 *);
-extern void ip_to_str_buf(const guint8 *ad, gchar *buf, int buf_len);
-extern gchar* fc_to_str(const guint8 *);
-extern gchar* fcwwn_to_str (const guint8 *);
-extern gchar* ip6_to_str(const struct e_in6_addr *);
-extern void ip6_to_str_buf(const struct e_in6_addr *, gchar *);
-extern gchar* ipx_addr_to_str(guint32, const guint8 *);
-extern gchar* ipxnet_to_string(const guint8 *ad);
-extern gchar* ipxnet_to_str_punct(const guint32 ad, char punct);
-extern gchar* vines_addr_to_str(const guint8 *addrp);
-extern gchar* time_secs_to_str(gint32);
-extern gchar* time_secs_to_str_unsigned(guint32);
-extern gchar* time_msecs_to_str(gint32);
-extern gchar* abs_time_to_str(nstime_t*, gboolean);
-extern gchar* abs_time_secs_to_str(time_t, gboolean);
-extern void display_signed_time(gchar *, int, gint32, gint32, to_str_time_res_t);
-extern void display_epoch_time(gchar *, int, time_t, gint32, to_str_time_res_t);
-
-extern gchar* guint32_to_str(guint32 u);
-extern void guint32_to_str_buf(guint32 u, gchar *buf, int buf_len);
-
-extern gchar* rel_time_to_str(nstime_t*);
-extern gchar* rel_time_to_secs_str(nstime_t*);
-extern gchar* guid_to_str(const e_guid_t*);
-extern gchar* guid_to_str_buf(const e_guid_t*, gchar*, int);
-
-extern char *decode_bits_in_field(gint bit_offset, gint no_of_bits, guint64 value);
-
-extern char *other_decode_bitfield_value(char *buf, guint32 val, guint32 mask,
- int width);
-extern char *decode_bitfield_value(char *buf, guint32 val, guint32 mask,
- int width);
-extern const char *decode_boolean_bitfield(guint32 val, guint32 mask, int width,
- const char *truedesc, const char *falsedesc);
-extern const char *decode_numeric_bitfield(guint32 val, guint32 mask, int width,
- const char *fmt);
+WS_DLL_PUBLIC gchar* address_to_str(wmem_allocator_t *scope, const address *addr);
+WS_DLL_PUBLIC gchar* address_with_resolution_to_str(wmem_allocator_t *scope, const address *addr);
+WS_DLL_PUBLIC gchar* tvb_address_with_resolution_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, int type, const gint offset);
+
+/*
+ * address_to_name takes as input an "address", as defined in address.h.
+ *
+ * If the address is of a type that can be translated into a name, and the
+ * user has activated name resolution, and the name can be resolved, it
+ * returns a string containing the translated name.
+ *
+ * Otherwise, it returns NULL.
+ */
+WS_DLL_PUBLIC const gchar *address_to_name(const address *addr);
+
+/*
+ * address_to_display takes as input an "address", as defined in address.h .
+ *
+ * If the address is of a type that can be translated into a name, and the
+ * user has activated name resolution, and the name can be resolved, it
+ * returns a string containing the translated name.
+ *
+ * Otherwise, if the address is of type AT_NONE, it returns "NONE".
+ *
+ * Otherwise, it returns a string containing the result of address_to_str
+ * on the argument, which should be a string representation for the address,
+ * e.g. "10.10.10.10" for IPv4 address 10.10.10.10.
+ */
+WS_DLL_PUBLIC
+gchar *address_to_display(wmem_allocator_t *allocator, const address *addr);
+
+WS_DLL_PUBLIC void address_to_str_buf(const address *addr, gchar *buf, int buf_len);
+
+#define tvb_ether_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_ETHER, offset)
+#define tvb_ip_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_IPv4, offset)
+#define tvb_ip6_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_IPv6, offset)
+#define tvb_fcwwn_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_FCWWN, offset)
+#define tvb_fc_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_FC, offset)
+#define tvb_eui64_to_str(tvb, offset) tvb_address_to_str(wmem_packet_scope(), tvb, AT_EUI64, offset)
+
+void ip_to_str_buf(const guint8 *ad, gchar *buf, const int buf_len);
+
+/* Returns length of the result. */
+int ip6_to_str_buf(const ws_in6_addr *ad, gchar *buf, int buf_size);
+
+/* Returns length of the result. Takes a prefix to be inserted before the address. */
+int ip6_to_str_buf_with_pfx(const ws_in6_addr *ad, gchar *buf, int buf_size, const char *prefix);
+
+extern gchar* ipxnet_to_str_punct(wmem_allocator_t *scope, const guint32 ad, const char punct);
+WS_DLL_PUBLIC gchar* eui64_to_str(wmem_allocator_t *scope, const guint64 ad);
+
+WS_DLL_PUBLIC gchar* abs_time_to_str(wmem_allocator_t *scope, const nstime_t*, const absolute_time_display_e fmt,
+ gboolean show_zone);
+WS_DLL_PUBLIC gchar* abs_time_secs_to_str(wmem_allocator_t *scope, const time_t, const absolute_time_display_e fmt,
+ gboolean show_zone);
+WS_DLL_PUBLIC void display_epoch_time(gchar *, int, const time_t, gint32, const to_str_time_res_t);
+
+WS_DLL_PUBLIC void display_signed_time(gchar *, int, const gint32, gint32, const to_str_time_res_t);
+
+WS_DLL_PUBLIC gchar* signed_time_secs_to_str(wmem_allocator_t *scope, const gint32 time_val);
+WS_DLL_PUBLIC gchar* unsigned_time_secs_to_str(wmem_allocator_t *scope, const guint32);
+WS_DLL_PUBLIC gchar* signed_time_msecs_to_str(wmem_allocator_t *scope, gint32 time_val);
+
+WS_DLL_PUBLIC void guint32_to_str_buf(guint32 u, gchar *buf, int buf_len);
+WS_DLL_PUBLIC void guint64_to_str_buf(guint64 u, gchar *buf, int buf_len);
+
+WS_DLL_PUBLIC gchar* rel_time_to_str(wmem_allocator_t *scope, const nstime_t*);
+WS_DLL_PUBLIC gchar* rel_time_to_secs_str(wmem_allocator_t *scope, const nstime_t*);
+WS_DLL_PUBLIC gchar* guid_to_str(wmem_allocator_t *scope, const e_guid_t*);
+gchar* guid_to_str_buf(const e_guid_t*, gchar*, int);
+
+WS_DLL_PUBLIC char *decode_bits_in_field(const guint bit_offset, const gint no_of_bits, const guint64 value);
+
+WS_DLL_PUBLIC const gchar* port_type_to_str (port_type type);
+
+/** Turn an address type retrieved from a tvb into a string.
+ *
+ * @param scope memory allocation scheme used
+ * @param tvb tvbuff to retrieve address
+ * @param type address type to retrieve
+ * @param offset offset into tvb to retrieve address
+ * @return A pointer to the formatted string
+ *
+ */
+WS_DLL_PUBLIC gchar* tvb_address_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, int type, const gint offset);
+
+/** Turn an address type retrieved from a tvb into a string.
+ *
+ * @param scope memory allocation scheme used
+ * @param tvb tvbuff to retrieve address
+ * @param type address type to retrieve
+ * @param offset offset into tvb to retrieve address
+ * @param length The length of the string
+ * @return A pointer to the formatted string
+ *
+ */
+WS_DLL_PUBLIC gchar* tvb_address_var_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, address_type type, const gint offset, int length);
+
+/**
+ * guint8_to_hex()
+ *
+ * Output guint8 hex represetation to 'out', and return pointer after last character (out + 4).
+ * It always output full representation (padded with 0).
+ *
+ * String is not NUL terminated by this routine.
+ * There needs to be at least 2 bytes in the buffer.
+ */
+WS_DLL_PUBLIC char *guint8_to_hex(char *out, guint8 val);
+
+/**
+ * word_to_hex()
+ *
+ * Output guint16 hex represetation to 'out', and return pointer after last character (out + 4).
+ * It always output full representation (padded with 0).
+ *
+ * String is not NUL terminated by this routine.
+ * There needs to be at least 4 bytes in the buffer.
+ */
+WS_DLL_PUBLIC char *word_to_hex(char *out, guint16 word);
+
+/**
+ * dword_to_hex()
+ *
+ * Output guint32 hex represetation to 'out', and return pointer after last character.
+ * It always output full representation (padded with 0).
+ *
+ * String is not NUL terminated by this routine.
+ * There needs to be at least 8 bytes in the buffer.
+ */
+WS_DLL_PUBLIC char *dword_to_hex(char *out, guint32 dword);
+
+/** Turn an array of bytes into a string showing the bytes in hex.
+ *
+ * @param scope memory allocation scheme used
+ * @param bd A pointer to the byte array
+ * @param bd_len The length of the byte array
+ * @return A pointer to the formatted string
+ */
+WS_DLL_PUBLIC char *bytes_to_str(wmem_allocator_t *scope, const guint8 *bd, int bd_len);
+
+/** Turn an array of bytes into a string showing the bytes in hex,
+ * separated by a punctuation character.
+ *
+ * @param scope memory allocation scheme used
+ * @param ad A pointer to the byte array
+ * @param len The length of the byte array
+ * @param punct The punctuation character
+ * @return A pointer to the formatted string
+ *
+ * @see bytes_to_str()
+ */
+WS_DLL_PUBLIC gchar *bytestring_to_str(wmem_allocator_t *scope, const guint8 *ad, const guint32 len, const char punct);
+
+/**
+ * bytes_to_hexstr()
+ *
+ * Output hex represetation of guint8 ad array, and return pointer after last character.
+ * It always output full representation (padded with 0).
+ *
+ * String is not NUL terminated by this routine.
+ * There needs to be at least len * 2 bytes in the buffer.
+ */
+WS_DLL_PUBLIC char *bytes_to_hexstr(char *out, const guint8 *ad, guint32 len);
+
+/**
+ * uint_to_str_back()
+ *
+ * Output guint32 decimal representation backward (last character will be written on ptr - 1),
+ * and return pointer to first character.
+ *
+ * String is not NUL terminated by this routine.
+ * There needs to be at least 10 bytes in the buffer.
+ */
+WS_DLL_PUBLIC char *uint_to_str_back(char *ptr, guint32 value);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
#endif /* __TO_STR_H__ */