aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGilbert Ramirez <gram@alumni.rice.edu>1999-07-08 03:05:55 +0000
committerGilbert Ramirez <gram@alumni.rice.edu>1999-07-08 03:05:55 +0000
commit56c0587491f07bda16d10d4f1aab6fbb5ba58eef (patch)
tree4a428e4eb50cf765c813574386505e98d372ea08
parent856e356a7a544706cf27edad3113db1acaa6704c (diff)
Fixed the byte_range implementation, and removed some of the C-style
operators that I had thrown in at the last moment. Sorry! But I'm trying to get rid of those embarrassing shift/reduce and reduce/reduce warnings. I also removed wiretap/wiretap.c, which is no longer needed. svn path=/trunk/; revision=345
-rw-r--r--dfilter-grammar.y38
-rw-r--r--wiretap/wiretap.c310
2 files changed, 29 insertions, 319 deletions
diff --git a/dfilter-grammar.y b/dfilter-grammar.y
index 83490243f8..06d479b891 100644
--- a/dfilter-grammar.y
+++ b/dfilter-grammar.y
@@ -39,7 +39,6 @@
#endif
void dfilter_yacc_init(void);
-static void dfilter_print_parse_tree(GNode *gnode);
static GNode* dfilter_mknode_join(GNode *n1, enum node_type ntype, int operand, GNode *n2);
static GNode* dfilter_mknode_unary(int operand, GNode *n2);
static GNode* dfilter_mknode_numeric_variable(gint id);
@@ -210,7 +209,11 @@ relation: numeric_variable numeric_relation numeric_value
;
-numeric_value: T_VAL_ID { $$ = dfilter_mknode_numeric_value(string_to_value($1)); }
+numeric_value: T_VAL_ID
+ {
+ $$ = dfilter_mknode_numeric_value(string_to_value($1));
+ g_free($1);
+ }
;
ether_value: T_VAL_ID ':' T_VAL_ID ':' T_VAL_ID ':' T_VAL_ID ':' T_VAL_ID ':' T_VAL_ID
@@ -225,10 +228,25 @@ ether_value: T_VAL_ID ':' T_VAL_ID ':' T_VAL_ID ':' T_VAL_ID ':' T_VAL_ID ':' T_
}
;
-ipv4_value: T_VAL_ID { $$ = dfilter_mknode_ipv4_value($1); }
+ipv4_value: T_VAL_ID
+ {
+ $$ = dfilter_mknode_ipv4_value($1);
+ g_free($1);
+ }
;
-bytes_value: numeric_variable
+bytes_value: T_VAL_ID
+ {
+ GByteArray *barray = g_byte_array_new();
+ guint8 val;
+ char *endptr;
+
+ dfilter_list_byte_arrays = g_slist_append(dfilter_list_byte_arrays, barray);
+ val = (guint8) strtoul($1, &endptr, 16);
+ g_byte_array_append(barray, &val, 1);
+ $$ = dfilter_mknode_bytes_value(barray);
+ g_free($1);
+ }
| byte_range { $$ = dfilter_mknode_bytes_value($1); }
;
@@ -243,6 +261,8 @@ byte_range: T_VAL_ID ':' T_VAL_ID
g_byte_array_append(barray, &val, 1);
val = (guint8) strtoul($3, &endptr, 16);
$$ = g_byte_array_append(barray, &val, 1);
+ g_free($1);
+ g_free($3);
}
| byte_range ':' T_VAL_ID
@@ -252,6 +272,7 @@ byte_range: T_VAL_ID ':' T_VAL_ID
val = (guint8) strtoul($3, &endptr, 16);
$$ = g_byte_array_append($1, &val, 1);
+ g_free($3);
}
;
@@ -277,10 +298,13 @@ protocol_name: T_FT_NONE { $$ = dfilter_mknode_existence($1); }
bytes_variable: any_variable_type '[' T_VAL_ID ':' T_VAL_ID ']'
{
$$ = dfilter_mknode_bytes_variable($1, string_to_value($3), string_to_value($5));
+ g_free($3);
+ g_free($5);
}
| any_variable_type '[' T_VAL_ID ']'
{
- $$ = dfilter_mknode_bytes_variable($1, string_to_value($3), 0);
+ $$ = dfilter_mknode_bytes_variable($1, string_to_value($3), 1);
+ g_free($3);
}
;
@@ -334,19 +358,15 @@ type_ne: TOK_NE { $$ = $1; }
;
type_gt: TOK_GT { $$ = $1; }
- | '>' { $$ = TOK_GT; }
;
type_ge: TOK_GE { $$ = $1; }
- | '>' '=' { $$ = TOK_GE; }
;
type_lt: TOK_LT { $$ = $1; }
- | '<' { $$ = TOK_LT; }
;
type_le: TOK_LE { $$ = $1; }
- | '<' '=' { $$ = TOK_LE; }
;
diff --git a/wiretap/wiretap.c b/wiretap/wiretap.c
deleted file mode 100644
index 01f422298c..0000000000
--- a/wiretap/wiretap.c
+++ /dev/null
@@ -1,310 +0,0 @@
-
-#include <stdio.h>
-#include <glib.h>
-#include "config.h"
-#include "wtap.h"
-#include "bpf-engine.h"
-
-#ifdef HAVE_GLIB10
-#include "glib-new.h"
-#endif
-
-void bpf_dump(wtap *wth);
-char *bpf_image(struct bpf_instruction *p, int n);
-
-int main(int argc, char **argv)
-{
- wtap *wth;
- char *fsyntax;
- int i;
-
- if (argc <= 1) {
- fprintf(stderr, "usage: wiretap filter\n");
- exit(-1);
- }
-
- fsyntax = g_strdup(argv[1]);
-
- for (i = 2; i < argc; i++) {
- fsyntax = g_strjoin(" ", fsyntax, argv[i], NULL);
- }
- wth = (wtap*)g_malloc(sizeof(wtap));
-
- /* initialization */
- wth->file_encap = WTAP_ENCAP_NONE;
- wth->filter.offline = NULL;
- wth->filter_type = WTAP_FILTER_NONE;
- wth->filter_length = 0;
- wth->offline_filter_lengths = NULL;
-
- wtap_offline_filter(wth, fsyntax);
- bpf_dump(wth);
-
- g_free(wth);
- return 0;
-}
-
-void
-bpf_dump(wtap *wth)
-{
- struct bpf_instruction *fentry;
- int flen;
- int i;
-
- fentry = wth->filter.offline[WTAP_ENCAP_ETHERNET];
- flen = wth->offline_filter_lengths[WTAP_ENCAP_ETHERNET];
-
- /* this loop is from tcpdump's bpf_dump.c */
- for (i = 0; i < flen; ++fentry, ++i) {
- puts(bpf_image(fentry, i));
- }
-}
-
-/* this entire function is from libpcap's bpf_image.c */
-char *
-bpf_image(struct bpf_instruction *p, int n)
-{
- int v;
- char *fmt, *op;
- static char image[256];
- char operand[64];
-
- v = p->k;
- switch (p->code) {
-
- default:
- op = "unimp";
- fmt = "0x%x";
- v = p->code;
- break;
-
- case BPF_RET|BPF_K:
- op = "ret";
- fmt = "#%d";
- break;
-
- case BPF_RET|BPF_A:
- op = "ret";
- fmt = "";
- break;
-
- case BPF_LD|BPF_W|BPF_ABS:
- op = "ld";
- fmt = "[%d]";
- break;
-
- case BPF_LD|BPF_H|BPF_ABS:
- op = "ldh";
- fmt = "[%d]";
- break;
-
- case BPF_LD|BPF_B|BPF_ABS:
- op = "ldb";
- fmt = "[%d]";
- break;
-
- case BPF_LD|BPF_W|BPF_LEN:
- op = "ld";
- fmt = "#pktlen";
- break;
-
- case BPF_LD|BPF_W|BPF_IND:
- op = "ld";
- fmt = "[x + %d]";
- break;
-
- case BPF_LD|BPF_H|BPF_IND:
- op = "ldh";
- fmt = "[x + %d]";
- break;
-
- case BPF_LD|BPF_B|BPF_IND:
- op = "ldb";
- fmt = "[x + %d]";
- break;
-
- case BPF_LD|BPF_IMM:
- op = "ld";
- fmt = "#0x%x";
- break;
-
- case BPF_LDX|BPF_IMM:
- op = "ldx";
- fmt = "#0x%x";
- break;
-
- case BPF_LDX|BPF_MSH|BPF_B:
- op = "ldxb";
- fmt = "4*([%d]&0xf)";
- break;
-
- case BPF_LD|BPF_MEM:
- op = "ld";
- fmt = "M[%d]";
- break;
-
- case BPF_LDX|BPF_MEM:
- op = "ldx";
- fmt = "M[%d]";
- break;
-
- case BPF_ST:
- op = "st";
- fmt = "M[%d]";
- break;
-
- case BPF_STX:
- op = "stx";
- fmt = "M[%d]";
- break;
-
- case BPF_JMP|BPF_JA:
- op = "ja";
- fmt = "%d";
- v = n + 1 + p->k;
- break;
-
- case BPF_JMP|BPF_JGT|BPF_K:
- op = "jgt";
- fmt = "#0x%x";
- break;
-
- case BPF_JMP|BPF_JGE|BPF_K:
- op = "jge";
- fmt = "#0x%x";
- break;
-
- case BPF_JMP|BPF_JEQ|BPF_K:
- op = "jeq";
- fmt = "#0x%08x";
- break;
-
- case BPF_JMP|BPF_JSET|BPF_K:
- op = "jset";
- fmt = "#0x%x";
- break;
-
- case BPF_JMP|BPF_JGT|BPF_X:
- op = "jgt";
- fmt = "x";
- break;
-
- case BPF_JMP|BPF_JGE|BPF_X:
- op = "jge";
- fmt = "x";
- break;
-
- case BPF_JMP|BPF_JEQ|BPF_X:
- op = "jeq";
- fmt = "x";
- break;
-
- case BPF_JMP|BPF_JSET|BPF_X:
- op = "jset";
- fmt = "x";
- break;
-
- case BPF_ALU|BPF_ADD|BPF_X:
- op = "add";
- fmt = "x";
- break;
-
- case BPF_ALU|BPF_SUB|BPF_X:
- op = "sub";
- fmt = "x";
- break;
-
- case BPF_ALU|BPF_MUL|BPF_X:
- op = "mul";
- fmt = "x";
- break;
-
- case BPF_ALU|BPF_DIV|BPF_X:
- op = "div";
- fmt = "x";
- break;
-
- case BPF_ALU|BPF_AND|BPF_X:
- op = "and";
- fmt = "x";
- break;
-
- case BPF_ALU|BPF_OR|BPF_X:
- op = "or";
- fmt = "x";
- break;
-
- case BPF_ALU|BPF_LSH|BPF_X:
- op = "lsh";
- fmt = "x";
- break;
-
- case BPF_ALU|BPF_RSH|BPF_X:
- op = "rsh";
- fmt = "x";
- break;
-
- case BPF_ALU|BPF_ADD|BPF_K:
- op = "add";
- fmt = "#%d";
- break;
-
- case BPF_ALU|BPF_SUB|BPF_K:
- op = "sub";
- fmt = "#%d";
- break;
-
- case BPF_ALU|BPF_MUL|BPF_K:
- op = "mul";
- fmt = "#%d";
- break;
-
- case BPF_ALU|BPF_DIV|BPF_K:
- op = "div";
- fmt = "#%d";
- break;
-
- case BPF_ALU|BPF_AND|BPF_K:
- op = "and";
- fmt = "#0x%08x";
- break;
-
- case BPF_ALU|BPF_OR|BPF_K:
- op = "or";
- fmt = "#0x%x";
- break;
-
- case BPF_ALU|BPF_LSH|BPF_K:
- op = "lsh";
- fmt = "#%d";
- break;
-
- case BPF_ALU|BPF_RSH|BPF_K:
- op = "rsh";
- fmt = "#%d";
- break;
-
- case BPF_ALU|BPF_NEG:
- op = "neg";
- fmt = "";
- break;
-
- case BPF_MISC|BPF_TAX:
- op = "tax";
- fmt = "";
- break;
-
- case BPF_MISC|BPF_TXA:
- op = "txa";
- fmt = "";
- break;
- }
- (void)sprintf(operand, fmt, v);
- (void)sprintf(image,
- (BPF_CLASS(p->code) == BPF_JMP &&
- BPF_OP(p->code) != BPF_JA) ?
- "(%03d) %-8s %-16s jt %d\tjf %d"
- : "(%03d) %-8s %s",
- n, op, operand, n + 1 + p->jt, n + 1 + p->jf);
- return image;
-}