2 /* From NetBSD: scanner.l,v 1.2 1995/03/06 11:39:12 mycroft Exp */
3 /* From Header: scanner.l,v 1.40 94/06/10 17:21:44 mccanne Exp (LBL) */
6 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994
7 * The Regents of the University of California. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that: (1) source code distributions
11 * retain the above copyright notice and this paragraph in its entirety, (2)
12 * distributions including binary code include the above copyright notice and
13 * this paragraph in its entirety in the documentation or other materials
14 * provided with the distribution, and (3) all advertising materials mentioning
15 * features or use of this software display the following acknowledgement:
16 * ``This product includes software developed by the University of California,
17 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
18 * the University nor the names of its contributors may be used to endorse
19 * or promote products derived from this software without specific prior
21 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27 static char rcsid[] = "$Id";
30 #include <sys/types.h>
35 #include <net/ppp_defs.h>
37 #include "pcap-namedb.h"
46 static int stoi(char *);
47 static inline int xdtoi(int);
50 static char *in_buffer;
53 #define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++)
56 extern YYSTYPE yylval;
60 N ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
61 B ([0-9A-Fa-f][0-9A-Fa-f]?)
81 greater return GREATER;
83 broadcast return TK_BROADCAST;
84 multicast return TK_MULTICAST;
90 len|length return LEN;
91 inbound return INBOUND;
92 outbound return OUTBOUND;
95 [+\-*/:\[\]!<>()&|=] return yytext[0];
102 {N} { yylval.i = stoi((char *)yytext); return NUM; }
103 ({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
104 yylval.s = sdup((char *)yytext); return HID;
106 [A-Za-z][-_.A-Za-z0-9]* { yylval.s = sdup((char *)yytext); return ID; }
107 "\\"[^ !()\n\t]+ { yylval.s = sdup((char *)yytext + 1); return ID; }
108 [^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+ { bpf_error("illegal token: %s\n", yytext); }
109 . { bpf_error("illegal char '%c'", *yytext); }
116 if (yy_current_buffer)
117 yy_delete_buffer(yy_current_buffer);
118 yy_switch_to_buffer(yy_scan_string(buf));
125 * Also define a yywrap. Note that if we're using flex, it will
126 * define a macro to map this identifier to pcap_wrap.
134 /* Hex digit to integer. */
148 * Convert string to integer. Just like atoi(), but checks for
149 * preceding 0x or 0 and uses hex or octal instead of decimal.
159 if (s[1] == 'x' || s[1] == 'X') {
169 n = n * base + xdtoi(*s++);