Deleted Added
full compact
scanner.l (75110) scanner.l (98533)
1%{
2/*
3 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
4 * The Regents of the University of California. 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 *
1%{
2/*
3 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
4 * The Regents of the University of California. 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 * $FreeBSD: head/contrib/libpcap/scanner.l 75110 2001-04-03 04:32:48Z fenner $
22 * $FreeBSD: head/contrib/libpcap/scanner.l 98533 2002-06-21 01:38:14Z fenner $
23 */
24
25#ifndef lint
26static const char rcsid[] =
23 */
24
25#ifndef lint
26static const char rcsid[] =
27 "@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.70 2000/10/28 10:18:40 guy Exp $ (LBL)";
27 "@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.81 2001/09/14 01:40:57 fenner Exp $ (LBL)";
28#endif
29
30#ifdef HAVE_CONFIG_H
31#include "config.h"
32#endif
33
34#include <sys/types.h>
35#include <sys/time.h>
36
37#include <ctype.h>
38#include <unistd.h>
39#include <string.h>
40
41#include "pcap-int.h"
42
43#include "gencode.h"
44#include <pcap-namedb.h>
45#ifdef INET6
46#include <netdb.h>
47#include <sys/socket.h>
48/* Workaround for AIX 4.3 */
49#if !defined(AI_NUMERICHOST)
50#define AI_NUMERICHOST 0x04
51#endif
52#endif /*INET6*/
53#include "tokdefs.h"
54
55#ifdef HAVE_OS_PROTO_H
56#include "os-proto.h"
57#endif
58
59static int stoi(char *);
60static inline int xdtoi(int);
61
62#ifdef FLEX_SCANNER
63#define YY_NO_UNPUT
64static YY_BUFFER_STATE in_buffer;
65#else
66static char *in_buffer;
67
68#undef getc
69#define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++)
70#endif
71
72#define yylval pcap_lval
73extern YYSTYPE yylval;
74
75%}
76
77N ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
78B ([0-9A-Fa-f][0-9A-Fa-f]?)
79W ([0-9A-Fa-f][0-9A-Fa-f]?[0-9A-Fa-f]?[0-9A-Fa-f]?)
80
81%a 15000
82%o 17000
83%e 6000
84%k 4000
85%p 19000
86%n 2000
87
88V680 {W}:{W}:{W}:{W}:{W}:{W}:{W}:{W}
89
90V670 ::{W}:{W}:{W}:{W}:{W}:{W}:{W}
91V671 {W}::{W}:{W}:{W}:{W}:{W}:{W}
92V672 {W}:{W}::{W}:{W}:{W}:{W}:{W}
93V673 {W}:{W}:{W}::{W}:{W}:{W}:{W}
94V674 {W}:{W}:{W}:{W}::{W}:{W}:{W}
95V675 {W}:{W}:{W}:{W}:{W}::{W}:{W}
96V676 {W}:{W}:{W}:{W}:{W}:{W}::{W}
97V677 {W}:{W}:{W}:{W}:{W}:{W}:{W}::
98
99V660 ::{W}:{W}:{W}:{W}:{W}:{W}
100V661 {W}::{W}:{W}:{W}:{W}:{W}
101V662 {W}:{W}::{W}:{W}:{W}:{W}
102V663 {W}:{W}:{W}::{W}:{W}:{W}
103V664 {W}:{W}:{W}:{W}::{W}:{W}
104V665 {W}:{W}:{W}:{W}:{W}::{W}
105V666 {W}:{W}:{W}:{W}:{W}:{W}::
106
107V650 ::{W}:{W}:{W}:{W}:{W}
108V651 {W}::{W}:{W}:{W}:{W}
109V652 {W}:{W}::{W}:{W}:{W}
110V653 {W}:{W}:{W}::{W}:{W}
111V654 {W}:{W}:{W}:{W}::{W}
112V655 {W}:{W}:{W}:{W}:{W}::
113
114V640 ::{W}:{W}:{W}:{W}
115V641 {W}::{W}:{W}:{W}
116V642 {W}:{W}::{W}:{W}
117V643 {W}:{W}:{W}::{W}
118V644 {W}:{W}:{W}:{W}::
119
120V630 ::{W}:{W}:{W}
121V631 {W}::{W}:{W}
122V632 {W}:{W}::{W}
123V633 {W}:{W}:{W}::
124
125V620 ::{W}:{W}
126V621 {W}::{W}
127V622 {W}:{W}::
128
129V610 ::{W}
130V611 {W}::
131
132V600 ::
133
134V6604 {W}:{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
135
136V6504 ::{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
137V6514 {W}::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
138V6524 {W}:{W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
139V6534 {W}:{W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
140V6544 {W}:{W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
141V6554 {W}:{W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
142
143V6404 ::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
144V6414 {W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
145V6424 {W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
146V6434 {W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
147V6444 {W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
148
149V6304 ::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
150V6314 {W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
151V6324 {W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
152V6334 {W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
153
154V6204 ::{W}:{W}:{N}\.{N}\.{N}\.{N}
155V6214 {W}::{W}:{N}\.{N}\.{N}\.{N}
156V6224 {W}:{W}::{N}\.{N}\.{N}\.{N}
157
158V6104 ::{W}:{N}\.{N}\.{N}\.{N}
159V6114 {W}::{N}\.{N}\.{N}\.{N}
160
161V6004 ::{N}\.{N}\.{N}\.{N}
162
163
164V6 ({V680}|{V670}|{V671}|{V672}|{V673}|{V674}|{V675}|{V676}|{V677}|{V660}|{V661}|{V662}|{V663}|{V664}|{V665}|{V666}|{V650}|{V651}|{V652}|{V653}|{V654}|{V655}|{V640}|{V641}|{V642}|{V643}|{V644}|{V630}|{V631}|{V632}|{V633}|{V620}|{V621}|{V622}|{V610}|{V611}|{V600}|{V6604}|{V6504}|{V6514}|{V6524}|{V6534}|{V6544}|{V6554}|{V6404}|{V6414}|{V6424}|{V6434}|{V6444}|{V6304}|{V6314}|{V6324}|{V6334}|{V6204}|{V6214}|{V6224}|{V6104}|{V6114}|{V6004})
165
166%%
167dst return DST;
168src return SRC;
169
170link|ether|ppp|slip return LINK;
171fddi|tr return LINK;
172arp return ARP;
173rarp return RARP;
174ip return IP;
28#endif
29
30#ifdef HAVE_CONFIG_H
31#include "config.h"
32#endif
33
34#include <sys/types.h>
35#include <sys/time.h>
36
37#include <ctype.h>
38#include <unistd.h>
39#include <string.h>
40
41#include "pcap-int.h"
42
43#include "gencode.h"
44#include <pcap-namedb.h>
45#ifdef INET6
46#include <netdb.h>
47#include <sys/socket.h>
48/* Workaround for AIX 4.3 */
49#if !defined(AI_NUMERICHOST)
50#define AI_NUMERICHOST 0x04
51#endif
52#endif /*INET6*/
53#include "tokdefs.h"
54
55#ifdef HAVE_OS_PROTO_H
56#include "os-proto.h"
57#endif
58
59static int stoi(char *);
60static inline int xdtoi(int);
61
62#ifdef FLEX_SCANNER
63#define YY_NO_UNPUT
64static YY_BUFFER_STATE in_buffer;
65#else
66static char *in_buffer;
67
68#undef getc
69#define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++)
70#endif
71
72#define yylval pcap_lval
73extern YYSTYPE yylval;
74
75%}
76
77N ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
78B ([0-9A-Fa-f][0-9A-Fa-f]?)
79W ([0-9A-Fa-f][0-9A-Fa-f]?[0-9A-Fa-f]?[0-9A-Fa-f]?)
80
81%a 15000
82%o 17000
83%e 6000
84%k 4000
85%p 19000
86%n 2000
87
88V680 {W}:{W}:{W}:{W}:{W}:{W}:{W}:{W}
89
90V670 ::{W}:{W}:{W}:{W}:{W}:{W}:{W}
91V671 {W}::{W}:{W}:{W}:{W}:{W}:{W}
92V672 {W}:{W}::{W}:{W}:{W}:{W}:{W}
93V673 {W}:{W}:{W}::{W}:{W}:{W}:{W}
94V674 {W}:{W}:{W}:{W}::{W}:{W}:{W}
95V675 {W}:{W}:{W}:{W}:{W}::{W}:{W}
96V676 {W}:{W}:{W}:{W}:{W}:{W}::{W}
97V677 {W}:{W}:{W}:{W}:{W}:{W}:{W}::
98
99V660 ::{W}:{W}:{W}:{W}:{W}:{W}
100V661 {W}::{W}:{W}:{W}:{W}:{W}
101V662 {W}:{W}::{W}:{W}:{W}:{W}
102V663 {W}:{W}:{W}::{W}:{W}:{W}
103V664 {W}:{W}:{W}:{W}::{W}:{W}
104V665 {W}:{W}:{W}:{W}:{W}::{W}
105V666 {W}:{W}:{W}:{W}:{W}:{W}::
106
107V650 ::{W}:{W}:{W}:{W}:{W}
108V651 {W}::{W}:{W}:{W}:{W}
109V652 {W}:{W}::{W}:{W}:{W}
110V653 {W}:{W}:{W}::{W}:{W}
111V654 {W}:{W}:{W}:{W}::{W}
112V655 {W}:{W}:{W}:{W}:{W}::
113
114V640 ::{W}:{W}:{W}:{W}
115V641 {W}::{W}:{W}:{W}
116V642 {W}:{W}::{W}:{W}
117V643 {W}:{W}:{W}::{W}
118V644 {W}:{W}:{W}:{W}::
119
120V630 ::{W}:{W}:{W}
121V631 {W}::{W}:{W}
122V632 {W}:{W}::{W}
123V633 {W}:{W}:{W}::
124
125V620 ::{W}:{W}
126V621 {W}::{W}
127V622 {W}:{W}::
128
129V610 ::{W}
130V611 {W}::
131
132V600 ::
133
134V6604 {W}:{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
135
136V6504 ::{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
137V6514 {W}::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
138V6524 {W}:{W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
139V6534 {W}:{W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
140V6544 {W}:{W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
141V6554 {W}:{W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
142
143V6404 ::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
144V6414 {W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
145V6424 {W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
146V6434 {W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
147V6444 {W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
148
149V6304 ::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
150V6314 {W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
151V6324 {W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
152V6334 {W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
153
154V6204 ::{W}:{W}:{N}\.{N}\.{N}\.{N}
155V6214 {W}::{W}:{N}\.{N}\.{N}\.{N}
156V6224 {W}:{W}::{N}\.{N}\.{N}\.{N}
157
158V6104 ::{W}:{N}\.{N}\.{N}\.{N}
159V6114 {W}::{N}\.{N}\.{N}\.{N}
160
161V6004 ::{N}\.{N}\.{N}\.{N}
162
163
164V6 ({V680}|{V670}|{V671}|{V672}|{V673}|{V674}|{V675}|{V676}|{V677}|{V660}|{V661}|{V662}|{V663}|{V664}|{V665}|{V666}|{V650}|{V651}|{V652}|{V653}|{V654}|{V655}|{V640}|{V641}|{V642}|{V643}|{V644}|{V630}|{V631}|{V632}|{V633}|{V620}|{V621}|{V622}|{V610}|{V611}|{V600}|{V6604}|{V6504}|{V6514}|{V6524}|{V6534}|{V6544}|{V6554}|{V6404}|{V6414}|{V6424}|{V6434}|{V6444}|{V6304}|{V6314}|{V6324}|{V6334}|{V6204}|{V6214}|{V6224}|{V6104}|{V6114}|{V6004})
165
166%%
167dst return DST;
168src return SRC;
169
170link|ether|ppp|slip return LINK;
171fddi|tr return LINK;
172arp return ARP;
173rarp return RARP;
174ip return IP;
175sctp return SCTP;
175tcp return TCP;
176udp return UDP;
177icmp return ICMP;
178igmp return IGMP;
179igrp return IGRP;
180pim return PIM;
176tcp return TCP;
177udp return UDP;
178icmp return ICMP;
179igmp return IGMP;
180igrp return IGRP;
181pim return PIM;
182vrrp return VRRP;
181
183
182ip6 return IPV6;
183icmp6 return ICMPV6;
184ip6 {
185#ifdef INET6
186 return IPV6;
187#else
188 bpf_error("%s not supported", yytext);
189#endif
190 }
191icmp6 {
192#ifdef INET6
193 return ICMPV6;
194#else
195 bpf_error("%s not supported", yytext);
196#endif
197 }
184ah return AH;
185esp return ESP;
186
187atalk return ATALK;
188aarp return AARP;
189decnet return DECNET;
190lat return LAT;
191sca return SCA;
192moprc return MOPRC;
193mopdl return MOPDL;
194
195iso return ISO;
196esis return ESIS;
197es-is return ESIS;
198isis return ISIS;
199is-is return ISIS;
200clnp return CLNP;
201
198ah return AH;
199esp return ESP;
200
201atalk return ATALK;
202aarp return AARP;
203decnet return DECNET;
204lat return LAT;
205sca return SCA;
206moprc return MOPRC;
207mopdl return MOPDL;
208
209iso return ISO;
210esis return ESIS;
211es-is return ESIS;
212isis return ISIS;
213is-is return ISIS;
214clnp return CLNP;
215
216stp return STP;
217
218ipx return IPX;
219
220netbeui return NETBEUI;
221
202host return HOST;
203net return NET;
204mask return MASK;
205port return PORT;
206proto return PROTO;
207protochain {
208#ifdef NO_PROTOCHAIN
209 bpf_error("%s not supported", yytext);
210#else
211 return PROTOCHAIN;
212#endif
213 }
214
215gateway return GATEWAY;
216
217less return LESS;
218greater return GREATER;
219byte return BYTE;
220broadcast return TK_BROADCAST;
221multicast return TK_MULTICAST;
222
223and|"&&" return AND;
224or|"||" return OR;
225not return '!';
226
227len|length return LEN;
228inbound return INBOUND;
229outbound return OUTBOUND;
230
231vlan return VLAN;
232
233[ \n\t] ;
234[+\-*/:\[\]!<>()&|=] return yytext[0];
235">=" return GEQ;
236"<=" return LEQ;
237"!=" return NEQ;
238"==" return '=';
239"<<" return LSH;
240">>" return RSH;
222host return HOST;
223net return NET;
224mask return MASK;
225port return PORT;
226proto return PROTO;
227protochain {
228#ifdef NO_PROTOCHAIN
229 bpf_error("%s not supported", yytext);
230#else
231 return PROTOCHAIN;
232#endif
233 }
234
235gateway return GATEWAY;
236
237less return LESS;
238greater return GREATER;
239byte return BYTE;
240broadcast return TK_BROADCAST;
241multicast return TK_MULTICAST;
242
243and|"&&" return AND;
244or|"||" return OR;
245not return '!';
246
247len|length return LEN;
248inbound return INBOUND;
249outbound return OUTBOUND;
250
251vlan return VLAN;
252
253[ \n\t] ;
254[+\-*/:\[\]!<>()&|=] return yytext[0];
255">=" return GEQ;
256"<=" return LEQ;
257"!=" return NEQ;
258"==" return '=';
259"<<" return LSH;
260">>" return RSH;
261${B} { yylval.e = pcap_ether_aton(((char *)yytext)+1);
262 return AID; }
241{N} { yylval.i = stoi((char *)yytext); return NUM; }
242({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
243 yylval.s = sdup((char *)yytext); return HID; }
244{B}:{B}:{B}:{B}:{B}:{B} { yylval.e = pcap_ether_aton((char *)yytext);
245 return EID; }
246{V6} {
247#ifdef INET6
248 struct addrinfo hints, *res;
249 memset(&hints, 0, sizeof(hints));
250 hints.ai_family = AF_INET6;
251 hints.ai_flags = AI_NUMERICHOST;
252 if (getaddrinfo(yytext, NULL, &hints, &res))
253 bpf_error("bogus IPv6 address %s", yytext);
254 else {
255 yylval.e = sdup((char *)yytext); return HID6;
256 }
257#else
258 bpf_error("IPv6 address %s not supported", yytext);
259#endif /*INET6*/
260 }
261{B}:+({B}:+)+ { bpf_error("bogus ethernet address %s", yytext); }
263{N} { yylval.i = stoi((char *)yytext); return NUM; }
264({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
265 yylval.s = sdup((char *)yytext); return HID; }
266{B}:{B}:{B}:{B}:{B}:{B} { yylval.e = pcap_ether_aton((char *)yytext);
267 return EID; }
268{V6} {
269#ifdef INET6
270 struct addrinfo hints, *res;
271 memset(&hints, 0, sizeof(hints));
272 hints.ai_family = AF_INET6;
273 hints.ai_flags = AI_NUMERICHOST;
274 if (getaddrinfo(yytext, NULL, &hints, &res))
275 bpf_error("bogus IPv6 address %s", yytext);
276 else {
277 yylval.e = sdup((char *)yytext); return HID6;
278 }
279#else
280 bpf_error("IPv6 address %s not supported", yytext);
281#endif /*INET6*/
282 }
283{B}:+({B}:+)+ { bpf_error("bogus ethernet address %s", yytext); }
262[A-Za-z0-9][-_.A-Za-z0-9]*[.A-Za-z0-9] {
284icmptype { yylval.i = 0; return NUM; }
285icmpcode { yylval.i = 1; return NUM; }
286icmp-echoreply { yylval.i = 0; return NUM; }
287icmp-unreach { yylval.i = 3; return NUM; }
288icmp-sourcequench { yylval.i = 4; return NUM; }
289icmp-redirect { yylval.i = 5; return NUM; }
290icmp-echo { yylval.i = 8; return NUM; }
291icmp-routeradvert { yylval.i = 9; return NUM; }
292icmp-routersolicit { yylval.i = 10; return NUM; }
293icmp-timxceed { yylval.i = 11; return NUM; }
294icmp-paramprob { yylval.i = 12; return NUM; }
295icmp-tstamp { yylval.i = 13; return NUM; }
296icmp-tstampreply { yylval.i = 14; return NUM; }
297icmp-ireq { yylval.i = 15; return NUM; }
298icmp-ireqreply { yylval.i = 16; return NUM; }
299icmp-maskreq { yylval.i = 17; return NUM; }
300icmp-maskreply { yylval.i = 18; return NUM; }
301tcpflags { yylval.i = 13; return NUM; }
302tcp-fin { yylval.i = 0x01; return NUM; }
303tcp-syn { yylval.i = 0x02; return NUM; }
304tcp-rst { yylval.i = 0x04; return NUM; }
305tcp-push { yylval.i = 0x08; return NUM; }
306tcp-ack { yylval.i = 0x10; return NUM; }
307tcp-urg { yylval.i = 0x20; return NUM; }
308[A-Za-z0-9]([-_.A-Za-z0-9]*[.A-Za-z0-9])? {
263 yylval.s = sdup((char *)yytext); return ID; }
264"\\"[^ !()\n\t]+ { yylval.s = sdup((char *)yytext + 1); return ID; }
309 yylval.s = sdup((char *)yytext); return ID; }
310"\\"[^ !()\n\t]+ { yylval.s = sdup((char *)yytext + 1); return ID; }
265[^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+i {
266 bpf_error("illegal token: %s\n", yytext); }
311[^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+ {
312 bpf_error("illegal token: %s", yytext); }
267. { bpf_error("illegal char '%c'", *yytext); }
268%%
269void
270lex_init(buf)
271 char *buf;
272{
273#ifdef FLEX_SCANNER
274 in_buffer = yy_scan_string(buf);
275#else
276 in_buffer = buf;
277#endif
278}
279
280/*
281 * Do any cleanup necessary after parsing.
282 */
283void
284lex_cleanup()
285{
286#ifdef FLEX_SCANNER
287 if (in_buffer != NULL)
288 yy_delete_buffer(in_buffer);
289 in_buffer = NULL;
290#endif
291}
292
293/*
294 * Also define a yywrap. Note that if we're using flex, it will
295 * define a macro to map this identifier to pcap_wrap.
296 */
297int
298yywrap()
299{
300 return 1;
301}
302
303/* Hex digit to integer. */
304static inline int
305xdtoi(c)
306 register int c;
307{
308 if (isdigit(c))
309 return c - '0';
310 else if (islower(c))
311 return c - 'a' + 10;
312 else
313 return c - 'A' + 10;
314}
315
316/*
317 * Convert string to integer. Just like atoi(), but checks for
318 * preceding 0x or 0 and uses hex or octal instead of decimal.
319 */
320static int
321stoi(s)
322 char *s;
323{
324 int base = 10;
325 int n = 0;
326
327 if (*s == '0') {
328 if (s[1] == 'x' || s[1] == 'X') {
329 s += 2;
330 base = 16;
331 }
332 else {
333 base = 8;
334 s += 1;
335 }
336 }
337 while (*s)
338 n = n * base + xdtoi(*s++);
339
340 return n;
341}
313. { bpf_error("illegal char '%c'", *yytext); }
314%%
315void
316lex_init(buf)
317 char *buf;
318{
319#ifdef FLEX_SCANNER
320 in_buffer = yy_scan_string(buf);
321#else
322 in_buffer = buf;
323#endif
324}
325
326/*
327 * Do any cleanup necessary after parsing.
328 */
329void
330lex_cleanup()
331{
332#ifdef FLEX_SCANNER
333 if (in_buffer != NULL)
334 yy_delete_buffer(in_buffer);
335 in_buffer = NULL;
336#endif
337}
338
339/*
340 * Also define a yywrap. Note that if we're using flex, it will
341 * define a macro to map this identifier to pcap_wrap.
342 */
343int
344yywrap()
345{
346 return 1;
347}
348
349/* Hex digit to integer. */
350static inline int
351xdtoi(c)
352 register int c;
353{
354 if (isdigit(c))
355 return c - '0';
356 else if (islower(c))
357 return c - 'a' + 10;
358 else
359 return c - 'A' + 10;
360}
361
362/*
363 * Convert string to integer. Just like atoi(), but checks for
364 * preceding 0x or 0 and uses hex or octal instead of decimal.
365 */
366static int
367stoi(s)
368 char *s;
369{
370 int base = 10;
371 int n = 0;
372
373 if (*s == '0') {
374 if (s[1] == 'x' || s[1] == 'X') {
375 s += 2;
376 base = 16;
377 }
378 else {
379 base = 8;
380 s += 1;
381 }
382 }
383 while (*s)
384 n = n * base + xdtoi(*s++);
385
386 return n;
387}