Commit Graph

111 Commits

Author SHA1 Message Date
Роман Донченко fc5ebe217f wiretap: Add a file_gets variant that returns a pointer to the NUL terminator
When using file_gets it's very difficult to determine how many characters
were read, because you can't distinguish between an embedded NUL and
a short line (note that the last line in a file may not have an LF at the
end). While it's still possible to do it via prefilling the buffer with
non-zero values, doing that is cumbersome, inefficient and error-prone.
This new function makes the task much easier.

The "p" in the name is meant to be reminiscent of the "p" in stpcpy.

Change-Id: I468d5ee71e3b6289925860651ba61b369301b3c9
Reviewed-on: https://code.wireshark.org/review/27333
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2018-05-07 06:44:24 +00:00
Dario Lombardo 9c11de60de wiretap: zero memory on allocation.
Change-Id: I0801725e2f6b17a5a3d3985b5039fa362694c7c7
Reviewed-on: https://code.wireshark.org/review/25989
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
2018-02-23 06:06:04 +00:00
Dario Lombardo 7650151311 more SPDX convertions.
Change-Id: I6b8404c28b31a81767a3b64ffe9ba96156c4c217
Reviewed-on: https://code.wireshark.org/review/25757
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-02-13 13:57:30 +00:00
Dario Lombardo 8cd389e161 replace SPDX identifier GPL-2.0+ with GPL-2.0-or-later.
The first is deprecated, as per https://spdx.org/licenses/.

Change-Id: I8e21e1d32d09b8b94b93a2dc9fbdde5ffeba6bed
Reviewed-on: https://code.wireshark.org/review/25661
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-02-08 14:57:36 +00:00
Dario Lombardo c440a24b1b wiretap: use SPDX identifiers (partial work).
Change-Id: I28436e003ce7fe31d53e6663f3cc7aca00845e4b
Reviewed-on: https://code.wireshark.org/review/25392
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-01-20 17:23:08 +00:00
Guy Harris 0870d4665d Remove an unnecessary test.
out.next is initialized to point to the beginning of the buffer when a
FILE_T is created, so it won't be null.

Change-Id: Ib29f713ab3c524c9c7d83e8d9f3bef89fde1d5b5
Reviewed-on: https://code.wireshark.org/review/25380
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-01-18 22:13:43 +00:00
Guy Harris ab6d2c6ac3 Don't insist on reading a full buffer from the input file.
Don't loop trying to read a full buffer from the input file.

If you're reading from a file, on UN*X or Windows, you should get the
entire read count unless you're fewer than buffer-size bytes from the
end of the file, in which case you should get what remains in the file.

If you're reading from a pipe, however, that could cause you to block
longer than necessary waiting for a full buffer rather than just for the
next chunk of data from the pipe - which might not be a bufferful, if
the program writing to the file is itself writing less-than-bufferful
chunks, as may be the case in, for example, a pipeline coming from a
live capture and with the intent that TShark display the packets as they
arrive.

While we're at it, if we're trying to do a seek and the seek takes place
within the buffer of uncompressed data, just adjust the position within
that buffer for forward seeks as well as backward seeks; this
substantially reduces the number of ws_lseek64() calls when making a
sequential pass through the file in Wireshark (e.g., running a tap or
filtering the display) and, as we purge the buffer after the
ws_lseek64(), substantically reduces the number of ws_read() calls in
that situation as well.

Have a data structure for a file data buffer, and use it for both the
"input" (compressed data) and "output" (uncompressed data) buffers.
Rename raw_read() to buf_read(), as it reads into a buffer.

Change-Id: I7982b3499a7613a993913a6db887054730764160
Ping-Bug: 14345
Reviewed-on: https://code.wireshark.org/review/25358
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-01-18 05:21:35 +00:00
Guy Harris df9044794a Test explicitly against 0 for integers and NULL for pointers, but not booleans.
That makes it clearer what's being tested, and makes the tests more
consistent, so we're always, not just sometimes, testing that way.

