1996-08-19 20:36:34 +00:00
|
|
|
%{
|
|
|
|
/*
|
1998-09-15 19:31:43 +00:00
|
|
|
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
|
1996-08-19 20:36:34 +00: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.
|
2000-01-30 00:43:38 +00:00
|
|
|
*
|
|
|
|
* $FreeBSD$
|
1996-08-19 20:36:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-05-27 00:05:23 +00:00
|
|
|
static const char rcsid[] =
|
2002-06-21 01:38:14 +00:00
|
|
|
"@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.81 2001/09/14 01:40:57 fenner Exp $ (LBL)";
|
2001-04-03 04:32:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
1996-08-19 20:36:34 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <unistd.h>
|
2000-01-30 00:43:38 +00:00
|
|
|
#include <string.h>
|
1996-08-19 20:36:34 +00:00
|
|
|
|
|
|
|
#include "pcap-int.h"
|
|
|
|
|
|
|
|
#include "gencode.h"
|
|
|
|
#include <pcap-namedb.h>
|
2000-01-30 00:43:38 +00:00
|
|
|
#ifdef INET6
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <sys/socket.h>
|
2001-04-03 04:32:48 +00:00
|
|
|
/* Workaround for AIX 4.3 */
|
|
|
|
#if !defined(AI_NUMERICHOST)
|
|
|
|
#define AI_NUMERICHOST 0x04
|
|
|
|
#endif
|
2000-01-30 00:43:38 +00:00
|
|
|
#endif /*INET6*/
|
1996-08-19 20:36:34 +00:00
|
|
|
#include "tokdefs.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_OS_PROTO_H
|
|
|
|
#include "os-proto.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int stoi(char *);
|
|
|
|
static inline int xdtoi(int);
|
|
|
|
|
|
|
|
#ifdef FLEX_SCANNER
|
1997-05-27 00:05:23 +00:00
|
|
|
#define YY_NO_UNPUT
|
2001-04-03 04:32:48 +00:00
|
|
|
static YY_BUFFER_STATE in_buffer;
|
1996-08-19 20:36:34 +00:00
|
|
|
#else
|
2001-04-03 04:32:48 +00:00
|
|
|
static char *in_buffer;
|
|
|
|
|
1996-08-19 20:36:34 +00:00
|
|
|
#undef getc
|
|
|
|
#define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define yylval pcap_lval
|
|
|
|
extern YYSTYPE yylval;
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
N ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
|
|
|
|
B ([0-9A-Fa-f][0-9A-Fa-f]?)
|
2000-01-30 00:43:38 +00:00
|
|
|
W ([0-9A-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
|
|
|
|
V6304 ::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
|
|
|
|
V6314 {W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
|
|
|
|
V6324 {W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
|
|
|
|
V6334 {W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
|
|
|
|
|
|
|
|
V6204 ::{W}:{W}:{N}\.{N}\.{N}\.{N}
|
|
|
|
V6214 {W}::{W}:{N}\.{N}\.{N}\.{N}
|
|
|
|
V6224 {W}:{W}::{N}\.{N}\.{N}\.{N}
|
|
|
|
|
|
|
|
V6104 ::{W}:{N}\.{N}\.{N}\.{N}
|
|
|
|
V6114 {W}::{N}\.{N}\.{N}\.{N}
|
|
|
|
|
|
|
|
V6004 ::{N}\.{N}\.{N}\.{N}
|
|
|
|
|
|
|
|
|
|
|
|
V6 ({V680}|{V670}|{V671}|{V672}|{V673}|{V674}|{V675}|{V676}|{V677}|{V660}|{V661}|{V662}|{V663}|{V664}|{V665}|{V666}|{V650}|{V651}|{V652}|{V653}|{V654}|{V655}|{V640}|{V641}|{V642}|{V643}|{V644}|{V630}|{V631}|{V632}|{V633}|{V620}|{V621}|{V622}|{V610}|{V611}|{V600}|{V6604}|{V6504}|{V6514}|{V6524}|{V6534}|{V6544}|{V6554}|{V6404}|{V6414}|{V6424}|{V6434}|{V6444}|{V6304}|{V6314}|{V6324}|{V6334}|{V6204}|{V6214}|{V6224}|{V6104}|{V6114}|{V6004})
|
1996-08-19 20:36:34 +00:00
|
|
|
|
|
|
|
%%
|
|
|
|
dst return DST;
|
|
|
|
src return SRC;
|
|
|
|
|
|
|
|
link|ether|ppp|slip return LINK;
|
2001-04-03 04:32:48 +00:00
|
|
|
fddi|tr return LINK;
|
1996-08-19 20:36:34 +00:00
|
|
|
arp return ARP;
|
|
|
|
rarp return RARP;
|
|
|
|
ip return IP;
|
2002-06-21 01:38:14 +00:00
|
|
|
sctp return SCTP;
|
1996-08-19 20:36:34 +00:00
|
|
|
tcp return TCP;
|
|
|
|
udp return UDP;
|
|
|
|
icmp return ICMP;
|
|
|
|
igmp return IGMP;
|
|
|
|
igrp return IGRP;
|
2000-01-30 00:43:38 +00:00
|
|
|
pim return PIM;
|
2002-06-21 01:38:14 +00:00
|
|
|
vrrp return VRRP;
|
2000-01-30 00:43:38 +00:00
|
|
|
|
2002-06-21 01:38:14 +00:00
|
|
|
ip6 {
|
|
|
|
#ifdef INET6
|
|
|
|
return IPV6;
|
|
|
|
#else
|
|
|
|
bpf_error("%s not supported", yytext);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
icmp6 {
|
|
|
|
#ifdef INET6
|
|
|
|
return ICMPV6;
|
|
|
|
#else
|
|
|
|
bpf_error("%s not supported", yytext);
|
|
|
|
#endif
|
|
|
|
}
|
2000-01-30 00:43:38 +00:00
|
|
|
ah return AH;
|
|
|
|
esp return ESP;
|
1996-08-19 20:36:34 +00:00
|
|
|
|
|
|
|
atalk return ATALK;
|
2001-04-03 04:32:48 +00:00
|
|
|
aarp return AARP;
|
1996-08-19 20:36:34 +00:00
|
|
|
decnet return DECNET;
|
|
|
|
lat return LAT;
|
|
|
|
sca return SCA;
|
|
|
|
moprc return MOPRC;
|
|
|
|
mopdl return MOPDL;
|
|
|
|
|
1996-08-21 20:01:08 +00:00
|
|
|
iso return ISO;
|
|
|
|
esis return ESIS;
|
|
|
|
es-is return ESIS;
|
|
|
|
isis return ISIS;
|
|
|
|
is-is return ISIS;
|
2001-04-03 04:32:48 +00:00
|
|
|
clnp return CLNP;
|
1996-08-21 20:01:08 +00:00
|
|
|
|
2002-06-21 01:38:14 +00:00
|
|
|
stp return STP;
|
|
|
|
|
|
|
|
ipx return IPX;
|
|
|
|
|
|
|
|
netbeui return NETBEUI;
|
|
|
|
|
1996-08-19 20:36:34 +00:00
|
|
|
host return HOST;
|
|
|
|
net return NET;
|
|
|
|
mask return MASK;
|
|
|
|
port return PORT;
|
|
|
|
proto return PROTO;
|
2000-01-30 00:43:38 +00:00
|
|
|
protochain {
|
|
|
|
#ifdef NO_PROTOCHAIN
|
|
|
|
bpf_error("%s not supported", yytext);
|
|
|
|
#else
|
|
|
|
return PROTOCHAIN;
|
|
|
|
#endif
|
|
|
|
}
|
1996-08-19 20:36:34 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2001-04-03 04:32:48 +00:00
|
|
|
vlan return VLAN;
|
|
|
|
|
1996-08-19 20:36:34 +00:00
|
|
|
[ \n\t] ;
|
|
|
|
[+\-*/:\[\]!<>()&|=] return yytext[0];
|
|
|
|
">=" return GEQ;
|
|
|
|
"<=" return LEQ;
|
|
|
|
"!=" return NEQ;
|
|
|
|
"==" return '=';
|
|
|
|
"<<" return LSH;
|
|
|
|
">>" return RSH;
|
2002-06-21 01:38:14 +00:00
|
|
|
${B} { yylval.e = pcap_ether_aton(((char *)yytext)+1);
|
|
|
|
return AID; }
|
1996-08-19 20:36:34 +00:00
|
|
|
{N} { yylval.i = stoi((char *)yytext); return NUM; }
|
|
|
|
({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
|
1998-09-15 19:31:43 +00:00
|
|
|
yylval.s = sdup((char *)yytext); return HID; }
|
1996-08-19 20:36:34 +00:00
|
|
|
{B}:{B}:{B}:{B}:{B}:{B} { yylval.e = pcap_ether_aton((char *)yytext);
|
|
|
|
return EID; }
|
2000-01-30 00:43:38 +00:00
|
|
|
{V6} {
|
|
|
|
#ifdef INET6
|
|
|
|
struct addrinfo hints, *res;
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
hints.ai_family = AF_INET6;
|
|
|
|
hints.ai_flags = AI_NUMERICHOST;
|
|
|
|
if (getaddrinfo(yytext, NULL, &hints, &res))
|
|
|
|
bpf_error("bogus IPv6 address %s", yytext);
|
|
|
|
else {
|
|
|
|
yylval.e = sdup((char *)yytext); return HID6;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
bpf_error("IPv6 address %s not supported", yytext);
|
|
|
|
#endif /*INET6*/
|
|
|
|
}
|
1996-08-19 20:36:34 +00:00
|
|
|
{B}:+({B}:+)+ { bpf_error("bogus ethernet address %s", yytext); }
|
2002-06-21 01:38:14 +00:00
|
|
|
icmptype { yylval.i = 0; return NUM; }
|
|
|
|
icmpcode { yylval.i = 1; return NUM; }
|
|
|
|
icmp-echoreply { yylval.i = 0; return NUM; }
|
|
|
|
icmp-unreach { yylval.i = 3; return NUM; }
|
|
|
|
icmp-sourcequench { yylval.i = 4; return NUM; }
|
|
|
|
icmp-redirect { yylval.i = 5; return NUM; }
|
|
|
|
icmp-echo { yylval.i = 8; return NUM; }
|
|
|
|
icmp-routeradvert { yylval.i = 9; return NUM; }
|
|
|
|
icmp-routersolicit { yylval.i = 10; return NUM; }
|
|
|
|
icmp-timxceed { yylval.i = 11; return NUM; }
|
|
|
|
icmp-paramprob { yylval.i = 12; return NUM; }
|
|
|
|
icmp-tstamp { yylval.i = 13; return NUM; }
|
|
|
|
icmp-tstampreply { yylval.i = 14; return NUM; }
|
|
|
|
icmp-ireq { yylval.i = 15; return NUM; }
|
|
|
|
icmp-ireqreply { yylval.i = 16; return NUM; }
|
|
|
|
icmp-maskreq { yylval.i = 17; return NUM; }
|
|
|
|
icmp-maskreply { yylval.i = 18; return NUM; }
|
|
|
|
tcpflags { yylval.i = 13; return NUM; }
|
|
|
|
tcp-fin { yylval.i = 0x01; return NUM; }
|
|
|
|
tcp-syn { yylval.i = 0x02; return NUM; }
|
|
|
|
tcp-rst { yylval.i = 0x04; return NUM; }
|
|
|
|
tcp-push { yylval.i = 0x08; return NUM; }
|
|
|
|
tcp-ack { yylval.i = 0x10; return NUM; }
|
|
|
|
tcp-urg { yylval.i = 0x20; return NUM; }
|
|
|
|
[A-Za-z0-9]([-_.A-Za-z0-9]*[.A-Za-z0-9])? {
|
1998-09-15 19:31:43 +00:00
|
|
|
yylval.s = sdup((char *)yytext); return ID; }
|
1996-08-19 20:36:34 +00:00
|
|
|
"\\"[^ !()\n\t]+ { yylval.s = sdup((char *)yytext + 1); return ID; }
|
2002-06-21 01:38:14 +00:00
|
|
|
[^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+ {
|
|
|
|
bpf_error("illegal token: %s", yytext); }
|
1996-08-19 20:36:34 +00:00
|
|
|
. { bpf_error("illegal char '%c'", *yytext); }
|
|
|
|
%%
|
|
|
|
void
|
|
|
|
lex_init(buf)
|
|
|
|
char *buf;
|
|
|
|
{
|
2001-04-03 04:32:48 +00:00
|
|
|
#ifdef FLEX_SCANNER
|
|
|
|
in_buffer = yy_scan_string(buf);
|
|
|
|
#else
|
1996-08-19 20:36:34 +00:00
|
|
|
in_buffer = buf;
|
2001-04-03 04:32:48 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do any cleanup necessary after parsing.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lex_cleanup()
|
|
|
|
{
|
|
|
|
#ifdef FLEX_SCANNER
|
|
|
|
if (in_buffer != NULL)
|
|
|
|
yy_delete_buffer(in_buffer);
|
|
|
|
in_buffer = NULL;
|
|
|
|
#endif
|
1996-08-19 20:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|