]> The Tcpdump Group git mirrors - libpcap/blob - scanner.l
use AC_DEFINE/3 to get defines into config.h.in
[libpcap] / scanner.l
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
23 #ifndef lint
24 static const char rcsid[] =
25 "@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.63 2000-06-10 14:42:27 assar Exp $ (LBL)";
26 #endif
27
28 #include <sys/types.h>
29 #include <sys/time.h>
30
31 #include <ctype.h>
32 #include <unistd.h>
33 #include <string.h>
34
35 #include "pcap-int.h"
36
37 #include "gencode.h"
38 #include <pcap-namedb.h>
39 #ifdef INET6
40 #include <netdb.h>
41 #include <sys/socket.h>
42 /* Workaround for AIX 4.3 */
43 #if !defined(AI_NUMERICHOST)
44 #define AI_NUMERICHOST 0x04
45 #endif
46 #endif /*INET6*/
47 #include "tokdefs.h"
48
49 #include "gnuc.h"
50 #ifdef HAVE_OS_PROTO_H
51 #include "os-proto.h"
52 #endif
53
54 static int stoi(char *);
55 static inline int xdtoi(int);
56
57 #ifdef FLEX_SCANNER
58 #define YY_NO_UNPUT
59 #undef YY_INPUT
60 #define YY_INPUT(buf, result, max)\
61 {\
62 char *src = in_buffer;\
63 int i;\
64 \
65 if (*src == 0)\
66 result = YY_NULL;\
67 else {\
68 for (i = 0; *src && i < max; ++i)\
69 buf[i] = *src++;\
70 in_buffer += i;\
71 result = i;\
72 }\
73 }
74 #else
75 #undef getc
76 #define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++)
77 #endif
78
79 #define yylval pcap_lval
80 extern YYSTYPE yylval;
81
82 static char *in_buffer;
83
84 %}
85
86 N ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
87 B ([0-9A-Fa-f][0-9A-Fa-f]?)
88 W ([0-9A-Fa-f][0-9A-Fa-f]?[0-9A-Fa-f]?[0-9A-Fa-f]?)
89
90 %a 15000
91 %o 17000
92 %e 6000
93 %k 4000
94 %p 19000
95 %n 2000
96
97 V680 {W}:{W}:{W}:{W}:{W}:{W}:{W}:{W}
98
99 V670 ::{W}:{W}:{W}:{W}:{W}:{W}:{W}
100 V671 {W}::{W}:{W}:{W}:{W}:{W}:{W}
101 V672 {W}:{W}::{W}:{W}:{W}:{W}:{W}
102 V673 {W}:{W}:{W}::{W}:{W}:{W}:{W}
103 V674 {W}:{W}:{W}:{W}::{W}:{W}:{W}
104 V675 {W}:{W}:{W}:{W}:{W}::{W}:{W}
105 V676 {W}:{W}:{W}:{W}:{W}:{W}::{W}
106 V677 {W}:{W}:{W}:{W}:{W}:{W}:{W}::
107
108 V660 ::{W}:{W}:{W}:{W}:{W}:{W}
109 V661 {W}::{W}:{W}:{W}:{W}:{W}
110 V662 {W}:{W}::{W}:{W}:{W}:{W}
111 V663 {W}:{W}:{W}::{W}:{W}:{W}
112 V664 {W}:{W}:{W}:{W}::{W}:{W}
113 V665 {W}:{W}:{W}:{W}:{W}::{W}
114 V666 {W}:{W}:{W}:{W}:{W}:{W}::
115
116 V650 ::{W}:{W}:{W}:{W}:{W}
117 V651 {W}::{W}:{W}:{W}:{W}
118 V652 {W}:{W}::{W}:{W}:{W}
119 V653 {W}:{W}:{W}::{W}:{W}
120 V654 {W}:{W}:{W}:{W}::{W}
121 V655 {W}:{W}:{W}:{W}:{W}::
122
123 V640 ::{W}:{W}:{W}:{W}
124 V641 {W}::{W}:{W}:{W}
125 V642 {W}:{W}::{W}:{W}
126 V643 {W}:{W}:{W}::{W}
127 V644 {W}:{W}:{W}:{W}::
128
129 V630 ::{W}:{W}:{W}
130 V631 {W}::{W}:{W}
131 V632 {W}:{W}::{W}
132 V633 {W}:{W}:{W}::
133
134 V620 ::{W}:{W}
135 V621 {W}::{W}
136 V622 {W}:{W}::
137
138 V610 ::{W}
139 V611 {W}::
140
141 V600 ::
142
143 V6604 {W}:{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
144
145 V6504 ::{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
146 V6514 {W}::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
147 V6524 {W}:{W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
148 V6534 {W}:{W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
149 V6544 {W}:{W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
150 V6554 {W}:{W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
151
152 V6404 ::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
153 V6414 {W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
154 V6424 {W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
155 V6434 {W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
156 V6444 {W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
157
158 V6304 ::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
159 V6314 {W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
160 V6324 {W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
161 V6334 {W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
162
163 V6204 ::{W}:{W}:{N}\.{N}\.{N}\.{N}
164 V6214 {W}::{W}:{N}\.{N}\.{N}\.{N}
165 V6224 {W}:{W}::{N}\.{N}\.{N}\.{N}
166
167 V6104 ::{W}:{N}\.{N}\.{N}\.{N}
168 V6114 {W}::{N}\.{N}\.{N}\.{N}
169
170 V6004 ::{N}\.{N}\.{N}\.{N}
171
172
173 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})
174
175 %%
176 dst return DST;
177 src return SRC;
178
179 link|ether|ppp|slip return LINK;
180 fddi return LINK;
181 arp return ARP;
182 rarp return RARP;
183 ip return IP;
184 tcp return TCP;
185 udp return UDP;
186 icmp return ICMP;
187 igmp return IGMP;
188 igrp return IGRP;
189 pim return PIM;
190
191 ip6 return IPV6;
192 icmp6 return ICMPV6;
193 ah return AH;
194 esp return ESP;
195
196 atalk return ATALK;
197 decnet return DECNET;
198 lat return LAT;
199 sca return SCA;
200 moprc return MOPRC;
201 mopdl return MOPDL;
202
203 host return HOST;
204 net return NET;
205 mask return MASK;
206 port return PORT;
207 proto return PROTO;
208 protochain {
209 #ifdef NO_PROTOCHAIN
210 bpf_error("%s not supported", yytext);
211 #else
212 return PROTOCHAIN;
213 #endif
214 }
215
216 gateway return GATEWAY;
217
218 less return LESS;
219 greater return GREATER;
220 byte return BYTE;
221 broadcast return TK_BROADCAST;
222 multicast return TK_MULTICAST;
223
224 and|"&&" return AND;
225 or|"||" return OR;
226 not return '!';
227
228 len|length return LEN;
229 inbound return INBOUND;
230 outbound return OUTBOUND;
231
232 [ \n\t] ;
233 [+\-*/:\[\]!<>()&|=] return yytext[0];
234 ">=" return GEQ;
235 "<=" return LEQ;
236 "!=" return NEQ;
237 "==" return '=';
238 "<<" return LSH;
239 ">>" return RSH;
240 {N} { yylval.i = stoi((char *)yytext); return NUM; }
241 ({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
242 yylval.s = sdup((char *)yytext); return HID; }
243 {B}:{B}:{B}:{B}:{B}:{B} { yylval.e = pcap_ether_aton((char *)yytext);
244 return EID; }
245 {V6} {
246 #ifdef INET6
247 struct addrinfo hints, *res;
248 memset(&hints, 0, sizeof(hints));
249 hints.ai_family = AF_INET6;
250 hints.ai_flags = AI_NUMERICHOST;
251 if (getaddrinfo(yytext, NULL, &hints, &res))
252 bpf_error("bogus IPv6 address %s", yytext);
253 else {
254 yylval.e = sdup((char *)yytext); return HID6;
255 }
256 #else
257 bpf_error("IPv6 address %s not supported", yytext);
258 #endif /*INET6*/
259 }
260 {B}:+({B}:+)+ { bpf_error("bogus ethernet address %s", yytext); }
261 [A-Za-z0-9][-_.A-Za-z0-9]*[.A-Za-z0-9] {
262 yylval.s = sdup((char *)yytext); return ID; }
263 "\\"[^ !()\n\t]+ { yylval.s = sdup((char *)yytext + 1); return ID; }
264 [^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+i {
265 bpf_error("illegal token: %s\n", yytext); }
266 . { bpf_error("illegal char '%c'", *yytext); }
267 %%
268 void
269 lex_init(buf)
270 char *buf;
271 {
272 in_buffer = buf;
273 #ifdef FLEX_SCANNER
274 /*
275 * Flush the scanner's input buffer, so that there's no cruft
276 * left over from a previous parse.
277 */
278 YY_FLUSH_BUFFER;
279 #endif
280 }
281
282 /*
283 * Also define a yywrap. Note that if we're using flex, it will
284 * define a macro to map this identifier to pcap_wrap.
285 */
286 int
287 yywrap()
288 {
289 return 1;
290 }
291
292 /* Hex digit to integer. */
293 static inline int
294 xdtoi(c)
295 register int c;
296 {
297 if (isdigit(c))
298 return c - '0';
299 else if (islower(c))
300 return c - 'a' + 10;
301 else
302 return c - 'A' + 10;
303 }
304
305 /*
306 * Convert string to integer. Just like atoi(), but checks for
307 * preceding 0x or 0 and uses hex or octal instead of decimal.
308 */
309 static int
310 stoi(s)
311 char *s;
312 {
313 int base = 10;
314 int n = 0;
315
316 if (*s == '0') {
317 if (s[1] == 'x' || s[1] == 'X') {
318 s += 2;
319 base = 16;
320 }
321 else {
322 base = 8;
323 s += 1;
324 }
325 }
326 while (*s)
327 n = n * base + xdtoi(*s++);
328
329 return n;
330 }
331