Wireshark  4.3.0
The Wireshark network protocol analyzer
range.h
Go to the documentation of this file.
1 /* range.h
2  * Range routines
3  *
4  * Dick Gooris <gooris@lucent.com>
5  * Ulf Lamping <ulf.lamping@web.de>
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * SPDX-License-Identifier: GPL-2.0-or-later
12  */
13 
14 #ifndef __RANGE_H__
15 #define __RANGE_H__
16 
17 #include <glib.h>
18 #include "ws_symbol_export.h"
19 #include <epan/wmem_scopes.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif /* __cplusplus */
24 
30 #define MAX_SCTP_PORT 65535
31 #define MAX_TCP_PORT 65535
32 #define MAX_UDP_PORT 65535
33 #define MAX_DCCP_PORT 65535
34 
35 typedef struct range_admin_tag {
36  guint32 low;
37  guint32 high;
39 #define RANGE_ADMIN_T_INITIALIZER { 0, 0 }
40 
42 typedef struct epan_range {
43  guint nranges;
46 
50 typedef enum {
51  CVT_NO_ERROR,
52  CVT_SYNTAX_ERROR,
53  CVT_NUMBER_TOO_BIG
55 
56 WS_DLL_PUBLIC range_t *range_empty(wmem_allocator_t *scope);
57 
58 
59 /*** Converts a range string to a fast comparable array of ranges.
60  * This function allocates a range_t large enough to hold the number
61  * of ranges specified, and fills the array range->ranges containing
62  * low and high values with the number of ranges being range->nranges.
63  * After having called this function, the function value_is_in_range()
64  * determines whether a given number is within the range or not.<BR>
65  * In case of a single number, we make a range where low is equal to high.
66  * We take care on wrongly entered ranges; opposite order will be taken
67  * care of.
68  *
69  * The following syntax is accepted :
70  *
71  * 1-20,30-40 Range from 1 to 20, and packets 30 to 40
72  * -20,30 Range from 1 to 20, and packet 30
73  * 20,30,40- 20, 30, and the range from 40 to the end
74  * 20-10,30-25 Range from 10 to 20, and from 25 to 30
75  * - All values
76  * @param scope memory scope for the range
77  * @param range the range
78  * @param es points to the string to be converted.
79  * @param max_value specifies the maximum value in a range.
80  * @return convert_ret_t
81  */
82 WS_DLL_PUBLIC convert_ret_t range_convert_str(wmem_allocator_t *scope, range_t **range, const gchar *es,
83  guint32 max_value);
84 
85 WS_DLL_PUBLIC convert_ret_t range_convert_str_work(wmem_allocator_t *scope, range_t **range, const gchar *es,
86  guint32 max_value, gboolean err_on_max);
87 
94 WS_DLL_PUBLIC gboolean value_is_in_range(const range_t *range, guint32 val);
95 
103 WS_DLL_PUBLIC gboolean range_add_value(wmem_allocator_t *scope, range_t **range, guint32 val);
104 
112 WS_DLL_PUBLIC gboolean range_remove_value(wmem_allocator_t *scope, range_t **range, guint32 val);
113 
119 WS_DLL_PUBLIC gboolean ranges_are_equal(const range_t *a, const range_t *b);
120 
128 WS_DLL_PUBLIC void range_foreach(range_t *range, void (*callback)(guint32 val, gpointer ptr), gpointer ptr);
129 
133 WS_DLL_PUBLIC char *range_convert_range(wmem_allocator_t *scope, const range_t *range);
134 
141 WS_DLL_PUBLIC range_t *range_copy(wmem_allocator_t *scope, const range_t *src);
142 
143 #ifdef __cplusplus
144 }
145 #endif /* __cplusplus */
146 
147 #endif /* __RANGE_H__ */
WS_DLL_PUBLIC gboolean range_remove_value(wmem_allocator_t *scope, range_t **range, guint32 val)
Definition: range.c:314
WS_DLL_PUBLIC gboolean value_is_in_range(const range_t *range, guint32 val)
Definition: range.c:260
WS_DLL_PUBLIC gboolean ranges_are_equal(const range_t *a, const range_t *b)
Definition: range.c:369
struct epan_range range_t
convert_ret_t
Definition: range.h:50
WS_DLL_PUBLIC void range_foreach(range_t *range, void(*callback)(guint32 val, gpointer ptr), gpointer ptr)
Definition: range.c:395
WS_DLL_PUBLIC range_t * range_copy(wmem_allocator_t *scope, const range_t *src)
Definition: range.c:432
WS_DLL_PUBLIC char * range_convert_range(wmem_allocator_t *scope, const range_t *range)
Definition: range.c:409
WS_DLL_PUBLIC gboolean range_add_value(wmem_allocator_t *scope, range_t **range, guint32 val)
Definition: range.c:277
Definition: wmem_allocator.h:27
Definition: range.h:42
range_admin_t ranges[1]
Definition: range.h:44
guint nranges
Definition: range.h:43
Definition: range.h:35