2004-09-04 01:32:13 +00:00
|
|
|
/* range.h
|
|
|
|
* Range routines
|
|
|
|
*
|
|
|
|
* Dick Gooris <gooris@lucent.com>
|
|
|
|
* Ulf Lamping <ulf.lamping@web.de>
|
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2004-09-04 01:32:13 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-02-08 16:59:17 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2004-09-04 01:32:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __RANGE_H__
|
|
|
|
#define __RANGE_H__
|
|
|
|
|
|
|
|
#include <glib.h>
|
2013-03-01 23:53:11 +00:00
|
|
|
#include "ws_symbol_export.h"
|
2015-01-10 00:50:09 +00:00
|
|
|
#include <epan/wmem/wmem.h>
|
2004-09-04 01:32:13 +00:00
|
|
|
|
2015-06-01 23:29:17 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2010-08-28 19:27:19 +00:00
|
|
|
/** @file
|
|
|
|
* Range strings a variant of value_strings
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**@todo where's the best place for these? */
|
2004-11-24 02:59:49 +00:00
|
|
|
#define MAX_SCTP_PORT 65535
|
|
|
|
#define MAX_TCP_PORT 65535
|
|
|
|
#define MAX_UDP_PORT 65535
|
2008-04-12 14:08:19 +00:00
|
|
|
#define MAX_DCCP_PORT 65535
|
2004-11-24 02:59:49 +00:00
|
|
|
|
2004-09-04 01:32:13 +00:00
|
|
|
typedef struct range_admin_tag {
|
|
|
|
guint32 low;
|
|
|
|
guint32 high;
|
|
|
|
} range_admin_t;
|
2017-06-02 08:29:42 +00:00
|
|
|
#define RANGE_ADMIN_T_INITIALIZER { 0, 0 }
|
2004-09-04 01:32:13 +00:00
|
|
|
|
2010-08-28 19:27:19 +00:00
|
|
|
/** user specified range(s) */
|
2013-12-20 23:25:36 +00:00
|
|
|
typedef struct epan_range {
|
2010-08-28 19:27:19 +00:00
|
|
|
guint nranges; /**< number of entries in ranges */
|
|
|
|
range_admin_t ranges[1]; /**< variable-length array */
|
2004-09-04 01:32:13 +00:00
|
|
|
} range_t;
|
|
|
|
|
2010-08-28 19:27:19 +00:00
|
|
|
/**
|
2004-10-16 08:33:40 +00:00
|
|
|
* Return value from range_convert_str().
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
CVT_NO_ERROR,
|
|
|
|
CVT_SYNTAX_ERROR,
|
2004-10-16 23:32:24 +00:00
|
|
|
CVT_NUMBER_TOO_BIG
|
2010-10-29 22:09:31 +00:00
|
|
|
} convert_ret_t;
|
2004-10-16 08:33:40 +00:00
|
|
|
|
2016-12-22 20:12:27 +00:00
|
|
|
WS_DLL_PUBLIC range_t *range_empty(wmem_allocator_t *scope);
|
2004-09-04 01:32:13 +00:00
|
|
|
|
2010-08-28 19:27:19 +00:00
|
|
|
|
|
|
|
/*** 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.<BR>
|
2010-10-29 22:09:31 +00:00
|
|
|
* In case of a single number, we make a range where low is equal to high.
|
2010-08-28 19:27:19 +00:00
|
|
|
* We take care on wrongly entered ranges; opposite order will be taken
|
|
|
|
* care of.
|
2010-10-29 22:09:31 +00:00
|
|
|
*
|
2010-08-28 19:27:19 +00:00
|
|
|
* 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
|
2016-12-22 20:12:27 +00:00
|
|
|
* @param scope memory scope for the range
|
2010-08-28 19:27:19 +00:00
|
|
|
* @param range the range
|
|
|
|
* @param es points to the string to be converted.
|
2013-08-10 21:28:17 +00:00
|
|
|
* @param max_value specifies the maximum value in a range.
|
|
|
|
* @return convert_ret_t
|
2010-08-28 19:27:19 +00:00
|
|
|
*/
|
2016-12-22 20:12:27 +00:00
|
|
|
WS_DLL_PUBLIC convert_ret_t range_convert_str(wmem_allocator_t *scope, range_t **range, const gchar *es,
|
2004-09-04 01:32:13 +00:00
|
|
|
guint32 max_value);
|
|
|
|
|
2016-12-22 20:12:27 +00:00
|
|
|
WS_DLL_PUBLIC convert_ret_t range_convert_str_work(wmem_allocator_t *scope, range_t **range, const gchar *es,
|
2010-10-29 22:09:31 +00:00
|
|
|
guint32 max_value, gboolean err_on_max);
|
|
|
|
|
2010-08-28 19:27:19 +00:00
|
|
|
/** This function returns TRUE if a given value is within one of the ranges
|
|
|
|
* stored in the ranges array.
|
|
|
|
* @param range the range
|
|
|
|
* @param val the value to check
|
|
|
|
* @return TRUE if the value is in range
|
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC gboolean value_is_in_range(range_t *range, guint32 val);
|
2004-09-04 01:32:13 +00:00
|
|
|
|
2016-09-22 03:16:58 +00:00
|
|
|
/** This function returns TRUE if val has successfully been added to
|
|
|
|
* a range. This may extend an existing range or create a new one
|
2016-12-22 20:12:27 +00:00
|
|
|
* @param scope memory scope of range (in case of reallocation)
|
2016-09-22 03:16:58 +00:00
|
|
|
* @param range to add value
|
|
|
|
* @param val value to add to range
|
|
|
|
* @return TRUE if the value is successsfully added to range
|
|
|
|
*/
|
2016-12-22 20:12:27 +00:00
|
|
|
WS_DLL_PUBLIC gboolean range_add_value(wmem_allocator_t *scope, range_t **range, guint32 val);
|
2016-09-22 03:16:58 +00:00
|
|
|
|
|
|
|
/** This function returns TRUE if val has successfully been removed from
|
|
|
|
* a range. This may remove an existing range.
|
2016-12-22 20:12:27 +00:00
|
|
|
* @param scope memory scope of range (in case of reallocation)
|
2016-09-22 03:16:58 +00:00
|
|
|
* @param range to remove value
|
|
|
|
* @param val value to remove within range
|
|
|
|
* @return TRUE if the value is successsfully removed to range
|
|
|
|
*/
|
2016-12-22 20:12:27 +00:00
|
|
|
WS_DLL_PUBLIC gboolean range_remove_value(wmem_allocator_t *scope, range_t **range, guint32 val);
|
2016-09-22 03:16:58 +00:00
|
|
|
|
2010-08-28 19:27:19 +00:00
|
|
|
/** This function returns TRUE if the two given range_t's are equal.
|
|
|
|
* @param a first range
|
|
|
|
* @param b second range
|
|
|
|
* @return TRUE if the value is in range
|
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC gboolean ranges_are_equal(range_t *a, range_t *b);
|
2004-10-14 23:45:09 +00:00
|
|
|
|
2010-08-28 19:27:19 +00:00
|
|
|
/** This function calls the provided callback function for each value in
|
2017-08-08 22:05:37 +00:00
|
|
|
* in the range. Takes a pointer argument, which is passed to the
|
|
|
|
* callback, along with the value in the range.
|
2010-08-28 19:27:19 +00:00
|
|
|
* @param range the range
|
2010-08-30 14:22:49 +00:00
|
|
|
* @param callback the callback function
|
2017-07-18 18:47:58 +00:00
|
|
|
* @param ptr pointer passed to the callback
|
|
|
|
*/
|
2017-08-08 22:05:37 +00:00
|
|
|
WS_DLL_PUBLIC void range_foreach(range_t *range, void (*callback)(guint32 val, gpointer ptr), gpointer ptr);
|
2017-07-18 18:47:58 +00:00
|
|
|
|
2010-10-29 22:09:31 +00:00
|
|
|
/**
|
2015-01-10 00:50:09 +00:00
|
|
|
* This function converts a range_t to a (wmem_alloc()-allocated) string.
|
2010-08-28 19:27:19 +00:00
|
|
|
*/
|
2015-06-01 23:29:17 +00:00
|
|
|
WS_DLL_PUBLIC char *range_convert_range(wmem_allocator_t *scope, const range_t *range);
|
2004-10-14 23:45:09 +00:00
|
|
|
|
2010-08-28 19:27:19 +00:00
|
|
|
/**
|
2016-12-22 20:12:27 +00:00
|
|
|
* Create a (wmem-alloc()ed) copy of a range
|
|
|
|
* @param scope memory scope for the copied range
|
2010-08-28 19:27:19 +00:00
|
|
|
* @param src the range to copy
|
|
|
|
* @return ep allocated copy of the range
|
|
|
|
*/
|
2016-12-22 20:12:27 +00:00
|
|
|
WS_DLL_PUBLIC range_t *range_copy(wmem_allocator_t *scope, range_t *src);
|
2004-10-16 23:32:24 +00:00
|
|
|
|
2015-06-01 23:29:17 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2004-09-04 01:32:13 +00:00
|
|
|
#endif /* __RANGE_H__ */
|