Change-Id: Ifac4a86d16d0652d04db3dec572c11e1335c945d
Reviewed-on: https://code.wireshark.org/review/25318
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-01-15 00:06:07 +00:00
Guy Harris 1d1e511ed9 Add a URL for RFC 1952.
Change-Id: I951829e173ef7a37ea1de7576ff919470e746974
Reviewed-on: https://code.wireshark.org/review/25317
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-01-14 23:47:53 +00:00
Guy Harris 9cc00c5623 Check for gzipped files even if we don't have libz.
If we aren't built with libz, report a new "decompression not supported"
error if the file is gzipped; the problem isn't that it's a new capture
file format we don't support, it's that a *compressed* capture file, in
some format, but we don't support the *compression* format used.

This can be extended if we add support for other compression formats.

Change-Id: I19239525d4e02357e3ca7189996556839af8fce2
Reviewed-on: https://code.wireshark.org/review/25315
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-01-14 21:08:18 +00:00
Guy Harris 71c68662c8 Add lzip to the "other compressed formats" comment.
Change-Id: Ic54840f5ed52387f1fac2296cb251ba521d3a392
Reviewed-on: https://code.wireshark.org/review/25008
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-12-27 02:21:59 +00:00
Guy Harris a9ec1e41b1 Squelch a warning from VS Code Analysis.
It warns that a 32-bit value is being shifted left and then converted to
a 64-bit type; presumably it means "this might overflow and not give you
the result you expect".  That's unlikely to be the case here, as few
UN*X file systems have a recommended I/O block size > 2^30, but we might
as well throw in a cast so the convert-to-a-64-bit-type is done first.

Change-Id: Id6ab11d750d5cf4cc03d060d63edc01b66cd179d
Reviewed-on: https://code.wireshark.org/review/20352
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-03-03 02:54:57 +00:00
Guy Harris 3309c08cd0 When opening the standard output for writing, dup it.
That way, we can close the resulting wtap_dumper the same way we close
any other wtap_dumper, including closing the FD, rather than trying to
do everything *except* closing the FD (which is tricky for a FILE *).

Change-Id: I8cb66e32784d73e598b2e8720a12f9bdab1c6205
Reviewed-on: https://code.wireshark.org/review/19054
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-12-03 22:17:41 +00:00
Guy Harris 48a66835ee Use wtap_read_bytes() to skip over bytes when reading a record.
Allow file_read() to take a null pointer as a buffer argument; a null
argument means "do everything except copy the bytes from the file to the
user buffer".  That means that wtap_read_bytes() and
wtap_read_bytes_or_eof() also support a null pointer as a buffer
argument.

Use wtap_read_bytes() with a null buffer argument rather than
file_skip() to skip forward over data.

This fixes some places where files were mis-identified as ERF files, as
the ERF open heuristics now get a short "read" error if they try to skip
over more bytes than exist in the file.

Change-Id: I4f73499d877c1f582e2bcf9b045034880cb09622
Reviewed-on: https://code.wireshark.org/review/17974
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-09-28 23:45:58 +00:00
João Valverde ecb4dc396e Include ws_diag_control.h in config.h
Change-Id: Ia394071710ecda3b0e6686a51fbca45a8ff20317
Reviewed-on: https://code.wireshark.org/review/14749
Petri-Dish: João Valverde <j@v6e.pt>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: João Valverde <j@v6e.pt>
2016-04-04 23:05:31 +00:00
João Valverde 6f98a0fac3 Rename "libz" to "zlib"
Change-Id: I12f92c983d587c2a4751428cdf299635090c9f0b
Reviewed-on: https://code.wireshark.org/review/14748
Reviewed-by: João Valverde <j@v6e.pt>
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-04-04 06:58:41 +00:00
Joerg Mayer c0e48778b7 Fix some warnings/errors of type
git/epan/dissectors/packet-a21.c:478:25: error: 'item' was marked unused but was used
      [-Werror,-Wused-but-marked-unused]
        proto_item_append_text(item, "%s", val_to_str_const(event_id, a21_event_vals, "Unknown"));
                               ^
