2 /* Must come first for _LARGE_FILE_API on AIX. */
8 * Must come first to avoid warnings on Windows.
10 * Flex-generated scanners may only include <inttypes.h> if __STDC_VERSION__
11 * is defined with a value >= 199901, meaning "full C99", and MSVC may not
12 * define it with that value, because it isn't 100% C99-compliant, even
13 * though it has an <inttypes.h> capable of defining everything the Flex
16 * We, however, will include it if we know we have an MSVC version that has
17 * it; this means that we may define the INTn_MAX and UINTn_MAX values in
18 * scanner.c, and then include <stdint.h>, which may define them differently
19 * (same value, but different string of characters), causing compiler warnings.
21 * If we include it here, and they're defined, that'll prevent scanner.c
24 #include <pcap-types.h>
28 * We want a reentrant scanner.
33 * And we need to pass the compiler state to the scanner.
35 %option extra-type="compiler_state_t *"
38 * We don't use input, so don't generate code for it.
43 * We don't use unput, so don't generate code for it.
48 * We don't read from the terminal.
50 %option never-interactive
53 * We want to stop processing when we get to the end of the input.
58 * We want to generate code that can be used by a reentrant parser
59 * generated by Bison or Berkeley YACC.
65 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
66 * The Regents of the University of California. All rights reserved.
68 * Redistribution and use in source and binary forms, with or without
69 * modification, are permitted provided that: (1) source code distributions
70 * retain the above copyright notice and this paragraph in its entirety, (2)
71 * distributions including binary code include the above copyright notice and
72 * this paragraph in its entirety in the documentation or other materials
73 * provided with the distribution, and (3) all advertising materials mentioning
74 * features or use of this software display the following acknowledgement:
75 * ``This product includes software developed by the University of California,
76 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
77 * the University nor the names of its contributors may be used to endorse
78 * or promote products derived from this software without specific prior
80 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
81 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
82 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
86 #include <pcap-stdinc.h>
99 * Earlier versions of Flex don't declare these, so we declare them
100 * ourselves to squelch warnings.
102 int pcap_get_column(yyscan_t);
103 void pcap_set_column(int, yyscan_t);
109 * To quote the MSDN page for getaddrinfo() at
111 * https://msdn.microsoft.com/en-us/library/windows/desktop/ms738520(v=vs.85).aspx
113 * "Support for getaddrinfo on Windows 2000 and older versions
114 * The getaddrinfo function was added to the Ws2_32.dll on Windows XP and
115 * later. To execute an application that uses this function on earlier
116 * versions of Windows, then you need to include the Ws2tcpip.h and
117 * Wspiapi.h files. When the Wspiapi.h include file is added, the
118 * getaddrinfo function is defined to the WspiapiGetAddrInfo inline
119 * function in the Wspiapi.h file. At runtime, the WspiapiGetAddrInfo
120 * function is implemented in such a way that if the Ws2_32.dll or the
121 * Wship6.dll (the file containing getaddrinfo in the IPv6 Technology
122 * Preview for Windows 2000) does not include getaddrinfo, then a
123 * version of getaddrinfo is implemented inline based on code in the
124 * Wspiapi.h header file. This inline code will be used on older Windows
125 * platforms that do not natively support the getaddrinfo function."
127 * We use getaddrinfo(), so we include Wspiapi.h here. pcap-stdinc.h
128 * includes Ws2tcpip.h, so we don't need to include it ourselves.
132 #include <sys/socket.h> /* for "struct sockaddr" in "struct addrinfo" */
133 #include <netdb.h> /* for "struct addrinfo" */
136 /* Workaround for AIX 4.3 */
137 #if !defined(AI_NUMERICHOST)
138 #define AI_NUMERICHOST 0x04
143 #include <pcap/namedb.h>
146 #ifdef HAVE_OS_PROTO_H
147 #include "os-proto.h"
150 static int stoi(char *);
151 static inline int xdtoi(int);
155 N ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
156 B ([0-9A-Fa-f][0-9A-Fa-f]?)
157 B2 ([0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f])
158 W ([0-9A-Fa-f][0-9A-Fa-f]?[0-9A-Fa-f]?[0-9A-Fa-f]?)
167 V680 {W}:{W}:{W}:{W}:{W}:{W}:{W}:{W}
169 V670 ::{W}:{W}:{W}:{W}:{W}:{W}:{W}
170 V671 {W}::{W}:{W}:{W}:{W}:{W}:{W}
171 V672 {W}:{W}::{W}:{W}:{W}:{W}:{W}
172 V673 {W}:{W}:{W}::{W}:{W}:{W}:{W}
173 V674 {W}:{W}:{W}:{W}::{W}:{W}:{W}
174 V675 {W}:{W}:{W}:{W}:{W}::{W}:{W}
175 V676 {W}:{W}:{W}:{W}:{W}:{W}::{W}
176 V677 {W}:{W}:{W}:{W}:{W}:{W}:{W}::
178 V660 ::{W}:{W}:{W}:{W}:{W}:{W}
179 V661 {W}::{W}:{W}:{W}:{W}:{W}
180 V662 {W}:{W}::{W}:{W}:{W}:{W}
181 V663 {W}:{W}:{W}::{W}:{W}:{W}
182 V664 {W}:{W}:{W}:{W}::{W}:{W}
183 V665 {W}:{W}:{W}:{W}:{W}::{W}
184 V666 {W}:{W}:{W}:{W}:{W}:{W}::
186 V650 ::{W}:{W}:{W}:{W}:{W}
187 V651 {W}::{W}:{W}:{W}:{W}
188 V652 {W}:{W}::{W}:{W}:{W}
189 V653 {W}:{W}:{W}::{W}:{W}
190 V654 {W}:{W}:{W}:{W}::{W}
191 V655 {W}:{W}:{W}:{W}:{W}::
193 V640 ::{W}:{W}:{W}:{W}
194 V641 {W}::{W}:{W}:{W}
195 V642 {W}:{W}::{W}:{W}
196 V643 {W}:{W}:{W}::{W}
197 V644 {W}:{W}:{W}:{W}::
213 V6604 {W}:{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
215 V6504 ::{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
216 V6514 {W}::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
217 V6524 {W}:{W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
218 V6534 {W}:{W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
219 V6544 {W}:{W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
220 V6554 {W}:{W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
222 V6404 ::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
223 V6414 {W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
224 V6424 {W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
225 V6434 {W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
226 V6444 {W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
228 V6304 ::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
229 V6314 {W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
230 V6324 {W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
231 V6334 {W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
233 V6204 ::{W}:{W}:{N}\.{N}\.{N}\.{N}
234 V6214 {W}::{W}:{N}\.{N}\.{N}\.{N}
235 V6224 {W}:{W}::{N}\.{N}\.{N}\.{N}
237 V6104 ::{W}:{N}\.{N}\.{N}\.{N}
238 V6114 {W}::{N}\.{N}\.{N}\.{N}
240 V6004 ::{N}\.{N}\.{N}\.{N}
243 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})
245 MAC ({B}:{B}:{B}:{B}:{B}:{B}|{B}\-{B}\-{B}\-{B}\-{B}\-{B}|{B}\.{B}\.{B}\.{B}\.{B}\.{B}|{B2}\.{B2}\.{B2}|{B2}{3})
253 link|ether|ppp|slip return LINK;
254 fddi|tr|wlan return LINK;
276 decnet return DECNET;
301 netbeui return NETBEUI;
307 portrange return PORTRANGE;
311 bpf_error(yyextra, "%s not supported", yytext);
317 gateway return GATEWAY;
320 subtype return SUBTYPE;
321 direction|dir return DIR;
322 address1|addr1 return ADDR1;
323 address2|addr2 return ADDR2;
324 address3|addr3 return ADDR3;
325 address4|addr4 return ADDR4;
330 greater return GREATER;
332 broadcast return TK_BROADCAST;
333 multicast return TK_MULTICAST;
339 len|length return LEN;
340 inbound return INBOUND;
341 outbound return OUTBOUND;
345 pppoed return PPPOED;
346 pppoes return PPPOES;
347 geneve return GENEVE;
355 oamf4ec return OAMF4EC;
356 oamf4sc return OAMF4SC;
361 connectmsg return CONNECTMSG;
362 metaconnect return METACONNECT;
364 on|ifname return PF_IFNAME;
365 rset|ruleset return PF_RSET;
366 rnr|rulenum return PF_RNR;
367 srnr|subrulenum return PF_SRNR;
368 reason return PF_REASON;
369 action return PF_ACTION;
388 [+\-*/%:\[\]!<>()&|\^=] return yytext[0];
395 ${B} { yylval->e = pcap_ether_aton(((char *)yytext)+1);
396 if (yylval->e == NULL)
397 bpf_error(yyextra, "malloc");
399 {MAC} { yylval->e = pcap_ether_aton((char *)yytext);
400 if (yylval->e == NULL)
401 bpf_error(yyextra, "malloc");
403 {N} { yylval->i = stoi((char *)yytext); return NUM; }
404 ({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
405 yylval->s = sdup(yyextra, (char *)yytext); return HID; }
408 struct addrinfo hints, *res;
409 memset(&hints, 0, sizeof(hints));
410 hints.ai_family = AF_INET6;
411 hints.ai_flags = AI_NUMERICHOST;
412 if (getaddrinfo(yytext, NULL, &hints, &res))
413 bpf_error(yyextra, "bogus IPv6 address %s", yytext);
416 yylval->s = sdup(yyextra, (char *)yytext); return HID6;
419 bpf_error(yyextra, "IPv6 address %s not supported", yytext);
422 {B}:+({B}:+)+ { bpf_error(yyextra, "bogus ethernet address %s", yytext); }
423 icmptype { yylval->i = 0; return NUM; }
424 icmpcode { yylval->i = 1; return NUM; }
425 icmp-echoreply { yylval->i = 0; return NUM; }
426 icmp-unreach { yylval->i = 3; return NUM; }
427 icmp-sourcequench { yylval->i = 4; return NUM; }
428 icmp-redirect { yylval->i = 5; return NUM; }
429 icmp-echo { yylval->i = 8; return NUM; }
430 icmp-routeradvert { yylval->i = 9; return NUM; }
431 icmp-routersolicit { yylval->i = 10; return NUM; }
432 icmp-timxceed { yylval->i = 11; return NUM; }
433 icmp-paramprob { yylval->i = 12; return NUM; }
434 icmp-tstamp { yylval->i = 13; return NUM; }
435 icmp-tstampreply { yylval->i = 14; return NUM; }
436 icmp-ireq { yylval->i = 15; return NUM; }
437 icmp-ireqreply { yylval->i = 16; return NUM; }
438 icmp-maskreq { yylval->i = 17; return NUM; }
439 icmp-maskreply { yylval->i = 18; return NUM; }
440 tcpflags { yylval->i = 13; return NUM; }
441 tcp-fin { yylval->i = 0x01; return NUM; }
442 tcp-syn { yylval->i = 0x02; return NUM; }
443 tcp-rst { yylval->i = 0x04; return NUM; }
444 tcp-push { yylval->i = 0x08; return NUM; }
445 tcp-ack { yylval->i = 0x10; return NUM; }
446 tcp-urg { yylval->i = 0x20; return NUM; }
447 tcp-ece { yylval->i = 0x40; return NUM; }
448 tcp-cwr { yylval->i = 0x80; return NUM; }
449 [A-Za-z0-9]([-_.A-Za-z0-9]*[.A-Za-z0-9])? {
450 yylval->s = sdup(yyextra, (char *)yytext); return ID; }
451 "\\"[^ !()\n\t]+ { yylval->s = sdup(yyextra, (char *)yytext + 1); return ID; }
452 [^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+ {
453 bpf_error(yyextra, "illegal token: %s", yytext); }
454 . { bpf_error(yyextra, "illegal char '%c'", *yytext); }
457 /* Hex digit to integer. */
471 * Convert string to integer. Just like atoi(), but checks for
472 * preceding 0x or 0 and uses hex or octal instead of decimal.
482 if (s[1] == 'x' || s[1] == 'X') {
492 n = n * base + xdtoi(*s++);