ieee80211: Fix the BAR Ack policy values
[metze/wireshark/wip.git] / epan / range.h
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  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25
26 #ifndef __RANGE_H__
27 #define __RANGE_H__
28
29 #include <glib.h>
30 #include "ws_symbol_export.h"
31 #include <epan/wmem/wmem.h>
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif /* __cplusplus */
36
37 /** @file
38  * Range strings a variant of value_strings
39  */
40
41 /**@todo where's the best place for these? */
42 #define MAX_SCTP_PORT 65535
43 #define MAX_TCP_PORT 65535
44 #define MAX_UDP_PORT 65535
45 #define MAX_DCCP_PORT 65535
46
47 typedef struct range_admin_tag {
48     guint32 low;
49     guint32 high;
50 } range_admin_t;
51
52 /** user specified range(s) */
53 typedef struct epan_range {
54     guint           nranges;   /**< number of entries in ranges */
55     range_admin_t   ranges[1]; /**< variable-length array */
56 } range_t;
57
58 /**
59  * Return value from range_convert_str().
60  */
61 typedef enum {
62     CVT_NO_ERROR,
63     CVT_SYNTAX_ERROR,
64     CVT_NUMBER_TOO_BIG
65 } convert_ret_t;
66
67 WS_DLL_PUBLIC range_t *range_empty(void);
68
69
70 /*** Converts a range string to a fast comparable array of ranges.
71  * This function allocates a range_t large enough to hold the number
72  * of ranges specified, and fills the array range->ranges containing
73  * low and high values with the number of ranges being range->nranges.
74  * After having called this function, the function value_is_in_range()
75  * determines whether a given number is within the range or not.<BR>
76  * In case of a single number, we make a range where low is equal to high.
77  * We take care on wrongly entered ranges; opposite order will be taken
78  * care of.
79  *
80  * The following syntax is accepted :
81  *
82  *   1-20,30-40     Range from 1 to 20, and packets 30 to 40
83  *   -20,30         Range from 1 to 20, and packet 30
84  *   20,30,40-      20, 30, and the range from 40 to the end
85  *   20-10,30-25    Range from 10 to 20, and from 25 to 30
86  *   -              All values
87  * @param range the range
88  * @param es points to the string to be converted.
89  * @param max_value specifies the maximum value in a range.
90  * @return convert_ret_t
91  */
92 WS_DLL_PUBLIC convert_ret_t range_convert_str(range_t **range, const gchar *es,
93     guint32 max_value);
94
95 convert_ret_t range_convert_str_work(range_t **range, const gchar *es,
96     guint32 max_value, gboolean err_on_max);
97
98 /** This function returns TRUE if a given value is within one of the ranges
99  * stored in the ranges array.
100  * @param range the range
101  * @param val the value to check
102  * @return TRUE if the value is in range
103  */
104 WS_DLL_PUBLIC gboolean value_is_in_range(range_t *range, guint32 val);
105
106 /** This function returns TRUE if the two given range_t's are equal.
107  * @param a first range
108  * @param b second range
109  * @return TRUE if the value is in range
110  */
111 WS_DLL_PUBLIC gboolean ranges_are_equal(range_t *a, range_t *b);
112
113 /** This function calls the provided callback function for each value in
114  * in the range.
115  * @param range the range
116  * @param callback the callback function
117  */
118 WS_DLL_PUBLIC void range_foreach(range_t *range, void (*callback)(guint32 val));
119
120 /**
121  * This function converts a range_t to a (wmem_alloc()-allocated) string.
122  */
123 WS_DLL_PUBLIC char *range_convert_range(wmem_allocator_t *scope, const range_t *range);
124
125 /**
126  * Create a copy of a range.
127  * @param src the range to copy
128  * @return ep allocated copy of the range
129  */
130 WS_DLL_PUBLIC range_t *range_copy(range_t *src);
131
132 #ifdef __cplusplus
133 }
134 #endif /* __cplusplus */
135
136 #endif /* __RANGE_H__ */