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[] =
25 "@(#) $Header: /usr/local/cvs/linux/tools/build/e100boot/libpcap-0.4/scanner.l,v 1.1 1999/08/26 10:05:27 johana 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;
110 gateway return GATEWAY;
113 greater return GREATER;
115 broadcast return TK_BROADCAST;
116 multicast return TK_MULTICAST;
122 len|length return LEN;
123 inbound return INBOUND;
124 outbound return OUTBOUND;
127 [+\-*/:\[\]!<>()&|=] return yytext[0];
134 {N} { yylval.i = stoi((char *)yytext); return NUM; }
135 ({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
136 yylval.s = sdup((char *)yytext); return HID; }
137 {B}:{B}:{B}:{B}:{B}:{B} { yylval.e = pcap_ether_aton((char *)yytext);
139 {B}:+({B}:+)+ { bpf_error("bogus ethernet address %s", yytext); }
140 [A-Za-z0-9][-_.A-Za-z0-9]*[.A-Za-z0-9] {
141 yylval.s = sdup((char *)yytext); return ID; }
142 "\\"[^ !()\n\t]+ { yylval.s = sdup((char *)yytext + 1); return ID; }
143 [^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+i {
144 bpf_error("illegal token: %s\n", yytext); }
145 . { bpf_error("illegal char '%c'", *yytext); }
155 * Also define a yywrap. Note that if we're using flex, it will
156 * define a macro to map this identifier to pcap_wrap.
164 /* Hex digit to integer. */
178 * Convert string to integer. Just like atoi(), but checks for
179 * preceding 0x or 0 and uses hex or octal instead of decimal.
189 if (s[1] == 'x' || s[1] == 'X') {
199 n = n * base + xdtoi(*s++);