2021-11-26 03:31:05 +00:00
|
|
|
/** @file
|
2001-04-01 02:47:56 +00:00
|
|
|
* Definitions for utilities to convert various other types to strings.
|
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2001-04-01 02:47:56 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
2018-02-08 16:59:17 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2001-04-01 02:47:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __TO_STR_H__
|
|
|
|
#define __TO_STR_H__
|
|
|
|
|
2001-09-14 07:10:13 +00:00
|
|
|
#include <glib.h>
|
2001-04-01 02:47:56 +00:00
|
|
|
|
2013-06-25 22:02:20 +00:00
|
|
|
#include "wsutil/nstime.h"
|
2016-06-01 21:22:46 +00:00
|
|
|
#include <wsutil/inet_addr.h>
|
2021-12-26 16:53:23 +00:00
|
|
|
#include <epan/proto.h>
|
2009-08-21 20:51:13 +00:00
|
|
|
#include <epan/packet_info.h>
|
2016-01-03 20:30:57 +00:00
|
|
|
#include <epan/ipv6.h>
|
2013-03-01 23:53:11 +00:00
|
|
|
#include "ws_symbol_export.h"
|
2021-07-26 00:31:17 +00:00
|
|
|
#include <epan/wmem_scopes.h>
|
2021-07-25 21:53:03 +00:00
|
|
|
#include <wsutil/to_str.h>
|
2001-09-14 07:10:13 +00:00
|
|
|
|
2014-12-24 05:06:35 +00:00
|
|
|
#define GUID_STR_LEN 37
|
2007-01-29 20:25:26 +00:00
|
|
|
#define MAX_ADDR_STR_LEN 256
|
2014-12-24 05:06:35 +00:00
|
|
|
#define VINES_ADDR_LEN 6
|
|
|
|
#define EUI64_STR_LEN 24
|
|
|
|
#define AX25_ADDR_LEN 7
|
|
|
|
#define FCWWN_ADDR_LEN 8
|
2005-04-28 09:51:55 +00:00
|
|
|
|
2021-12-26 16:53:23 +00:00
|
|
|
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;
|
|
|
|
|
2013-08-30 21:15:24 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2002-08-28 20:41:00 +00:00
|
|
|
/*
|
2001-04-01 02:47:56 +00:00
|
|
|
* These are utility functions which convert various types to strings,
|
2002-08-28 20:41:00 +00:00
|
|
|
* but for which no more specific module applies.
|
2001-04-01 02:47:56 +00:00
|
|
|
*/
|
|
|
|
|
2021-09-16 14:50:39 +00:00
|
|
|
/*
|
|
|
|
************** Address
|
|
|
|
*/
|
|
|
|
|
|
|
|
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);
|
2015-01-06 00:26:28 +00:00
|
|
|
|
2015-07-02 23:17:20 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-01-08 13:25:17 +00:00
|
|
|
WS_DLL_PUBLIC const gchar *address_to_name(const address *addr);
|
2015-07-02 23:17:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-09-16 14:50:39 +00:00
|
|
|
WS_DLL_PUBLIC gchar *address_to_display(wmem_allocator_t *allocator, const address *addr);
|
2015-07-02 23:17:20 +00:00
|
|
|
|
2021-09-16 14:50:39 +00:00
|
|
|
WS_DLL_PUBLIC void address_to_str_buf(const address *addr, gchar *buf, int buf_len);
|
2015-01-06 00:26:28 +00:00
|
|
|
|
2021-09-16 14:50:39 +00:00
|
|
|
WS_DLL_PUBLIC const gchar *port_type_to_str (port_type type);
|
2016-05-09 20:21:44 +00:00
|
|
|
|
2021-09-16 14:50:39 +00:00
|
|
|
/*
|
|
|
|
************** TVB
|
|
|
|
*/
|
2016-05-09 20:21:44 +00:00
|
|
|
|
2021-09-16 14:50:39 +00:00
|
|
|
WS_DLL_PUBLIC gchar* tvb_address_with_resolution_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, int type, const gint offset);
|
2010-02-23 19:28:38 +00:00
|
|
|
|
2021-10-03 20:19:56 +00:00
|
|
|
#define tvb_ether_to_str(scope, tvb, offset) tvb_address_to_str(scope, tvb, AT_ETHER, offset)
|
2001-04-01 02:47:56 +00:00
|
|
|
|
2021-10-07 14:25:12 +00:00
|
|
|
#define tvb_ip_to_str(scope, tvb, offset) tvb_address_to_str(scope, tvb, AT_IPv4, offset)
|
2009-05-15 18:38:13 +00:00
|
|
|
|
2021-10-07 17:31:23 +00:00
|
|
|
#define tvb_ip6_to_str(scope, tvb, offset) tvb_address_to_str(scope, tvb, AT_IPv6, offset)
|
2021-09-16 14:50:39 +00:00
|
|
|
|
2021-10-04 17:14:21 +00:00
|
|
|
#define tvb_fcwwn_to_str(scope, tvb, offset) tvb_address_to_str(scope, tvb, AT_FCWWN, offset)
|
2021-09-16 14:50:39 +00:00
|
|
|
|
2021-10-04 17:14:21 +00:00
|
|
|
#define tvb_fc_to_str(scope, tvb, offset) tvb_address_to_str(scope, tvb, AT_FC, offset)
|
2021-09-16 14:50:39 +00:00
|
|
|
|
2021-10-04 17:14:21 +00:00
|
|
|
#define tvb_eui64_to_str(scope, tvb, offset) tvb_address_to_str(scope, tvb, AT_EUI64, offset)
|
2013-06-17 21:54:21 +00:00
|
|
|
|
2015-01-06 00:26:28 +00:00
|
|
|
/** 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
|
|
|
|
*
|
|
|
|
*/
|
2015-02-09 01:36:03 +00:00
|
|
|
WS_DLL_PUBLIC gchar* tvb_address_to_str(wmem_allocator_t *scope, tvbuff_t *tvb, int type, const gint offset);
|
2015-01-06 00:26:28 +00:00
|
|
|
|
|
|
|
/** 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
|
2015-04-28 19:52:39 +00:00
|
|
|
* @param length The length of the string
|
2015-01-06 00:26:28 +00:00
|
|
|
* @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);
|
|
|
|
|
2021-09-16 14:50:39 +00:00
|
|
|
/*
|
|
|
|
************** Time
|
|
|
|
*/
|
|
|
|
|
2021-12-28 02:49:38 +00:00
|
|
|
#define ABS_TIME_TO_STR_SHOW_ZONE (1U << 0)
|
|
|
|
#define ABS_TIME_TO_STR_ADD_DQUOTES (1U << 1)
|
2021-09-16 14:50:39 +00:00
|
|
|
|
2021-12-28 02:49:38 +00:00
|
|
|
WS_DLL_PUBLIC char *abs_time_to_str_ex(wmem_allocator_t *scope,
|
|
|
|
const nstime_t *, field_display_e fmt,
|
|
|
|
int flags);
|
|
|
|
|
|
|
|
#define abs_time_to_str(scope, nst, fmt, show_zone) \
|
|
|
|
abs_time_to_str_ex(scope, nst, fmt, (show_zone) ? ABS_TIME_TO_STR_SHOW_ZONE : 0)
|
|
|
|
|
|
|
|
WS_DLL_PUBLIC char *abs_time_secs_to_str_ex(wmem_allocator_t *scope,
|
|
|
|
const time_t, field_display_e fmt,
|
|
|
|
int flags);
|
|
|
|
|
|
|
|
#define abs_time_secs_to_str(scope, nst, fmt, show_zone) \
|
|
|
|
abs_time_secs_to_str_ex(scope, nst, fmt, (show_zone) ? ABS_TIME_TO_STR_SHOW_ZONE : 0)
|
2021-09-16 14:50:39 +00:00
|
|
|
|
|
|
|
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 gint64, 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 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 *);
|
|
|
|
|
|
|
|
/*
|
|
|
|
************** Misc
|
|
|
|
*/
|
|
|
|
|
|
|
|
WS_DLL_PUBLIC gchar *guid_to_str_buf(const e_guid_t *, gchar *, int);
|
|
|
|
|
|
|
|
WS_DLL_PUBLIC gchar *guid_to_str(wmem_allocator_t *scope, const e_guid_t *);
|
|
|
|
|
2021-10-04 17:35:37 +00:00
|
|
|
WS_DLL_PUBLIC char *decode_bits_in_field(wmem_allocator_t *scope, const guint bit_offset, const gint no_of_bits, const guint64 value, const guint encoding);
|
2021-09-16 14:50:39 +00:00
|
|
|
|
2013-08-30 21:15:24 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2001-04-01 02:47:56 +00:00
|
|
|
#endif /* __TO_STR_H__ */
|