diff options
author | Michael Mann <mmann78@netscape.net> | 2014-03-18 13:21:51 -0400 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2014-03-19 05:04:54 +0000 |
commit | 04d950130624c14ac8af39c621f69851d8088ed6 (patch) | |
tree | ec315eb356b27def24a385b7b5aa8bdf72529b11 /wiretap/file_wrappers.c | |
parent | d832cb18db4e152177cf13673385288987ba9448 (diff) |
Add capture file reader/writer support for Lua so scripts can implement new capture file formats.
This enables a Lua script to implement a brand new capture file format reader/writer, so that for example one could write a script to read from vendor-specific "logs" of packets, and show them as normal packets in wireshark.
Change-Id: Id394edfffa94529f39789844c382b7ab6cc2d814
Reviewed-on: https://code.wireshark.org/review/431
Reviewed-by: Hadriel Kaplan <hadrielk@yahoo.com>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'wiretap/file_wrappers.c')
-rw-r--r-- | wiretap/file_wrappers.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/wiretap/file_wrappers.c b/wiretap/file_wrappers.c index 1bfccf0570..0f30493ee6 100644 --- a/wiretap/file_wrappers.c +++ b/wiretap/file_wrappers.c @@ -1208,6 +1208,53 @@ file_read(void *buf, unsigned int len, FILE_T file) } /* + * XXX - this *peeks* at next byte, not a character. + */ +int +file_peekc(FILE_T file) +{ + int ret = 0; + + /* check that we're reading and that there's no error */ + if (file->err) + return -1; + + /* try output buffer (no need to check for skip request) */ + if (file->have) { + return *(file->next); + } + + /* process a skip request */ + if (file->seek_pending) { + file->seek_pending = FALSE; + if (gz_skip(file, file->skip) == -1) + return -1; + } + /* if we processed a skip request, there may be data in the buffer, + * or an error could have occured; likewise if we didn't do seek but + * now call fill_out_buffer, the errors can occur. So we do this while + * loop to check before and after - this is basically the logic from + * file_read() but only for peeking not consuming a byte + */ + while (1) { + if (file->have) { + return *(file->next); + } + else if (file->err) { + return -1; + } + else if (file->eof && file->avail_in == 0) { + return -1; + } + else if (fill_out_buffer(file) == -1) { + return -1; + } + } + /* it's actually impossible to get here */ + return ret; +} + +/* * XXX - this gets a byte, not a character. */ int |