2 * $Id: ftype-integer.c,v 1.10 2002/08/28 20:41:00 jmayer Exp $
4 * Ethereal - Network traffic analyzer
5 * By Gerald Combs <gerald@ethereal.com>
6 * Copyright 2001 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include "ftypes-int.h"
30 #include <epan/resolv.h>
34 int_fvalue_new(fvalue_t *fv)
36 fv->value.integer = 0;
40 set_integer(fvalue_t *fv, guint32 value)
42 fv->value.integer = value;
46 get_integer(fvalue_t *fv)
48 return fv->value.integer;
52 val_from_string(fvalue_t *fv, char *s, LogFunc logfunc)
56 fv->value.integer = strtoul(s, &endptr, 0);
58 if (endptr == s || *endptr != '\0') {
59 /* This isn't a valid number. */
61 logfunc("\"%s\" is not a valid number.", s);
64 if (errno == ERANGE) {
65 if (logfunc != NULL) {
66 if (fv->value.integer == ULONG_MAX) {
67 logfunc("\"%s\" causes an integer overflow.",
71 logfunc("\"%s\" is not an integer.", s);
81 ipxnet_from_string(fvalue_t *fv, char *s, LogFunc logfunc)
87 * Don't log a message if this fails; we'll try looking it
88 * up as an IPX network name if it does, and if that fails,
89 * we'll log a message.
91 if (val_from_string(fv, s, NULL)) {
95 val = get_ipxnet_addr(s, &known);
97 fv->value.integer = val;
101 logfunc("\"%s\" is not a valid IPX network name or address.", s);
106 cmp_eq(fvalue_t *a, fvalue_t *b)
108 return a->value.integer == b->value.integer;
112 cmp_ne(fvalue_t *a, fvalue_t *b)
114 return a->value.integer != b->value.integer;
118 u_cmp_gt(fvalue_t *a, fvalue_t *b)
120 return (int)a->value.integer > (int)b->value.integer;
124 u_cmp_ge(fvalue_t *a, fvalue_t *b)
126 return (int)a->value.integer >= (int)b->value.integer;
130 u_cmp_lt(fvalue_t *a, fvalue_t *b)
132 return (int)a->value.integer < (int)b->value.integer;
136 u_cmp_le(fvalue_t *a, fvalue_t *b)
138 return (int)a->value.integer <= (int)b->value.integer;
142 s_cmp_gt(fvalue_t *a, fvalue_t *b)
144 return a->value.integer > b->value.integer;
148 s_cmp_ge(fvalue_t *a, fvalue_t *b)
150 return a->value.integer >= b->value.integer;
154 s_cmp_lt(fvalue_t *a, fvalue_t *b)
156 return a->value.integer < b->value.integer;
160 s_cmp_le(fvalue_t *a, fvalue_t *b)
162 return a->value.integer <= b->value.integer;
165 /* BOOLEAN-specific */
168 boolean_fvalue_new(fvalue_t *fv)
170 fv->value.integer = TRUE;
173 /* Checks for equality with zero or non-zero */
175 bool_eq(fvalue_t *a, fvalue_t *b)
177 if (a->value.integer) {
178 if (b->value.integer) {
186 if (b->value.integer) {
195 /* Checks for inequality with zero or non-zero */
197 bool_ne(fvalue_t *a, fvalue_t *b)
199 return (!bool_eq(a,b));
205 ftype_register_integers(void)
208 static ftype_t uint8_type = {
234 static ftype_t uint16_type = {
260 static ftype_t uint24_type = {
286 static ftype_t uint32_type = {
312 static ftype_t int8_type = {
338 static ftype_t int16_type = {
364 static ftype_t int24_type = {
390 static ftype_t int32_type = {
416 static ftype_t boolean_type = {
443 static ftype_t ipxnet_type = {
445 "IPX network number",
471 ftype_register(FT_UINT8, &uint8_type);
472 ftype_register(FT_UINT16, &uint16_type);
473 ftype_register(FT_UINT24, &uint24_type);
474 ftype_register(FT_UINT32, &uint32_type);
475 ftype_register(FT_INT8, &int8_type);
476 ftype_register(FT_INT16, &int16_type);
477 ftype_register(FT_INT24, &int24_type);
478 ftype_register(FT_INT32, &int32_type);
479 ftype_register(FT_BOOLEAN, &boolean_type);
480 ftype_register(FT_IPXNET, &ipxnet_type);