3 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
4 * The Regents of the University of California. All rights reserved.
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
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.
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)";
33 #include <pcap-stdinc.h>
40 #ifdef HAVE_SYS_BITYPES_H
41 #include <sys/bitypes.h>
43 #include <sys/types.h>
54 #include <pcap-stdinc.h>
60 #include <sys/socket.h> /* for "struct sockaddr" in "struct addrinfo" */
61 #include <netdb.h> /* for "struct addrinfo" */
64 /* Workaround for AIX 4.3 */
65 #if !defined(AI_NUMERICHOST)
66 #define AI_NUMERICHOST 0x04
69 #include <pcap/namedb.h>
72 #ifdef HAVE_OS_PROTO_H
76 static int stoi(char *);
77 static inline int xdtoi(int);
82 static YY_BUFFER_STATE in_buffer;
84 static const char *in_buffer;
87 #define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++)
90 #define yylval pcap_lval
91 extern YYSTYPE yylval;
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]?)
107 V680 {W}:{W}:{W}:{W}:{W}:{W}:{W}:{W}
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}::
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}::
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}::
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}::
153 V6604 {W}:{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
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}
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}
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}
173 V6204 ::{W}:{W}:{N}\.{N}\.{N}\.{N}
174 V6214 {W}::{W}:{N}\.{N}\.{N}\.{N}
175 V6224 {W}:{W}::{N}\.{N}\.{N}\.{N}
177 V6104 ::{W}:{N}\.{N}\.{N}\.{N}
178 V6114 {W}::{N}\.{N}\.{N}\.{N}
180 V6004 ::{N}\.{N}\.{N}\.{N}
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})
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})
193 link|ether|ppp|slip return LINK;
194 fddi|tr|wlan return LINK;
213 bpf_error("%s not supported", yytext);
220 bpf_error("%s not supported", yytext);
228 decnet return DECNET;
253 netbeui return NETBEUI;
259 portrange return PORTRANGE;
263 bpf_error("%s not supported", yytext);
269 gateway return GATEWAY;
272 subtype return SUBTYPE;
273 direction|dir return DIR;
274 address1|addr1 return ADDR1;
275 address2|addr2 return ADDR2;
276 address3|addr3 return ADDR3;
277 address4|addr4 return ADDR4;
282 greater return GREATER;
284 broadcast return TK_BROADCAST;
285 multicast return TK_MULTICAST;
291 len|length return LEN;
292 inbound return INBOUND;
293 outbound return OUTBOUND;
297 pppoed return PPPOED;
298 pppoes return PPPOES;
306 oamf4ec return OAMF4EC;
307 oamf4sc return OAMF4SC;
312 connectmsg return CONNECTMSG;
313 metaconnect return METACONNECT;
315 on|ifname return PF_IFNAME;
316 rset|ruleset return PF_RSET;
317 rnr|rulenum return PF_RNR;
318 srnr|subrulenum return PF_SRNR;
319 reason return PF_REASON;
320 action return PF_ACTION;
332 [+\-*/:\[\]!<>()&|=] return yytext[0];
339 ${B} { yylval.e = pcap_ether_aton(((char *)yytext)+1);
341 {MAC} { yylval.e = pcap_ether_aton((char *)yytext);
343 {N} { yylval.i = stoi((char *)yytext); return NUM; }
344 ({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
345 yylval.s = sdup((char *)yytext); return HID; }
348 struct addrinfo hints, *res;
349 memset(&hints, 0, sizeof(hints));
350 hints.ai_family = AF_INET6;
351 hints.ai_flags = AI_NUMERICHOST;
352 if (getaddrinfo(yytext, NULL, &hints, &res))
353 bpf_error("bogus IPv6 address %s", yytext);
356 yylval.s = sdup((char *)yytext); return HID6;
359 bpf_error("IPv6 address %s not supported", yytext);
362 {B}:+({B}:+)+ { bpf_error("bogus ethernet address %s", yytext); }
363 icmptype { yylval.i = 0; return NUM; }
364 icmpcode { yylval.i = 1; return NUM; }
365 icmp-echoreply { yylval.i = 0; return NUM; }
366 icmp-unreach { yylval.i = 3; return NUM; }
367 icmp-sourcequench { yylval.i = 4; return NUM; }
368 icmp-redirect { yylval.i = 5; return NUM; }
369 icmp-echo { yylval.i = 8; return NUM; }
370 icmp-routeradvert { yylval.i = 9; return NUM; }
371 icmp-routersolicit { yylval.i = 10; return NUM; }
372 icmp-timxceed { yylval.i = 11; return NUM; }
373 icmp-paramprob { yylval.i = 12; return NUM; }
374 icmp-tstamp { yylval.i = 13; return NUM; }
375 icmp-tstampreply { yylval.i = 14; return NUM; }
376 icmp-ireq { yylval.i = 15; return NUM; }
377 icmp-ireqreply { yylval.i = 16; return NUM; }
378 icmp-maskreq { yylval.i = 17; return NUM; }
379 icmp-maskreply { yylval.i = 18; return NUM; }
380 tcpflags { yylval.i = 13; return NUM; }
381 tcp-fin { yylval.i = 0x01; return NUM; }
382 tcp-syn { yylval.i = 0x02; return NUM; }
383 tcp-rst { yylval.i = 0x04; return NUM; }
384 tcp-push { yylval.i = 0x08; return NUM; }
385 tcp-ack { yylval.i = 0x10; return NUM; }
386 tcp-urg { yylval.i = 0x20; return NUM; }
387 [A-Za-z0-9]([-_.A-Za-z0-9]*[.A-Za-z0-9])? {
388 yylval.s = sdup((char *)yytext); return ID; }
389 "\\"[^ !()\n\t]+ { yylval.s = sdup((char *)yytext + 1); return ID; }
390 [^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+ {
391 bpf_error("illegal token: %s", yytext); }
392 . { bpf_error("illegal char '%c'", *yytext); }
399 in_buffer = yy_scan_string(buf);
406 * Do any cleanup necessary after parsing.
412 if (in_buffer != NULL)
413 yy_delete_buffer(in_buffer);
419 * Also define a yywrap. Note that if we're using flex, it will
420 * define a macro to map this identifier to pcap_wrap.
428 /* Hex digit to integer. */
442 * Convert string to integer. Just like atoi(), but checks for
443 * preceding 0x or 0 and uses hex or octal instead of decimal.
453 if (s[1] == 'x' || s[1] == 'X') {
463 n = n * base + xdtoi(*s++);