4 * Parser for display filters
6 * $Id: dfilter-grammar.y,v 1.38 2000/02/05 06:07:16 guy Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@zing.org>
10 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h>
36 #ifdef HAVE_NETINET_IN_H
37 # include <netinet/in.h>
40 #ifdef NEED_SNPRINTF_H
46 # include "snprintf.h"
73 #include "dfilter-int.h"
79 static GNode* dfilter_mknode_join(GNode *n1, enum node_type ntype, int operand, GNode *n2);
80 static GNode* dfilter_mknode_unary(int operand, GNode *n2);
81 static GNode* dfilter_mknode_numeric_variable(gint id);
82 static GNode* dfilter_mknode_numeric_value(guint32 val);
83 static GNode* dfilter_mknode_floating_variable(gint id);
84 static GNode* dfilter_mknode_floating_value(double val);
85 static GNode* dfilter_mknode_ether_value(gchar*);
86 static GNode* dfilter_mknode_ether_variable(gint id);
87 static GNode* dfilter_mknode_ipxnet_value(guint32);
88 static GNode* dfilter_mknode_ipxnet_variable(gint id);
89 static GNode* dfilter_mknode_ipv4_value(char *host, int nmask_bits);
90 static GNode* dfilter_mknode_ipv4_variable(gint id);
91 static GNode* dfilter_mknode_ipv6_value(char *host);
92 static GNode* dfilter_mknode_ipv6_variable(gint id);
93 static GNode* dfilter_mknode_existence(gint id);
94 static GNode* dfilter_mknode_bytes_value(GByteArray *barray);
95 static GNode* dfilter_mknode_bytes_variable(gint id, gint offset, guint length);
97 static guint32 string_to_guint32(char *s, gboolean *success);
98 static double string_to_double(char *s, gboolean *success);
99 static int ether_str_to_guint8_array(const char *s, guint8 *mac);
100 static guint dfilter_get_bytes_variable_offset(GNode *gnode);
101 static guint dfilter_get_bytes_value_length(GNode* gnode);
102 static void dfilter_set_bytes_variable_length(GNode *gnode, guint length);
103 static guint dfilter_get_bytes_variable_length(GNode *gnode);
104 static gint dfilter_get_bytes_variable_field_registered_length(GNode *gnode);
105 static char* dfilter_get_variable_abbrev(GNode *gnode);
106 static int check_bytes_variable_sanity(GNode *gnode);
108 /* This is the dfilter we're currently processing. It's how
109 * dfilter_compile communicates with us.
111 dfilter *global_df = NULL;
116 gint operand; /* logical, relation, alternation */
119 gint type; /* using macros defined below, in this yacc grammar */
129 %type <node> statement expression relation
130 %type <node> numeric_value numeric_variable
131 %type <node> floating_value floating_variable
132 %type <node> ether_value ether_variable
133 %type <node> ipxnet_value ipxnet_variable
134 %type <node> ipv4_value ipv4_variable
135 %type <node> ipv6_value ipv6_variable
136 %type <node> variable_name
137 %type <node> bytes_value bytes_variable
139 %type <operand> numeric_relation
140 %type <operand> equality_relation
141 %type <operand> bytes_relation
143 %type <variable> any_variable_type
145 %token <variable> T_FT_UINT8
146 %token <variable> T_FT_UINT16
147 %token <variable> T_FT_UINT24
148 %token <variable> T_FT_UINT32
149 %token <variable> T_FT_INT8
150 %token <variable> T_FT_INT16
151 %token <variable> T_FT_INT24
152 %token <variable> T_FT_INT32
153 %token <variable> T_FT_ETHER
154 %token <variable> T_FT_IPv4
155 %token <variable> T_FT_IPv6
156 %token <variable> T_FT_NONE
157 %token <variable> T_FT_BYTES
158 %token <variable> T_FT_BOOLEAN
159 %token <variable> T_FT_STRING
160 %token <variable> T_FT_IPXNET
161 %token <variable> T_FT_DOUBLE
163 %token <string> T_VAL_UNQUOTED_STRING
164 %token <string> T_VAL_BYTE_STRING
165 %token <byte_range> T_VAL_BYTE_RANGE
167 %token <operand> TOK_AND TOK_OR TOK_NOT TOK_XOR
168 %token <operand> TOK_EQ TOK_NE TOK_GT TOK_GE TOK_LT TOK_LE
177 statement: expression
179 global_df->dftree = $1;
181 | /* NULL */ { if (global_df != NULL) global_df->dftree = NULL; }
184 expression: '(' expression ')' { $$ = $2; }
185 | expression TOK_AND expression { $$ = dfilter_mknode_join($1, logical, $2, $3); }
186 | expression TOK_OR expression { $$ = dfilter_mknode_join($1, logical, $2, $3); }
187 | expression TOK_XOR expression { $$ = dfilter_mknode_join($1, logical, $2, $3); }
188 | TOK_NOT expression { $$ = dfilter_mknode_unary(TOK_NOT, $2); }
189 | relation { $$ = $1; }
190 | variable_name { $$ = $1; }
191 | expression error { YYABORT; }
194 relation: numeric_variable numeric_relation numeric_value
196 $$ = dfilter_mknode_join($1, relation, $2, $3);
198 | numeric_variable numeric_relation numeric_variable
200 $$ = dfilter_mknode_join($1, relation, $2, $3);
203 | floating_variable numeric_relation floating_value
205 $$ = dfilter_mknode_join($1, relation, $2, $3);
207 | floating_variable numeric_relation floating_variable
209 $$ = dfilter_mknode_join($1, relation, $2, $3);
212 | ether_variable equality_relation ether_value
214 $$ = dfilter_mknode_join($1, relation, $2, $3);
216 | ether_variable equality_relation ether_variable
218 $$ = dfilter_mknode_join($1, relation, $2, $3);
221 | ipxnet_variable equality_relation ipxnet_value
223 $$ = dfilter_mknode_join($1, relation, $2, $3);
225 | ipxnet_variable equality_relation ipxnet_variable
227 $$ = dfilter_mknode_join($1, relation, $2, $3);
231 | ipv4_variable numeric_relation ipv4_value
233 $$ = dfilter_mknode_join($1, relation, $2, $3);
235 | ipv4_variable numeric_relation ipv4_variable
237 $$ = dfilter_mknode_join($1, relation, $2, $3);
240 | ipv6_variable equality_relation ipv6_value
242 $$ = dfilter_mknode_join($1, relation, $2, $3);
244 | ipv6_variable equality_relation ipv6_variable
246 $$ = dfilter_mknode_join($1, relation, $2, $3);
249 | bytes_variable bytes_relation bytes_value
253 a_len = dfilter_get_bytes_variable_length($1);
254 b_len = dfilter_get_bytes_value_length($3);
257 dfilter_set_bytes_variable_length($1, b_len);
261 if (!check_bytes_variable_sanity($1)) {
265 if (a_len != b_len) {
266 dfilter_fail("Field \"%s\" has %u byte%s being compared, but %u byte%s "
268 dfilter_get_variable_abbrev($1),
269 a_len, plurality(a_len, "", "s"),
270 b_len, plurality(b_len, "", "s"),
271 plurality(b_len, "was", "were"));
275 $$ = dfilter_mknode_join($1, relation, $2, $3);
277 | bytes_variable bytes_relation bytes_variable
281 a_len = dfilter_get_bytes_variable_length($1);
282 b_len = dfilter_get_bytes_variable_length($3);
284 if (!check_bytes_variable_sanity($1)) {
288 if (!check_bytes_variable_sanity($3)) {
292 if (a_len != b_len) {
293 dfilter_fail("Fields \"%s\" and \"%s\" are being compared with "
294 "disparate lengths of %u byte%s and %u byte%s.",
295 dfilter_get_variable_abbrev($1),
296 dfilter_get_variable_abbrev($3),
297 a_len, plurality(a_len, "", "s"),
298 b_len, plurality(b_len, "", "s"));
302 $$ = dfilter_mknode_join($1, relation, $2, $3);
308 numeric_value: T_VAL_UNQUOTED_STRING
311 $$ = dfilter_mknode_numeric_value(string_to_guint32($1, &success));
319 ether_value: T_VAL_BYTE_STRING
321 $$ = dfilter_mknode_ether_value($1);
329 ipxnet_value: T_VAL_UNQUOTED_STRING
332 $$ = dfilter_mknode_ipxnet_value(string_to_guint32($1, &success));
340 floating_value: T_VAL_UNQUOTED_STRING
343 $$ = dfilter_mknode_floating_value(string_to_double($1, &success));
352 /* e.g., 0.0, 0.1, 0.01 ... */
354 $$ = dfilter_mknode_floating_value(string_to_double($1, &success));
362 ipv4_value: T_VAL_UNQUOTED_STRING
364 $$ = dfilter_mknode_ipv4_value($1, 32);
373 $$ = dfilter_mknode_ipv4_value($1, 32);
380 | T_VAL_UNQUOTED_STRING '/' T_VAL_UNQUOTED_STRING
385 nmask_bits = string_to_guint32($3, &success);
392 if (nmask_bits > 32) {
393 dfilter_fail("The number of netmask bits in \"%s/%s\" should "
394 "be between 0 and 32.", $1, $3);
400 $$ = dfilter_mknode_ipv4_value($1, nmask_bits);
408 | T_VAL_BYTE_STRING '/' T_VAL_UNQUOTED_STRING
413 nmask_bits = string_to_guint32($3, &success);
420 if (nmask_bits > 32) {
421 dfilter_fail("The number of netmask bits in \"%s/%s\" should "
422 "be between 0 and 32.", $1, $3);
427 $$ = dfilter_mknode_ipv4_value($1, nmask_bits);
436 ipv6_value: T_VAL_UNQUOTED_STRING
438 $$ = dfilter_mknode_ipv6_value($1);
447 $$ = dfilter_mknode_ipv6_value($1);
455 bytes_value: T_VAL_BYTE_STRING
459 /* the next function appends to list_of_byte_arrays for me */
460 barray = byte_str_to_guint8_array($1);
461 $$ = dfilter_mknode_bytes_value(barray);
465 | T_VAL_UNQUOTED_STRING
472 val32 = string_to_guint32($1, &success);
478 dfilter_fail("The value \"%s\" cannot be stored in a single-byte byte-string. "
479 "Use the multi-byte \"xx:yy\" representation.", $1);
483 val8 = (guint8) val32;
484 barray = g_byte_array_new();
485 global_df->list_of_byte_arrays = g_slist_append(global_df->list_of_byte_arrays, barray);
486 g_byte_array_append(barray, &val8, 1);
488 $$ = dfilter_mknode_bytes_value(barray);
493 numeric_variable: T_FT_UINT8 { $$ = dfilter_mknode_numeric_variable($1.id); }
494 | T_FT_UINT16 { $$ = dfilter_mknode_numeric_variable($1.id); }
495 | T_FT_UINT24 { $$ = dfilter_mknode_numeric_variable($1.id); }
496 | T_FT_UINT32 { $$ = dfilter_mknode_numeric_variable($1.id); }
497 | T_FT_INT8 { $$ = dfilter_mknode_numeric_variable($1.id); }
498 | T_FT_INT16 { $$ = dfilter_mknode_numeric_variable($1.id); }
499 | T_FT_INT24 { $$ = dfilter_mknode_numeric_variable($1.id); }
500 | T_FT_INT32 { $$ = dfilter_mknode_numeric_variable($1.id); }
503 ether_variable: T_FT_ETHER { $$ = dfilter_mknode_ether_variable($1.id); }
506 floating_variable: T_FT_DOUBLE { $$ = dfilter_mknode_floating_variable($1.id); }
509 ipxnet_variable: T_FT_IPXNET { $$ = dfilter_mknode_ipxnet_variable($1.id); }
512 ipv4_variable: T_FT_IPv4 { $$ = dfilter_mknode_ipv4_variable($1.id); }
515 ipv6_variable: T_FT_IPv6 { $$ = dfilter_mknode_ipv6_variable($1.id); }
518 variable_name: any_variable_type
523 if ($1.type == T_FT_BOOLEAN) {
524 /* Make "variable == TRUE" for BOOLEAN variable */
525 variable = dfilter_mknode_numeric_variable($1.id);
526 value = dfilter_mknode_numeric_value(TRUE);
527 $$ = dfilter_mknode_join(variable, relation, TOK_EQ, value);
530 $$ = dfilter_mknode_existence($1.id);
535 bytes_variable: any_variable_type T_VAL_BYTE_RANGE
537 $$ = dfilter_mknode_bytes_variable($1.id, $2.offset, $2.length);
541 any_variable_type: T_FT_UINT8 { $$ = $1; }
542 | T_FT_UINT16 { $$ = $1; }
543 | T_FT_UINT24 { $$ = $1; }
544 | T_FT_UINT32 { $$ = $1; }
545 | T_FT_INT8 { $$ = $1; }
546 | T_FT_INT16 { $$ = $1; }
547 | T_FT_INT24 { $$ = $1; }
548 | T_FT_INT32 { $$ = $1; }
549 | T_FT_DOUBLE { $$ = $1; }
550 | T_FT_ETHER { $$ = $1; }
551 | T_FT_IPv4 { $$ = $1; }
552 | T_FT_IPv6 { $$ = $1; }
553 | T_FT_IPXNET { $$ = $1; }
554 | T_FT_NONE { $$ = $1; }
555 | T_FT_BYTES { $$ = $1; }
556 | T_FT_BOOLEAN { $$ = $1; }
557 | T_FT_STRING { $$ = $1; }
560 numeric_relation: TOK_EQ { $$ = TOK_EQ; }
561 | TOK_NE { $$ = TOK_NE; }
562 | TOK_GT { $$ = TOK_GT; }
563 | TOK_GE { $$ = TOK_GE; }
564 | TOK_LT { $$ = TOK_LT; }
565 | TOK_LE { $$ = TOK_LE; }
568 equality_relation: TOK_EQ { $$ = TOK_EQ; }
569 | TOK_NE { $$ = TOK_NE; }
572 bytes_relation: TOK_EQ { $$ = TOK_EQ; }
573 | TOK_NE { $$ = TOK_NE; }
574 | TOK_GT { $$ = TOK_GT; }
575 | TOK_LT { $$ = TOK_LT; }
581 dfilter_mknode_join(GNode *n1, enum node_type ntype, int operand, GNode *n2)
583 dfilter_node *node_root;
586 node_root = g_mem_chunk_alloc(global_df->node_memchunk);
587 node_root->ntype = ntype;
588 node_root->elem_size = 0;
589 node_root->fill_array_func = NULL;
590 node_root->check_relation_func = NULL;
591 if (ntype == relation) {
592 node_root->value.relation = operand;
594 else if (ntype == logical) {
595 node_root->value.logical = operand;
598 g_assert_not_reached();
601 gnode_root = g_node_new(node_root);
602 g_node_append(gnode_root, n1);
603 g_node_append(gnode_root, n2);
609 dfilter_mknode_unary(int operand, GNode *n2)
611 dfilter_node *node_root;
614 node_root = g_mem_chunk_alloc(global_df->node_memchunk);
615 node_root->ntype = logical;
616 node_root->value.logical = operand;
617 node_root->elem_size = 0;
618 node_root->fill_array_func = NULL;
619 node_root->check_relation_func = NULL;
621 gnode_root = g_node_new(node_root);
622 g_node_append(gnode_root, n2);
629 dfilter_mknode_numeric_variable(gint id)
634 node = g_mem_chunk_alloc(global_df->node_memchunk);
635 node->ntype = variable;
636 node->elem_size = sizeof(guint32);
637 node->fill_array_func = fill_array_numeric_variable;
638 node->check_relation_func = check_relation_numeric;
639 node->value.variable = id;
640 gnode = g_node_new(node);
646 dfilter_mknode_ether_variable(gint id)
651 node = g_mem_chunk_alloc(global_df->node_memchunk);
652 node->ntype = variable;
653 node->elem_size = sizeof(guint8) * 6;
654 node->fill_array_func = fill_array_ether_variable;
655 node->check_relation_func = check_relation_ether;
656 node->value.variable = id;
657 gnode = g_node_new(node);
663 dfilter_mknode_floating_variable(gint id)
668 node = g_mem_chunk_alloc(global_df->node_memchunk);
669 node->ntype = variable;
670 node->elem_size = sizeof(double);
671 node->fill_array_func = fill_array_floating_variable;
672 node->check_relation_func = check_relation_floating;
673 node->value.variable = id;
674 gnode = g_node_new(node);
680 dfilter_mknode_ipxnet_variable(gint id)
685 node = g_mem_chunk_alloc(global_df->node_memchunk);
686 node->ntype = variable;
687 node->elem_size = sizeof(guint8) * 4;
688 node->fill_array_func = fill_array_numeric_variable; /* cheating ! */
689 node->check_relation_func = check_relation_numeric; /* cheating ! */
690 node->value.variable = id;
691 gnode = g_node_new(node);
697 dfilter_mknode_ipv4_variable(gint id)
702 node = g_mem_chunk_alloc(global_df->node_memchunk);
703 node->ntype = variable;
704 node->elem_size = sizeof(ipv4_addr);
705 node->fill_array_func = fill_array_ipv4_variable;
706 node->check_relation_func = check_relation_ipv4;
707 node->value.variable = id;
708 gnode = g_node_new(node);
714 dfilter_mknode_ipv6_variable(gint id)
719 node = g_mem_chunk_alloc(global_df->node_memchunk);
720 node->ntype = variable;
721 node->elem_size = 16;
722 node->fill_array_func = fill_array_ipv6_variable;
723 node->check_relation_func = check_relation_ipv6;
724 node->value.variable = id;
725 gnode = g_node_new(node);
731 dfilter_mknode_bytes_variable(gint id, gint offset, guint length)
736 node = g_mem_chunk_alloc(global_df->node_memchunk);
737 node->ntype = variable;
738 node->elem_size = sizeof(GByteArray*);
739 node->fill_array_func = fill_array_bytes_variable;
740 node->check_relation_func = check_relation_bytes;
741 node->value.variable = id;
742 node->offset = offset;
743 node->length = length;
744 gnode = g_node_new(node);
749 /* Gets length of variable represented by node from proto_register */
751 dfilter_get_bytes_variable_field_registered_length(GNode *gnode)
753 dfilter_node *node = gnode->data;
755 /* Is this really a bytes_variable? */
756 g_assert(node->fill_array_func = fill_array_bytes_variable);
758 return proto_registrar_get_length(node->value.variable);
761 /* Sets the length of a bytes_variable node */
763 dfilter_set_bytes_variable_length(GNode *gnode, guint length)
765 dfilter_node *node = gnode->data;
767 /* Is this really a bytes_variable? */
768 g_assert(node->fill_array_func = fill_array_bytes_variable);
770 node->length = length;
773 /* Gets the length of a bytes_variable node */
775 dfilter_get_bytes_variable_length(GNode *gnode)
777 dfilter_node *node = gnode->data;
779 /* Is this really a bytes_variable? */
780 g_assert(node->fill_array_func = fill_array_bytes_variable);
785 /* Gets the offset of a bytes_variable node */
787 dfilter_get_bytes_variable_offset(GNode *gnode)
789 dfilter_node *node = gnode->data;
791 /* Is this really a bytes_variable? */
792 g_assert(node->fill_array_func = fill_array_bytes_variable);
798 dfilter_get_variable_abbrev(GNode *gnode)
800 dfilter_node *node = gnode->data;
802 return proto_registrar_get_abbrev(node->value.variable);
806 dfilter_mknode_numeric_value(guint32 val)
811 node = g_mem_chunk_alloc(global_df->node_memchunk);
812 node->ntype = numeric;
813 node->elem_size = sizeof(guint32);
814 node->fill_array_func = fill_array_numeric_value;
815 node->check_relation_func = check_relation_numeric;
816 node->value.numeric = val;
817 gnode = g_node_new(node);
823 dfilter_mknode_floating_value(double val)
828 node = g_mem_chunk_alloc(global_df->node_memchunk);
829 node->ntype = floating;
830 node->elem_size = sizeof(double);
831 node->fill_array_func = fill_array_floating_value;
832 node->check_relation_func = check_relation_floating;
833 node->value.floating = val;
834 gnode = g_node_new(node);
839 /* Returns NULL on bad parse of ETHER value */
841 dfilter_mknode_ether_value(gchar *byte_string)
846 node = g_mem_chunk_alloc(global_df->node_memchunk);
848 node->elem_size = sizeof(guint8) * 6;
849 node->fill_array_func = fill_array_ether_value;
850 node->check_relation_func = check_relation_ether;
852 if (!ether_str_to_guint8_array(byte_string, &node->value.ether[0])) {
853 /* Rather than free the mem_chunk allocation, let it
854 * stay. It will be cleaned up when "dfilter_compile()"
855 * calls "dfilter_destroy()". */
856 dfilter_fail("\"%s\" is not a valid hardware address.",
861 gnode = g_node_new(node);
866 dfilter_mknode_ipxnet_value(guint32 ipx_net_val)
871 node = g_mem_chunk_alloc(global_df->node_memchunk);
872 node->ntype = ipxnet;
873 node->elem_size = sizeof(guint8) * 4;
874 node->fill_array_func = fill_array_numeric_value; /* cheating ! */
875 node->check_relation_func = check_relation_numeric; /* cheating ! */
876 node->value.numeric = ipx_net_val;
877 gnode = g_node_new(node);
882 /* Returns NULL on bad parse of IP value */
884 dfilter_mknode_ipv4_value(char *host, int nmask_bits)
890 node = g_mem_chunk_alloc(global_df->node_memchunk);
891 node->ntype = numeric;
892 node->elem_size = sizeof(ipv4_addr);
893 node->fill_array_func = fill_array_ipv4_value;
894 node->check_relation_func = check_relation_ipv4;
895 if (!get_host_ipaddr(host, &addr)) {
896 /* Rather than free the mem_chunk allocation, let it
897 * stay. It will be cleaned up when "dfilter_compile()"
898 * calls "dfilter_destroy()". */
899 dfilter_fail("\"%s\" isn't a valid host name or IP address.",
903 ipv4_addr_set_host_order_addr(&node->value.ipv4, addr);
904 ipv4_addr_set_netmask_bits(&node->value.ipv4, nmask_bits);
906 gnode = g_node_new(node);
910 /* Returns NULL on bad parse of IPv6 value */
912 dfilter_mknode_ipv6_value(char *host)
917 node = g_mem_chunk_alloc(global_df->node_memchunk);
919 node->elem_size = 16;
920 node->fill_array_func = fill_array_ipv6_value;
921 node->check_relation_func = check_relation_ipv6;
923 if (!get_host_ipaddr6(host, (struct e_in6_addr*)&node->value.ipv6[0])) {
924 /* Rather than free the mem_chunk allocation, let it
925 * stay. It will be cleaned up when "dfilter_compile()"
926 * calls "dfilter_destroy()". */
927 dfilter_fail("\"%s\" isn't a valid IPv6 address.",
932 gnode = g_node_new(node);
937 dfilter_mknode_bytes_value(GByteArray *barray)
942 node = g_mem_chunk_alloc(global_df->node_memchunk);
944 node->elem_size = sizeof(GByteArray*);
945 node->fill_array_func = fill_array_bytes_value;
946 node->check_relation_func = check_relation_bytes;
947 node->value.bytes = barray;
948 node->offset = G_MAXINT;
949 node->length = barray->len;
950 gnode = g_node_new(node);
955 /* Given a node representing a bytes_value, returns
956 * the length of the byte array */
958 dfilter_get_bytes_value_length(GNode* gnode)
960 dfilter_node *node = gnode->data;
962 g_assert(node->ntype == bytes);
967 string_to_guint32(char *s, gboolean *success)
972 val = strtoul(s, &endptr, 0);
974 if (endptr == s || *endptr != '\0') {
975 /* This isn't a valid number. */
976 dfilter_fail("\"%s\" is not a valid number.", s);
979 if (errno == ERANGE) {
981 if (val == ULONG_MAX) {
982 dfilter_fail("\"%s\" causes an integer overflow.", s);
985 dfilter_fail("\"%s\" is not an integer.", s);
993 string_to_double(char *s, gboolean *success)
998 retval = strtod(s, &endptr);
1002 dfilter_fail("\"%s\" is not a valid floating-point number.", s);
1006 if (errno == ERANGE) {
1009 dfilter_fail("\"%s\" causes a floating-point underflow.", s);
1011 else if (retval == HUGE_VAL) {
1012 dfilter_fail("\"%s\" causes a floating-point overflow.", s);
1015 dfilter_fail("\"%s\" is not a valid floating-point.", s);
1022 dfilter_mknode_existence(gint id)
1027 node = g_mem_chunk_alloc(global_df->node_memchunk);
1028 node->ntype = existence;
1029 node->elem_size = sizeof(guint32);
1030 node->fill_array_func = NULL;
1031 node->check_relation_func = NULL;
1032 node->value.variable = id;
1033 gnode = g_node_new(node);
1039 /* converts a string representing an ether HW address
1040 * to a guint8 array.
1042 * Returns 0 on failure, 1 on success.
1045 ether_str_to_guint8_array(const char *s, guint8 *mac)
1047 char ether_str[18]; /* 2+1+2+1+2+1+2+1+2+1+2 + 1 */
1051 if (strlen(s) > 17) {
1054 strcpy(ether_str, s); /* local copy of string */
1056 while ((p = strtok(str, "-:."))) {
1057 /* catch short strings with too many hex bytes: 0.0.0.0.0.0.0 */
1061 mac[i] = (guint8) strtoul(p, NULL, 16);
1063 /* subsequent calls to strtok() require NULL as arg 1 */
1067 return 0; /* failed to read 6 hex pairs */
1069 return 1; /* read exactly 6 hex pairs */
1074 check_bytes_variable_sanity(GNode *gnode)
1076 int a_off, a_len, reg_len, t_off;
1078 a_off = dfilter_get_bytes_variable_offset(gnode);
1079 a_len = dfilter_get_bytes_variable_length(gnode);
1080 reg_len = dfilter_get_bytes_variable_field_registered_length(gnode);
1083 t_off = a_off >= 0 ? a_off : reg_len + a_off;
1084 if (t_off + a_len > reg_len) {
1085 dfilter_fail("The \"%s\" field is only %u byte%s wide, but "
1086 "%u byte%s %s supplied.",
1087 dfilter_get_variable_abbrev(gnode),
1088 reg_len, plurality(reg_len, "", "s"),
1089 a_len, plurality(a_len, "", "s"),
1090 plurality(a_len, "was", "were"));