Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Enumerations | Functions
range.h File Reference
#include "ws_symbol_export.h"
#include <epan/wmem_scopes.h>

Go to the source code of this file.

Classes

struct  range_admin_tag
 Represents a single contiguous range of unsigned integer values with an inclusive lower and upper bound. More...
 
struct  epan_range
 

Macros

#define MAX_SCTP_PORT   65535
 
#define MAX_TCP_PORT   65535
 
#define MAX_UDP_PORT   65535
 
#define MAX_DCCP_PORT   65535
 
#define RANGE_ADMIN_T_INITIALIZER   { 0, 0 }
 

Typedefs

typedef struct range_admin_tag range_admin_t
 Represents a single contiguous range of unsigned integer values with an inclusive lower and upper bound.
 
typedef struct epan_range range_t
 

Enumerations

enum  convert_ret_t { CVT_NO_ERROR , CVT_SYNTAX_ERROR , CVT_NUMBER_TOO_BIG }
 Return value from range_convert_str(). More...
 

Functions

WS_DLL_PUBLIC range_trange_empty (wmem_allocator_t *scope)
 Creates an empty range_t structure.
 
WS_DLL_PUBLIC convert_ret_t range_convert_str (wmem_allocator_t *scope, range_t **range, const char *es, uint32_t max_value)
 Converts a range string to a fast comparable array of ranges.
 
WS_DLL_PUBLIC convert_ret_t range_convert_str_work (wmem_allocator_t *scope, range_t **range, const char *es, uint32_t max_value, bool err_on_max)
 Internal worker for converting a textual range specification.
 
WS_DLL_PUBLIC bool value_is_in_range (const range_t *range, uint32_t val)
 
WS_DLL_PUBLIC bool range_add_value (wmem_allocator_t *scope, range_t **range, uint32_t val)
 
WS_DLL_PUBLIC bool range_remove_value (wmem_allocator_t *scope, range_t **range, uint32_t val)
 
WS_DLL_PUBLIC bool ranges_are_equal (const range_t *a, const range_t *b)
 
WS_DLL_PUBLIC void range_foreach (range_t *range, void(*callback)(uint32_t val, void *ptr), void *ptr)
 
WS_DLL_PUBLIC char * range_convert_range (wmem_allocator_t *scope, const range_t *range)
 
WS_DLL_PUBLIC range_trange_copy (wmem_allocator_t *scope, const range_t *src)
 

Detailed Description

Range strings a variant of value_strings

Macro Definition Documentation

◆ MAX_SCTP_PORT

#define MAX_SCTP_PORT   65535
Todo:
where's the best place for these?

◆ RANGE_ADMIN_T_INITIALIZER

#define RANGE_ADMIN_T_INITIALIZER   { 0, 0 }

Default initializer for a range_admin_t, setting both bounds to zero.

Typedef Documentation

◆ range_t

typedef struct epan_range range_t

user specified range(s)

Enumeration Type Documentation

◆ convert_ret_t

Return value from range_convert_str().

Enumerator
CVT_NO_ERROR 

The range string was parsed successfully without errors

CVT_SYNTAX_ERROR 

The range string contains invalid or unrecognised syntax

CVT_NUMBER_TOO_BIG 

The range string contains a numeric value that exceeds the allowed maximum

Function Documentation

◆ range_add_value()

WS_DLL_PUBLIC bool range_add_value ( wmem_allocator_t scope,
range_t **  range,
uint32_t  val 
)

This function returns true if val has successfully been added to a range. This may extend an existing range or create a new one

Parameters
scopememory scope of range (in case of reallocation)
rangeto add value
valvalue to add to range
Returns
true if the value is successfully added to range

◆ range_convert_range()

WS_DLL_PUBLIC char * range_convert_range ( wmem_allocator_t scope,
const range_t range 
)

This function converts a range_t to a (wmem_alloc()-allocated) string.

◆ range_convert_str()

WS_DLL_PUBLIC convert_ret_t range_convert_str ( wmem_allocator_t scope,
range_t **  range,
const char *  es,
uint32_t  max_value 
)

Converts a range string to a fast comparable array of ranges.

This function allocates a range_t large enough to hold the number of ranges specified, and fills the array range->ranges containing low and high values with the number of ranges being range->nranges. After having called this function, the function value_is_in_range() determines whether a given number is within the range or not.
In case of a single number, we make a range where low is equal to high. We take care on wrongly entered ranges; opposite order will be taken care of.

The following syntax is accepted :

1-20,30-40 Range from 1 to 20, and packets 30 to 40 -20,30 Range from 1 to 20, and packet 30 20,30,40- 20, 30, and the range from 40 to the end 20-10,30-25 Range from 10 to 20, and from 25 to 30

  • All values
    Parameters
    scopememory scope for the range
    rangethe range
    espoints to the string to be converted.
    max_valuespecifies the maximum value in a range.
    Returns
    convert_ret_t indicating success or the type of parsing error.

◆ range_convert_str_work()

WS_DLL_PUBLIC convert_ret_t range_convert_str_work ( wmem_allocator_t scope,
range_t **  range,
const char *  es,
uint32_t  max_value,
bool  err_on_max 
)

Internal worker for converting a textual range specification.

Parameters
scopeMemory scope used for allocating the resulting range_t.
rangeOutput pointer receiving the allocated and populated range_t.
esThe textual range expression to parse.
max_valueMaximum allowed value for open‑ended or bounded ranges.
err_on_maxIf true, treat values > max_value as errors; if false, clamp them to max_value.
Returns
convert_ret_t indicating success or the type of parsing error.

◆ range_copy()

WS_DLL_PUBLIC range_t * range_copy ( wmem_allocator_t scope,
const range_t src 
)

Create a (wmem-alloc()ed) copy of a range

Parameters
scopememory scope for the copied range
srcthe range to copy
Returns
ep allocated copy of the range

◆ range_empty()

WS_DLL_PUBLIC range_t * range_empty ( wmem_allocator_t scope)

Creates an empty range_t structure.

This function allocates memory for a new range_t structure and initializes it to represent an empty range.

Parameters
scopeThe memory allocation scope.
Returns
A pointer to the newly created range_t structure, or NULL if allocation fails.

◆ range_foreach()

WS_DLL_PUBLIC void range_foreach ( range_t range,
void(*)(uint32_t val, void *ptr)  callback,
void *  ptr 
)

This function calls the provided callback function for each value in in the range. Takes a pointer argument, which is passed to the callback, along with the value in the range.

Parameters
rangethe range
callbackthe callback function
ptrpointer passed to the callback

◆ range_remove_value()

WS_DLL_PUBLIC bool range_remove_value ( wmem_allocator_t scope,
range_t **  range,
uint32_t  val 
)

This function returns true if val has successfully been removed from a range. This may remove an existing range.

Parameters
scopememory scope of range (in case of reallocation)
rangeto remove value
valvalue to remove within range
Returns
true if the value is successfully removed to range

◆ ranges_are_equal()

WS_DLL_PUBLIC bool ranges_are_equal ( const range_t a,
const range_t b 
)

This function returns true if the two given range_t's are equal.

Parameters
afirst range
bsecond range
Returns
true if the value is in range

◆ value_is_in_range()

WS_DLL_PUBLIC bool value_is_in_range ( const range_t range,
uint32_t  val 
)

This function returns true if a given value is within one of the ranges stored in the ranges array.

Parameters
rangethe range
valthe value to check
Returns
true if the value is in range