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