%top {
/* Must come first for _LARGE_FILE_API on AIX. */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
/*
* Must come first to avoid warnings on Windows.
*
* Flex-generated scanners may only include <inttypes.h> if __STDC_VERSION__
* is defined with a value >= 199901, meaning "full C99", and MSVC may not
* define it with that value, because it isn't 100% C99-compliant, even
* though it has an <inttypes.h> capable of defining everything the Flex
* scanner needs.
*
* We, however, will include it if we know we have an MSVC version that has
* it * scanner.c, and then include <stdint.h>, which may define them differently
* (same value, but different string of characters), causing compiler warnings.
*
* If we include it here, and they're defined, that'll prevent scanner.c
* from defining them. So we include <pcap/pcap-inttypes.h>, to get
* <inttypes.h> if we have it.
*/
#include <pcap/pcap-inttypes.h>
#include "diag-control.h"
}
/*
* We want a reentrant scanner.
*/
%option reentrant
/*
* And we need to pass the compiler state to the scanner.
*/
%option extra-type="compiler_state_t *"
/*
* We don't use input, so don't generate code for it.
*/
%option noinput
/*
* We don't use unput, so don't generate code for it.
*/
%option nounput
/*
* We don't read from the terminal.
*/
%option never-interactive
/*
* We want to stop processing when we get to the end of the input.
*/
%option noyywrap
/*
* We want to generate code that can be used by a reentrant parser
* generated by Bison or Berkeley YACC.
*/
%option bison-bridge
%{
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
* 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.
*/
#include <ctype.h>
#include <string.h>
#include "pcap-int.h"
#include "gencode.h"
#include "grammar.h"
/*
* Earlier versions of Flex don't declare these, so we declare them
* ourselves to squelch warnings.
*/
int pcap_get_column(yyscan_t)void pcap_set_column(int, yyscan_t)
#ifdef INET6
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
/*
* To quote the MSDN page for getaddrinfo() at
*
* https://msdn.microsoft.com/en-us/library/windows/desktop/ms738520(v=vs.85).aspx
*
* "Support for getaddrinfo on Windows 2000 and older versions
* The getaddrinfo function was added to the Ws2_32.dll on Windows XP and
* later. To execute an application that uses this function on earlier
* versions of Windows, then you need to include the Ws2tcpip.h and
* Wspiapi.h files. When the Wspiapi.h include file is added, the
* getaddrinfo function is defined to the WspiapiGetAddrInfo inline
* function in the Wspiapi.h file. At runtime, the WspiapiGetAddrInfo
* function is implemented in such a way that if the Ws2_32.dll or the
* Wship6.dll (the file containing getaddrinfo in the IPv6 Technology
* Preview for Windows 2000) does not include getaddrinfo, then a
* version of getaddrinfo is implemented inline based on code in the
* Wspiapi.h header file. This inline code will be used on older Windows
* platforms that do not natively support the getaddrinfo function."
*
* We use getaddrinfo(), so we include Wspiapi.h here.
*/
#include <wspiapi.h>
#else /* _WIN32 */
#include <sys/socket.h> /* for "struct sockaddr" in "struct addrinfo" */
#include <netdb.h> /* for "struct addrinfo" */
#endif /* _WIN32 */
/* Workaround for AIX 4.3 */
#if !defined(AI_NUMERICHOST)
#define AI_NUMERICHOST 0x04
#endif
#endif /*INET6*/
#include <pcap/namedb.h>
#include "grammar.h"
#ifdef HAVE_OS_PROTO_H
#include "os-proto.h"
#endif
static int stoi(char *)static inline int xdtoi(int)
/*
* Disable diagnostics in the code generated by Flex.
*/
DIAG_OFF_FLEX
%}
N ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
B ([0-9A-Fa-f][0-9A-Fa-f]?)
B2 ([0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f])
W ([0-9A-Fa-f][0-9A-Fa-f]?[0-9A-Fa-f]?[0-9A-Fa-f]?)
%a 18400
%o 21500
%e 7600
%k 4550
%p 27600
%n 2000
V680 {W}:{W}:{W}:{W}:{W}:{W}:{W}:{W}
V670 ::{W}:{W}:{W}:{W}:{W}:{W}:{W}
V671 {W}::{W}:{W}:{W}:{W}:{W}:{W}
V672 {W}:{W}::{W}:{W}:{W}:{W}:{W}
V673 {W}:{W}:{W}::{W}:{W}:{W}:{W}
V674 {W}:{W}:{W}:{W}::{W}:{W}:{W}
V675 {W}:{W}:{W}:{W}:{W}::{W}:{W}
V676 {W}:{W}:{W}:{W}:{W}:{W}::{W}
V677 {W}:{W}:{W}:{W}:{W}:{W}:{W}::
V660 ::{W}:{W}:{W}:{W}:{W}:{W}
V661 {W}::{W}:{W}:{W}:{W}:{W}
V662 {W}:{W}::{W}:{W}:{W}:{W}
V663 {W}:{W}:{W}::{W}:{W}:{W}
V664 {W}:{W}:{W}:{W}::{W}:{W}
V665 {W}:{W}:{W}:{W}:{W}::{W}
V666 {W}:{W}:{W}:{W}:{W}:{W}::
V650 ::{W}:{W}:{W}:{W}:{W}
V651 {W}::{W}:{W}:{W}:{W}
V652 {W}:{W}::{W}:{W}:{W}
V653 {W}:{W}:{W}::{W}:{W}
V654 {W}:{W}:{W}:{W}::{W}
V655 {W}:{W}:{W}:{W}:{W}::
V640 ::{W}:{W}:{W}:{W}
V641 {W}::{W}:{W}:{W}
V642 {W}:{W}::{W}:{W}
V643 {W}:{W}:{W}::{W}
V644 {W}:{W}:{W}:{W}::
V630 ::{W}:{W}:{W}
V631 {W}::{W}:{W}
V632 {W}:{W}::{W}
V633 {W}:{W}:{W}::
V620 ::{W}:{W}
V621 {W}::{W}
V622 {W}:{W}::
V610 ::{W}
V611 {W}::
V600 ::
V6604 {W}:{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
V6504 ::{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
V6514 {W}::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
V6524 {W}:{W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
V6534 {W}:{W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
V6544 {W}:{W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
V6554 {W}:{W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
V6404 ::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
V6414 {W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
V6424 {W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
V6434 {W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
V6444 {W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
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})
MAC ({B}:{B}:{B}:{B}:{B}:{B}|{B}\-{B}\-{B}\-{B}\-{B}\-{B}|{B}\.{B}\.{B}\.{B}\.{B}\.{B}|{B2}\.{B2}\.{B2}|{B2}{3})
%%
dst return DSTsrc return SRC
link|ether|ppp|slip return LINKfddi|tr|wlan return LINKarp return ARPrarp return RARPip return IPsctp return SCTPtcp return TCPudp return UDPicmp return ICMPigmp return IGMPigrp return IGRPpim return PIMvrrp return VRRPcarp return CARPradio return RADIO
ip6 return IPV6icmp6 return ICMPV6ah return AHesp return ESP
atalk return ATALKaarp return AARPdecnet return DECNETlat return LATsca return SCAmoprc return MOPRCmopdl return MOPDL
iso return ISOesis return ESISes-is return ESISisis return ISISis-is return ISISl1 return L1l2 return L2iih return IIHlsp return LSPsnp return SNPcsnp return CSNPpsnp return PSNP
clnp return CLNP
stp return STP
ipx return IPX
netbeui return NETBEUI
host return HOSTnet return NETmask return NETMASKport return PORTportrange return PORTRANGEproto return PROTOprotochain return PROTOCHAIN
gateway return GATEWAY
type return TYPEsubtype return SUBTYPEdirection|dir return DIRaddress1|addr1 return ADDR1address2|addr2 return ADDR2address3|addr3 return ADDR3address4|addr4 return ADDR4ra return RAta return TA
less return LESSgreater return GREATERbyte return CBYTEbroadcast return TK_BROADCASTmulticast return TK_MULTICAST
and|"&&" return ANDor|"||" return ORnot return '!'
len|length return LENinbound return INBOUNDoutbound return OUTBOUND
vlan return VLANmpls return MPLSpppoed return PPPOEDpppoes return PPPOESgeneve return GENEVE
lane return LANEllc return LLCmetac return METACbcc return BCCoam return OAMoamf4 return OAMF4oamf4ec return OAMF4ECoamf4sc return OAMF4SCsc return SCilmic return ILMICvpi return VPIvci return VCIconnectmsg return CONNECTMSGmetaconnect return METACONNECT
on|ifname return PF_IFNAMErset|ruleset return PF_RSETrnr|rulenum return PF_RNRsrnr|subrulenum return PF_SRNRreason return PF_REASONaction return PF_ACTION
fisu return FISUlssu return LSSUlsu return LSSUmsu return MSUhfisu return HFISUhlssu return HLSSUhmsu return HMSUsio return SIOopc return OPCdpc return DPCsls return SLShsio return HSIOhopc return HOPChdpc return HDPChsls return HSLS
[ \r\n\t] [+\-*/%:\[\]!<>()&|\^=] return yytext[0]">=" return GEQ"<=" return LEQ"!=" return NEQ"==" return '='"<<" return LSH">>" return RSH${B} { yylval->s = sdup(yyextra, yytext){MAC} { yylval->s = sdup(yyextra, yytext){N} { yylval->i = stoi((char *)yytext)({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
yylval->s = sdup(yyextra, (char *)yytext){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_set_error(yyextra, "bogus IPv6 address %s", yytext) yylval->s = NULL } else {
freeaddrinfo(res) yylval->s = sdup(yyextra, (char *)yytext) }
#else
bpf_set_error(yyextra, "IPv6 address %s not supported", yytext) yylval->s = NULL#endif /*INET6*/
return HID6 }
{B}:+({B}:+)+ { bpf_set_error(yyextra, "bogus ethernet address %s", yytext)icmptype { yylval->i = 0icmpcode { yylval->i = 1icmp-echoreply { yylval->i = 0icmp-unreach { yylval->i = 3icmp-sourcequench { yylval->i = 4icmp-redirect { yylval->i = 5icmp-echo { yylval->i = 8icmp-routeradvert { yylval->i = 9icmp-routersolicit { yylval->i = 10icmp-timxceed { yylval->i = 11icmp-paramprob { yylval->i = 12icmp-tstamp { yylval->i = 13icmp-tstampreply { yylval->i = 14icmp-ireq { yylval->i = 15icmp-ireqreply { yylval->i = 16icmp-maskreq { yylval->i = 17icmp-maskreply { yylval->i = 18
icmp6type { yylval->i = 0icmp6code { yylval->i = 1
icmp6-echo { yylval->i = 128icmp6-echoreply { yylval->i = 129icmp6-multicastlistenerquery { yylval->i = 130icmp6-multicastlistenerreportv1 { yylval->i = 131icmp6-multicastlistenerdone { yylval->i = 132icmp6-routersolicit { yylval->i = 133icmp6-routeradvert { yylval->i = 134icmp6-neighborsolicit { yylval->i = 135icmp6-neighboradvert { yylval->i = 136icmp6-redirect { yylval->i = 137icmp6-routerrenum { yylval->i = 138icmp6-nodeinformationquery { yylval->i = 139icmp6-nodeinformationresponse { yylval->i = 140icmp6-ineighbordiscoverysolicit { yylval->i = 141icmp6-ineighbordiscoveryadvert { yylval->i = 142icmp6-multicastlistenerreportv2 { yylval->i = 143icmp6-homeagentdiscoveryrequest { yylval->i = 144icmp6-homeagentdiscoveryreply { yylval->i = 145icmp6-mobileprefixsolicit { yylval->i = 146icmp6-mobileprefixadvert { yylval->i = 147icmp6-certpathsolicit { yylval->i = 148icmp6-certpathadvert { yylval->i = 149icmp6-multicastrouteradvert { yylval->i = 151icmp6-multicastroutersolicit { yylval->i = 152icmp6-multicastrouterterm { yylval->i = 153
tcpflags { yylval->i = 13tcp-fin { yylval->i = 0x01tcp-syn { yylval->i = 0x02tcp-rst { yylval->i = 0x04tcp-push { yylval->i = 0x08tcp-ack { yylval->i = 0x10tcp-urg { yylval->i = 0x20tcp-ece { yylval->i = 0x40tcp-cwr { yylval->i = 0x80[A-Za-z0-9]([-_.A-Za-z0-9]*[.A-Za-z0-9])? {
yylval->s = sdup(yyextra, (char *)yytext)"\\"[^ !()\n\t]+ { yylval->s = sdup(yyextra, (char *)yytext + 1). { return LEX_ERROR%%
/*
* Turn diagnostics back on, so we check the code that we've written.
*/
DIAG_ON_FLEX
/* Hex digit to integer. */
static inline int
xdtoi(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(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}