1 %{
2 /*
3 * Copyright (c) 1988-1990 The Regents of the University of California.
4 * 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 */
22
23 #ifndef lint
24 static char rcsid[] =
25 "@(#) $Header: tcplex.l,v 1.21 91/06/06 22:35:55 mccanne Exp $ (LBL)";
26 #endif
27
28 /*
29 * Compiling with gcc under SunOS will cause problems unless we have this
30 * cruft here. The flex skeleton includes stddef.h which defines these types
31 * (under gcc). They will conflict with Sun's definitions in sys/types.h.
32 */
33 #define size_t xxxsize_t
34 #define ptrdiff_t xxxptrdiff_t
35 #include <sys/types.h>
36 #undef size_t
37 #undef ptrdiff_t
38
39 #include "nametoaddr.h"
40
41 /*
42 * We need bpf since enum bpf_code is in YYSTYPE.
43 */
44 #include <sys/time.h>
45 #include <net/bpf.h>
46
47 #include "tokdefs.h"
48
49 #ifdef FLEX_SCANNER
50 #undef YY_INPUT
51 #define YY_INPUT(buf, result, max)\
52 {\
53 char *src = in_buffer;\
54 int i;\
55 \
56 if (*src == 0)\
57 result = YY_NULL;\
58 else {\
59 for (i = 0; *src && i < max; ++i)\
60 buf[i] = *src++;\
61 in_buffer += i;\
62 result = i;\
63 }\
64 }
65 #else
66 #undef getc
67 #define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++)
68 #endif
69
70 extern YYSTYPE yylval;
71 static char *in_buffer;
72
73 %}
74
75 N ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
76 B ([0-9A-Fa-f][0-9A-Fa-f]?)
77
78 %a 3000
79
80 %%
81 dst return DST;
82 src return SRC;
83
84 ether return ETHER;
85 arp return ARP;
86 rarp return RARP;
87 ip return IP;
88 tcp return TCP;
89 udp return UDP;
90 icmp return ICMP;
91
92 host return HOST;
93 net return NET;
94 port return PORT;
95 proto return PROTO;
96
97 gateway return GATEWAY;
98
99 less return LESS;
100 greater return GREATER;
101 byte return BYTE;
102 broadcast return BROADCAST;
103
104 and return AND;
105 or return OR;
106 not return '!';
107
108 len return LEN;
109
110 [ \n\t] ;
111 [+\-*/:\[\]!<>()&|=] return yytext[0];
112 ">=" return GEQ;
113 "<=" return LEQ;
114 "!=" return NEQ;
115 "<<" return LSH;
116 ">>" return RSH;
117 {N} { yylval.i = stoi(yytext); return NUM; }
118 ({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
119 yylval.h = atoin(yytext); return HID;
120 }
121 {B}:{B}:{B}:{B}:{B}:{B} { yylval.e = ETHER_aton(yytext); return EID; }
122 {B}:+({B}:+)+ { error("bogus ethernet address %s", yytext); }
123 [A-Za-z][-_.A-Za-z0-9]* { yylval.s = yytext; return ID; }
124 "\\"[^ !()\n\t]+ { yylval.s = yytext + 1; return ID; }
125 [^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+ { error("illegal token: %s\n", yytext); }
126 . { error("illegal char '%c'", *yytext); }
127 %%
128 void
lex_init(buf)129 lex_init(buf)
130 char *buf;
131 {
132 in_buffer = buf;
133 }
134 #ifndef FLEX_SCANNER
135 int
yywrap()136 yywrap()
137 /* so we don't need -ll */
138 {
139 return 1;
140 }
141 #endif
142