1335640Shselasky%top {
2335640Shselasky/* Must come first for _LARGE_FILE_API on AIX. */
3335640Shselasky#ifdef HAVE_CONFIG_H
4335640Shselasky#include <config.h>
5335640Shselasky#endif
6335640Shselasky
7335640Shselasky/*
8335640Shselasky * Must come first to avoid warnings on Windows.
9335640Shselasky *
10335640Shselasky * Flex-generated scanners may only include <inttypes.h> if __STDC_VERSION__
11335640Shselasky * is defined with a value >= 199901, meaning "full C99", and MSVC may not
12335640Shselasky * define it with that value, because it isn't 100% C99-compliant, even
13335640Shselasky * though it has an <inttypes.h> capable of defining everything the Flex
14335640Shselasky * scanner needs.
15335640Shselasky *
16335640Shselasky * We, however, will include it if we know we have an MSVC version that has
17335640Shselasky * it; this means that we may define the INTn_MAX and UINTn_MAX values in
18335640Shselasky * scanner.c, and then include <stdint.h>, which may define them differently
19335640Shselasky * (same value, but different string of characters), causing compiler warnings.
20335640Shselasky *
21335640Shselasky * If we include it here, and they're defined, that'll prevent scanner.c
22335640Shselasky * from defining them.  So we include <pcap/pcap-inttypes.h>, to get
23335640Shselasky * <inttypes.h> if we have it.
24335640Shselasky */
25335640Shselasky#include <pcap/pcap-inttypes.h>
26335640Shselasky
27335640Shselasky#include "diag-control.h"
28335640Shselasky}
29335640Shselasky
30335640Shselasky/*
31335640Shselasky * We want a reentrant scanner.
32335640Shselasky */
33335640Shselasky%option reentrant
34335640Shselasky
35335640Shselasky/*
36335640Shselasky * And we need to pass the compiler state to the scanner.
37335640Shselasky */
38335640Shselasky%option extra-type="compiler_state_t *"
39335640Shselasky
40335640Shselasky/*
41335640Shselasky * We don't use input, so don't generate code for it.
42335640Shselasky */
43335640Shselasky%option noinput
44335640Shselasky
45335640Shselasky/*
46335640Shselasky * We don't use unput, so don't generate code for it.
47335640Shselasky */
48335640Shselasky%option nounput
49335640Shselasky
50335640Shselasky/*
51335640Shselasky * We don't read from the terminal.
52335640Shselasky */
53335640Shselasky%option never-interactive
54335640Shselasky
55335640Shselasky/*
56335640Shselasky * We want to stop processing when we get to the end of the input.
57335640Shselasky */
58335640Shselasky%option noyywrap
59335640Shselasky
60335640Shselasky/*
61335640Shselasky * We want to generate code that can be used by a reentrant parser
62335640Shselasky * generated by Bison or Berkeley YACC.
63335640Shselasky */
64335640Shselasky%option bison-bridge
65335640Shselasky
66335640Shselasky%{
67335640Shselasky/*
68335640Shselasky * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
69335640Shselasky *	The Regents of the University of California.  All rights reserved.
70335640Shselasky *
71335640Shselasky * Redistribution and use in source and binary forms, with or without
72335640Shselasky * modification, are permitted provided that: (1) source code distributions
73335640Shselasky * retain the above copyright notice and this paragraph in its entirety, (2)
74335640Shselasky * distributions including binary code include the above copyright notice and
75335640Shselasky * this paragraph in its entirety in the documentation or other materials
76335640Shselasky * provided with the distribution, and (3) all advertising materials mentioning
77335640Shselasky * features or use of this software display the following acknowledgement:
78335640Shselasky * ``This product includes software developed by the University of California,
79335640Shselasky * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
80335640Shselasky * the University nor the names of its contributors may be used to endorse
81335640Shselasky * or promote products derived from this software without specific prior
82335640Shselasky * written permission.
83335640Shselasky * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
84335640Shselasky * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
85335640Shselasky * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
86335640Shselasky */
87335640Shselasky
88335640Shselasky#include <ctype.h>
89335640Shselasky#include <string.h>
90335640Shselasky
91335640Shselasky#include "pcap-int.h"
92335640Shselasky
93335640Shselasky#include "gencode.h"
94335640Shselasky
95335640Shselasky#include "grammar.h"
96335640Shselasky
97335640Shselasky/*
98335640Shselasky * Earlier versions of Flex don't declare these, so we declare them
99335640Shselasky * ourselves to squelch warnings.
100335640Shselasky */
101335640Shselaskyint pcap_get_column(yyscan_t);
102335640Shselaskyvoid pcap_set_column(int, yyscan_t);
103335640Shselasky
104335640Shselasky#ifdef INET6
105335640Shselasky
106335640Shselasky#ifdef _WIN32
107335640Shselasky#include <winsock2.h>
108335640Shselasky#include <ws2tcpip.h>
109335640Shselasky/*
110335640Shselasky * To quote the MSDN page for getaddrinfo() at
111335640Shselasky *
112335640Shselasky *    https://msdn.microsoft.com/en-us/library/windows/desktop/ms738520(v=vs.85).aspx
113335640Shselasky *
114335640Shselasky * "Support for getaddrinfo on Windows 2000 and older versions
115335640Shselasky * The getaddrinfo function was added to the Ws2_32.dll on Windows XP and
116335640Shselasky * later. To execute an application that uses this function on earlier
117335640Shselasky * versions of Windows, then you need to include the Ws2tcpip.h and
118335640Shselasky * Wspiapi.h files. When the Wspiapi.h include file is added, the
119335640Shselasky * getaddrinfo function is defined to the WspiapiGetAddrInfo inline
120335640Shselasky * function in the Wspiapi.h file. At runtime, the WspiapiGetAddrInfo
121335640Shselasky * function is implemented in such a way that if the Ws2_32.dll or the
122335640Shselasky * Wship6.dll (the file containing getaddrinfo in the IPv6 Technology
123335640Shselasky * Preview for Windows 2000) does not include getaddrinfo, then a
124335640Shselasky * version of getaddrinfo is implemented inline based on code in the
125335640Shselasky * Wspiapi.h header file. This inline code will be used on older Windows
126335640Shselasky * platforms that do not natively support the getaddrinfo function."
127335640Shselasky *
128335640Shselasky * We use getaddrinfo(), so we include Wspiapi.h here.
129335640Shselasky */
130335640Shselasky#include <wspiapi.h>
131335640Shselasky#else /* _WIN32 */
132335640Shselasky#include <sys/socket.h>	/* for "struct sockaddr" in "struct addrinfo" */
133335640Shselasky#include <netdb.h>	/* for "struct addrinfo" */
134335640Shselasky#endif /* _WIN32 */
135335640Shselasky
136335640Shselasky/* Workaround for AIX 4.3 */
137335640Shselasky#if !defined(AI_NUMERICHOST)
138335640Shselasky#define AI_NUMERICHOST 0x04
139335640Shselasky#endif
140335640Shselasky
141335640Shselasky#endif /*INET6*/
142335640Shselasky
143335640Shselasky#include <pcap/namedb.h>
144335640Shselasky#include "grammar.h"
145335640Shselasky
146335640Shselasky#ifdef HAVE_OS_PROTO_H
147335640Shselasky#include "os-proto.h"
148335640Shselasky#endif
149335640Shselasky
150335640Shselaskystatic int stoi(char *);
151335640Shselaskystatic inline int xdtoi(int);
152335640Shselasky
153335640Shselasky/*
154335640Shselasky * Disable diagnostics in the code generated by Flex.
155335640Shselasky */
156335640ShselaskyDIAG_OFF_FLEX
157335640Shselasky
158335640Shselasky%}
159335640Shselasky
160335640ShselaskyN		([0-9]+|(0X|0x)[0-9A-Fa-f]+)
161335640ShselaskyB		([0-9A-Fa-f][0-9A-Fa-f]?)
162335640ShselaskyB2		([0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f])
163335640ShselaskyW		([0-9A-Fa-f][0-9A-Fa-f]?[0-9A-Fa-f]?[0-9A-Fa-f]?)
164335640Shselasky
165335640Shselasky%a 18400
166335640Shselasky%o 21500
167335640Shselasky%e 7600
168335640Shselasky%k 4550
169335640Shselasky%p 27600
170335640Shselasky%n 2000
171335640Shselasky
172335640ShselaskyV680		{W}:{W}:{W}:{W}:{W}:{W}:{W}:{W}
173335640Shselasky
174335640ShselaskyV670		::{W}:{W}:{W}:{W}:{W}:{W}:{W}
175335640ShselaskyV671		{W}::{W}:{W}:{W}:{W}:{W}:{W}
176335640ShselaskyV672		{W}:{W}::{W}:{W}:{W}:{W}:{W}
177335640ShselaskyV673		{W}:{W}:{W}::{W}:{W}:{W}:{W}
178335640ShselaskyV674		{W}:{W}:{W}:{W}::{W}:{W}:{W}
179335640ShselaskyV675		{W}:{W}:{W}:{W}:{W}::{W}:{W}
180335640ShselaskyV676		{W}:{W}:{W}:{W}:{W}:{W}::{W}
181335640ShselaskyV677		{W}:{W}:{W}:{W}:{W}:{W}:{W}::
182335640Shselasky
183335640ShselaskyV660		::{W}:{W}:{W}:{W}:{W}:{W}
184335640ShselaskyV661		{W}::{W}:{W}:{W}:{W}:{W}
185335640ShselaskyV662		{W}:{W}::{W}:{W}:{W}:{W}
186335640ShselaskyV663		{W}:{W}:{W}::{W}:{W}:{W}
187335640ShselaskyV664		{W}:{W}:{W}:{W}::{W}:{W}
188335640ShselaskyV665		{W}:{W}:{W}:{W}:{W}::{W}
189335640ShselaskyV666		{W}:{W}:{W}:{W}:{W}:{W}::
190335640Shselasky
191335640ShselaskyV650		::{W}:{W}:{W}:{W}:{W}
192335640ShselaskyV651		{W}::{W}:{W}:{W}:{W}
193335640ShselaskyV652		{W}:{W}::{W}:{W}:{W}
194335640ShselaskyV653		{W}:{W}:{W}::{W}:{W}
195335640ShselaskyV654		{W}:{W}:{W}:{W}::{W}
196335640ShselaskyV655		{W}:{W}:{W}:{W}:{W}::
197335640Shselasky
198335640ShselaskyV640		::{W}:{W}:{W}:{W}
199335640ShselaskyV641		{W}::{W}:{W}:{W}
200335640ShselaskyV642		{W}:{W}::{W}:{W}
201335640ShselaskyV643		{W}:{W}:{W}::{W}
202335640ShselaskyV644		{W}:{W}:{W}:{W}::
203335640Shselasky
204335640ShselaskyV630		::{W}:{W}:{W}
205335640ShselaskyV631		{W}::{W}:{W}
206335640ShselaskyV632		{W}:{W}::{W}
207335640ShselaskyV633		{W}:{W}:{W}::
208335640Shselasky
209335640ShselaskyV620		::{W}:{W}
210335640ShselaskyV621		{W}::{W}
211335640ShselaskyV622		{W}:{W}::
212335640Shselasky
213335640ShselaskyV610		::{W}
214335640ShselaskyV611		{W}::
215335640Shselasky
216335640ShselaskyV600		::
217335640Shselasky
218335640ShselaskyV6604		{W}:{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
219335640Shselasky
220335640ShselaskyV6504		::{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
221335640ShselaskyV6514		{W}::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
222335640ShselaskyV6524		{W}:{W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
223335640ShselaskyV6534		{W}:{W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
224335640ShselaskyV6544		{W}:{W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
225335640ShselaskyV6554		{W}:{W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
226335640Shselasky
227335640ShselaskyV6404		::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
228335640ShselaskyV6414		{W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
229335640ShselaskyV6424		{W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
230335640ShselaskyV6434		{W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
231335640ShselaskyV6444		{W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
232335640Shselasky
233335640ShselaskyV6304		::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
234335640ShselaskyV6314		{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
235335640ShselaskyV6324		{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
236335640ShselaskyV6334		{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
237335640Shselasky
238335640ShselaskyV6204		::{W}:{W}:{N}\.{N}\.{N}\.{N}
239335640ShselaskyV6214		{W}::{W}:{N}\.{N}\.{N}\.{N}
240335640ShselaskyV6224		{W}:{W}::{N}\.{N}\.{N}\.{N}
241335640Shselasky
242335640ShselaskyV6104		::{W}:{N}\.{N}\.{N}\.{N}
243335640ShselaskyV6114		{W}::{N}\.{N}\.{N}\.{N}
244335640Shselasky
245335640ShselaskyV6004		::{N}\.{N}\.{N}\.{N}
246335640Shselasky
247335640Shselasky
248335640ShselaskyV6		({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})
249335640Shselasky
250335640ShselaskyMAC		({B}:{B}:{B}:{B}:{B}:{B}|{B}\-{B}\-{B}\-{B}\-{B}\-{B}|{B}\.{B}\.{B}\.{B}\.{B}\.{B}|{B2}\.{B2}\.{B2}|{B2}{3})
251335640Shselasky
252335640Shselasky
253335640Shselasky
254335640Shselasky%%
255335640Shselaskydst		return DST;
256335640Shselaskysrc		return SRC;
257335640Shselasky
258335640Shselaskylink|ether|ppp|slip  return LINK;
259335640Shselaskyfddi|tr|wlan	return LINK;
260335640Shselaskyarp		return ARP;
261335640Shselaskyrarp		return RARP;
262335640Shselaskyip		return IP;
263335640Shselaskysctp		return SCTP;
264335640Shselaskytcp		return TCP;
265335640Shselaskyudp		return UDP;
266335640Shselaskyicmp		return ICMP;
267335640Shselaskyigmp		return IGMP;
268335640Shselaskyigrp		return IGRP;
269335640Shselaskypim		return PIM;
270335640Shselaskyvrrp		return VRRP;
271335640Shselaskycarp		return CARP;
272335640Shselaskyradio		return RADIO;
273335640Shselasky
274335640Shselaskyip6		return IPV6;
275335640Shselaskyicmp6		return ICMPV6;
276335640Shselaskyah		return AH;
277335640Shselaskyesp		return ESP;
278335640Shselasky
279335640Shselaskyatalk		return ATALK;
280335640Shselaskyaarp		return AARP;
281335640Shselaskydecnet		return DECNET;
282335640Shselaskylat		return LAT;
283335640Shselaskysca		return SCA;
284335640Shselaskymoprc		return MOPRC;
285335640Shselaskymopdl		return MOPDL;
286335640Shselasky
287335640Shselaskyiso		return ISO;
288335640Shselaskyesis		return ESIS;
289335640Shselaskyes-is		return ESIS;
290335640Shselaskyisis		return ISIS;
291335640Shselaskyis-is		return ISIS;
292335640Shselaskyl1              return L1;
293335640Shselaskyl2              return L2;
294335640Shselaskyiih             return IIH;
295335640Shselaskylsp             return LSP;
296335640Shselaskysnp             return SNP;
297335640Shselaskycsnp            return CSNP;
298335640Shselaskypsnp            return PSNP;
299335640Shselasky
300335640Shselaskyclnp		return CLNP;
301335640Shselasky
302335640Shselaskystp		return STP;
303335640Shselasky
304335640Shselaskyipx		return IPX;
305335640Shselasky
306335640Shselaskynetbeui		return NETBEUI;
307335640Shselasky
308335640Shselaskyhost		return HOST;
309335640Shselaskynet		return NET;
310335640Shselaskymask		return NETMASK;
311335640Shselaskyport		return PORT;
312335640Shselaskyportrange	return PORTRANGE;
313335640Shselaskyproto		return PROTO;
314356341Scyprotochain	return PROTOCHAIN;
315335640Shselasky
316335640Shselaskygateway		return GATEWAY;
317335640Shselasky
318335640Shselaskytype		return TYPE;
319335640Shselaskysubtype		return SUBTYPE;
320335640Shselaskydirection|dir	return DIR;
321335640Shselaskyaddress1|addr1	return ADDR1;
322335640Shselaskyaddress2|addr2	return ADDR2;
323335640Shselaskyaddress3|addr3	return ADDR3;
324335640Shselaskyaddress4|addr4	return ADDR4;
325335640Shselaskyra		return RA;
326335640Shselaskyta		return TA;
327335640Shselasky
328335640Shselaskyless		return LESS;
329335640Shselaskygreater		return GREATER;
330335640Shselaskybyte		return CBYTE;
331335640Shselaskybroadcast	return TK_BROADCAST;
332335640Shselaskymulticast	return TK_MULTICAST;
333335640Shselasky
334335640Shselaskyand|"&&"	return AND;
335335640Shselaskyor|"||"		return OR;
336335640Shselaskynot		return '!';
337335640Shselasky
338335640Shselaskylen|length	return LEN;
339335640Shselaskyinbound		return INBOUND;
340335640Shselaskyoutbound	return OUTBOUND;
341335640Shselasky
342335640Shselaskyvlan		return VLAN;
343335640Shselaskympls		return MPLS;
344335640Shselaskypppoed		return PPPOED;
345335640Shselaskypppoes		return PPPOES;
346335640Shselaskygeneve		return GENEVE;
347335640Shselasky
348335640Shselaskylane		return LANE;
349335640Shselaskyllc		return LLC;
350335640Shselaskymetac		return METAC;
351335640Shselaskybcc		return BCC;
352335640Shselaskyoam		return OAM;
353335640Shselaskyoamf4		return OAMF4;
354335640Shselaskyoamf4ec		return OAMF4EC;
355335640Shselaskyoamf4sc		return OAMF4SC;
356335640Shselaskysc		return SC;
357335640Shselaskyilmic		return ILMIC;
358335640Shselaskyvpi		return VPI;
359335640Shselaskyvci		return VCI;
360335640Shselaskyconnectmsg	return CONNECTMSG;
361335640Shselaskymetaconnect	return METACONNECT;
362335640Shselasky
363335640Shselaskyon|ifname	return PF_IFNAME;
364335640Shselaskyrset|ruleset	return PF_RSET;
365335640Shselaskyrnr|rulenum	return PF_RNR;
366335640Shselaskysrnr|subrulenum	return PF_SRNR;
367335640Shselaskyreason		return PF_REASON;
368335640Shselaskyaction		return PF_ACTION;
369335640Shselasky
370335640Shselaskyfisu		return FISU;
371335640Shselaskylssu		return LSSU;
372335640Shselaskylsu		return LSSU;
373335640Shselaskymsu		return MSU;
374335640Shselaskyhfisu		return HFISU;
375335640Shselaskyhlssu		return HLSSU;
376335640Shselaskyhmsu		return HMSU;
377335640Shselaskysio		return SIO;
378335640Shselaskyopc		return OPC;
379335640Shselaskydpc		return DPC;
380335640Shselaskysls		return SLS;
381335640Shselaskyhsio		return HSIO;
382335640Shselaskyhopc		return HOPC;
383335640Shselaskyhdpc		return HDPC;
384335640Shselaskyhsls		return HSLS;
385335640Shselasky
386335640Shselasky[ \r\n\t]		;
387335640Shselasky[+\-*/%:\[\]!<>()&|\^=]	return yytext[0];
388335640Shselasky">="			return GEQ;
389335640Shselasky"<="			return LEQ;
390335640Shselasky"!="			return NEQ;
391335640Shselasky"=="			return '=';
392335640Shselasky"<<"			return LSH;
393335640Shselasky">>"			return RSH;
394356341Scy${B}			{ yylval->s = sdup(yyextra, yytext); return AID; }
395356341Scy{MAC}			{ yylval->s = sdup(yyextra, yytext); return EID; }
396335640Shselasky{N}			{ yylval->i = stoi((char *)yytext); return NUM; }
397335640Shselasky({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N})	{
398335640Shselasky			yylval->s = sdup(yyextra, (char *)yytext); return HID; }
399335640Shselasky{V6}			{
400335640Shselasky#ifdef INET6
401335640Shselasky			  struct addrinfo hints, *res;
402335640Shselasky			  memset(&hints, 0, sizeof(hints));
403335640Shselasky			  hints.ai_family = AF_INET6;
404335640Shselasky			  hints.ai_flags = AI_NUMERICHOST;
405356341Scy			  if (getaddrinfo(yytext, NULL, &hints, &res)) {
406356341Scy				bpf_set_error(yyextra, "bogus IPv6 address %s", yytext);
407356341Scy				yylval->s = NULL;
408356341Scy			  } else {
409335640Shselasky				freeaddrinfo(res);
410356341Scy				yylval->s = sdup(yyextra, (char *)yytext);
411335640Shselasky			  }
412335640Shselasky#else
413356341Scy			  bpf_set_error(yyextra, "IPv6 address %s not supported", yytext);
414356341Scy			  yylval->s = NULL;
415335640Shselasky#endif /*INET6*/
416356341Scy			  return HID6;
417335640Shselasky			}
418356341Scy{B}:+({B}:+)+		{ bpf_set_error(yyextra, "bogus ethernet address %s", yytext); yylval->s = NULL; return EID; }
419335640Shselaskyicmptype		{ yylval->i = 0; return NUM; }
420335640Shselaskyicmpcode		{ yylval->i = 1; return NUM; }
421335640Shselaskyicmp-echoreply		{ yylval->i = 0; return NUM; }
422335640Shselaskyicmp-unreach		{ yylval->i = 3; return NUM; }
423335640Shselaskyicmp-sourcequench	{ yylval->i = 4; return NUM; }
424335640Shselaskyicmp-redirect		{ yylval->i = 5; return NUM; }
425335640Shselaskyicmp-echo		{ yylval->i = 8; return NUM; }
426335640Shselaskyicmp-routeradvert	{ yylval->i = 9; return NUM; }
427335640Shselaskyicmp-routersolicit	{ yylval->i = 10; return NUM; }
428335640Shselaskyicmp-timxceed		{ yylval->i = 11; return NUM; }
429335640Shselaskyicmp-paramprob		{ yylval->i = 12; return NUM; }
430335640Shselaskyicmp-tstamp		{ yylval->i = 13; return NUM; }
431335640Shselaskyicmp-tstampreply	{ yylval->i = 14; return NUM; }
432335640Shselaskyicmp-ireq		{ yylval->i = 15; return NUM; }
433335640Shselaskyicmp-ireqreply		{ yylval->i = 16; return NUM; }
434335640Shselaskyicmp-maskreq		{ yylval->i = 17; return NUM; }
435335640Shselaskyicmp-maskreply		{ yylval->i = 18; return NUM; }
436335640Shselasky
437335640Shselaskyicmp6type       { yylval->i = 0; return NUM; }
438335640Shselaskyicmp6code       { yylval->i = 1; return NUM; }
439335640Shselasky
440335640Shselaskyicmp6-echo      { yylval->i = 128; return NUM; }
441335640Shselaskyicmp6-echoreply { yylval->i = 129; return NUM; }
442335640Shselaskyicmp6-multicastlistenerquery    { yylval->i = 130; return NUM; }
443335640Shselaskyicmp6-multicastlistenerreportv1 { yylval->i = 131; return NUM; }
444335640Shselaskyicmp6-multicastlistenerdone     { yylval->i = 132; return NUM; }
445335640Shselaskyicmp6-routersolicit   { yylval->i = 133; return NUM; }
446335640Shselaskyicmp6-routeradvert    { yylval->i = 134; return NUM; }
447335640Shselaskyicmp6-neighborsolicit { yylval->i = 135; return NUM; }
448335640Shselaskyicmp6-neighboradvert  { yylval->i = 136; return NUM; }
449335640Shselaskyicmp6-redirect    { yylval->i = 137; return NUM; }
450335640Shselaskyicmp6-routerrenum { yylval->i = 138; return NUM; }
451335640Shselaskyicmp6-nodeinformationquery      { yylval->i = 139; return NUM; }
452335640Shselaskyicmp6-nodeinformationresponse   { yylval->i = 140; return NUM; }
453335640Shselaskyicmp6-ineighbordiscoverysolicit { yylval->i = 141; return NUM; }
454335640Shselaskyicmp6-ineighbordiscoveryadvert  { yylval->i = 142; return NUM; }
455335640Shselaskyicmp6-multicastlistenerreportv2 { yylval->i = 143; return NUM; }
456335640Shselaskyicmp6-homeagentdiscoveryrequest { yylval->i = 144; return NUM; }
457335640Shselaskyicmp6-homeagentdiscoveryreply   { yylval->i = 145; return NUM; }
458335640Shselaskyicmp6-mobileprefixsolicit       { yylval->i = 146; return NUM; }
459335640Shselaskyicmp6-mobileprefixadvert        { yylval->i = 147; return NUM; }
460335640Shselaskyicmp6-certpathsolicit           { yylval->i = 148; return NUM; }
461335640Shselaskyicmp6-certpathadvert            { yylval->i = 149; return NUM; }
462335640Shselaskyicmp6-multicastrouteradvert     { yylval->i = 151; return NUM; }
463335640Shselaskyicmp6-multicastroutersolicit    { yylval->i = 152; return NUM; }
464335640Shselaskyicmp6-multicastrouterterm       { yylval->i = 153; return NUM; }
465335640Shselasky
466335640Shselaskytcpflags		{ yylval->i = 13; return NUM; }
467335640Shselaskytcp-fin			{ yylval->i = 0x01; return NUM; }
468335640Shselaskytcp-syn			{ yylval->i = 0x02; return NUM; }
469335640Shselaskytcp-rst			{ yylval->i = 0x04; return NUM; }
470335640Shselaskytcp-push		{ yylval->i = 0x08; return NUM; }
471335640Shselaskytcp-ack			{ yylval->i = 0x10; return NUM; }
472335640Shselaskytcp-urg			{ yylval->i = 0x20; return NUM; }
473335640Shselaskytcp-ece			{ yylval->i = 0x40; return NUM; }
474335640Shselaskytcp-cwr			{ yylval->i = 0x80; return NUM; }
475335640Shselasky[A-Za-z0-9]([-_.A-Za-z0-9]*[.A-Za-z0-9])? {
476335640Shselasky			 yylval->s = sdup(yyextra, (char *)yytext); return ID; }
477335640Shselasky"\\"[^ !()\n\t]+	{ yylval->s = sdup(yyextra, (char *)yytext + 1); return ID; }
478356341Scy.			{ return LEX_ERROR; }
479335640Shselasky%%
480335640Shselasky
481335640Shselasky/*
482335640Shselasky * Turn diagnostics back on, so we check the code that we've written.
483335640Shselasky */
484335640ShselaskyDIAG_ON_FLEX
485335640Shselasky
486335640Shselasky/* Hex digit to integer. */
487335640Shselaskystatic inline int
488335640Shselaskyxdtoi(int c)
489335640Shselasky{
490335640Shselasky	if (isdigit(c))
491335640Shselasky		return c - '0';
492335640Shselasky	else if (islower(c))
493335640Shselasky		return c - 'a' + 10;
494335640Shselasky	else
495335640Shselasky		return c - 'A' + 10;
496335640Shselasky}
497335640Shselasky
498335640Shselasky/*
499335640Shselasky * Convert string to integer.  Just like atoi(), but checks for
500335640Shselasky * preceding 0x or 0 and uses hex or octal instead of decimal.
501335640Shselasky */
502335640Shselaskystatic int
503335640Shselaskystoi(char *s)
504335640Shselasky{
505335640Shselasky	int base = 10;
506335640Shselasky	int n = 0;
507335640Shselasky
508335640Shselasky	if (*s == '0') {
509335640Shselasky		if (s[1] == 'x' || s[1] == 'X') {
510335640Shselasky			s += 2;
511335640Shselasky			base = 16;
512335640Shselasky		}
513335640Shselasky		else {
514335640Shselasky			base = 8;
515335640Shselasky			s += 1;
516335640Shselasky		}
517335640Shselasky	}
518335640Shselasky	while (*s)
519335640Shselasky		n = n * base + xdtoi(*s++);
520335640Shselasky
521335640Shselasky	return n;
522335640Shselasky}
523