]> The Tcpdump Group git mirrors - libpcap/blob - scanner.l
Fixup indentation in init_linktype().
[libpcap] / scanner.l
1 %top {
2 /* Must come first for _LARGE_FILE_API on AIX. */
3 #include <config.h>
4
5 /*
6 * Must come first to avoid warnings on Windows.
7 *
8 * Flex-generated scanners may only include <inttypes.h> if __STDC_VERSION__
9 * is defined with a value >= 199901, meaning "full C99", and MSVC may not
10 * define it with that value, because it isn't 100% C99-compliant, even
11 * though it has an <inttypes.h> capable of defining everything the Flex
12 * scanner needs.
13 *
14 * We, however, will include it if we know we have an MSVC version that has
15 * it; this means that we may define the INTn_MAX and UINTn_MAX values in
16 * scanner.c, and then include <stdint.h>, which may define them differently
17 * (same value, but different string of characters), causing compiler warnings.
18 *
19 * If we include it here, and they're defined, that'll prevent scanner.c
20 * from defining them. So we include <pcap/pcap-inttypes.h>, to get
21 * <inttypes.h> if we have it.
22 */
23 #include <pcap/pcap-inttypes.h>
24
25 /*
26 * grammar.h requires gencode.h and sometimes breaks in a polluted namespace
27 * (see ftmacros.h), so include it early.
28 */
29 #include "gencode.h"
30 #include "grammar.h"
31
32 #include "diag-control.h"
33
34 /*
35 * Convert string to 32-bit unsigned integer; the string starts at
36 * string and is string_len bytes long.
37 *
38 * On success, sets *val to the value and returns 1.
39 * On failure, sets the BPF error string and returns 0.
40 *
41 * Also used in gencode.c
42 */
43 typedef enum {
44 STOULEN_OK,
45 STOULEN_NOT_HEX_NUMBER,
46 STOULEN_NOT_OCTAL_NUMBER,
47 STOULEN_NOT_DECIMAL_NUMBER,
48 STOULEN_ERROR
49 } stoulen_ret;
50
51 stoulen_ret stoulen(const char *string, size_t stringlen, bpf_u_int32 *val,
52 compiler_state_t *cstate);
53 }
54
55 /*
56 * We want a reentrant scanner.
57 */
58 %option reentrant
59
60 /*
61 * And we need to pass the compiler state to the scanner.
62 */
63 %option extra-type="compiler_state_t *"
64
65 /*
66 * We don't use input, so don't generate code for it.
67 */
68 %option noinput
69
70 /*
71 * We don't use unput, so don't generate code for it.
72 */
73 %option nounput
74
75 /*
76 * We don't read from the terminal.
77 */
78 %option never-interactive
79
80 /*
81 * We want to stop processing when we get to the end of the input.
82 */
83 %option noyywrap
84
85 /*
86 * We want to generate code that can be used by a reentrant parser
87 * generated by Bison or Berkeley YACC.
88 */
89 %option bison-bridge
90
91 %{
92 /*
93 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
94 * The Regents of the University of California. All rights reserved.
95 *
96 * Redistribution and use in source and binary forms, with or without
97 * modification, are permitted provided that: (1) source code distributions
98 * retain the above copyright notice and this paragraph in its entirety, (2)
99 * distributions including binary code include the above copyright notice and
100 * this paragraph in its entirety in the documentation or other materials
101 * provided with the distribution, and (3) all advertising materials mentioning
102 * features or use of this software display the following acknowledgement:
103 * ``This product includes software developed by the University of California,
104 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
105 * the University nor the names of its contributors may be used to endorse
106 * or promote products derived from this software without specific prior
107 * written permission.
108 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
109 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
110 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
111 */
112
113 #include <string.h>
114
115 #include "pcap-int.h"
116
117 /*
118 * Earlier versions of Flex don't declare these, so we declare them
119 * ourselves to squelch warnings.
120 */
121 int pcap_get_column(yyscan_t);
122 void pcap_set_column(int, yyscan_t);
123
124 #ifdef INET6
125
126 #ifdef _WIN32
127 #include <winsock2.h>
128 #include <ws2tcpip.h>
129 #else /* _WIN32 */
130 #include <sys/socket.h> /* for "struct sockaddr" in "struct addrinfo" */
131 #include <netdb.h> /* for "struct addrinfo" */
132 #endif /* _WIN32 */
133
134 #endif /*INET6*/
135
136 #include <pcap/namedb.h>
137 #include "grammar.h"
138
139 #ifdef HAVE_OS_PROTO_H
140 #include "os-proto.h"
141 #endif
142
143 static int stou(const char *, YYSTYPE *, compiler_state_t *);
144
145 /*
146 * Disable diagnostics in the code generated by Flex.
147 */
148 DIAG_OFF_FLEX
149
150 %}
151
152 N ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
153 B ([0-9A-Fa-f][0-9A-Fa-f]?)
154 B2 ([0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f])
155 W ([0-9A-Fa-f][0-9A-Fa-f]?[0-9A-Fa-f]?[0-9A-Fa-f]?)
156
157 %a 18400
158 %o 21500
159 %e 7600
160 %k 4550
161 %p 27600
162 %n 2000
163
164 V680 {W}:{W}:{W}:{W}:{W}:{W}:{W}:{W}
165
166 V670 ::{W}:{W}:{W}:{W}:{W}:{W}:{W}
167 V671 {W}::{W}:{W}:{W}:{W}:{W}:{W}
168 V672 {W}:{W}::{W}:{W}:{W}:{W}:{W}
169 V673 {W}:{W}:{W}::{W}:{W}:{W}:{W}
170 V674 {W}:{W}:{W}:{W}::{W}:{W}:{W}
171 V675 {W}:{W}:{W}:{W}:{W}::{W}:{W}
172 V676 {W}:{W}:{W}:{W}:{W}:{W}::{W}
173 V677 {W}:{W}:{W}:{W}:{W}:{W}:{W}::
174
175 V660 ::{W}:{W}:{W}:{W}:{W}:{W}
176 V661 {W}::{W}:{W}:{W}:{W}:{W}
177 V662 {W}:{W}::{W}:{W}:{W}:{W}
178 V663 {W}:{W}:{W}::{W}:{W}:{W}
179 V664 {W}:{W}:{W}:{W}::{W}:{W}
180 V665 {W}:{W}:{W}:{W}:{W}::{W}
181 V666 {W}:{W}:{W}:{W}:{W}:{W}::
182
183 V650 ::{W}:{W}:{W}:{W}:{W}
184 V651 {W}::{W}:{W}:{W}:{W}
185 V652 {W}:{W}::{W}:{W}:{W}
186 V653 {W}:{W}:{W}::{W}:{W}
187 V654 {W}:{W}:{W}:{W}::{W}
188 V655 {W}:{W}:{W}:{W}:{W}::
189
190 V640 ::{W}:{W}:{W}:{W}
191 V641 {W}::{W}:{W}:{W}
192 V642 {W}:{W}::{W}:{W}
193 V643 {W}:{W}:{W}::{W}
194 V644 {W}:{W}:{W}:{W}::
195
196 V630 ::{W}:{W}:{W}
197 V631 {W}::{W}:{W}
198 V632 {W}:{W}::{W}
199 V633 {W}:{W}:{W}::
200
201 V620 ::{W}:{W}
202 V621 {W}::{W}
203 V622 {W}:{W}::
204
205 V610 ::{W}
206 V611 {W}::
207
208 V600 ::
209
210 V6604 {W}:{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
211
212 V6504 ::{W}:{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
213 V6514 {W}::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
214 V6524 {W}:{W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
215 V6534 {W}:{W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
216 V6544 {W}:{W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
217 V6554 {W}:{W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
218
219 V6404 ::{W}:{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
220 V6414 {W}::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
221 V6424 {W}:{W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
222 V6434 {W}:{W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
223 V6444 {W}:{W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
224
225 V6304 ::{W}:{W}:{W}:{N}\.{N}\.{N}\.{N}
226 V6314 {W}::{W}:{W}:{N}\.{N}\.{N}\.{N}
227 V6324 {W}:{W}::{W}:{N}\.{N}\.{N}\.{N}
228 V6334 {W}:{W}:{W}::{N}\.{N}\.{N}\.{N}
229
230 V6204 ::{W}:{W}:{N}\.{N}\.{N}\.{N}
231 V6214 {W}::{W}:{N}\.{N}\.{N}\.{N}
232 V6224 {W}:{W}::{N}\.{N}\.{N}\.{N}
233
234 V6104 ::{W}:{N}\.{N}\.{N}\.{N}
235 V6114 {W}::{N}\.{N}\.{N}\.{N}
236
237 V6004 ::{N}\.{N}\.{N}\.{N}
238
239
240 V6 ({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})
241
242 MAC ({B}:{B}:{B}:{B}:{B}:{B}|{B}\-{B}\-{B}\-{B}\-{B}\-{B}|{B}\.{B}\.{B}\.{B}\.{B}\.{B}|{B2}\.{B2}\.{B2}|{B2}{3})
243
244
245
246 %%
247 dst return DST;
248 src return SRC;
249
250 link|ether|ppp|slip return LINK;
251 fddi|tr|wlan return LINK;
252 arp return ARP;
253 rarp return RARP;
254 ip return IP;
255 sctp return SCTP;
256 tcp return TCP;
257 udp return UDP;
258 icmp return ICMP;
259 igmp return IGMP;
260 igrp return IGRP;
261 pim return PIM;
262 vrrp return VRRP;
263 carp return CARP;
264 radio return RADIO;
265
266 ip6 return IPV6;
267 icmp6 return ICMPV6;
268 ah return AH;
269 esp return ESP;
270
271 atalk return ATALK;
272 aarp return AARP;
273 decnet return DECNET;
274 lat return LAT;
275 sca return SCA;
276 moprc return MOPRC;
277 mopdl return MOPDL;
278
279 iso return ISO;
280 esis return ESIS;
281 es-is return ESIS;
282 isis return ISIS;
283 is-is return ISIS;
284 l1 return L1;
285 l2 return L2;
286 iih return IIH;
287 lsp return LSP;
288 snp return SNP;
289 csnp return CSNP;
290 psnp return PSNP;
291
292 clnp return CLNP;
293
294 stp return STP;
295
296 ipx return IPX;
297
298 netbeui return NETBEUI;
299
300 host return HOST;
301 net return NET;
302 mask return NETMASK;
303 port return PORT;
304 portrange return PORTRANGE;
305 proto return PROTO;
306 protochain return PROTOCHAIN;
307
308 gateway return GATEWAY;
309
310 type return TYPE;
311 subtype return SUBTYPE;
312 direction|dir return DIR;
313 address1|addr1 return ADDR1;
314 address2|addr2 return ADDR2;
315 address3|addr3 return ADDR3;
316 address4|addr4 return ADDR4;
317 ra return RA;
318 ta return TA;
319
320 less return LESS;
321 greater return GREATER;
322 byte return CBYTE;
323 broadcast return TK_BROADCAST;
324 multicast return TK_MULTICAST;
325
326 and|"&&" return AND;
327 or|"||" return OR;
328 not return '!';
329
330 len|length return LEN;
331 inbound return INBOUND;
332 outbound return OUTBOUND;
333
334 ifindex return IFINDEX;
335
336 vlan return VLAN;
337 mpls return MPLS;
338 pppoed return PPPOED;
339 pppoes return PPPOES;
340 geneve return GENEVE;
341 vxlan return VXLAN;
342
343 lane return LANE;
344 llc return LLC;
345 metac return METAC;
346 bcc return BCC;
347 oam return OAM;
348 oamf4 return OAMF4;
349 oamf4ec return OAMF4EC;
350 oamf4sc return OAMF4SC;
351 sc return SC;
352 ilmic return ILMIC;
353 vpi return VPI;
354 vci return VCI;
355 connectmsg return CONNECTMSG;
356 metaconnect return METACONNECT;
357
358 on|ifname return PF_IFNAME;
359 rset|ruleset return PF_RSET;
360 rnr|rulenum return PF_RNR;
361 srnr|subrulenum return PF_SRNR;
362 reason return PF_REASON;
363 action return PF_ACTION;
364
365 fisu return FISU;
366 lssu return LSSU;
367 lsu return LSSU;
368 msu return MSU;
369 hfisu return HFISU;
370 hlssu return HLSSU;
371 hmsu return HMSU;
372 sio return SIO;
373 opc return OPC;
374 dpc return DPC;
375 sls return SLS;
376 hsio return HSIO;
377 hopc return HOPC;
378 hdpc return HDPC;
379 hsls return HSLS;
380
381 [ \r\n\t] ;
382 [+\-*/%:\[\]!<>()&|\^=] return yytext[0];
383 ">=" return GEQ;
384 "<=" return LEQ;
385 "!=" return NEQ;
386 "==" return '=';
387 "<<" return LSH;
388 ">>" return RSH;
389 ${B} { yylval->s = sdup(yyextra, yytext); return AID; }
390 {MAC} { yylval->s = sdup(yyextra, yytext); return EID; }
391 {N} { return stou(yytext, yylval, yyextra); }
392 ({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
393 yylval->s = sdup(yyextra, (char *)yytext); return HID; }
394 {V6} {
395 #ifdef INET6
396 struct addrinfo hints, *res;
397 memset(&hints, 0, sizeof(hints));
398 hints.ai_family = AF_INET6;
399 hints.ai_flags = AI_NUMERICHOST;
400 if (getaddrinfo(yytext, NULL, &hints, &res)) {
401 bpf_set_error(yyextra, "bogus IPv6 address %s", yytext);
402 yylval->s = NULL;
403 } else {
404 freeaddrinfo(res);
405 yylval->s = sdup(yyextra, (char *)yytext);
406 }
407 #else
408 bpf_set_error(yyextra, "IPv6 address %s not supported", yytext);
409 yylval->s = NULL;
410 #endif /*INET6*/
411 return HID6;
412 }
413 {B}:+({B}:+)+ { bpf_set_error(yyextra, "bogus ethernet address %s", yytext); yylval->s = NULL; return EID; }
414 icmptype { yylval->h = 0; return NUM; }
415 icmpcode { yylval->h = 1; return NUM; }
416 icmp-echoreply { yylval->h = 0; return NUM; }
417 icmp-unreach { yylval->h = 3; return NUM; }
418 icmp-sourcequench { yylval->h = 4; return NUM; }
419 icmp-redirect { yylval->h = 5; return NUM; }
420 icmp-echo { yylval->h = 8; return NUM; }
421 icmp-routeradvert { yylval->h = 9; return NUM; }
422 icmp-routersolicit { yylval->h = 10; return NUM; }
423 icmp-timxceed { yylval->h = 11; return NUM; }
424 icmp-paramprob { yylval->h = 12; return NUM; }
425 icmp-tstamp { yylval->h = 13; return NUM; }
426 icmp-tstampreply { yylval->h = 14; return NUM; }
427 icmp-ireq { yylval->h = 15; return NUM; }
428 icmp-ireqreply { yylval->h = 16; return NUM; }
429 icmp-maskreq { yylval->h = 17; return NUM; }
430 icmp-maskreply { yylval->h = 18; return NUM; }
431
432 icmp6type { yylval->h = 0; return NUM; }
433 icmp6code { yylval->h = 1; return NUM; }
434
435 icmp6-destinationunreach { yylval->h = 1; return NUM; }
436 icmp6-packettoobig { yylval->h = 2; return NUM; }
437 icmp6-timeexceeded { yylval->h = 3; return NUM; }
438 icmp6-parameterproblem { yylval->h = 4; return NUM; }
439 icmp6-echo { yylval->h = 128; return NUM; }
440 icmp6-echoreply { yylval->h = 129; return NUM; }
441 icmp6-multicastlistenerquery { yylval->h = 130; return NUM; }
442 icmp6-multicastlistenerreportv1 { yylval->h = 131; return NUM; }
443 icmp6-multicastlistenerdone { yylval->h = 132; return NUM; }
444 icmp6-routersolicit { yylval->h = 133; return NUM; }
445 icmp6-routeradvert { yylval->h = 134; return NUM; }
446 icmp6-neighborsolicit { yylval->h = 135; return NUM; }
447 icmp6-neighboradvert { yylval->h = 136; return NUM; }
448 icmp6-redirect { yylval->h = 137; return NUM; }
449 icmp6-routerrenum { yylval->h = 138; return NUM; }
450 icmp6-nodeinformationquery { yylval->h = 139; return NUM; }
451 icmp6-nodeinformationresponse { yylval->h = 140; return NUM; }
452 icmp6-ineighbordiscoverysolicit { yylval->h = 141; return NUM; }
453 icmp6-ineighbordiscoveryadvert { yylval->h = 142; return NUM; }
454 icmp6-multicastlistenerreportv2 { yylval->h = 143; return NUM; }
455 icmp6-homeagentdiscoveryrequest { yylval->h = 144; return NUM; }
456 icmp6-homeagentdiscoveryreply { yylval->h = 145; return NUM; }
457 icmp6-mobileprefixsolicit { yylval->h = 146; return NUM; }
458 icmp6-mobileprefixadvert { yylval->h = 147; return NUM; }
459 icmp6-certpathsolicit { yylval->h = 148; return NUM; }
460 icmp6-certpathadvert { yylval->h = 149; return NUM; }
461 icmp6-multicastrouteradvert { yylval->h = 151; return NUM; }
462 icmp6-multicastroutersolicit { yylval->h = 152; return NUM; }
463 icmp6-multicastrouterterm { yylval->h = 153; return NUM; }
464
465 tcpflags { yylval->h = 13; return NUM; }
466 tcp-fin { yylval->h = 0x01; return NUM; }
467 tcp-syn { yylval->h = 0x02; return NUM; }
468 tcp-rst { yylval->h = 0x04; return NUM; }
469 tcp-push { yylval->h = 0x08; return NUM; }
470 tcp-ack { yylval->h = 0x10; return NUM; }
471 tcp-urg { yylval->h = 0x20; return NUM; }
472 tcp-ece { yylval->h = 0x40; return NUM; }
473 tcp-cwr { yylval->h = 0x80; return NUM; }
474 [A-Za-z0-9]([-_.A-Za-z0-9]*[.A-Za-z0-9])? {
475 yylval->s = sdup(yyextra, (char *)yytext); return ID; }
476 "\\"[^ !()\n\t]+ { yylval->s = sdup(yyextra, (char *)yytext + 1); return ID; }
477 . { return LEX_ERROR; }
478 %%
479
480 /*
481 * Turn diagnostics back on, so we check the code that we've written.
482 */
483 DIAG_ON_FLEX
484
485 stoulen_ret
486 stoulen(const char *string, size_t string_len, bpf_u_int32 *val,
487 compiler_state_t *cstate)
488 {
489 bpf_u_int32 n = 0;
490 unsigned int digit;
491 const char *s = string;
492
493 /*
494 * string is guaranteed either to be a string of decimal digits
495 * or 0[xX] followed by a string of hex digits.
496 */
497 if (string_len >= 1 && *s == '0') {
498 if (string_len >= 2 && (s[1] == 'x' || s[1] == 'X')) {
499 /*
500 * Begins with 0x or 0X, so hex.
501 * Guaranteed to be all hex digits following the
502 * prefix, so anything that's not 0-9 or a-f is
503 * A-F.
504 */
505 s += 2; /* skip the prefix */
506 string_len -= 2;
507 while (string_len != 0) {
508 digit = *s++;
509 string_len--;
510 if (digit >= '0' && digit <= '9')
511 digit = digit - '0';
512 else if (digit >= 'a' && digit <= 'f')
513 digit = digit - 'a' + 10;
514 else if (digit >= 'A' && digit <= 'F')
515 digit = digit - 'A' + 10;
516 else {
517 /*
518 * Not a valid hex number.
519 * Don't treat this as an error,
520 * in case the caller wants to
521 * interpret it as something else.
522 */
523 return STOULEN_NOT_HEX_NUMBER;
524 }
525
526 /*
527 * Check for overflow.
528 */
529 if (n > 0xFFFFFFFU) {
530 /*
531 * We have more than 28 bits of
532 * number, and are about to
533 * add 4 more; that won't fit
534 * in 32 bits.
535 */
536 bpf_set_error(cstate,
537 "number %.*s overflows 32 bits",
538 (int)string_len, string);
539 return STOULEN_ERROR;
540 }
541 n = (n << 4) + digit;
542 }
543 } else {
544 /*
545 * Begins with 0, but not 0x or 0X, so octal.
546 * Guaranteed to be all *decimal* digits following
547 * the prefix, so we need to catch 8 and 9 and
548 * report an error.
549 */
550 s += 1;
551 string_len -= 1;
552 while (string_len != 0) {
553 digit = *s++;
554 string_len--;
555 if (digit >= '0' && digit <= '7')
556 digit = digit - '0';
557 else {
558 /*
559 * Not a valid octal number.
560 * Don't treat this as an error,
561 * in case the caller wants to
562 * interpret it as something else.
563 */
564 return STOULEN_NOT_OCTAL_NUMBER;
565 }
566 if (n > 03777777777U) {
567 /*
568 * We have more than 29 bits of
569 * number, and are about to add
570 * 3 more; that won't fit in
571 * 32 bits.
572 */
573 bpf_set_error(cstate,
574 "number %.*s overflows 32 bits",
575 (int)string_len, string);
576 return STOULEN_ERROR;
577 }
578 n = (n << 3) + digit;
579 }
580 }
581 } else {
582 /*
583 * Decimal.
584 */
585 while (string_len != 0) {
586 digit = *s++;
587 string_len--;
588 if (digit >= '0' && digit <= '9')
589 digit = digit - '0';
590 else {
591 /*
592 * Not a valid decimal number.
593 * Don't treat this as an error,
594 * in case the caller wants to
595 * interpret it as something else.
596 */
597 return STOULEN_NOT_DECIMAL_NUMBER;
598 }
599 #define CUTOFF_DEC (0xFFFFFFFFU / 10U)
600 #define CUTLIM_DEC (0xFFFFFFFFU % 10U)
601 if (n > CUTOFF_DEC ||
602 (n == CUTOFF_DEC && digit > CUTLIM_DEC)) {
603 /*
604 * Adding that digit will result in a
605 * number that won't fit in 32 bits.
606 */
607 bpf_set_error(cstate,
608 "number %.*s overflows 32 bits",
609 (int)string_len, string);
610 return STOULEN_ERROR;
611 }
612 n = (n * 10) + digit;
613 }
614 }
615
616 *val = n;
617 return STOULEN_OK;
618 }
619
620 /*
621 * Convert string to 32-bit unsigned integer. Just like atoi(), but checks for
622 * preceding 0x or 0 and uses hex or octal instead of decimal.
623 *
624 * On success, sets yylval->h to the value and returns NUM.
625 * On failure, sets the BPF error string and returns LEX_ERROR, to force
626 * the parse to stop.
627 */
628 static int
629 stou(const char *yytext_arg, YYSTYPE *yylval_arg, compiler_state_t *yyextra_arg)
630 {
631 stoulen_ret ret;
632
633 ret = stoulen(yytext_arg, strlen(yytext_arg), &yylval_arg->h,
634 yyextra_arg);
635 switch (ret) {
636
637 case STOULEN_OK:
638 return NUM;
639
640 case STOULEN_NOT_OCTAL_NUMBER:
641 bpf_set_error(yyextra_arg, "number %s contains non-octal digit",
642 yytext_arg);
643 return LEX_ERROR;
644
645 case STOULEN_NOT_HEX_NUMBER:
646 bpf_set_error(yyextra_arg, "number %s contains non-hex digit",
647 yytext_arg);
648 return LEX_ERROR;
649
650 case STOULEN_NOT_DECIMAL_NUMBER:
651 bpf_set_error(yyextra_arg, "number %s contains non-decimal digit",
652 yytext_arg);
653 return LEX_ERROR;
654
655 case STOULEN_ERROR:
656 /* Error already set. */
657 return LEX_ERROR;
658
659 default:
660 /* Should not happen */
661 bpf_set_error(yyextra_arg, "stoulen returned %d - this should not happen", ret);
662 return LEX_ERROR;
663 }
664 }