Move more numerical epan/*to_str() routines to wsutil

This commit is contained in:
João Valverde 2021-09-16 14:54:09 +01:00
parent 5b4c7e1c46
commit 24fd8c6740
13 changed files with 167 additions and 210 deletions

View File

@ -90,7 +90,7 @@
#include <wsutil/inet_addr.h>
#include <epan/strutil.h>
#include <epan/to_str-int.h>
#include <epan/to_str.h>
#include <epan/maxmind_db.h>
#include <epan/prefs.h>
#include <epan/uat.h>

View File

@ -13,7 +13,6 @@
#include "packet.h"
#include "address_types.h"
#include "to_str.h"
#include "to_str-int.h"
#include "addr_resolv.h"
#include "wsutil/pint.h"
#include "wsutil/str_util.h"

View File

@ -63,7 +63,7 @@
#include <epan/address_types.h>
#include <epan/addr_resolv.h>
#include <epan/to_str.h>
#include <epan/to_str-int.h>
#include <epan/to_str.h>
#include <epan/conversation.h>
#include <epan/tap.h>
#include <epan/etypes.h>

View File

@ -14,7 +14,7 @@
#include <epan/strutil.h>
#include <epan/oids.h>
#include <epan/osi-utils.h>
#include <epan/to_str-int.h>
#include <epan/to_str.h>
#define CMP_MATCHES cmp_matches

View File

@ -13,7 +13,7 @@
#include "ftypes-int.h"
#include <epan/addr_resolv.h>
#include <epan/strutil.h>
#include <epan/to_str-int.h>
#include <epan/to_str.h>
#include <wsutil/pint.h>

View File

@ -10,7 +10,7 @@
#include <ftypes-int.h>
#include <epan/strutil.h>
#include <wsutil/to_str.h>
#include <epan/to_str.h>
#include <string.h>
#include <wsutil/glib-compat.h>

View File

@ -19,7 +19,7 @@
#include <epan/epan.h>
#include <epan/epan_dissect.h>
#include <epan/to_str.h>
#include <epan/to_str-int.h>
#include <epan/to_str.h>
#include <epan/expert.h>
#include <epan/column.h>
#include <epan/column-info.h>

View File

@ -40,7 +40,6 @@
#include <epan/wmem_scopes.h>
#include "charsets.h"
#include "column-utils.h"
#include "to_str-int.h"
#include "to_str.h"
#include "osi-utils.h"
#include "expert.h"

View File

@ -1,74 +0,0 @@
/* to_str-int.h
* Definitions for utilities to convert various other types to strings.
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef __TO_STR_INT_H__
#define __TO_STR_INT_H__
#include <glib.h>
/**
* word_to_hex_punct()
*
* Output guint16 hex represetation to 'out', and return pointer after last character.
* Each byte will be separated with punct character (cannot be NUL).
* It always output full representation (padded with 0).
*
* String is not NUL terminated by this routine.
* There needs to be at least 5 bytes in the buffer.
*/
char *word_to_hex_punct(char *out, guint16 word, char punct);
/**
* word_to_hex_npad()
*
* Output guint16 hex represetation to 'out', and return pointer after last character.
* Value is not padded.
*
* String is not NUL terminated by this routine.
* There needs to be at least 4 bytes in the buffer.
*/
char *word_to_hex_npad(char *out, guint16 word);
/**
* dword_to_hex_punct()
*
* Output guint32 hex represetation to 'out', and return pointer after last character.
* Each byte will be separated with punct character (cannot be NUL).
* It always output full representation (padded with 0).
*
* String is not NUL terminated by this routine.
* There needs to be at least 11 bytes in the buffer.
*/
char *dword_to_hex_punct(char *out, guint32 dword, char punct);
/**
* qword_to_hex()
*
* Output guint64 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 16 bytes in the buffer.
*/
char *qword_to_hex(char *out, guint64 qword);
/**
* qword_to_hex_punct()
*
* Output guint64 hex represetation to 'out', and return pointer after last character.
* Each byte will be separated with punct character (cannot be NUL).
* It always output full representation (padded with 0).
*
* String is not NUL terminated by this routine.
* There needs to be at least 22 bytes in the buffer.
*/
char *qword_to_hex_punct(char *out, guint64 qword, char punct);
#endif /* __TO_STR_INT_H__ */

View File

