Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
Macros | Functions
to_str.h File Reference
#include "wsutil/nstime.h"
#include <wsutil/inet_cidr.h>
#include <epan/proto.h>
#include <epan/packet_info.h>
#include "ws_symbol_export.h"
#include <epan/wmem_scopes.h>
#include <wsutil/to_str.h>

Go to the source code of this file.

Macros

#define GUID_STR_LEN   37
 
#define MAX_ADDR_STR_LEN   256
 
#define VINES_ADDR_LEN   6
 
#define EUI64_STR_LEN   24
 
#define EUI64_ADDR_LEN   8
 
#define AX25_ADDR_LEN   7
 
#define FCWWN_ADDR_LEN   8
 
#define tvb_ether_to_str(scope, tvb, offset)   tvb_address_to_str(scope, tvb, AT_ETHER, offset)
 
#define tvb_ip_to_str(scope, tvb, offset)   tvb_address_to_str(scope, tvb, AT_IPv4, offset)
 
#define tvb_ip6_to_str(scope, tvb, offset)   tvb_address_to_str(scope, tvb, AT_IPv6, offset)
 
#define tvb_fcwwn_to_str(scope, tvb, offset)   tvb_address_to_str(scope, tvb, AT_FCWWN, offset)
 
#define tvb_fc_to_str(scope, tvb, offset)   tvb_address_to_str(scope, tvb, AT_FC, offset)
 
#define tvb_eui64_to_str(scope, tvb, offset)   tvb_address_to_str(scope, tvb, AT_EUI64, offset)
 
#define ABS_TIME_TO_STR_SHOW_ZONE   (1U << 0)
 
#define ABS_TIME_TO_STR_ADD_DQUOTES   (1U << 1)
 
#define ABS_TIME_TO_STR_SHOW_UTC_ONLY   (1U << 2)
 
#define ABS_TIME_TO_STR_ISO8601   (1U << 3)
 
#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)
 
#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)
 

Functions

WS_DLL_PUBLIC char * address_to_str (wmem_allocator_t *scope, const address *addr)
 Converts an address to a string.
 
WS_DLL_PUBLIC char * address_with_resolution_to_str (wmem_allocator_t *scope, const address *addr)
 Converts an address to a string with name resolution if possible.
 
WS_DLL_PUBLIC const char * address_to_name (const address *addr)
 Converts an address to a name string if possible.
 
WS_DLL_PUBLIC char * address_to_display (wmem_allocator_t *allocator, const address *addr)
 Converts an address to a string representation to be displayed.
 
WS_DLL_PUBLIC void address_to_str_buf (const address *addr, char *buf, int buf_len)
 Convert an address to a string buffer.
 
WS_DLL_PUBLIC const char * port_type_to_str (port_type type)
 Converts a port type to its string representation.
 
WS_DLL_PUBLIC char * tvb_address_with_resolution_to_str (wmem_allocator_t *scope, tvbuff_t *tvb, int type, const unsigned offset)
 Converts a TVB address to a string with resolution.
 
WS_DLL_PUBLIC char * tvb_address_to_str (wmem_allocator_t *scope, tvbuff_t *tvb, int type, const unsigned offset)
 
WS_DLL_PUBLIC char * tvb_address_var_to_str (wmem_allocator_t *scope, tvbuff_t *tvb, address_type type, const unsigned offset, unsigned length)
 
WS_DLL_PUBLIC char * abs_time_to_str_ex (wmem_allocator_t *scope, const nstime_t *abs_time, field_display_e fmt, int flags)
 Convert an absolute time to a string representation.
 
char * abs_time_to_unix_str (wmem_allocator_t *scope, const nstime_t *rel_time)
 Converts an absolute time to a Unix timestamp string.
 
WS_DLL_PUBLIC char * abs_time_secs_to_str_ex (wmem_allocator_t *scope, const time_t abs_time_secs, field_display_e fmt, int flags)
 Convert an absolute time in seconds to a string representation.
 
WS_DLL_PUBLIC char * signed_time_secs_to_str (wmem_allocator_t *scope, const int32_t time_val)
 Convert a signed value in seconds to a string.
 
WS_DLL_PUBLIC char * unsigned_time_secs_to_str (wmem_allocator_t *scope, const uint32_t time_val)
 Convert an unsigned value in seconds to a string.
 
WS_DLL_PUBLIC char * signed_time_msecs_to_str (wmem_allocator_t *scope, int32_t time_val)
 Convert a signed time value in milliseconds to a string.
 
WS_DLL_PUBLIC char * rel_time_to_str (wmem_allocator_t *scope, const nstime_t *rel_time)
 Convert a relative time to a string representation.
 