Added manual change id because file-jpeg.c forced the use of commit -n

Change-Id: Iffff53d6253758c8454d9583f0a11f317c8390cb
Reviewed-on: https://code.wireshark.org/review/14666
Reviewed-by: Jörg Mayer <jmayer@loplof.de>
2016-03-28 11:43:56 +00:00
Guy Harris 22e5cdbb9b No need for a routine to return a GSList of extensions for compressed files.
Just use the table - or an empty table if we're not including the
compressed file extensions.

Change-Id: I0b3ef3987e1986953f2957c27c84b2ee59b90bc0
Reviewed-on: https://code.wireshark.org/review/13611
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-01-29 21:16:02 +00:00
Guy Harris 2943ac5381 Make zlib API constness-aware, take 2.
ZLIB_CONST must be defined before including zlib.h to expose z_const,
*AND* z_const shouldn't be used unless it's defined, because older
versions of zlib don't define it even if you define ZLIB_CONST.

While we're at it, throw in some DIAG_OFF(cast-qual)/DIAG_ON(cast-qual)
pairs to suppress unavoidable "cast throws away const qualification"
warnings.

The original "make zlib constness-aware" change also removed an
unnecessary include of <zlib.h> from wiretap/wtap.c, so we do that as
well.

Change-Id: I3c5269a8fbc54bbbb4d316544cc7b8fa30614c19
Reviewed-on: https://code.wireshark.org/review/12675
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-12-16 17:58:09 +00:00
Guy Harris 6d60c4d468 Revert "Make zlib API constness-aware"
This reverts commit fb0246c6fd.  That commit assumes that if you define Z_CONST, z_const will be defined; that is *not* the case with older versions of zlib, which don't define z_const under any circumstances.

Change-Id: I6f9b7ea18922799b1aaf94dc2c63120128f2550a
Reviewed-on: https://code.wireshark.org/review/12671
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-12-16 08:59:07 +00:00
João Valverde fb0246c6fd Make zlib API constness-aware
ZLIB_CONST must be defined before including zlib.h to expose 'z_const'.

Change-Id: Ic0dbd59ed3c760dd84ef4546f6ff4d5d3db91519
Reviewed-on: https://code.wireshark.org/review/12547
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2015-12-16 05:40:41 +00:00
Guy Harris 827b7dd756 Skip only the actual file descriptor close when writing to stdout.
Have a "this is stdout" flag for a wtap_dumper, and have "open the
standard output for dumping" routines that set that flag.  When closing
a wtap_dumper, do most of the work regardless of whether we're writing
to the standard output or not (so that everything gets written out) and
only skip the closing of the underlying file descriptor.

Change-Id: I9f7e4d142b3bd598055d806b7ded1cb4c378de8e
Reviewed-on: https://code.wireshark.org/review/11673
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-11-10 10:11:50 +00:00
Guy Harris caa1e87410 Use ws_{read,write,fdopen,close}.
Be more consistent about using the ws_ routines, as we suggest in
README.developer.

In C++ on UN*X, define ws_close as ::close rather than close, so that it
works even in classes with methods or members named "close".

Change-Id: Ide2652229e6b6b4624cbddae0e909a4ea1efa591
Reviewed-on: https://code.wireshark.org/review/11637
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-11-08 10:32:09 +00:00
Guy Harris 9d52712ed8 More unnecessary <stdio.h> includes.
libwiretap no longer uses standard I/O routines to read files; those
includes are left over from when it did.

Change-Id: Ia46c5e24ed25c6bd254cd271746ace539a37e590
Reviewed-on: https://code.wireshark.org/review/11634
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-11-08 01:26:49 +00:00
Guy Harris 0162e54075 Clean up includes of unistd.h, fcntl.h, and sys/stat.h.
Have wsutil/file_util.h include them on UN*X, just as it includes io.h
on Windows, so we can have a rule of "if you do file operations, include
<wsutil/file_util.h> and use the routines in it".

