aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/candump_scanner.l
diff options
context:
space:
mode:
authorMaksim Salau <maksim.salau@gmail.com>2019-07-18 21:20:03 +0300
committerAnders Broman <a.broman58@gmail.com>2019-07-20 07:29:33 +0000
commit40e0e5d282daf3b21bc614a64e4e16e289f65768 (patch)
tree845eaae50a8febfb6567f5187724de31536060df /wiretap/candump_scanner.l
parentc43bd0def1aaf6db2febcd008d7e83021ef85427 (diff)
wiretap: candump: Don't generate a temporary PCAP file
It's preferable to parse text files and generate packets on demand, rather than generate a temporary PCAP file and dump all available packets into it. Parsing on the fly has a benefit of handling damaged files up to the point of damage, while the approach with a temporary file doesn't allow either to report that the original file is damaged or perform conversion in the first place. This version works faster than the previous one. Command: time ./run/tshark -r ./candump-2019-07-01_111120.log.gz > /dev/null The test file is attached to the bug 15889 The current version: real 0m0,597s user 0m0,533s sys 0m0,118s The previous version: real 0m2,176s user 0m1,966s sys 0m0,100s Bug: 15889 Change-Id: I862ce47752531c2e9d9459f5d865c1fc08f32fea Reviewed-on: https://code.wireshark.org/review/34007 Petri-Dish: Anders Broman <a.broman58@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'wiretap/candump_scanner.l')
-rw-r--r--wiretap/candump_scanner.l22
1 files changed, 14 insertions, 8 deletions
diff --git a/wiretap/candump_scanner.l b/wiretap/candump_scanner.l
index 98b98ee791..b74f14cc17 100644
--- a/wiretap/candump_scanner.l
+++ b/wiretap/candump_scanner.l
@@ -48,22 +48,28 @@
#define YY_NO_UNISTD_H
#endif
-static int candump_yyinput(void *buf, unsigned int max_size,
- candump_state_t *state)
+static int candump_yyinput(void *buf, candump_state_t *state)
{
- int result = file_read(buf, max_size, state->fh);
+ int c = file_getc(state->fh);
- if (result == EOF)
+ if (c == EOF)
{
state->err = file_error(state->fh, &state->err_info);
- result = YY_NULL;
+ return YY_NULL;
}
- return result;
+ *(char *)buf = c;
+
+ return 1;
}
#define YY_INPUT(buf, result, max_size) \
- do { (result) = candump_yyinput((buf), (max_size), yyextra); } while (0)
+ do { (result) = candump_yyinput((buf), yyextra); } while (0)
+
+/* Count bytes read. This is required in order to rewind the file
+ * to the beginning of the next packet, since flex reads more bytes
+ * before executing the action that does yyterminate(). */
+#define YY_USER_ACTION do { yyextra->file_bytes_read += yyleng; } while (0);
/*
* Sleazy hack to suppress compiler warnings in yy_fatal_error().
@@ -87,7 +93,7 @@ HEX [0-9A-Fa-f]
%%
[ \t] { return TOKEN_SPACE; };
-[\r\n] { return TOKEN_ENDL; }
+[\r\n][ \t\r\n]* { yyterminate(); }
\({INT}+\.{INT}+\) {
yyextra->token.v0 = strtoul(yytext + 1, NULL, 10);