diff options
author | Xin LI <delphij@FreeBSD.org> | 2017-02-13 08:23:39 +0000 |
---|---|---|
committer | Xin LI <delphij@FreeBSD.org> | 2017-02-13 08:23:39 +0000 |
commit | ada6f083b93b4adce9c3b3ba00112528244a3b86 (patch) | |
tree | cb89d2b7657c6b206bb28e5a9ab17ef556d64986 /contrib/libpcap/scanner.l | |
parent | 5dbc2ac93dbe46c66b0159f9cbf67146ae43656d (diff) | |
parent | c8c6d70e300aa9261c4766502c179fc4cd2b22a0 (diff) | |
download | src-ada6f083b93b4adce9c3b3ba00112528244a3b86.tar.gz src-ada6f083b93b4adce9c3b3ba00112528244a3b86.zip |
MFV r313676: libpcap 1.8.1
MFC after: 1 month
Notes
Notes:
svn path=/head/; revision=313695
Diffstat (limited to 'contrib/libpcap/scanner.l')
-rw-r--r-- | contrib/libpcap/scanner.l | 251 |
1 files changed, 138 insertions, 113 deletions
diff --git a/contrib/libpcap/scanner.l b/contrib/libpcap/scanner.l index 98c78428ccb2..d71a9bed1b5d 100644 --- a/contrib/libpcap/scanner.l +++ b/contrib/libpcap/scanner.l @@ -1,3 +1,46 @@ +%top { +/* Must come first for _LARGE_FILE_API on AIX. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +} + +/* + * 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 @@ -22,23 +65,19 @@ * $FreeBSD$ */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#ifdef WIN32 -#include <pcap-stdinc.h> -#else /* WIN32 */ -#if HAVE_INTTYPES_H -#include <inttypes.h> -#elif HAVE_STDINT_H -#include <stdint.h> -#endif -#ifdef HAVE_SYS_BITYPES_H -#include <sys/bitypes.h> +#ifdef _WIN32 + #include <pcap-stdinc.h> +#else + #if HAVE_INTTYPES_H + #include <inttypes.h> + #elif HAVE_STDINT_H + #include <stdint.h> + #endif + #ifdef HAVE_SYS_BITYPES_H + #include <sys/bitypes.h> + #endif + #include <sys/types.h> #endif -#include <sys/types.h> -#endif /* WIN32 */ #include <ctype.h> #include <string.h> @@ -46,25 +85,56 @@ #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 <pcap-stdinc.h> -#ifdef __MINGW32__ -#include "ip6_misc.h" -#endif -#else /* WIN32 */ +#ifdef _WIN32 +/* + * 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. pcap-stdinc.h + * includes Ws2tcpip.h, so we don't need to include it ourselves. + */ +#include <Wspiapi.h> +#else /* _WIN32 */ #include <sys/socket.h> /* for "struct sockaddr" in "struct addrinfo" */ #include <netdb.h> /* for "struct addrinfo" */ -#endif /* WIN32 */ +#endif /* _WIN32 */ /* Workaround for AIX 4.3 */ #if !defined(AI_NUMERICHOST) #define AI_NUMERICHOST 0x04 #endif + #endif /*INET6*/ + #include <pcap/namedb.h> -#include "tokdefs.h" +#include "grammar.h" #ifdef HAVE_OS_PROTO_H #include "os-proto.h" @@ -73,19 +143,6 @@ static int stoi(char *); static inline int xdtoi(int); -#ifdef FLEX_SCANNER -#define YY_NO_INPUT -#define YY_NO_UNPUT -static YY_BUFFER_STATE in_buffer; -#else -static const char *in_buffer; - -#undef getc -#define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++) -#endif - -extern YYSTYPE yylval; - %} N ([0-9]+|(0X|0x)[0-9A-Fa-f]+) @@ -244,7 +301,7 @@ portrange return PORTRANGE; proto return PROTO; protochain { #ifdef NO_PROTOCHAIN - bpf_error("%s not supported", yytext); + bpf_error(yyextra, "%s not supported", yytext); #else return PROTOCHAIN; #endif @@ -280,6 +337,7 @@ vlan return VLAN; mpls return MPLS; pppoed return PPPOED; pppoes return PPPOES; +geneve return GENEVE; lane return LANE; llc return LLC; @@ -327,17 +385,17 @@ hsls return HSLS; "==" return '='; "<<" return LSH; ">>" return RSH; -${B} { yylval.e = pcap_ether_aton(((char *)yytext)+1); - if (yylval.e == NULL) - bpf_error("malloc"); +${B} { yylval->e = pcap_ether_aton(((char *)yytext)+1); + if (yylval->e == NULL) + bpf_error(yyextra, "malloc"); return AID; } -{MAC} { yylval.e = pcap_ether_aton((char *)yytext); - if (yylval.e == NULL) - bpf_error("malloc"); +{MAC} { yylval->e = pcap_ether_aton((char *)yytext); + if (yylval->e == NULL) + bpf_error(yyextra, "malloc"); return EID; } -{N} { yylval.i = stoi((char *)yytext); return NUM; } +{N} { yylval->i = stoi((char *)yytext); return NUM; } ({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) { - yylval.s = sdup((char *)yytext); return HID; } + yylval->s = sdup(yyextra, (char *)yytext); return HID; } {V6} { #ifdef INET6 struct addrinfo hints, *res; @@ -345,82 +403,49 @@ ${B} { yylval.e = pcap_ether_aton(((char *)yytext)+1); hints.ai_family = AF_INET6; hints.ai_flags = AI_NUMERICHOST; if (getaddrinfo(yytext, NULL, &hints, &res)) - bpf_error("bogus IPv6 address %s", yytext); + bpf_error(yyextra, "bogus IPv6 address %s", yytext); else { freeaddrinfo(res); - yylval.s = sdup((char *)yytext); return HID6; + yylval->s = sdup(yyextra, (char *)yytext); return HID6; } #else - bpf_error("IPv6 address %s not supported", yytext); + bpf_error(yyextra, "IPv6 address %s not supported", yytext); #endif /*INET6*/ } -{B}:+({B}:+)+ { bpf_error("bogus ethernet address %s", yytext); } -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; } -tcp-ece { yylval.i = 0x40; return NUM; } -tcp-cwr { yylval.i = 0x80; return NUM; } +{B}:+({B}:+)+ { bpf_error(yyextra, "bogus ethernet address %s", yytext); } +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; } +tcp-ece { yylval->i = 0x40; return NUM; } +tcp-cwr { yylval->i = 0x80; return NUM; } [A-Za-z0-9]([-_.A-Za-z0-9]*[.A-Za-z0-9])? { - yylval.s = sdup((char *)yytext); return ID; } -"\\"[^ !()\n\t]+ { yylval.s = sdup((char *)yytext + 1); return ID; } + yylval->s = sdup(yyextra, (char *)yytext); return ID; } +"\\"[^ !()\n\t]+ { yylval->s = sdup(yyextra, (char *)yytext + 1); return ID; } [^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+ { - bpf_error("illegal token: %s", yytext); } -. { bpf_error("illegal char '%c'", *yytext); } + bpf_error(yyextra, "illegal token: %s", yytext); } +. { bpf_error(yyextra, "illegal char '%c'", *yytext); } %% -void -lex_init(buf) - const char *buf; -{ -#ifdef FLEX_SCANNER - in_buffer = yy_scan_string(buf); -#else - in_buffer = buf; -#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 -} - -/* - * 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 |