]> git.ozlabs.org Git - ppp.git/blob - pppd/scanner.l
syslog stuff back to main.c; removed set_filters
[ppp.git] / pppd / scanner.l
1 %{
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) */
4
5 /*
6  * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994
7  *      The Regents of the University of California.  All rights reserved.
8  *
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
20  * written permission.
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.
24  */
25
26 #ifndef lint
27 static char rcsid[] = "$Id";
28 #endif
29
30 #include <sys/types.h>
31 #include <sys/time.h>
32
33 #include <ctype.h>
34
35 #include <net/ppp_defs.h>
36 #include "pcap.h"
37 #include "pcap-namedb.h"
38
39 #include "gencode.h"
40 #include "y.tab.h"
41
42 #ifndef __GNUC__
43 #define inline
44 #endif
45
46 static int stoi(char *);
47 static inline int xdtoi(int);
48
49 #ifndef FLEX_SCANNER
50 static char *in_buffer;
51
52 #undef getc
53 #define getc(fp)  (*in_buffer == 0 ? EOF : *in_buffer++)
54 #endif
55
56 extern YYSTYPE yylval;
57
58 %}
59
60 N               ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
61 B               ([0-9A-Fa-f][0-9A-Fa-f]?)
62
63 %a 3000
64
65 %%
66 dst             return DST;
67 src             return SRC;
68
69 link|ppp        return LINK;
70 ip              return IP;
71 tcp             return TCP;
72 udp             return UDP;
73 icmp            return ICMP;
74
75 host            return HOST;
76 net             return NET;
77 port            return PORT;
78 proto           return PROTO;
79
80 less            return LESS;
81 greater         return GREATER;
82 byte            return BYTE;
83 broadcast       return TK_BROADCAST;
84 multicast       return TK_MULTICAST;
85
86 and|"&&"        return AND;
87 or|"||"         return OR;
88 not             return '!';
89
90 len|length      return LEN;
91 inbound         return INBOUND;
92 outbound        return OUTBOUND;
93
94 [ \n\t]                 ;
95 [+\-*/:\[\]!<>()&|=]    return yytext[0];
96 ">="                    return GEQ;
97 "<="                    return LEQ;
98 "!="                    return NEQ;
99 "=="                    return '=';
100 "<<"                    return LSH;
101 ">>"                    return RSH;
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;
105 }
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); }
110 %%
111 void
112 lex_init(buf)
113         char *buf;
114 {
115 #ifdef FLEX_SCANNER
116         if (yy_current_buffer)
117                 yy_delete_buffer(yy_current_buffer);
118         yy_switch_to_buffer(yy_scan_string(buf));
119 #else
120         in_buffer = buf;
121 #endif
122 }
123
124 /*
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.
127  */
128 int
129 yywrap()
130 {
131         return 1;
132 }
133
134 /* Hex digit to integer. */
135 static inline int
136 xdtoi(c)
137         register int c;
138 {
139         if (isdigit(c))
140                 return c - '0';
141         else if (islower(c))
142                 return c - 'a' + 10;
143         else
144                 return c - 'A' + 10;
145 }
146
147 /*
148  * Convert string to integer.  Just like atoi(), but checks for
149  * preceding 0x or 0 and uses hex or octal instead of decimal.
150  */
151 static int
152 stoi(s)
153         char *s;
154 {
155         int base = 10;
156         int n = 0;
157
158         if (*s == '0') {
159                 if (s[1] == 'x' || s[1] == 'X') {
160                         s += 2;
161                         base = 16;
162                 }
163                 else {
164                         base = 8;
165                         s += 1;
166                 }
167         }
168         while (*s)
169                 n = n * base + xdtoi(*s++);
170
171         return n;
172 }
173