WS_DLL_PUBLIC char * rel_time_to_secs_str (wmem_allocator_t *scope, const nstime_t *rel_time)
 Converts a relative time to a string representation in seconds.
 
WS_DLL_PUBLIC char * guid_to_str_buf (const e_guid_t *guid, char *buf, int buf_len)
 Convert a GUID to a string buffer.
 
WS_DLL_PUBLIC char * guid_to_str (wmem_allocator_t *scope, const e_guid_t *guid)
 Convert a GUID to a string.
 
WS_DLL_PUBLIC char * decode_bits_in_field (wmem_allocator_t *scope, const unsigned bit_offset, const int no_of_bits, const uint64_t value, const unsigned encoding)
 Decodes bits from a given offset and number of bits in a value.
 

Detailed Description

Definitions for utilities to convert various other types to strings.

Wireshark - Network traffic analyzer By Gerald Combs geral.nosp@m.d@wi.nosp@m.resha.nosp@m.rk.o.nosp@m.rg Copyright 1998 Gerald Combs

SPDX-License-Identifier: GPL-2.0-or-later

Function Documentation

◆ abs_time_secs_to_str_ex()

WS_DLL_PUBLIC char * abs_time_secs_to_str_ex ( wmem_allocator_t scope,
const time_t  abs_time_secs,
field_display_e  fmt,
int  flags 
)

Convert an absolute time in seconds to a string representation.

Parameters
scopeMemory allocation scope for the resulting string.
abs_time_secsAbsolute time in seconds.
fmtFormat of the time string (e.g., ABSOLUTE_TIME_LOCAL).
flagsFlags indicating additional formatting options.
Returns
String representation of the absolute time.

◆ abs_time_to_str_ex()

WS_DLL_PUBLIC char * abs_time_to_str_ex ( wmem_allocator_t scope,
const nstime_t abs_time,
field_display_e  fmt,
int  flags 
)

Convert an absolute time to a string representation.

Converts an absolute time to a human-readable string based on the specified format.

Parameters
scopeMemory allocator scope for the returned string.
abs_timePointer to the nstime_t structure representing the absolute time.
fmtThe format of the output string (e.g., ABSOLUTE_TIME_LOCAL, ABSOLUTE_TIME_UNIX).
flagsAdditional flags that modify the formatting behavior.
Returns
A dynamically allocated string representing the formatted time.

◆ abs_time_to_unix_str()

char * abs_time_to_unix_str ( wmem_allocator_t scope,
const nstime_t rel_time 
)

Converts an absolute time to a Unix timestamp string.

Parameters
scopeMemory allocation scope.
rel_timeRelative time structure.
Returns
String representing the Unix timestamp.

◆ address_to_display()

WS_DLL_PUBLIC char * address_to_display ( wmem_allocator_t allocator,
const address addr 
)

Converts an address to a string representation to be displayed.

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.

Parameters
allocatorMemory allocation scope for the resulting string.
addrThe address to convert.
Returns
A string containing the translated name, "NONE", or a string representation of the address.

◆ address_to_name()

WS_DLL_PUBLIC const char * address_to_name ( const address addr)

Converts an address to a name string if possible.

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.

Parameters
addrThe address to convert.
Returns
A string containing the translated name, or NULL if translation is not possible

◆ address_to_str()

WS_DLL_PUBLIC char * address_to_str ( wmem_allocator_t scope,
const address addr 
)

Converts an address to a string.

Parameters
scopeMemory allocation scope for the resulting string.
addrThe address to convert.
Returns
A string representation of the address.

◆ address_to_str_buf()

WS_DLL_PUBLIC void address_to_str_buf ( const address addr,
char *  buf,
int  buf_len 
)

Convert an address to a string buffer.

Parameters
addrThe address structure to convert.
bufThe buffer to store the resulting string.
buf_lenThe length of the buffer.

◆ address_with_resolution_to_str()

WS_DLL_PUBLIC char * address_with_resolution_to_str ( wmem_allocator_t scope,
const address addr 
)

Converts an address to a string with name resolution if possible.

Parameters
scopeMemory allocation scope.
addrThe address to convert.
Returns
A string containing the translated name or address string.

◆ decode_bits_in_field()

WS_DLL_PUBLIC char * decode_bits_in_field ( wmem_allocator_t scope,
const unsigned  bit_offset,
const int  no_of_bits,
const uint64_t  value,
const unsigned  encoding 
)

Decodes bits from a given offset and number of bits in a value.

