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