Remove includes of unistd.h, fcntl.h, and sys/stat.h that aren't
necessary (whether because of the addition of them to wsutil/file_util.h
or because they weren't needed in the first place).

Change-Id: Ie241dd74deff284e39a5f690a297dbb6e1dc485f
Reviewed-on: https://code.wireshark.org/review/11619
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-11-07 21:52:23 +00:00
Guy Harris 17ea21f902 Make everything unsigned.
The LHS of the & operation is unsigned; make the RHS unsigned as well.
That squelches a Sun/Oracle C warning.

Change-Id: I6983cc89603a512020b8e8b560c00632de6b2fb3
Reviewed-on: https://code.wireshark.org/review/8363
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-05-09 01:31:01 +00:00
Stig Bjørlykke 39b0c2def0 Wiretap: Added file_seek SEEK_END support.
This is needed for Lua File:seek("end").

Change-Id: I28fb23f2f29ca8083c77bf065db8816e039ae5a1
Reviewed-on: https://code.wireshark.org/review/4722
Reviewed-by: Michal Labedzki <michal.labedzki@tieto.com>
Tested-by: Michal Labedzki <michal.labedzki@tieto.com>
Petri-Dish: Michal Labedzki <michal.labedzki@tieto.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2014-11-19 08:41:34 +00:00
Guy Harris 30742dd7c8 Expand comments.
Change-Id: I92348f98cd04ff0e7fc05e472075315ca0fd260e
Reviewed-on: https://code.wireshark.org/review/4931
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-10-25 23:08:55 +00:00
Guy Harris dbf8024eeb No need to set *err_info if there's no error.
Change-Id: I98ae9ec50e079d48b6247bb208528b7c5ad16027
Reviewed-on: https://code.wireshark.org/review/4564
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-10-08 21:05:05 +00:00
Gerald Combs c303a2ebf5 Make sure we don't dereference a null pointer.
Change-Id: I033c60cdc5b78f4db31903277c659661e0dc5123
Reviewed-on: https://code.wireshark.org/review/4561
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2014-10-08 20:46:20 +00:00
Guy Harris 70ba2f88d1 Set err_info to null for errors that don't have an informaton string.
Change-Id: Ibbcf3496ebfb20c53b953db84b2ddb69083dcb86
Reviewed-on: https://code.wireshark.org/review/4556
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-10-08 18:44:30 +00:00
Michal Labedzki 56a09d24dc Try to fix some buildbot warnings
Most interesting are:
 warning: cannot optimize loop, the loop counter may overflow [-Wunsafe-loop-optimizations]
 warning: ISO C forbids zero-size array [-Wpedantic]
 warning: ISO C90 doesn't support unnamed structs/unions [-Wpedantic]
 warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual
 warning: initializer element is not computable at load time [enabled by default]

Change-Id: I5573c6bdca856a304877d9bef643f8c0fa93cdaf
Reviewed-on: https://code.wireshark.org/review/3174
Petri-Dish: Michal Labedzki <michal.labedzki@tieto.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michal Labedzki <michal.labedzki@tieto.com>
2014-09-22 10:52:03 +00:00
Bill Meier cc286bad25 Various minor changes:
- Create/use some extended value_strings
- Remove unneeded #includes;
- Do whitespace changes;
- Add editor modelines.

Change-Id: I2e1ea37dddfd5e8656c90c0d45a6596c4912bb2c
Reviewed-on: https://code.wireshark.org/review/4065
Reviewed-by: Bill Meier <wmeier@newsguy.com>
2014-09-10 16:17:29 +00:00
Bill Meier 93cc6f004f Fix some spelling & grammar.
Change-Id: Iedeaa411caa0823922dd79c27897a2349d4e6907
Reviewed-on: https://code.wireshark.org/review/4054
Reviewed-by: Bill Meier <wmeier@newsguy.com>
2014-09-09 19:43:27 +00:00
Peter Wu 0492921adc Replace lseek/fstat by ws_lseek64/ws_fstat64
lseek returns an off_t type which is system-dependent. Use ws_lseek64 in
favor of lseek as that supports 64-bit quanities.

Use ws_fstat64 instead of stat to support 64-bit file sizes on Windows.
For the majority of the changes, this makes no difference as they do not
apply to Windows ("ifndef _WIN32"; availability of st_blksize).

There are no other users of "struct stat" besides the portability code
in wsutil. Forbid the use of fstat and lseek in checkAPIs.

Change-Id: I17b930ab9543f21a9d3100f3795d250c9b9ae459
Reviewed-on: https://code.wireshark.org/review/3198
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-07-25 21:26:01 +00:00
Michael Mann 04d9501306 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>
2014-03-19 05:04:54 +00:00
Alexis La Goutte 296591399f Remove all $Id$ from top of file
(Using sed : sed -i '/^ \* \$Id\$/,+1 d')

Fix manually some typo (in export_object_dicom.c and crc16-plain.c)

Change-Id: I4c1ae68d1c4afeace8cb195b53c715cf9e1227a8
Reviewed-on: https://code.wireshark.org/review/497
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-03-04 14:27:33 +00:00
Peter Hatina f62450ff93 allow tshark reading from pipes
Change-Id: If20a14b949667911df44f09c6a705b7645d4c49e
Reviewed-on: https://code.wireshark.org/review/85
Reviewed-by: Evan Huus <eapache@gmail.com>
Tested-by: Evan Huus <eapache@gmail.com>
2014-02-03 13:31:27 +00:00
Martin Kaiser 9f3740b414 simplify file_error()
svn path=/trunk/; revision=52944
2013-10-29 11:04:03 +00:00
Martin Kaiser 5ec452c288 allow err_info==NULL in file_error()
this fixes https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=9309
reported by Peter Wu

svn path=/trunk/; revision=52943
2013-10-29 09:15:02 +00:00
Guy Harris 0751daed8a Don't cast away constness (except where APIs render that impossible).
svn path=/trunk/; revision=50854
2013-07-23 23:34:45 +00:00
Guy Harris 52972f605d Handle operating systems that are anticipating the day when files should
be read in chunks > 2GB.

svn path=/trunk/; revision=50847
2013-07-23 18:34:10 +00:00
Guy Harris e4d65e993f file_skip() only needs to return a Boolean; if anybody cares what the
seek offset is after calling it, they can use file_tell().  (Some
routines were already assuming it returned a gboolean.)

svn path=/trunk/; revision=49733
2013-06-03 23:07:42 +00:00
Anders Broman 089dfcd108 From beroset:
remove C++ incompatibilities 
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8416

svn path=/trunk/; revision=48424
2013-03-19 19:02:25 +00:00
Guy Harris 073e2aa45a Make some Boolean flags gbooleans, rename one of them to more clearly
indicate what it means, and use an enum for the compression types.

Note that file_getc() returns a byte, not a character.

svn path=/trunk/; revision=46983
2013-01-06 20:36:33 +00:00
Guy Harris 40a5e8b991 Clean up comment alignment.
Get rid of unnecessary pointer cast.

svn path=/trunk/; revision=46982
2013-01-06 20:20:35 +00:00
Michael Mann 86d690880f replace "unsigned" datatype with "guint". Some mpeg files needed "unsigned int" instead.
bugs 7825-7827 (https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7825)

svn path=/trunk/; revision=46928
2013-01-04 05:22:43 +00:00
Gerald Combs 7b55219d1a Microsoft CRT's _write expects an unsigned int.
svn path=/trunk/; revision=46684
2012-12-21 18:59:42 +00:00
Guy Harris 14d5511143 Squelch a warning - the code shouldn't ever let "have" get so large that
it exceeds size_t on any platform, including Win64.

svn path=/trunk/; revision=46652
2012-12-21 04:52:15 +00:00
Guy Harris 5996b49c53 Squelch implicit 64-bit-to-32-bit conversion warnings.
svn path=/trunk/; revision=46650
2012-12-21 03:32:16 +00:00