Parameters
scopeMemory allocator scope for allocating the result string.
bit_offsetOffset within the value where decoding starts.
no_of_bitsNumber of bits to decode from the value.
valueThe 64-bit unsigned integer containing the bits to decode.
encodingEncoding type, such as little-endian or big-endian.
Returns
A string representing the decoded bits, or NULL on failure.

◆ guid_to_str()

WS_DLL_PUBLIC char * guid_to_str ( wmem_allocator_t scope,
const e_guid_t guid 
)

Convert a GUID to a string.

Parameters
scopeMemory allocation scope.
guidPointer to the GUID structure.
Returns
String representation of the GUID.

◆ guid_to_str_buf()

WS_DLL_PUBLIC char * guid_to_str_buf ( const e_guid_t guid,
char *  buf,
int  buf_len 
)

Convert a GUID to a string buffer.

Parameters
guidPointer to the GUID structure to convert.
bufBuffer to store the resulting string.
buf_lenLength of the buffer.
Returns
A pointer to the buffer containing the string representation of the GUID.

◆ port_type_to_str()

WS_DLL_PUBLIC const char * port_type_to_str ( port_type  type)

Converts a port type to its string representation.

Parameters
typeThe port type to convert.
Returns
const char* A string representing the port type.

◆ rel_time_to_secs_str()

WS_DLL_PUBLIC char * rel_time_to_secs_str ( wmem_allocator_t scope,
const nstime_t rel_time 
)

Converts a relative time to a string representation in seconds.

Parameters
scopeMemory allocation scope for the resulting string.
rel_timePointer to the nstime_t structure representing the relative time.
Returns
A dynamically allocated string representing the time in seconds.

◆ rel_time_to_str()

WS_DLL_PUBLIC char * rel_time_to_str ( wmem_allocator_t scope,
const nstime_t rel_time 
)

Convert a relative time to a string representation.

Parameters
scopeMemory allocator scope for the resulting string.
rel_timePointer to the nstime_t structure representing the relative time.
Returns
A dynamically allocated string representing the relative time in seconds and nanoseconds.

◆ signed_time_msecs_to_str()

WS_DLL_PUBLIC char * signed_time_msecs_to_str ( wmem_allocator_t scope,
int32_t  time_val 
)

Convert a signed time value in milliseconds to a string.

Parameters
scopeMemory allocation scope for the resulting string.
time_valSigned time value in milliseconds.
Returns
String representation of the time value.

◆ signed_time_secs_to_str()

WS_DLL_PUBLIC char * signed_time_secs_to_str ( wmem_allocator_t scope,
const int32_t  time_val 
)

Convert a signed value in seconds to a string.

Parameters
scopeMemory allocation scope.
time_valSigned time value in seconds.
Returns
String representation of the time value.

◆ tvb_address_to_str()

WS_DLL_PUBLIC char * tvb_address_to_str ( wmem_allocator_t scope,
tvbuff_t tvb,
int  type,
const unsigned  offset 
)

Turn an address type retrieved from a tvb into a string.

Parameters
scopememory allocation scheme used
tvbtvbuff to retrieve address
typeaddress type to retrieve
offsetoffset into tvb to retrieve address
Returns
A pointer to the formatted string

◆ tvb_address_var_to_str()

WS_DLL_PUBLIC char * tvb_address_var_to_str ( wmem_allocator_t scope,
tvbuff_t tvb,
address_type  type,
const unsigned  offset,
unsigned  length 
)

Turn an address type retrieved from a tvb into a string.

Parameters
scopememory allocation scheme used
tvbtvbuff to retrieve address
typeaddress type to retrieve
offsetoffset into tvb to retrieve address
lengthThe length of the string
Returns
A pointer to the formatted string

◆ tvb_address_with_resolution_to_str()

WS_DLL_PUBLIC char * tvb_address_with_resolution_to_str ( wmem_allocator_t scope,
tvbuff_t tvb,
int  type,
const unsigned  offset 
)

Converts a TVB address to a string with resolution.

Parameters
scopeMemory allocator scope.
tvbThe TV buffer containing the address data.
typeThe address type (e.g., AT_ETHER, AT_IPv4).
offsetThe offset within the TV buffer where the address starts.
Returns
char* A string representation of the address with resolution, or NULL if an error occurs.

◆ unsigned_time_secs_to_str()

WS_DLL_PUBLIC char * unsigned_time_secs_to_str ( wmem_allocator_t scope,
const uint32_t  time_val 
)

Convert an unsigned value in seconds to a string.

Parameters
scopeMemory allocation scope.
time_valTime value in seconds.
Returns
String representation of the time value.