Deleted Added
full compact
scanner.l (146771) scanner.l (147897)
1%{
2/*
3 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
4 * The Regents of the University of California. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that: (1) source code distributions
8 * retain the above copyright notice and this paragraph in its entirety, (2)
9 * distributions including binary code include the above copyright notice and
10 * this paragraph in its entirety in the documentation or other materials
11 * provided with the distribution, and (3) all advertising materials mentioning
12 * features or use of this software display the following acknowledgement:
13 * ``This product includes software developed by the University of California,
14 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
15 * the University nor the names of its contributors may be used to endorse
16 * or promote products derived from this software without specific prior
17 * written permission.
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 *
1%{
2/*
3 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
4 * The Regents of the University of California. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that: (1) source code distributions
8 * retain the above copyright notice and this paragraph in its entirety, (2)
9 * distributions including binary code include the above copyright notice and
10 * this paragraph in its entirety in the documentation or other materials
11 * provided with the distribution, and (3) all advertising materials mentioning
12 * features or use of this software display the following acknowledgement:
13 * ``This product includes software developed by the University of California,
14 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
15 * the University nor the names of its contributors may be used to endorse
16 * or promote products derived from this software without specific prior
17 * written permission.
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 *
22 * $FreeBSD: head/contrib/libpcap/scanner.l 146771 2005-05-29 18:09:04Z sam $
22 * $FreeBSD: head/contrib/libpcap/scanner.l 147897 2005-07-11 03:43:25Z sam $
23 */
24
25#ifndef lint
26static const char rcsid[] _U_ =
23 */
24
25#ifndef lint
26static const char rcsid[] _U_ =
27 "@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.99 2004/06/16 08:20:28 hannes Exp $ (LBL)";
27 "@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.99.2.3 2005/06/20 21:30:19 guy Exp $ (LBL)";
28#endif
29
30#ifdef HAVE_CONFIG_H
31#include "config.h"
32#endif
33
34#include <ctype.h>
35#include <string.h>
36
37#include "pcap-int.h"
38
39#include "gencode.h"
40#ifdef INET6
41#ifdef WIN32
42#include <pcap-stdinc.h>
43
44#ifdef __MINGW32__
45#include "IP6_misc.h"
46#endif
47#else /* WIN32 */
48#include <sys/socket.h> /* for "struct sockaddr" in "struct addrinfo" */
49#include <netdb.h> /* for "struct addrinfo" */
50#endif /* WIN32 */
51
52/* Workaround for AIX 4.3 */
53#if !defined(AI_NUMERICHOST)
54#define AI_NUMERICHOST 0x04
55#endif
56#endif /*INET6*/
57#include <pcap-namedb.h>
58#include "tokdefs.h"
59
60#ifdef HAVE_OS_PROTO_H
61#include "os-proto.h"
62#endif
63
64static int stoi(char *);
65static inline int xdtoi(int);
66
67#ifdef FLEX_SCANNER
68#define YY_NO_UNPUT
69static YY_BUFFER_STATE in_buffer;
70#else
71static char *in_buffer;
72
73#undef getc
74#define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++)
75#endif
76
77extern YYSTYPE yylval;
78
79%}
80
81N ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
82B ([0-9A-Fa-f][0-9A-Fa-f]?)
83W ([0-9A-Fa-f][0-9A-Fa-f]?[0-9A-Fa-f]?[0-9A-Fa-f]?)
84
85%a 16000
86%o 19000
87%e 6000
88%k 4000
89%p 25000
90%n 2000
91
92V680 {W}:{W}:{W}:{W}:{W}:{W}:{W}:{W}
93
94V670 ::{W}:{W}:{W}:{W}:{W}:{W}:{W}
95V671 {W}::{W}:{W}:{W}:{W}:{W}:{W}
96V672 {W}:{W}::{W}:{W}:{W}:{W}:{W}
97V673 {W}:{W}:{W}::{W}:{W}:{W}:{W}
98V674 {W}:{W}:{W}:{W}::{W}:{W}:{W}
99V675 {W}:{W}:{W}:{W}:{W}::{W}:{W}
100V676 {W}:{W}:{W}:{W}:{W}:{W}::{W}
101V677 {W}:{W}:{W}:{W}:{W}:{W}:{W}::
102
103V660 ::{W}:{W}:{W}:{W}:{W}:{W}
104V661 {W}::{W}:{W}:{W}:{W}:{W}
105V662 {W}:{W}::{W}:{W}:{W}:{W}
106V663 {W}:{W}:{W}::{W}:{W}:{W}
107V664 {W}:{W}:{W}:{W}::{W}:{W}
108V665 {W}:{W}:{W}:{W}:{W}::{W}
109V666 {W}:{W}:{W}:{W}:{W}:{W}::
110
111V650 ::{W}:{W}:{W}:{W}:{W}
112V651 {W}::{W}:{W}:{W}:{W}
113V652 {W}:{W}::{W}:{W}:{W}
114V653 {W}:{W}:{W}::{W}:{W}
115V654 {W}:{W}:{W}:{W}::{W}
116V655 {W}:{W}:{W}:{W}:{W}::
117
118V640 ::{W}:{W}:{W}:{W}
119V641 {W}::{W}:{W}:{W}
120V642 {W}:{W}::{W}:{W}
121V643 {W}:{W}:{W}::{W}
122V644 {W}:{W}:{W}:{W}::
123
124V630 ::{W}:{W}:{W}
125V631 {W}::{W}:{W}
126V632 {W}:{W}::{W}
127V633 {W}:{W}:{W}::
128
129V620 ::{W}:{W}
130V621 {W}::{W}
131V622 {W}:{W}::
132
133V610 ::{W}
134V611 {W}::
135
136V600 ::
137
138V6604 {W}:{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
139
140V6504 ::{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
141V6514 {W}::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
142V6524 {W}:{W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
143V6534 {W}:{W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
144V6544 {W}:{W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
145V6554 {W}:{W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
146
147V6404 ::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
148V6414 {W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
149V6424 {W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
150V6434 {W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
151V6444 {W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
152
153V6304 ::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
154V6314 {W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
155V6324 {W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
156V6334 {W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
157
158V6204 ::{W}:{W}:{N}\.{N}\.{N}\.{N}
159V6214 {W}::{W}:{N}\.{N}\.{N}\.{N}
160V6224 {W}:{W}::{N}\.{N}\.{N}\.{N}
161
162V6104 ::{W}:{N}\.{N}\.{N}\.{N}
163V6114 {W}::{N}\.{N}\.{N}\.{N}
164
165V6004 ::{N}\.{N}\.{N}\.{N}
166
167
168V6 ({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})
169
170%%
171dst return DST;
172src return SRC;
173
174link|ether|ppp|slip return LINK;
175fddi|tr|wlan return LINK;
176arp return ARP;
177rarp return RARP;
178ip return IP;
179sctp return SCTP;
180tcp return TCP;
181udp return UDP;
182icmp return ICMP;
183igmp return IGMP;
184igrp return IGRP;
185pim return PIM;
186vrrp return VRRP;
28#endif
29
30#ifdef HAVE_CONFIG_H
31#include "config.h"
32#endif
33
34#include <ctype.h>
35#include <string.h>
36
37#include "pcap-int.h"
38
39#include "gencode.h"
40#ifdef INET6
41#ifdef WIN32
42#include <pcap-stdinc.h>
43
44#ifdef __MINGW32__
45#include "IP6_misc.h"
46#endif
47#else /* WIN32 */
48#include <sys/socket.h> /* for "struct sockaddr" in "struct addrinfo" */
49#include <netdb.h> /* for "struct addrinfo" */
50#endif /* WIN32 */
51
52/* Workaround for AIX 4.3 */
53#if !defined(AI_NUMERICHOST)
54#define AI_NUMERICHOST 0x04
55#endif
56#endif /*INET6*/
57#include <pcap-namedb.h>
58#include "tokdefs.h"
59
60#ifdef HAVE_OS_PROTO_H
61#include "os-proto.h"
62#endif
63
64static int stoi(char *);
65static inline int xdtoi(int);
66
67#ifdef FLEX_SCANNER
68#define YY_NO_UNPUT
69static YY_BUFFER_STATE in_buffer;
70#else
71static char *in_buffer;
72
73#undef getc
74#define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++)
75#endif
76
77extern YYSTYPE yylval;
78
79%}
80
81N ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
82B ([0-9A-Fa-f][0-9A-Fa-f]?)
83W ([0-9A-Fa-f][0-9A-Fa-f]?[0-9A-Fa-f]?[0-9A-Fa-f]?)
84
85%a 16000
86%o 19000
87%e 6000
88%k 4000
89%p 25000
90%n 2000
91
92V680 {W}:{W}:{W}:{W}:{W}:{W}:{W}:{W}
93
94V670 ::{W}:{W}:{W}:{W}:{W}:{W}:{W}
95V671 {W}::{W}:{W}:{W}:{W}:{W}:{W}
96V672 {W}:{W}::{W}:{W}:{W}:{W}:{W}
97V673 {W}:{W}:{W}::{W}:{W}:{W}:{W}
98V674 {W}:{W}:{W}:{W}::{W}:{W}:{W}
99V675 {W}:{W}:{W}:{W}:{W}::{W}:{W}
100V676 {W}:{W}:{W}:{W}:{W}:{W}::{W}
101V677 {W}:{W}:{W}:{W}:{W}:{W}:{W}::
102
103V660 ::{W}:{W}:{W}:{W}:{W}:{W}
104V661 {W}::{W}:{W}:{W}:{W}:{W}
105V662 {W}:{W}::{W}:{W}:{W}:{W}
106V663 {W}:{W}:{W}::{W}:{W}:{W}
107V664 {W}:{W}:{W}:{W}::{W}:{W}
108V665 {W}:{W}:{W}:{W}:{W}::{W}
109V666 {W}:{W}:{W}:{W}:{W}:{W}::
110
111V650 ::{W}:{W}:{W}:{W}:{W}
112V651 {W}::{W}:{W}:{W}:{W}
113V652 {W}:{W}::{W}:{W}:{W}
114V653 {W}:{W}:{W}::{W}:{W}
115V654 {W}:{W}:{W}:{W}::{W}
116V655 {W}:{W}:{W}:{W}:{W}::
117
118V640 ::{W}:{W}:{W}:{W}
119V641 {W}::{W}:{W}:{W}
120V642 {W}:{W}::{W}:{W}
121V643 {W}:{W}:{W}::{W}
122V644 {W}:{W}:{W}:{W}::
123
124V630 ::{W}:{W}:{W}
125V631 {W}::{W}:{W}
126V632 {W}:{W}::{W}
127V633 {W}:{W}:{W}::
128
129V620 ::{W}:{W}
130V621 {W}::{W}
131V622 {W}:{W}::
132
133V610 ::{W}
134V611 {W}::
135
136V600 ::
137
138V6604 {W}:{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
139
140V6504 ::{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
141V6514 {W}::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
142V6524 {W}:{W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
143V6534 {W}:{W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
144V6544 {W}:{W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
145V6554 {W}:{W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
146
147V6404 ::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
148V6414 {W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
149V6424 {W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
150V6434 {W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
151V6444 {W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
152
153V6304 ::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
154V6314 {W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
155V6324 {W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
156V6334 {W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
157
158V6204 ::{W}:{W}:{N}\.{N}\.{N}\.{N}
159V6214 {W}::{W}:{N}\.{N}\.{N}\.{N}
160V6224 {W}:{W}::{N}\.{N}\.{N}\.{N}
161
162V6104 ::{W}:{N}\.{N}\.{N}\.{N}
163V6114 {W}::{N}\.{N}\.{N}\.{N}
164
165V6004 ::{N}\.{N}\.{N}\.{N}
166
167
168V6 ({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})
169
170%%
171dst return DST;
172src return SRC;
173
174link|ether|ppp|slip return LINK;
175fddi|tr|wlan return LINK;
176arp return ARP;
177rarp return RARP;
178ip return IP;
179sctp return SCTP;
180tcp return TCP;
181udp return UDP;
182icmp return ICMP;
183igmp return IGMP;
184igrp return IGRP;
185pim return PIM;
186vrrp return VRRP;
187radio return RADIO;
187
188ip6 {
189#ifdef INET6
190 return IPV6;
191#else
192 bpf_error("%s not supported", yytext);
193#endif
194 }
195icmp6 {
196#ifdef INET6
197 return ICMPV6;
198#else
199 bpf_error("%s not supported", yytext);
200#endif
201 }
202ah return AH;
203esp return ESP;
204
205atalk return ATALK;
206aarp return AARP;
207decnet return DECNET;
208lat return LAT;
209sca return SCA;
210moprc return MOPRC;
211mopdl return MOPDL;
212
213iso return ISO;
214esis return ESIS;
215es-is return ESIS;
216isis return ISIS;
217is-is return ISIS;
218l1 return L1;
219l2 return L2;
220iih return IIH;
221lsp return LSP;
222snp return SNP;
223csnp return CSNP;
224psnp return PSNP;
225
226clnp return CLNP;
227
228stp return STP;
229
230ipx return IPX;
231
232netbeui return NETBEUI;
233
234host return HOST;
235net return NET;
236mask return NETMASK;
237port return PORT;
188
189ip6 {
190#ifdef INET6
191 return IPV6;
192#else
193 bpf_error("%s not supported", yytext);
194#endif
195 }
196icmp6 {
197#ifdef INET6
198 return ICMPV6;
199#else
200 bpf_error("%s not supported", yytext);
201#endif
202 }
203ah return AH;
204esp return ESP;
205
206atalk return ATALK;
207aarp return AARP;
208decnet return DECNET;
209lat return LAT;
210sca return SCA;
211moprc return MOPRC;
212mopdl return MOPDL;
213
214iso return ISO;
215esis return ESIS;
216es-is return ESIS;
217isis return ISIS;
218is-is return ISIS;
219l1 return L1;
220l2 return L2;
221iih return IIH;
222lsp return LSP;
223snp return SNP;
224csnp return CSNP;
225psnp return PSNP;
226
227clnp return CLNP;
228
229stp return STP;
230
231ipx return IPX;
232
233netbeui return NETBEUI;
234
235host return HOST;
236net return NET;
237mask return NETMASK;
238port return PORT;
239portrange return PORTRANGE;
238proto return PROTO;
239protochain {
240#ifdef NO_PROTOCHAIN
241 bpf_error("%s not supported", yytext);
242#else
243 return PROTOCHAIN;
244#endif
245 }
246
247gateway return GATEWAY;
248
249less return LESS;
250greater return GREATER;
251byte return CBYTE;
252broadcast return TK_BROADCAST;
253multicast return TK_MULTICAST;
254
255and|"&&" return AND;
256or|"||" return OR;
257not return '!';
258
259len|length return LEN;
260inbound return INBOUND;
261outbound return OUTBOUND;
262
263vlan return VLAN;
264mpls return MPLS;
265
266lane return LANE;
267llc return LLC;
268metac return METAC;
269bcc return BCC;
270oam return OAM;
271oamf4 return OAMF4;
272oamf4ec return OAMF4EC;
273oamf4sc return OAMF4SC;
274sc return SC;
275ilmic return ILMIC;
276vpi return VPI;
277vci return VCI;
278connectmsg return CONNECTMSG;
279metaconnect return METACONNECT;
280
281on|ifname return PF_IFNAME;
282rset|ruleset return PF_RSET;
283rnr|rulenum return PF_RNR;
284srnr|subrulenum return PF_SRNR;
285reason return PF_REASON;
286action return PF_ACTION;
287
240proto return PROTO;
241protochain {
242#ifdef NO_PROTOCHAIN
243 bpf_error("%s not supported", yytext);
244#else
245 return PROTOCHAIN;
246#endif
247 }
248
249gateway return GATEWAY;
250
251less return LESS;
252greater return GREATER;
253byte return CBYTE;
254broadcast return TK_BROADCAST;
255multicast return TK_MULTICAST;
256
257and|"&&" return AND;
258or|"||" return OR;
259not return '!';
260
261len|length return LEN;
262inbound return INBOUND;
263outbound return OUTBOUND;
264
265vlan return VLAN;
266mpls return MPLS;
267
268lane return LANE;
269llc return LLC;
270metac return METAC;
271bcc return BCC;
272oam return OAM;
273oamf4 return OAMF4;
274oamf4ec return OAMF4EC;
275oamf4sc return OAMF4SC;
276sc return SC;
277ilmic return ILMIC;
278vpi return VPI;
279vci return VCI;
280connectmsg return CONNECTMSG;
281metaconnect return METACONNECT;
282
283on|ifname return PF_IFNAME;
284rset|ruleset return PF_RSET;
285rnr|rulenum return PF_RNR;
286srnr|subrulenum return PF_SRNR;
287reason return PF_REASON;
288action return PF_ACTION;
289
290sio return SIO;
291opc return OPC;
292dpc return DPC;
293sls return SLS;
294
288[ \r\n\t] ;
289[+\-*/:\[\]!<>()&|=] return yytext[0];
290">=" return GEQ;
291"<=" return LEQ;
292"!=" return NEQ;
293"==" return '=';
294"<<" return LSH;
295">>" return RSH;
296${B} { yylval.e = pcap_ether_aton(((char *)yytext)+1);
297 return AID; }
298{N} { yylval.i = stoi((char *)yytext); return NUM; }
299({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
300 yylval.s = sdup((char *)yytext); return HID; }
301{B}:{B}:{B}:{B}:{B}:{B} { yylval.e = pcap_ether_aton((char *)yytext);
302 return EID; }
303{V6} {
304#ifdef INET6
305 struct addrinfo hints, *res;
306 memset(&hints, 0, sizeof(hints));
307 hints.ai_family = AF_INET6;
308 hints.ai_flags = AI_NUMERICHOST;
309 if (getaddrinfo(yytext, NULL, &hints, &res))
310 bpf_error("bogus IPv6 address %s", yytext);
311 else {
312 yylval.s = sdup((char *)yytext); return HID6;
313 }
314#else
315 bpf_error("IPv6 address %s not supported", yytext);
316#endif /*INET6*/
317 }
318{B}:+({B}:+)+ { bpf_error("bogus ethernet address %s", yytext); }
319icmptype { yylval.i = 0; return NUM; }
320icmpcode { yylval.i = 1; return NUM; }
321icmp-echoreply { yylval.i = 0; return NUM; }
322icmp-unreach { yylval.i = 3; return NUM; }
323icmp-sourcequench { yylval.i = 4; return NUM; }
324icmp-redirect { yylval.i = 5; return NUM; }
325icmp-echo { yylval.i = 8; return NUM; }
326icmp-routeradvert { yylval.i = 9; return NUM; }
327icmp-routersolicit { yylval.i = 10; return NUM; }
328icmp-timxceed { yylval.i = 11; return NUM; }
329icmp-paramprob { yylval.i = 12; return NUM; }
330icmp-tstamp { yylval.i = 13; return NUM; }
331icmp-tstampreply { yylval.i = 14; return NUM; }
332icmp-ireq { yylval.i = 15; return NUM; }
333icmp-ireqreply { yylval.i = 16; return NUM; }
334icmp-maskreq { yylval.i = 17; return NUM; }
335icmp-maskreply { yylval.i = 18; return NUM; }
336tcpflags { yylval.i = 13; return NUM; }
337tcp-fin { yylval.i = 0x01; return NUM; }
338tcp-syn { yylval.i = 0x02; return NUM; }
339tcp-rst { yylval.i = 0x04; return NUM; }
340tcp-push { yylval.i = 0x08; return NUM; }
341tcp-ack { yylval.i = 0x10; return NUM; }
342tcp-urg { yylval.i = 0x20; return NUM; }
343[A-Za-z0-9]([-_.A-Za-z0-9]*[.A-Za-z0-9])? {
344 yylval.s = sdup((char *)yytext); return ID; }
345"\\"[^ !()\n\t]+ { yylval.s = sdup((char *)yytext + 1); return ID; }
346[^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+ {
347 bpf_error("illegal token: %s", yytext); }
348. { bpf_error("illegal char '%c'", *yytext); }
349%%
350void
351lex_init(buf)
352 char *buf;
353{
354#ifdef FLEX_SCANNER
355 in_buffer = yy_scan_string(buf);
356#else
357 in_buffer = buf;
358#endif
359}
360
361/*
362 * Do any cleanup necessary after parsing.
363 */
364void
365lex_cleanup()
366{
367#ifdef FLEX_SCANNER
368 if (in_buffer != NULL)
369 yy_delete_buffer(in_buffer);
370 in_buffer = NULL;
371#endif
372}
373
374/*
375 * Also define a yywrap. Note that if we're using flex, it will
376 * define a macro to map this identifier to pcap_wrap.
377 */
378int
379yywrap()
380{
381 return 1;
382}
383
384/* Hex digit to integer. */
385static inline int
386xdtoi(c)
387 register int c;
388{
389 if (isdigit(c))
390 return c - '0';
391 else if (islower(c))
392 return c - 'a' + 10;
393 else
394 return c - 'A' + 10;
395}
396
397/*
398 * Convert string to integer. Just like atoi(), but checks for
399 * preceding 0x or 0 and uses hex or octal instead of decimal.
400 */
401static int
402stoi(s)
403 char *s;
404{
405 int base = 10;
406 int n = 0;
407
408 if (*s == '0') {
409 if (s[1] == 'x' || s[1] == 'X') {
410 s += 2;
411 base = 16;
412 }
413 else {
414 base = 8;
415 s += 1;
416 }
417 }
418 while (*s)
419 n = n * base + xdtoi(*s++);
420
421 return n;
422}
295[ \r\n\t] ;
296[+\-*/:\[\]!<>()&|=] return yytext[0];
297">=" return GEQ;
298"<=" return LEQ;
299"!=" return NEQ;
300"==" return '=';
301"<<" return LSH;
302">>" return RSH;
303${B} { yylval.e = pcap_ether_aton(((char *)yytext)+1);
304 return AID; }
305{N} { yylval.i = stoi((char *)yytext); return NUM; }
306({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
307 yylval.s = sdup((char *)yytext); return HID; }
308{B}:{B}:{B}:{B}:{B}:{B} { yylval.e = pcap_ether_aton((char *)yytext);
309 return EID; }
310{V6} {
311#ifdef INET6
312 struct addrinfo hints, *res;
313 memset(&hints, 0, sizeof(hints));
314 hints.ai_family = AF_INET6;
315 hints.ai_flags = AI_NUMERICHOST;
316 if (getaddrinfo(yytext, NULL, &hints, &res))
317 bpf_error("bogus IPv6 address %s", yytext);
318 else {
319 yylval.s = sdup((char *)yytext); return HID6;
320 }
321#else
322 bpf_error("IPv6 address %s not supported", yytext);
323#endif /*INET6*/
324 }
325{B}:+({B}:+)+ { bpf_error("bogus ethernet address %s", yytext); }
326icmptype { yylval.i = 0; return NUM; }
327icmpcode { yylval.i = 1; return NUM; }
328icmp-echoreply { yylval.i = 0; return NUM; }
329icmp-unreach { yylval.i = 3; return NUM; }
330icmp-sourcequench { yylval.i = 4; return NUM; }
331icmp-redirect { yylval.i = 5; return NUM; }
332icmp-echo { yylval.i = 8; return NUM; }
333icmp-routeradvert { yylval.i = 9; return NUM; }
334icmp-routersolicit { yylval.i = 10; return NUM; }
335icmp-timxceed { yylval.i = 11; return NUM; }
336icmp-paramprob { yylval.i = 12; return NUM; }
337icmp-tstamp { yylval.i = 13; return NUM; }
338icmp-tstampreply { yylval.i = 14; return NUM; }
339icmp-ireq { yylval.i = 15; return NUM; }
340icmp-ireqreply { yylval.i = 16; return NUM; }
341icmp-maskreq { yylval.i = 17; return NUM; }
342icmp-maskreply { yylval.i = 18; return NUM; }
343tcpflags { yylval.i = 13; return NUM; }
344tcp-fin { yylval.i = 0x01; return NUM; }
345tcp-syn { yylval.i = 0x02; return NUM; }
346tcp-rst { yylval.i = 0x04; return NUM; }
347tcp-push { yylval.i = 0x08; return NUM; }
348tcp-ack { yylval.i = 0x10; return NUM; }
349tcp-urg { yylval.i = 0x20; return NUM; }
350[A-Za-z0-9]([-_.A-Za-z0-9]*[.A-Za-z0-9])? {
351 yylval.s = sdup((char *)yytext); return ID; }
352"\\"[^ !()\n\t]+ { yylval.s = sdup((char *)yytext + 1); return ID; }
353[^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+ {
354 bpf_error("illegal token: %s", yytext); }
355. { bpf_error("illegal char '%c'", *yytext); }
356%%
357void
358lex_init(buf)
359 char *buf;
360{
361#ifdef FLEX_SCANNER
362 in_buffer = yy_scan_string(buf);
363#else
364 in_buffer = buf;
365#endif
366}
367
368/*
369 * Do any cleanup necessary after parsing.
370 */
371void
372lex_cleanup()
373{
374#ifdef FLEX_SCANNER
375 if (in_buffer != NULL)
376 yy_delete_buffer(in_buffer);
377 in_buffer = NULL;
378#endif
379}
380
381/*
382 * Also define a yywrap. Note that if we're using flex, it will
383 * define a macro to map this identifier to pcap_wrap.
384 */
385int
386yywrap()
387{
388 return 1;
389}
390
391/* Hex digit to integer. */
392static inline int
393xdtoi(c)
394 register int c;
395{
396 if (isdigit(c))
397 return c - '0';
398 else if (islower(c))
399 return c - 'a' + 10;
400 else
401 return c - 'A' + 10;
402}
403
404/*
405 * Convert string to integer. Just like atoi(), but checks for
406 * preceding 0x or 0 and uses hex or octal instead of decimal.
407 */
408static int
409stoi(s)
410 char *s;
411{
412 int base = 10;
413 int n = 0;
414
415 if (*s == '0') {
416 if (s[1] == 'x' || s[1] == 'X') {
417 s += 2;
418 base = 16;
419 }
420 else {
421 base = 8;
422 s += 1;
423 }
424 }
425 while (*s)
426 n = n * base + xdtoi(*s++);
427
428 return n;
429}