4 * Parser for display filters
6 * $Id: dfilter-grammar.y,v 1.37 1999/11/15 06:32:11 gram 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_UINT32
148 %token <variable> T_FT_INT8
149 %token <variable> T_FT_INT16
150 %token <variable> T_FT_INT32
151 %token <variable> T_FT_ETHER
152 %token <variable> T_FT_IPv4
153 %token <variable> T_FT_IPv6
154 %token <variable> T_FT_NONE
155 %token <variable> T_FT_BYTES
156 %token <variable> T_FT_BOOLEAN
157 %token <variable> T_FT_STRING
158 %token <variable> T_FT_IPXNET
159 %token <variable> T_FT_DOUBLE
161 %token <string> T_VAL_UNQUOTED_STRING
162 %token <string> T_VAL_BYTE_STRING
163 %token <byte_range> T_VAL_BYTE_RANGE
165 %token <operand> TOK_AND TOK_OR TOK_NOT TOK_XOR
166 %token <operand> TOK_EQ TOK_NE TOK_GT TOK_GE TOK_LT TOK_LE
175 statement: expression
177 global_df->dftree = $1;
179 | /* NULL */ { if (global_df != NULL) global_df->dftree = NULL; }
182 expression: '(' expression ')' { $$ = $2; }
183 | expression TOK_AND expression { $$ = dfilter_mknode_join($1, logical, $2, $3); }
184 | expression TOK_OR expression { $$ = dfilter_mknode_join($1, logical, $2, $3); }
185 | expression TOK_XOR expression { $$ = dfilter_mknode_join($1, logical, $2, $3); }
186 | TOK_NOT expression { $$ = dfilter_mknode_unary(TOK_NOT, $2); }
187 | relation { $$ = $1; }
188 | variable_name { $$ = $1; }
189 | expression error { YYABORT; }
192 relation: numeric_variable numeric_relation numeric_value
194 $$ = dfilter_mknode_join($1, relation, $2, $3);
196 | numeric_variable numeric_relation numeric_variable
198 $$ = dfilter_mknode_join($1, relation, $2, $3);
201 | floating_variable numeric_relation floating_value
203 $$ = dfilter_mknode_join($1, relation, $2, $3);
205 | floating_variable numeric_relation floating_variable
207 $$ = dfilter_mknode_join($1, relation, $2, $3);
210 | ether_variable equality_relation ether_value
212 $$ = dfilter_mknode_join($1, relation, $2, $3);
214 | ether_variable equality_relation ether_variable
216 $$ = dfilter_mknode_join($1, relation, $2, $3);
219 | ipxnet_variable equality_relation ipxnet_value
221 $$ = dfilter_mknode_join($1, relation, $2, $3);
223 | ipxnet_variable equality_relation ipxnet_variable
225 $$ = dfilter_mknode_join($1, relation, $2, $3);
229 | ipv4_variable numeric_relation ipv4_value
231 $$ = dfilter_mknode_join($1, relation, $2, $3);
233 | ipv4_variable numeric_relation ipv4_variable
235 $$ = dfilter_mknode_join($1, relation, $2, $3);
238 | ipv6_variable equality_relation ipv6_value
240 $$ = dfilter_mknode_join($1, relation, $2, $3);
242 | ipv6_variable equality_relation ipv6_variable
244 $$ = dfilter_mknode_join($1, relation, $2, $3);
247 | bytes_variable bytes_relation bytes_value
251 a_len = dfilter_get_bytes_variable_length($1);
252 b_len = dfilter_get_bytes_value_length($3);
255 dfilter_set_bytes_variable_length($1, b_len);
259 if (!check_bytes_variable_sanity($1)) {
263 if (a_len != b_len) {
264 dfilter_fail("Field \"%s\" has %u byte%s being compared, but %u byte%s "
266 dfilter_get_variable_abbrev($1),
267 a_len, plurality(a_len, "", "s"),
268 b_len, plurality(b_len, "", "s"),
269 plurality(b_len, "was", "were"));
273 $$ = dfilter_mknode_join($1, relation, $2, $3);
275 | bytes_variable bytes_relation bytes_variable
279 a_len = dfilter_get_bytes_variable_length($1);
280 b_len = dfilter_get_bytes_variable_length($3);
282 if (!check_bytes_variable_sanity($1)) {
286 if (!check_bytes_variable_sanity($3)) {
290 if (a_len != b_len) {
291 dfilter_fail("Fields \"%s\" and \"%s\" are being compared with "
292 "disparate lengths of %u byte%s and %u byte%s.",
293 dfilter_get_variable_abbrev($1),
294 dfilter_get_variable_abbrev($3),
295 a_len, plurality(a_len, "", "s"),
296 b_len, plurality(b_len, "", "s"));
300 $$ = dfilter_mknode_join($1, relation, $2, $3);
306 numeric_value: T_VAL_UNQUOTED_STRING
309 $$ = dfilter_mknode_numeric_value(string_to_guint32($1, &success));
317 ether_value: T_VAL_BYTE_STRING
319 $$ = dfilter_mknode_ether_value($1);
327 ipxnet_value: T_VAL_UNQUOTED_STRING
330 $$ = dfilter_mknode_ipxnet_value(string_to_guint32($1, &success));
338 floating_value: T_VAL_UNQUOTED_STRING
341 $$ = dfilter_mknode_floating_value(string_to_double($1, &success));
350 /* e.g., 0.0, 0.1, 0.01 ... */
352 $$ = dfilter_mknode_floating_value(string_to_double($1, &success));
360 ipv4_value: T_VAL_UNQUOTED_STRING
362 $$ = dfilter_mknode_ipv4_value($1, 32);
371 $$ = dfilter_mknode_ipv4_value($1, 32);
378 | T_VAL_UNQUOTED_STRING '/' T_VAL_UNQUOTED_STRING
383 nmask_bits = string_to_guint32($3, &success);
390 if (nmask_bits > 32) {
391 dfilter_fail("The number of netmask bits in \"%s/%s\" should "
392 "be between 0 and 32.", $1, $3);
398 $$ = dfilter_mknode_ipv4_value($1, nmask_bits);
406 | T_VAL_BYTE_STRING '/' T_VAL_UNQUOTED_STRING
411 nmask_bits = string_to_guint32($3, &success);
418 if (nmask_bits > 32) {
419 dfilter_fail("The number of netmask bits in \"%s/%s\" should "
420 "be between 0 and 32.", $1, $3);
425 $$ = dfilter_mknode_ipv4_value($1, nmask_bits);
434 ipv6_value: T_VAL_UNQUOTED_STRING
436 $$ = dfilter_mknode_ipv6_value($1);
445 $$ = dfilter_mknode_ipv6_value($1);
453 bytes_value: T_VAL_BYTE_STRING
457 /* the next function appends to list_of_byte_arrays for me */
458 barray = byte_str_to_guint8_array($1);
459 $$ = dfilter_mknode_bytes_value(barray);
463 | T_VAL_UNQUOTED_STRING
470 val32 = string_to_guint32($1, &success);
476 dfilter_fail("The value \"%s\" cannot be stored in a single-byte byte-string. "
477 "Use the multi-byte \"xx:yy\" representation.", $1);
481 val8 = (guint8) val32;
482 barray = g_byte_array_new();
483 global_df->list_of_byte_arrays = g_slist_append(global_df->list_of_byte_arrays, barray);
484 g_byte_array_append(barray, &val8, 1);
486 $$ = dfilter_mknode_bytes_value(barray);
491 numeric_variable: T_FT_UINT8 { $$ = dfilter_mknode_numeric_variable($1.id); }
492 | T_FT_UINT16 { $$ = dfilter_mknode_numeric_variable($1.id); }
493 | T_FT_UINT32 { $$ = dfilter_mknode_numeric_variable($1.id); }
494 | T_FT_INT8 { $$ = dfilter_mknode_numeric_variable($1.id); }
495 | T_FT_INT16 { $$ = dfilter_mknode_numeric_variable($1.id); }
496 | T_FT_INT32 { $$ = dfilter_mknode_numeric_variable($1.id); }
499 ether_variable: T_FT_ETHER { $$ = dfilter_mknode_ether_variable($1.id); }
502 floating_variable: T_FT_DOUBLE { $$ = dfilter_mknode_floating_variable($1.id); }
505 ipxnet_variable: T_FT_IPXNET { $$ = dfilter_mknode_ipxnet_variable($1.id); }
508 ipv4_variable: T_FT_IPv4 { $$ = dfilter_mknode_ipv4_variable($1.id); }
511 ipv6_variable: T_FT_IPv6 { $$ = dfilter_mknode_ipv6_variable($1.id); }
514 variable_name: any_variable_type
519 if ($1.type == T_FT_BOOLEAN) {
520 /* Make "variable == TRUE" for BOOLEAN variable */
521 variable = dfilter_mknode_numeric_variable($1.id);
522 value = dfilter_mknode_numeric_value(TRUE);
523 $$ = dfilter_mknode_join(variable, relation, TOK_EQ, value);
526 $$ = dfilter_mknode_existence($1.id);
531 bytes_variable: any_variable_type T_VAL_BYTE_RANGE
533 $$ = dfilter_mknode_bytes_variable($1.id, $2.offset, $2.length);
537 any_variable_type: T_FT_UINT8 { $$ = $1; }
538 | T_FT_UINT16 { $$ = $1; }
539 | T_FT_UINT32 { $$ = $1; }
540 | T_FT_INT8 { $$ = $1; }
541 | T_FT_INT16 { $$ = $1; }
542 | T_FT_INT32 { $$ = $1; }
543 | T_FT_DOUBLE { $$ = $1; }
544 | T_FT_ETHER { $$ = $1; }
545 | T_FT_IPv4 { $$ = $1; }
546 | T_FT_IPv6 { $$ = $1; }
547 | T_FT_IPXNET { $$ = $1; }
548 | T_FT_NONE { $$ = $1; }
549 | T_FT_BYTES { $$ = $1; }
550 | T_FT_BOOLEAN { $$ = $1; }
551 | T_FT_STRING { $$ = $1; }
554 numeric_relation: TOK_EQ { $$ = TOK_EQ; }
555 | TOK_NE { $$ = TOK_NE; }
556 | TOK_GT { $$ = TOK_GT; }
557 | TOK_GE { $$ = TOK_GE; }
558 | TOK_LT { $$ = TOK_LT; }
559 | TOK_LE { $$ = TOK_LE; }
562 equality_relation: TOK_EQ { $$ = TOK_EQ; }
563 | TOK_NE { $$ = TOK_NE; }
566 bytes_relation: TOK_EQ { $$ = TOK_EQ; }
567 | TOK_NE { $$ = TOK_NE; }
568 | TOK_GT { $$ = TOK_GT; }
569 | TOK_LT { $$ = TOK_LT; }
575 dfilter_mknode_join(GNode *n1, enum node_type ntype, int operand, GNode *n2)
577 dfilter_node *node_root;
580 node_root = g_mem_chunk_alloc(global_df->node_memchunk);
581 node_root->ntype = ntype;
582 node_root->elem_size = 0;
583 node_root->fill_array_func = NULL;
584 node_root->check_relation_func = NULL;
585 if (ntype == relation) {
586 node_root->value.relation = operand;
588 else if (ntype == logical) {
589 node_root->value.logical = operand;
592 g_assert_not_reached();
595 gnode_root = g_node_new(node_root);
596 g_node_append(gnode_root, n1);
597 g_node_append(gnode_root, n2);
603 dfilter_mknode_unary(int operand, GNode *n2)
605 dfilter_node *node_root;
608 node_root = g_mem_chunk_alloc(global_df->node_memchunk);
609 node_root->ntype = logical;
610 node_root->value.logical = operand;
611 node_root->elem_size = 0;
612 node_root->fill_array_func = NULL;
613 node_root->check_relation_func = NULL;
615 gnode_root = g_node_new(node_root);
616 g_node_append(gnode_root, n2);
623 dfilter_mknode_numeric_variable(gint id)
628 node = g_mem_chunk_alloc(global_df->node_memchunk);
629 node->ntype = variable;
630 node->elem_size = sizeof(guint32);
631 node->fill_array_func = fill_array_numeric_variable;
632 node->check_relation_func = check_relation_numeric;
633 node->value.variable = id;
634 gnode = g_node_new(node);
640 dfilter_mknode_ether_variable(gint id)
645 node = g_mem_chunk_alloc(global_df->node_memchunk);
646 node->ntype = variable;
647 node->elem_size = sizeof(guint8) * 6;
648 node->fill_array_func = fill_array_ether_variable;
649 node->check_relation_func = check_relation_ether;
650 node->value.variable = id;
651 gnode = g_node_new(node);
657 dfilter_mknode_floating_variable(gint id)
662 node = g_mem_chunk_alloc(global_df->node_memchunk);
663 node->ntype = variable;
664 node->elem_size = sizeof(double);
665 node->fill_array_func = fill_array_floating_variable;
666 node->check_relation_func = check_relation_floating;
667 node->value.variable = id;
668 gnode = g_node_new(node);
674 dfilter_mknode_ipxnet_variable(gint id)
679 node = g_mem_chunk_alloc(global_df->node_memchunk);
680 node->ntype = variable;
681 node->elem_size = sizeof(guint8) * 4;
682 node->fill_array_func = fill_array_numeric_variable; /* cheating ! */
683 node->check_relation_func = check_relation_numeric; /* cheating ! */
684 node->value.variable = id;
685 gnode = g_node_new(node);
691 dfilter_mknode_ipv4_variable(gint id)
696 node = g_mem_chunk_alloc(global_df->node_memchunk);
697 node->ntype = variable;
698 node->elem_size = sizeof(ipv4_addr);
699 node->fill_array_func = fill_array_ipv4_variable;
700 node->check_relation_func = check_relation_ipv4;
701 node->value.variable = id;
702 gnode = g_node_new(node);
708 dfilter_mknode_ipv6_variable(gint id)
713 node = g_mem_chunk_alloc(global_df->node_memchunk);
714 node->ntype = variable;
715 node->elem_size = 16;
716 node->fill_array_func = fill_array_ipv6_variable;
717 node->check_relation_func = check_relation_ipv6;
718 node->value.variable = id;
719 gnode = g_node_new(node);
725 dfilter_mknode_bytes_variable(gint id, gint offset, guint length)
730 node = g_mem_chunk_alloc(global_df->node_memchunk);
731 node->ntype = variable;
732 node->elem_size = sizeof(GByteArray*);
733 node->fill_array_func = fill_array_bytes_variable;
734 node->check_relation_func = check_relation_bytes;
735 node->value.variable = id;
736 node->offset = offset;
737 node->length = length;
738 gnode = g_node_new(node);
743 /* Gets length of variable represented by node from proto_register */
745 dfilter_get_bytes_variable_field_registered_length(GNode *gnode)
747 dfilter_node *node = gnode->data;
749 /* Is this really a bytes_variable? */
750 g_assert(node->fill_array_func = fill_array_bytes_variable);
752 return proto_registrar_get_length(node->value.variable);
755 /* Sets the length of a bytes_variable node */
757 dfilter_set_bytes_variable_length(GNode *gnode, guint length)
759 dfilter_node *node = gnode->data;
761 /* Is this really a bytes_variable? */
762 g_assert(node->fill_array_func = fill_array_bytes_variable);
764 node->length = length;
767 /* Gets the length of a bytes_variable node */
769 dfilter_get_bytes_variable_length(GNode *gnode)
771 dfilter_node *node = gnode->data;
773 /* Is this really a bytes_variable? */
774 g_assert(node->fill_array_func = fill_array_bytes_variable);
779 /* Gets the offset of a bytes_variable node */
781 dfilter_get_bytes_variable_offset(GNode *gnode)
783 dfilter_node *node = gnode->data;
785 /* Is this really a bytes_variable? */
786 g_assert(node->fill_array_func = fill_array_bytes_variable);
792 dfilter_get_variable_abbrev(GNode *gnode)
794 dfilter_node *node = gnode->data;
796 return proto_registrar_get_abbrev(node->value.variable);
800 dfilter_mknode_numeric_value(guint32 val)
805 node = g_mem_chunk_alloc(global_df->node_memchunk);
806 node->ntype = numeric;
807 node->elem_size = sizeof(guint32);
808 node->fill_array_func = fill_array_numeric_value;
809 node->check_relation_func = check_relation_numeric;
810 node->value.numeric = val;
811 gnode = g_node_new(node);
817 dfilter_mknode_floating_value(double val)
822 node = g_mem_chunk_alloc(global_df->node_memchunk);
823 node->ntype = floating;
824 node->elem_size = sizeof(double);
825 node->fill_array_func = fill_array_floating_value;
826 node->check_relation_func = check_relation_floating;
827 node->value.floating = val;
828 gnode = g_node_new(node);
833 /* Returns NULL on bad parse of ETHER value */
835 dfilter_mknode_ether_value(gchar *byte_string)
840 node = g_mem_chunk_alloc(global_df->node_memchunk);
842 node->elem_size = sizeof(guint8) * 6;
843 node->fill_array_func = fill_array_ether_value;
844 node->check_relation_func = check_relation_ether;
846 if (!ether_str_to_guint8_array(byte_string, &node->value.ether[0])) {
847 /* Rather than free the mem_chunk allocation, let it
848 * stay. It will be cleaned up when "dfilter_compile()"
849 * calls "dfilter_destroy()". */
850 dfilter_fail("\"%s\" is not a valid hardware address.",
855 gnode = g_node_new(node);
860 dfilter_mknode_ipxnet_value(guint32 ipx_net_val)
865 node = g_mem_chunk_alloc(global_df->node_memchunk);
866 node->ntype = ipxnet;
867 node->elem_size = sizeof(guint8) * 4;
868 node->fill_array_func = fill_array_numeric_value; /* cheating ! */
869 node->check_relation_func = check_relation_numeric; /* cheating ! */
870 node->value.numeric = ipx_net_val;
871 gnode = g_node_new(node);
876 /* Returns NULL on bad parse of IP value */
878 dfilter_mknode_ipv4_value(char *host, int nmask_bits)
884 node = g_mem_chunk_alloc(global_df->node_memchunk);
885 node->ntype = numeric;
886 node->elem_size = sizeof(ipv4_addr);
887 node->fill_array_func = fill_array_ipv4_value;
888 node->check_relation_func = check_relation_ipv4;
889 if (!get_host_ipaddr(host, &addr)) {
890 /* Rather than free the mem_chunk allocation, let it
891 * stay. It will be cleaned up when "dfilter_compile()"
892 * calls "dfilter_destroy()". */
893 dfilter_fail("\"%s\" isn't a valid host name or IP address.",
897 ipv4_addr_set_host_order_addr(&node->value.ipv4, addr);
898 ipv4_addr_set_netmask_bits(&node->value.ipv4, nmask_bits);
900 gnode = g_node_new(node);
904 /* Returns NULL on bad parse of IPv6 value */
906 dfilter_mknode_ipv6_value(char *host)
911 node = g_mem_chunk_alloc(global_df->node_memchunk);
913 node->elem_size = 16;
914 node->fill_array_func = fill_array_ipv6_value;
915 node->check_relation_func = check_relation_ipv6;
917 if (!get_host_ipaddr6(host, (struct e_in6_addr*)&node->value.ipv6[0])) {
918 /* Rather than free the mem_chunk allocation, let it
919 * stay. It will be cleaned up when "dfilter_compile()"
920 * calls "dfilter_destroy()". */
921 dfilter_fail("\"%s\" isn't a valid IPv6 address.",
926 gnode = g_node_new(node);
931 dfilter_mknode_bytes_value(GByteArray *barray)
936 node = g_mem_chunk_alloc(global_df->node_memchunk);
938 node->elem_size = sizeof(GByteArray*);
939 node->fill_array_func = fill_array_bytes_value;
940 node->check_relation_func = check_relation_bytes;
941 node->value.bytes = barray;
942 node->offset = G_MAXINT;
943 node->length = barray->len;
944 gnode = g_node_new(node);
949 /* Given a node representing a bytes_value, returns
950 * the length of the byte array */
952 dfilter_get_bytes_value_length(GNode* gnode)
954 dfilter_node *node = gnode->data;
956 g_assert(node->ntype == bytes);
961 string_to_guint32(char *s, gboolean *success)
966 val = strtoul(s, &endptr, 0);
968 if (endptr == s || *endptr != '\0') {
969 /* This isn't a valid number. */
970 dfilter_fail("\"%s\" is not a valid number.", s);
973 if (errno == ERANGE) {
975 if (val == ULONG_MAX) {
976 dfilter_fail("\"%s\" causes an integer overflow.", s);
979 dfilter_fail("\"%s\" is not an integer.", s);
987 string_to_double(char *s, gboolean *success)
992 retval = strtod(s, &endptr);
996 dfilter_fail("\"%s\" is not a valid floating-point number.", s);
1000 if (errno == ERANGE) {
1003 dfilter_fail("\"%s\" causes a floating-point underflow.", s);
1005 else if (retval == HUGE_VAL) {
1006 dfilter_fail("\"%s\" causes a floating-point overflow.", s);
1009 dfilter_fail("\"%s\" is not a valid floating-point.", s);
1016 dfilter_mknode_existence(gint id)
1021 node = g_mem_chunk_alloc(global_df->node_memchunk);
1022 node->ntype = existence;
1023 node->elem_size = sizeof(guint32);
1024 node->fill_array_func = NULL;
1025 node->check_relation_func = NULL;
1026 node->value.variable = id;
1027 gnode = g_node_new(node);
1033 /* converts a string representing an ether HW address
1034 * to a guint8 array.
1036 * Returns 0 on failure, 1 on success.
1039 ether_str_to_guint8_array(const char *s, guint8 *mac)
1041 char ether_str[18]; /* 2+1+2+1+2+1+2+1+2+1+2 + 1 */
1045 if (strlen(s) > 17) {
1048 strcpy(ether_str, s); /* local copy of string */
1050 while ((p = strtok(str, "-:."))) {
1051 /* catch short strings with too many hex bytes: 0.0.0.0.0.0.0 */
1055 mac[i] = (guint8) strtoul(p, NULL, 16);
1057 /* subsequent calls to strtok() require NULL as arg 1 */
1061 return 0; /* failed to read 6 hex pairs */
1063 return 1; /* read exactly 6 hex pairs */
1068 check_bytes_variable_sanity(GNode *gnode)
1070 int a_off, a_len, reg_len, t_off;
1072 a_off = dfilter_get_bytes_variable_offset(gnode);
1073 a_len = dfilter_get_bytes_variable_length(gnode);
1074 reg_len = dfilter_get_bytes_variable_field_registered_length(gnode);
1077 t_off = a_off >= 0 ? a_off : reg_len + a_off;
1078 if (t_off + a_len > reg_len) {
1079 dfilter_fail("The \"%s\" field is only %u byte%s wide, but "
1080 "%u byte%s %s supplied.",
1081 dfilter_get_variable_abbrev(gnode),
1082 reg_len, plurality(reg_len, "", "s"),
1083 a_len, plurality(a_len, "", "s"),
1084 plurality(a_len, "was", "were"));