@ -18,7 +18,6 @@
#include <epan/wmem_scopes.h>
#include "proto.h"
#include "to_str.h"
#include "to_str-int.h"
#include "strutil.h"
#include <wsutil/pint.h>
#include <wsutil/utf8_entities.h>
@ -31,100 +30,6 @@
*/
#define BUF_TOO_SMALL_ERR "[Buffer too small]"
static inline char
low_nibble_of_octet_to_hex(guint8 oct)
{
/* At least one version of Apple's C compiler/linker is buggy, causing
a complaint from the linker about the "literal C string section"
not ending with '\0' if we initialize a 16-element "char" array with
a 16-character string, the fact that initializing such an array with
such a string is perfectly legitimate ANSI C nonwithstanding, the 17th
'\0' byte in the string nonwithstanding. */
static const gchar hex_digits[16] =
{ '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
return hex_digits[oct & 0xF];
}
static inline char *
byte_to_hex(char *out, guint32 dword)
{
*out++ = low_nibble_of_octet_to_hex(dword >> 4);
*out++ = low_nibble_of_octet_to_hex(dword);
return out;
}
char *
guint8_to_hex(char *out, guint8 val)
{
return byte_to_hex(out, val);
}
char *
word_to_hex(char *out, guint16 word)
{
out = byte_to_hex(out, word >> 8);
out = byte_to_hex(out, word);
return out;
}
char *
word_to_hex_punct(char *out, guint16 word, char punct)
{
out = byte_to_hex(out, word >> 8);
*out++ = punct;
out = byte_to_hex(out, word);
return out;
}
char *
word_to_hex_npad(char *out, guint16 word)
{
if (word >= 0x1000)
*out++ = low_nibble_of_octet_to_hex((guint8)(word >> 12));
if (word >= 0x0100)
*out++ = low_nibble_of_octet_to_hex((guint8)(word >> 8));
if (word >= 0x0010)
*out++ = low_nibble_of_octet_to_hex((guint8)(word >> 4));
*out++ = low_nibble_of_octet_to_hex((guint8)(word >> 0));
return out;
}
char *
dword_to_hex(char *out, guint32 dword)
{
out = word_to_hex(out, dword >> 16);
out = word_to_hex(out, dword);
return out;
}
char *
dword_to_hex_punct(char *out, guint32 dword, char punct)
{
out = word_to_hex_punct(out, dword >> 16, punct);
*out++ = punct;
out = word_to_hex_punct(out, dword, punct);
return out;
}
char *
qword_to_hex(char *out, guint64 qword)
{
out = dword_to_hex(out, (guint32)(qword >> 32));
out = dword_to_hex(out, (guint32)(qword & 0xffffffff));
return out;
}
char *
qword_to_hex_punct(char *out, guint64 qword, char punct)
{
out = dword_to_hex_punct(out, (guint32)(qword >> 32), punct);
*out++ = punct;
out = dword_to_hex_punct(out, (guint32)(qword & 0xffffffff), punct);
return out;
}
static int
guint32_to_str_buf_len(const guint32 u)
{

View File

@ -136,39 +136,6 @@ WS_DLL_PUBLIC gchar* tvb_address_to_str(wmem_allocator_t *scope, tvbuff_t *tvb,
*/
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);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -80,6 +80,76 @@ byte_to_hex(char *out, guint32 dword)
return out;
}
char *
guint8_to_hex(char *out, guint8 val)
{
return byte_to_hex(out, val);
}
char *
word_to_hex(char *out, guint16 word)
{
out = byte_to_hex(out, word >> 8);
out = byte_to_hex(out, word);
return out;
}
char *
word_to_hex_punct(char *out, guint16 word, char punct)
{
out = byte_to_hex(out, word >> 8);
*out++ = punct;
out = byte_to_hex(out, word);
return out;
}
char *
word_to_hex_npad(char *out, guint16 word)
{
if (word >= 0x1000)
*out++ = low_nibble_of_octet_to_hex((guint8)(word >> 12));
if (word >= 0x0100)
*out++ = low_nibble_of_octet_to_hex((guint8)(word >> 8));
if (word >= 0x0010)
*out++ = low_nibble_of_octet_to_hex((guint8)(word >> 4));
*out++ = low_nibble_of_octet_to_hex((guint8)(word >> 0));
return out;
}
char *
dword_to_hex(char *out, guint32 dword)
{
out = word_to_hex(out, dword >> 16);
out = word_to_hex(out, dword);
return out;
}
char *
dword_to_hex_punct(char *out, guint32 dword, char punct)
{
out = word_to_hex_punct(out, dword >> 16, punct);
*out++ = punct;
out = word_to_hex_punct(out, dword, punct);
return out;
}
char *
qword_to_hex(char *out, guint64 qword)
{
out = dword_to_hex(out, (guint32)(qword >> 32));
out = dword_to_hex(out, (guint32)(qword & 0xffffffff));
return out;
}
char *
qword_to_hex_punct(char *out, guint64 qword, char punct)
{
out = dword_to_hex_punct(out, (guint32)(qword >> 32), punct);
*out++ = punct;
out = dword_to_hex_punct(out, (guint32)(qword & 0xffffffff), punct);
return out;
}
/*
* This does *not* null-terminate the string. It returns a pointer
* to the position in the string following the last character it

View File

@ -20,6 +20,97 @@
extern "C" {
#endif /* __cplusplus */
/**
* 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);
/**
* word_to_hex_punct()
*
* Output guint16 hex represetation to 'out', and return pointer after last character.
* Each byte will be separated with punct character (cannot be NUL).
* It always output full representation (padded with 0).
*
* String is not NUL terminated by this routine.
* There needs to be at least 5 bytes in the buffer.
*/
WS_DLL_PUBLIC char *word_to_hex_punct(char *out, guint16 word, char punct);
/**
* word_to_hex_npad()
*
* Output guint16 hex represetation to 'out', and return pointer after last character.
* Value is not padded.
*
* 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_npad(char *out, guint16 word);
/**
* dword_to_hex_punct()
*
* Output guint32 hex represetation to 'out', and return pointer after last character.
* Each byte will be separated with punct character (cannot be NUL).
* It always output full representation (padded with 0).
*
* String is not NUL terminated by this routine.
* There needs to be at least 11 bytes in the buffer.
*/
WS_DLL_PUBLIC char *dword_to_hex_punct(char *out, guint32 dword, char punct);
/**
* qword_to_hex()
*
* Output guint64 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 16 bytes in the buffer.
*/
WS_DLL_PUBLIC char *qword_to_hex(char *out, guint64 qword);
/**
* qword_to_hex_punct()
*
* Output guint64 hex represetation to 'out', and return pointer after last character.
* Each byte will be separated with punct character (cannot be NUL).
* It always output full representation (padded with 0).
*
* String is not NUL terminated by this routine.
* There needs to be at least 22 bytes in the buffer.
*/
WS_DLL_PUBLIC char *qword_to_hex_punct(char *out, guint64 qword, char punct);
/**
* bytes_to_hexstr()
*