2 /* $OpenBSD: scanner.l,v 1.5 1996/07/12 13:19:13 mickey Exp $ */
5 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
6 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that: (1) source code distributions
10 * retain the above copyright notice and this paragraph in its entirety, (2)
11 * distributions including binary code include the above copyright notice and
12 * this paragraph in its entirety in the documentation or other materials
13 * provided with the distribution, and (3) all advertising materials mentioning
14 * features or use of this software display the following acknowledgement:
15 * ``This product includes software developed by the University of California,
16 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
17 * the University nor the names of its contributors may be used to endorse
18 * or promote products derived from this software without specific prior
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27 "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/pcap/scanner.l,v 1.1.1.1 1999/05/02 03:57:55 wsanchez Exp $ (LBL)";
30 #include <sys/types.h>
37 #include <pcap-namedb.h>
39 #ifdef HAVE_OS_PROTO_H
47 static int stoi(char *);
48 static inline int xdtoi(int);
52 #define YY_INPUT(buf, result, max)\
54 char *src = in_buffer;\
60 for (i = 0; *src && i < max; ++i)\
68 #define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++)
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;
106 gateway return GATEWAY;
109 greater return GREATER;
111 broadcast return TK_BROADCAST;
112 multicast return TK_MULTICAST;
118 len|length return LEN;
119 inbound return INBOUND;
120 outbound return OUTBOUND;
123 [+\-*/:\[\]!<>()&|=] return yytext[0];
130 {N} { yylval.i = stoi((char *)yytext); return NUM; }
131 ({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
132 yylval.s = sdup((char *)yytext); return HID;
134 {B}:{B}:{B}:{B}:{B}:{B} { yylval.e = pcap_ether_aton((char *)yytext);
136 {B}:+({B}:+)+ { bpf_error("bogus ethernet address %s", yytext); }
137 [A-Za-z][-_.A-Za-z0-9]* { yylval.s = sdup((char *)yytext); return ID; }
138 "\\"[^ !()\n\t]+ { yylval.s = sdup((char *)yytext + 1); return ID; }
139 [^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+ { bpf_error("illegal token: %s\n", yytext); }
140 . { bpf_error("illegal char '%c'", *yytext); }
150 * Also define a yywrap. Note that if we're using flex, it will
151 * define a macro to map this identifier to pcap_wrap.
159 /* Hex digit to integer. */
173 * Convert string to integer. Just like atoi(), but checks for
174 * preceding 0x or 0 and uses hex or octal instead of decimal.
184 if (s[1] == 'x' || s[1] == 'X') {
194 n = n * base + xdtoi(*s++);