3 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
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[] =
25 "@(#) $Header: scanner.l,v 1.55 96/09/27 22:34:45 leres Exp $ (LBL)";
28 #include <sys/types.h>
37 #include <pcap-namedb.h>
41 #ifdef HAVE_OS_PROTO_H
45 static int stoi(char *);
46 static inline int xdtoi(int);
51 #define YY_INPUT(buf, result, max)\
53 char *src = in_buffer;\
59 for (i = 0; *src && i < max; ++i)\
67 #define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++)
70 #define yylval pcap_lval
71 extern YYSTYPE yylval;
73 static char *in_buffer;
77 N ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
78 B ([0-9A-Fa-f][0-9A-Fa-f]?)
86 link|ether|ppp|slip return LINK;
116 gateway return GATEWAY;
119 greater return GREATER;
121 broadcast return TK_BROADCAST;
122 multicast return TK_MULTICAST;
128 len|length return LEN;
129 inbound return INBOUND;
130 outbound return OUTBOUND;
133 [+\-*/:\[\]!<>()&|=] return yytext[0];
140 {N} { yylval.i = stoi((char *)yytext); return NUM; }
141 ({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
142 yylval.s = sdup((char *)yytext); return HID;
144 {B}:{B}:{B}:{B}:{B}:{B} { yylval.e = pcap_ether_aton((char *)yytext);
146 {B}:+({B}:+)+ { bpf_error("bogus ethernet address %s", yytext); }
147 [A-Za-z][-_.A-Za-z0-9]* { yylval.s = sdup((char *)yytext); return ID; }
148 "\\"[^ !()\n\t]+ { yylval.s = sdup((char *)yytext + 1); return ID; }
149 [^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+ { bpf_error("illegal token: %s\n", yytext); }
150 . { bpf_error("illegal char '%c'", *yytext); }
160 * Also define a yywrap. Note that if we're using flex, it will
161 * define a macro to map this identifier to pcap_wrap.
169 /* Hex digit to integer. */
183 * Convert string to integer. Just like atoi(), but checks for
184 * preceding 0x or 0 and uses hex or octal instead of decimal.
194 if (s[1] == 'x' || s[1] == 'X') {
204 n = n * base + xdtoi(*s++);