1995-03-06 14:32:59 +03:00
|
|
|
%{
|
1998-04-09 04:32:31 +04:00
|
|
|
/* $NetBSD: scanner.l,v 1.5 1998/04/09 00:32:35 tv Exp $ */
|
1995-03-06 14:37:58 +03:00
|
|
|
|
1995-03-06 14:32:59 +03:00
|
|
|
/*
|
1997-10-03 19:53:00 +04:00
|
|
|
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
|
1995-03-06 14:32:59 +03:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that: (1) source code distributions
|
|
|
|
* retain the above copyright notice and this paragraph in its entirety, (2)
|
|
|
|
* distributions including binary code include the above copyright notice and
|
|
|
|
* this paragraph in its entirety in the documentation or other materials
|
|
|
|
* provided with the distribution, and (3) all advertising materials mentioning
|
|
|
|
* features or use of this software display the following acknowledgement:
|
|
|
|
* ``This product includes software developed by the University of California,
|
|
|
|
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
|
|
|
* the University nor the names of its contributors may be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*/
|
|
|
|
|
1997-10-03 19:53:00 +04:00
|
|
|
#include <sys/cdefs.h>
|
1995-03-06 14:32:59 +03:00
|
|
|
#ifndef lint
|
1997-10-03 19:53:00 +04:00
|
|
|
#if 0
|
|
|
|
static const char rcsid[] =
|
|
|
|
"@(#) Header: scanner.l,v 1.56 97/07/21 13:31:50 leres Exp (LBL)";
|
|
|
|
#else
|
1998-04-09 04:32:31 +04:00
|
|
|
__RCSID("$NetBSD: scanner.l,v 1.5 1998/04/09 00:32:35 tv Exp $");
|
1997-10-03 19:53:00 +04:00
|
|
|
#endif
|
1995-03-06 14:32:59 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#include <ctype.h>
|
1996-12-13 11:25:54 +03:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "pcap-int.h"
|
1995-03-06 14:32:59 +03:00
|
|
|
|
|
|
|
#include "gencode.h"
|
1996-12-13 11:25:54 +03:00
|
|
|
#include <pcap-namedb.h>
|
1998-04-09 04:32:31 +04:00
|
|
|
#include "grammar.h"
|
1995-03-06 14:32:59 +03:00
|
|
|
|
1996-12-13 11:25:54 +03:00
|
|
|
#include "gnuc.h"
|
|
|
|
#ifdef HAVE_OS_PROTO_H
|
|
|
|
#include "os-proto.h"
|
1995-03-06 14:32:59 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static int stoi(char *);
|
|
|
|
static inline int xdtoi(int);
|
|
|
|
|
|
|
|
#ifdef FLEX_SCANNER
|
1997-10-03 19:53:00 +04:00
|
|
|
#define YY_NO_UNPUT
|
1995-03-06 14:32:59 +03:00
|
|
|
#undef YY_INPUT
|
|
|
|
#define YY_INPUT(buf, result, max)\
|
|
|
|
{\
|
|
|
|
char *src = in_buffer;\
|
|
|
|
int i;\
|
|
|
|
\
|
|
|
|
if (*src == 0)\
|
|
|
|
result = YY_NULL;\
|
|
|
|
else {\
|
|
|
|
for (i = 0; *src && i < max; ++i)\
|
|
|
|
buf[i] = *src++;\
|
|
|
|
in_buffer += i;\
|
|
|
|
result = i;\
|
|
|
|
}\
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#undef getc
|
|
|
|
#define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++)
|
|
|
|
#endif
|
|
|
|
|
1996-12-13 11:25:54 +03:00
|
|
|
#define yylval pcap_lval
|
1995-03-06 14:32:59 +03:00
|
|
|
extern YYSTYPE yylval;
|
|
|
|
|
|
|
|
static char *in_buffer;
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
N ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
|
|
|
|
B ([0-9A-Fa-f][0-9A-Fa-f]?)
|
|
|
|
|
|
|
|
%a 3000
|
|
|
|
|
|
|
|
%%
|
|
|
|
dst return DST;
|
|
|
|
src return SRC;
|
|
|
|
|
|
|
|
link|ether|ppp|slip return LINK;
|
|
|
|
fddi return LINK;
|
|
|
|
arp return ARP;
|
|
|
|
rarp return RARP;
|
|
|
|
ip return IP;
|
|
|
|
tcp return TCP;
|
|
|
|
udp return UDP;
|
|
|
|
icmp return ICMP;
|
1996-12-13 11:25:54 +03:00
|
|
|
igmp return IGMP;
|
|
|
|
igrp return IGRP;
|
1995-03-06 14:32:59 +03:00
|
|
|
|
1996-12-13 11:25:54 +03:00
|
|
|
atalk return ATALK;
|
1995-03-06 14:32:59 +03:00
|
|
|
decnet return DECNET;
|
|
|
|
lat return LAT;
|
1996-12-13 11:25:54 +03:00
|
|
|
sca return SCA;
|
1995-03-06 14:32:59 +03:00
|
|
|
moprc return MOPRC;
|
|
|
|
mopdl return MOPDL;
|
|
|
|
|
|
|
|
host return HOST;
|
|
|
|
net return NET;
|
1996-12-13 11:25:54 +03:00
|
|
|
mask return MASK;
|
1995-03-06 14:32:59 +03:00
|
|
|
port return PORT;
|
|
|
|
proto return PROTO;
|
|
|
|
|
|
|
|
gateway return GATEWAY;
|
|
|
|
|
|
|
|
less return LESS;
|
|
|
|
greater return GREATER;
|
|
|
|
byte return BYTE;
|
|
|
|
broadcast return TK_BROADCAST;
|
|
|
|
multicast return TK_MULTICAST;
|
|
|
|
|
|
|
|
and|"&&" return AND;
|
|
|
|
or|"||" return OR;
|
|
|
|
not return '!';
|
|
|
|
|
|
|
|
len|length return LEN;
|
|
|
|
inbound return INBOUND;
|
|
|
|
outbound return OUTBOUND;
|
|
|
|
|
|
|
|
[ \n\t] ;
|
|
|
|
[+\-*/:\[\]!<>()&|=] return yytext[0];
|
|
|
|
">=" return GEQ;
|
|
|
|
"<=" return LEQ;
|
|
|
|
"!=" return NEQ;
|
|
|
|
"==" return '=';
|
|
|
|
"<<" return LSH;
|
|
|
|
">>" return RSH;
|
|
|
|
{N} { yylval.i = stoi((char *)yytext); return NUM; }
|
|
|
|
({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
|
1997-10-03 19:53:00 +04:00
|
|
|
yylval.s = sdup((char *)yytext); return HID; }
|
1995-03-06 14:32:59 +03:00
|
|
|
{B}:{B}:{B}:{B}:{B}:{B} { yylval.e = pcap_ether_aton((char *)yytext);
|
|
|
|
return EID; }
|
|
|
|
{B}:+({B}:+)+ { bpf_error("bogus ethernet address %s", yytext); }
|
1997-10-03 19:53:00 +04:00
|
|
|
[A-Za-z0-9][-_.A-Za-z0-9]*[.A-Za-z0-9] {
|
|
|
|
yylval.s = sdup((char *)yytext); return ID; }
|
1995-03-06 14:32:59 +03:00
|
|
|
"\\"[^ !()\n\t]+ { yylval.s = sdup((char *)yytext + 1); return ID; }
|
1997-10-03 19:53:00 +04:00
|
|
|
[^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+i {
|
|
|
|
bpf_error("illegal token: %s\n", yytext); }
|
1995-03-06 14:32:59 +03:00
|
|
|
. { bpf_error("illegal char '%c'", *yytext); }
|
|
|
|
%%
|
|
|
|
void
|
|
|
|
lex_init(buf)
|
|
|
|
char *buf;
|
|
|
|
{
|
|
|
|
in_buffer = buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Also define a yywrap. Note that if we're using flex, it will
|
|
|
|
* define a macro to map this identifier to pcap_wrap.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
yywrap()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hex digit to integer. */
|
|
|
|
static inline int
|
|
|
|
xdtoi(c)
|
|
|
|
register int c;
|
|
|
|
{
|
|
|
|
if (isdigit(c))
|
|
|
|
return c - '0';
|
|
|
|
else if (islower(c))
|
|
|
|
return c - 'a' + 10;
|
|
|
|
else
|
|
|
|
return c - 'A' + 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert string to integer. Just like atoi(), but checks for
|
|
|
|
* preceding 0x or 0 and uses hex or octal instead of decimal.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
stoi(s)
|
|
|
|
char *s;
|
|
|
|
{
|
|
|
|
int base = 10;
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
if (*s == '0') {
|
|
|
|
if (s[1] == 'x' || s[1] == 'X') {
|
|
|
|
s += 2;
|
|
|
|
base = 16;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
base = 8;
|
|
|
|
s += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (*s)
|
|
|
|
n = n * base + xdtoi(*s++);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|