]> The Tcpdump Group git mirrors - libpcap/blob - scanner.l
EOPNOTSUPP from an ethtool ioctl should not be a fatal error.
[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[] _U_ =
25 "@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.112 2008-02-06 10:21:30 guy Exp $ (LBL)";
26 #endif
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #ifdef WIN32
33 #include <pcap-stdinc.h>
34 #else /* WIN32 */
35 #if HAVE_INTTYPES_H
36 #include <inttypes.h>
37 #elif HAVE_STDINT_H
38 #include <stdint.h>
39 #endif
40 #ifdef HAVE_SYS_BITYPES_H
41 #include <sys/bitypes.h>
42 #endif
43 #include <sys/types.h>
44 #endif /* WIN32 */
45
46 #include <ctype.h>
47 #include <string.h>
48
49 #include "pcap-int.h"
50
51 #include "gencode.h"
52 #ifdef INET6
53 #ifdef WIN32
54 #include <pcap-stdinc.h>
55
56 #ifdef __MINGW32__
57 #include "ip6_misc.h"
58 #endif
59 #else /* WIN32 */
60 #include <sys/socket.h> /* for "struct sockaddr" in "struct addrinfo" */
61 #include <netdb.h> /* for "struct addrinfo" */
62 #endif /* WIN32 */
63
64 /* Workaround for AIX 4.3 */
65 #if !defined(AI_NUMERICHOST)
66 #define AI_NUMERICHOST 0x04
67 #endif
68 #endif /*INET6*/
69 #include <pcap/namedb.h>
70 #include "tokdefs.h"
71
72 #ifdef HAVE_OS_PROTO_H
73 #include "os-proto.h"
74 #endif
75
76 static int stoi(char *);
77 static inline int xdtoi(int);
78
79 #ifdef FLEX_SCANNER
80 #define YY_NO_INPUT
81 #define YY_NO_UNPUT
82 static YY_BUFFER_STATE in_buffer;
83 #else
84 static const char *in_buffer;
85
86 #undef getc
87 #define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++)
88 #endif
89
90 #define yylval pcap_lval
91 extern YYSTYPE yylval;
92
93 %}
94
95 N ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
96 B ([0-9A-Fa-f][0-9A-Fa-f]?)
97 B2 ([0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f])
98 W ([0-9A-Fa-f][0-9A-Fa-f]?[0-9A-Fa-f]?[0-9A-Fa-f]?)
99
100 %a 18400
101 %o 21500
102 %e 7600
103 %k 4550
104 %p 27600
105 %n 2000
106
107 V680 {W}:{W}:{W}:{W}:{W}:{W}:{W}:{W}
108
109 V670 ::{W}:{W}:{W}:{W}:{W}:{W}:{W}
110 V671 {W}::{W}:{W}:{W}:{W}:{W}:{W}
111 V672 {W}:{W}::{W}:{W}:{W}:{W}:{W}
112 V673 {W}:{W}:{W}::{W}:{W}:{W}:{W}
113 V674 {W}:{W}:{W}:{W}::{W}:{W}:{W}
114 V675 {W}:{W}:{W}:{W}:{W}::{W}:{W}
115 V676 {W}:{W}:{W}:{W}:{W}:{W}::{W}
116 V677 {W}:{W}:{W}:{W}:{W}:{W}:{W}::
117
118 V660 ::{W}:{W}:{W}:{W}:{W}:{W}
119 V661 {W}::{W}:{W}:{W}:{W}:{W}
120 V662 {W}:{W}::{W}:{W}:{W}:{W}
121 V663 {W}:{W}:{W}::{W}:{W}:{W}
122 V664 {W}:{W}:{W}:{W}::{W}:{W}
123 V665 {W}:{W}:{W}:{W}:{W}::{W}
124 V666 {W}:{W}:{W}:{W}:{W}:{W}::
125
126 V650 ::{W}:{W}:{W}:{W}:{W}
127 V651 {W}::{W}:{W}:{W}:{W}
128 V652 {W}:{W}::{W}:{W}:{W}
129 V653 {W}:{W}:{W}::{W}:{W}
130 V654 {W}:{W}:{W}:{W}::{W}
131 V655 {W}:{W}:{W}:{W}:{W}::
132
133 V640 ::{W}:{W}:{W}:{W}
134 V641 {W}::{W}:{W}:{W}
135 V642 {W}:{W}::{W}:{W}
136 V643 {W}:{W}:{W}::{W}
137 V644 {W}:{W}:{W}:{W}::
138
139 V630 ::{W}:{W}:{W}
140 V631 {W}::{W}:{W}
141 V632 {W}:{W}::{W}
142 V633 {W}:{W}:{W}::
143
144 V620 ::{W}:{W}
145 V621 {W}::{W}
146 V622 {W}:{W}::
147
148 V610 ::{W}
149 V611 {W}::
150
151 V600 ::
152
153 V6604 {W}:{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
154
155 V6504 ::{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
156 V6514 {W}::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
157 V6524 {W}:{W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
158 V6534 {W}:{W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
159 V6544 {W}:{W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
160 V6554 {W}:{W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
161
162 V6404 ::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
163 V6414 {W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
164 V6424 {W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
165 V6434 {W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
166 V6444 {W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
167
168 V6304 ::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
169 V6314 {W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
170 V6324 {W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
171 V6334 {W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
172
173 V6204 ::{W}:{W}:{N}\.{N}\.{N}\.{N}
174 V6214 {W}::{W}:{N}\.{N}\.{N}\.{N}
175 V6224 {W}:{W}::{N}\.{N}\.{N}\.{N}
176
177 V6104 ::{W}:{N}\.{N}\.{N}\.{N}
178 V6114 {W}::{N}\.{N}\.{N}\.{N}
179
180 V6004 ::{N}\.{N}\.{N}\.{N}
181
182
183 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})
184
185 MAC ({B}:{B}:{B}:{B}:{B}:{B}|{B}\-{B}\-{B}\-{B}\-{B}\-{B}|{B}\.{B}\.{B}\.{B}\.{B}\.{B}|{B2}\.{B2}\.{B2}|{B2}{3})
186
187
188
189 %%
190 dst return DST;
191 src return SRC;
192
193 link|ether|ppp|slip return LINK;
194 fddi|tr|wlan return LINK;
195 arp return ARP;
196 rarp return RARP;
197 ip return IP;
198 sctp return SCTP;
199 tcp return TCP;
200 udp return UDP;
201 icmp return ICMP;
202 igmp return IGMP;
203 igrp return IGRP;
204 pim return PIM;
205 vrrp return VRRP;
206 radio return RADIO;
207
208 ip6 {
209 #ifdef INET6
210 return IPV6;
211 #else
212 bpf_error("%s not supported", yytext);
213 #endif
214 }
215 icmp6 {
216 #ifdef INET6
217 return ICMPV6;
218 #else
219 bpf_error("%s not supported", yytext);
220 #endif
221 }
222 ah return AH;
223 esp return ESP;
224
225 atalk return ATALK;
226 aarp return AARP;
227 decnet return DECNET;
228 lat return LAT;
229 sca return SCA;
230 moprc return MOPRC;
231 mopdl return MOPDL;
232
233 iso return ISO;
234 esis return ESIS;
235 es-is return ESIS;
236 isis return ISIS;
237 is-is return ISIS;
238 l1 return L1;
239 l2 return L2;
240 iih return IIH;
241 lsp return LSP;
242 snp return SNP;
243 csnp return CSNP;
244 psnp return PSNP;
245
246 clnp return CLNP;
247
248 stp return STP;
249
250 ipx return IPX;
251
252 netbeui return NETBEUI;
253
254 host return HOST;
255 net return NET;
256 mask return NETMASK;
257 port return PORT;
258 portrange return PORTRANGE;
259 proto return PROTO;
260 protochain {
261 #ifdef NO_PROTOCHAIN
262 bpf_error("%s not supported", yytext);
263 #else
264 return PROTOCHAIN;
265 #endif
266 }
267
268 gateway return GATEWAY;
269
270 type return TYPE;
271 subtype return SUBTYPE;
272 direction|dir return DIR;
273 address1|addr1 return ADDR1;
274 address2|addr2 return ADDR2;
275 address3|addr3 return ADDR3;
276 address4|addr4 return ADDR4;
277 ra return RA;
278 ta return TA;
279
280 less return LESS;
281 greater return GREATER;
282 byte return CBYTE;
283 broadcast return TK_BROADCAST;
284 multicast return TK_MULTICAST;
285
286 and|"&&" return AND;
287 or|"||" return OR;
288 not return '!';
289
290 len|length return LEN;
291 inbound return INBOUND;
292 outbound return OUTBOUND;
293
294 vlan return VLAN;
295 mpls return MPLS;
296 pppoed return PPPOED;
297 pppoes return PPPOES;
298
299 lane return LANE;
300 llc return LLC;
301 metac return METAC;
302 bcc return BCC;
303 oam return OAM;
304 oamf4 return OAMF4;
305 oamf4ec return OAMF4EC;
306 oamf4sc return OAMF4SC;
307 sc return SC;
308 ilmic return ILMIC;
309 vpi return VPI;
310 vci return VCI;
311 connectmsg return CONNECTMSG;
312 metaconnect return METACONNECT;
313
314 on|ifname return PF_IFNAME;
315 rset|ruleset return PF_RSET;
316 rnr|rulenum return PF_RNR;
317 srnr|subrulenum return PF_SRNR;
318 reason return PF_REASON;
319 action return PF_ACTION;
320
321 fisu return FISU;
322 lssu return LSSU;
323 lsu return LSSU;
324 msu return MSU;
325 sio return SIO;
326 opc return OPC;
327 dpc return DPC;
328 sls return SLS;
329
330 [ \r\n\t] ;
331 [+\-*/:\[\]!<>()&|=] return yytext[0];
332 ">=" return GEQ;
333 "<=" return LEQ;
334 "!=" return NEQ;
335 "==" return '=';
336 "<<" return LSH;
337 ">>" return RSH;
338 ${B} { yylval.e = pcap_ether_aton(((char *)yytext)+1);
339 return AID; }
340 {MAC} { yylval.e = pcap_ether_aton((char *)yytext);
341 return EID; }
342 {N} { yylval.i = stoi((char *)yytext); return NUM; }
343 ({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
344 yylval.s = sdup((char *)yytext); return HID; }
345 {V6} {
346 #ifdef INET6
347 struct addrinfo hints, *res;
348 memset(&hints, 0, sizeof(hints));
349 hints.ai_family = AF_INET6;
350 hints.ai_flags = AI_NUMERICHOST;
351 if (getaddrinfo(yytext, NULL, &hints, &res))
352 bpf_error("bogus IPv6 address %s", yytext);
353 else {
354 freeaddrinfo(res);
355 yylval.s = sdup((char *)yytext); return HID6;
356 }
357 #else
358 bpf_error("IPv6 address %s not supported", yytext);
359 #endif /*INET6*/
360 }
361 {B}:+({B}:+)+ { bpf_error("bogus ethernet address %s", yytext); }
362 icmptype { yylval.i = 0; return NUM; }
363 icmpcode { yylval.i = 1; return NUM; }
364 icmp-echoreply { yylval.i = 0; return NUM; }
365 icmp-unreach { yylval.i = 3; return NUM; }
366 icmp-sourcequench { yylval.i = 4; return NUM; }
367 icmp-redirect { yylval.i = 5; return NUM; }
368 icmp-echo { yylval.i = 8; return NUM; }
369 icmp-routeradvert { yylval.i = 9; return NUM; }
370 icmp-routersolicit { yylval.i = 10; return NUM; }
371 icmp-timxceed { yylval.i = 11; return NUM; }
372 icmp-paramprob { yylval.i = 12; return NUM; }
373 icmp-tstamp { yylval.i = 13; return NUM; }
374 icmp-tstampreply { yylval.i = 14; return NUM; }
375 icmp-ireq { yylval.i = 15; return NUM; }
376 icmp-ireqreply { yylval.i = 16; return NUM; }
377 icmp-maskreq { yylval.i = 17; return NUM; }
378 icmp-maskreply { yylval.i = 18; return NUM; }
379 tcpflags { yylval.i = 13; return NUM; }
380 tcp-fin { yylval.i = 0x01; return NUM; }
381 tcp-syn { yylval.i = 0x02; return NUM; }
382 tcp-rst { yylval.i = 0x04; return NUM; }
383 tcp-push { yylval.i = 0x08; return NUM; }
384 tcp-ack { yylval.i = 0x10; return NUM; }
385 tcp-urg { yylval.i = 0x20; return NUM; }
386 [A-Za-z0-9]([-_.A-Za-z0-9]*[.A-Za-z0-9])? {
387 yylval.s = sdup((char *)yytext); return ID; }
388 "\\"[^ !()\n\t]+ { yylval.s = sdup((char *)yytext + 1); return ID; }
389 [^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+ {
390 bpf_error("illegal token: %s", yytext); }
391 . { bpf_error("illegal char '%c'", *yytext); }
392 %%
393 void
394 lex_init(buf)
395 const char *buf;
396 {
397 #ifdef FLEX_SCANNER
398 in_buffer = yy_scan_string(buf);
399 #else
400 in_buffer = buf;
401 #endif
402 }
403
404 /*
405 * Do any cleanup necessary after parsing.
406 */
407 void
408 lex_cleanup()
409 {
410 #ifdef FLEX_SCANNER
411 if (in_buffer != NULL)
412 yy_delete_buffer(in_buffer);
413 in_buffer = NULL;
414 #endif
415 }
416
417 /*
418 * Also define a yywrap. Note that if we're using flex, it will
419 * define a macro to map this identifier to pcap_wrap.
420 */
421 int
422 yywrap()
423 {
424 return 1;
425 }
426
427 /* Hex digit to integer. */
428 static inline int
429 xdtoi(c)
430 register int c;
431 {
432 if (isdigit(c))
433 return c - '0';
434 else if (islower(c))
435 return c - 'a' + 10;
436 else
437 return c - 'A' + 10;
438 }
439
440 /*
441 * Convert string to integer. Just like atoi(), but checks for
442 * preceding 0x or 0 and uses hex or octal instead of decimal.
443 */
444 static int
445 stoi(s)
446 char *s;
447 {
448 int base = 10;
449 int n = 0;
450
451 if (*s == '0') {
452 if (s[1] == 'x' || s[1] == 'X') {
453 s += 2;
454 base = 16;
455 }
456 else {
457 base = 8;
458 s += 1;
459 }
460 }
461 while (*s)
462 n = n * base + xdtoi(*s++);
463
464 return n;
465 }