Commit Graph

222 Commits

Author SHA1 Message Date
Evan Huus dae86605b6 Reject pcap files that claim on-the-wire packet sizes > 64MB. This fixes many
heuristic cases broken in r49999 when we permitted packets > 64KB, since that
relaxed so severely the definition of a valid packet header.

64MB is an arbitrary and perhaps suboptimal number, but it seems to do the right
thing in all the examples I have handy.

Fixes https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=9634

svn path=/trunk/; revision=54812
2014-01-15 02:09:11 +00:00
Guy Harris 9d41c658fe No seek-read routines use the length argument, so eliminate it from
wtap_seek_read().

svn path=/trunk/; revision=54570
2014-01-02 20:47:21 +00:00
Jakub Zawadzki d99fdfda63 Replace macros: BSWAP16, BSWAP32, BSWAP64 with glib-version.
XXX, people are not aware that expression of this macros might be evaluated multiple times, like:
 -  BSWAP16(tvb_get_letohs(tvb, off)) : \
 +  GUINT16_SWAP_LE_BE(tvb_get_letohs(tvb, off)) : \

Should be tvb_get_ntohs() called?


svn path=/trunk/; revision=53653
2013-11-29 19:21:20 +00:00
Guy Harris 853da2eb9b The "file types" we have are actually combinations of types and
subtypes, e.g. Network Monitor version 1 and Network Monitor version 2
are separate "file types", even though they both come from Network
Monitor.

Rename various functions, #defines, and variables appropriately.

svn path=/trunk/; revision=53166
2013-11-08 09:53:01 +00:00
Guy Harris 3e8b8f0b1a Explain that we don't have to worry about fixed-length buffers whose
size is based on the snapshot length.

svn path=/trunk/; revision=50647
2013-07-16 00:18:55 +00:00
Evan Huus a39e5b9b4a On the suggestion of Cal Turney, via
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8937

Don't warn if a file has packets larger than the global snapshot length.

svn path=/trunk/; revision=50646
2013-07-15 23:58:47 +00:00
Evan Huus 3f1f630570 Don't limit the on-the-wire length of packets to 64KB, there are larger packets
out there (especially over USB) and we should be able to load them as long as
they are snapped to a sane length.

Also validate that packets do not specify a snapshot length larger than the one
in the file header, though only make it a warning, as this is not necessarily a
fatally corrupt packet.

https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8808

svn path=/trunk/; revision=49999
2013-06-18 01:02:26 +00:00
Guy Harris 32b95570df Merge "read record header" and "read packet data" routines into a single
routine, used both by read and seek-read routines.

svn path=/trunk/; revision=49988
2013-06-17 21:18:47 +00:00
Guy Harris 8c9edf1280 Have the seek-read routines take a Buffer rather than a guint8 pointer
as the "where to put the packet data" argument.

This lets more of the libwiretap code be common between the read and
seek-read code paths, and also allows for more flexibility in the "fill
in the data" path - we can expand the buffer as needed in both cases.

svn path=/trunk/; revision=49949
2013-06-16 00:20:00 +00:00
Jörg Mayer d9dd3f3e4e Fix "set but not used" compile warning turning error
svn path=/trunk/; revision=49405
2013-05-18 08:13:51 +00:00
Guy Harris 3fc0506b41 In libpcap_process_header(), fill in what phdr points to, not wth->phdr.
svn path=/trunk/; revision=49403
2013-05-18 03:15:06 +00:00
Guy Harris 33e1232f23 In the pcapng seek-read routine, *don't* fill in wth->phdr; seek-read
routines are passed a separate struct wtap_pkthdr to be filled in.

Get rid of the pseudo_header member of the wblock structure - the
pseudo-header is part of the struct wtap_pkthdr.

Get rid of the union wtap_pseudo_header * argument to
pcap_process_pseudo_header() - it's passed a pointer to a struct
pcap_pkthdr, and that structure contains the union in question.

Have libpcap_read_header() take a FILE_T argument, rather than using
only the "sequential" handle of the wtap it's handed.  Have the libpcap
read routine return the offset of the beginning of the pcap record, and
have the seek-read routine read the header and fill in the struct
wtap_pkthdr handed to it.

svn path=/trunk/; revision=49401
2013-05-18 02:36:00 +00:00
Evan Huus 202680971d Wiretap file open routines should not free wth->priv on error, since that
leads to a double-free in wtap_close. Fix all the instances I found via
manual code review, and add a brief comment to the list of open routines in
file_access.c

Fixes https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8518

svn path=/trunk/; revision=48552
2013-03-25 22:04:15 +00:00
Guy Harris 88e9d1c1e5 Do not call wtap_file_read_unknown_bytes() or
wtap_file_read_expected_bytes() from an open routine - open routines are
supposed to return -1 on error, 0 if the file doesn't appear to be a
file of the specified type, or 1 if the file does appear to be a file of
the specified type, but those macros will cause the caller to return
FALSE on errors (so that, even if there's an I/O error, it reports "the
file isn't a file of the specified type" rather than "we got an error
trying to read the file").

When doing reads in an open routine before we've concluded that the file
is probably of the right type, return 0, rather than -1, if we get
WTAP_ERR_SHORT_READ - if we don't have enough data to check whether a
file is of a given type, we should keep trying other types, not give up.
For reads done *after* we've concluded the file is probably of the right
type, if a read doesn't return the number of bytes we asked for, but
returns an error of 0, return WTAP_ERR_SHORT_READ - the file is
apparently cut short.

For NetMon and NetXRay/Windows Sniffer files, use a #define for the
magic number size, and use that for both magic numbers.

svn path=/trunk/; revision=46803
2012-12-27 12:19:25 +00:00
Jakub Zawadzki 78631020b8 Add wtap_pseudo_header union to wtap_pkthdr structure.
Use pkthdr instead of pseudo_header as argument for dissecting.

svn path=/trunk/; revision=45601
2012-10-16 21:50:57 +00:00
Jeff Morriss 3551a86c36 We always HAVE_CONFIG_H so don't bother checking whether we have it or not.
svn path=/trunk/; revision=45015
2012-09-20 01:29:52 +00:00
Michael Mann 7184dac548 Addresses https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=3895. Note that this doesn't write a Nokia file type properly, it just doesn't corrupt an existing one (read in by Wireshark) if resaved.
svn path=/trunk/; revision=43815
2012-07-19 01:00:49 +00:00
Jakub Zawadzki bf81b42e1e Update Free Software Foundation address.
(COPYING will be updated in next commit)

svn path=/trunk/; revision=43536
2012-06-28 22:56:06 +00:00
Guy Harris e954e00926 Interface lists currently have to be constructed in the open routine
(otherwise, nobody sees them); do so.

Fix some cases where we weren't doing the proper post-processing after
doing the heuristics for format changes that didn't involve magic-number
changes (discovered because constructing the interface list is now being
done as part of that post-processing).

Fixes bug 7287.

svn path=/trunk/; revision=42872
2012-05-28 00:43:13 +00:00
Anders Broman 8a62ebc28d From Stephen Donnelly:
Add frame.interface_id support for pcap DLT_ERF file format

https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7281

svn path=/trunk/; revision=42824
2012-05-24 09:24:05 +00:00
Guy Harris 33bb54a945 file_seek() used to be a wrapper around fseek() or gzseek(), both of
which could use lseek() and were thus expensive due to system call
overhead.  To avoid making a system call for every packet on a
sequential read, we maintained a data_offset field in the wtap structure
for sequential reads.

It's now a routine that just returns information from the FILE_T data
structure, so it's cheap.  Use it, rather than maintaining the data_offset
field.

Readers for some file formats need to maintain file offset themselves;
have them do so in their private data structures.

svn path=/trunk/; revision=42423
2012-05-04 16:56:18 +00:00
Jakub Zawadzki 8a1dc57c03 Remove doubled semicolons and semicolons outside function.
svn path=/trunk/; revision=42053
2012-04-13 20:22:31 +00:00
Guy Harris b6ff142f60 Add a presence flag field to the packet information structure filled in
by Wiretap, to indicate whether certain fields in that structure
actually have data in them.

Use the "time stamp present" flag to omit showing time stamp information
for packets (and "packets") that don't have time stamps; don't bother
working very hard to "fake" a time stamp for data files.

Use the "interface ID present" flag to omit the interface ID for packets
that don't have an interface ID.

We don't use the "captured length, separate from packet length, present"
flag to omit the captured length; that flag might be present but equal
to the packet length, and if you want to know if a packet was cut short
by a snapshot length, comparing the values would be the way to do that.

More work is needed to have wiretap/pcapng.c properly report the flags,
e.g. reporting no time stamp being present for a Simple Packet Block.

svn path=/trunk/; revision=41185
2012-02-25 23:24:34 +00:00
Guy Harris d94bd07f99 Rename WTAP_ERR_BAD_RECORD to WTAP_ERR_BAD_FILE; it really reports any
form of corruption/bogosity in a file, including in a file header as
well as in records in the file.  Change the error message
wtap_strerror() returns for it to reflect that.

Use it for some file header problems for which it wasn't already being
used - WTAP_ERR_UNSUPPORTED shouldn't be used for that, it should only
be used for files that we have no reason to believe are invalid but that
have a version number we don't know about or some other
non-link-layer-encapsulation-type value we don't know about.

svn path=/trunk/; revision=40175
2011-12-13 09:53:50 +00:00
Guy Harris 6ac265b512 Merge pcap_fill_in_pseudo_header() into pcap_read_post_process().
svn path=/trunk/; revision=38844
2011-09-01 19:58:25 +00:00
Guy Harris e9fc1b72aa Use guint8 rather than guchar for raw octets and pointers to arrays of
same.

Add to wiretap/pcap-common.c a routine to fill in the pseudo-header for
ATM (by looking at the VPI, VCI, and packet data, and guessing) and
Ethernet (setting the FCS length appropriately).  Use it for both pcap
and pcap-ng files.

svn path=/trunk/; revision=38840
2011-09-01 09:43:10 +00:00
Gerald Combs 04f147f4fa Make sure we don't write invalid record lengths.
svn path=/trunk/; revision=37634
2011-06-09 18:31:39 +00:00
Guy Harris 6cbf6ce16c Add a new WTAP_ERR_DECOMPRESS error, and use that for errors discovered
by the gunzipping code.  Have it also supply a err_info string, and
report it.  Have file_error() supply an err_info string.

Put "the file" - or, for WTAP_ERR_DECOMPRESS, "the compressed file", to
suggest a decompression error - into the rawshark and tshark errors,
along the lines of what other programs print.

Fix a case in the Netscaler code where we weren't fetching the error
code on a read failure.

svn path=/trunk/; revision=36748
2011-04-21 09:41:52 +00:00
Guy Harris 2b8ebd389b "This file format can't be written to a pipe" and "this file format
can't be saved in compress form" are both equivalent to "this file file
format requires seeking when writing it".  Change the "can compress"
Boolean in the file format table to "writing requires seeking", give all
the entries the proper value, and do the checks for attempting to write
a file format to a pipe or write it in compressed format to common code.

This means we don't need to pass the "can't seek" flag to the dump open
routines.

svn path=/trunk/; revision=36575
2011-04-12 00:44:44 +00:00
Guy Harris 4c93827e34 From Jakub Zawadzki:
file_read(buf, bsize, count, file) macro is compilant with fread
function and takes elements count+ size of each element, however to make
it compilant with gzread() it always returns number of bytes.

In wiretap file_read() this is not really used, file_read is called
either with bsize set to 1 or count to 1.

Attached patch remove bsize argument from macro.

svn path=/trunk/; revision=36491
2011-04-06 06:51:19 +00:00
Guy Harris 1bf478fdef Rename wtap_dump_file_write_all() to wtap_dump_file_write(), and have
everybody use it; the places using the old wtap_dump_file_write() were
using it in the same way the old wtap_dump_file_write_all() did.

That also lets us get rid of wtap_dump_file_ferror().

Also, have the new wtap_dump_file_write() check for errors from
gzwrite() and fwrite() differently - the former returns 0 on error, the
latter can return a short write on error.

svn path=/trunk/; revision=33113
2010-06-06 19:14:32 +00:00
Guy Harris 21a210b777 From Chris Maynard:
Support PPP-over-USB.

	Don't remove the USB pseudo-header from the packet data for
	Linux USB packets, just byte-swap it if necessary and have the
	USB dissector fetch the pseudo-header from the raw packet data.

	Update USB language ID values.

svn path=/trunk/; revision=32534
2010-04-21 20:51:22 +00:00
Guy Harris 17392a865a Move the definitions of all the private data structures out of
wtap-int.h, and change the unions of pointers to those private data
structures into just void *'s.

Have the generic wtap close routine free up the private data, rather
than the type-specific close routine, just as the wtap_dumper close
routine does for its private data.  Get rid of close routines that don't
do anything any more.

svn path=/trunk/; revision=32015
2010-02-26 07:59:54 +00:00
Guy Harris dde6d97f63 Define the private data structures for some particular capture file
types in the modules for those capture file types, not in wtap-int.h, so
wtap-int.h doesn't have to change when the code to handle that
particular capture type changes, or a new capture file type is added.
(Ultimately, we should do this for all the private data structures.)

svn path=/trunk/; revision=31974
2010-02-24 07:21:17 +00:00
Guy Harris c85899e946 Move the declarations of wtap_pcap_encap_to_wtap_encap() and
wtap_wtap_encap_to_pcap_encap() to wiretap/pcap-encap.h.  Include it
where it's needed; don't include other Wiretap headers where they're not
needed.

Include pcapng.h in pcapng.c, to declare the functions defined in
pcapng.c.  Add some casts to squelch some warnings, and add to a comment
to indicate one of the problems.

svn path=/trunk/; revision=31960
2010-02-23 03:50:42 +00:00
Guy Harris 1c88b1f221 Fix a comment.
svn path=/trunk/; revision=31693
2010-01-27 00:35:32 +00:00
Guy Harris 7be78a2d55 Treat 13 as if it came from OpenBSD except on BSD/OS, so that if there
are any BSD/OS users still out there using Wireshark to read RFC 1483
ATM captures from BSD/OS, they can still do so, but all other users get
to read OpenBSD DLT_ENC captures, not just users *on* OpenBSD.

That also lets us simplify some hacks to deal with a link-layer type of
13 on Nokia IPSO captures.

svn path=/trunk/; revision=30159
2009-09-25 21:55:39 +00:00
Michael Tüxen ce11d99c12 Fix copy/paste error introduced in rev. 28863.
Thanks to Guy for finding and reporting it. 

svn path=/trunk/; revision=28865
2009-06-27 18:10:10 +00:00
Michael Tüxen dce1889fd7 Cleanup. Should be included in Wireshark 1.2.1 and higher to keep
merging future bug fixes simple.

svn path=/trunk/; revision=28863
2009-06-27 16:08:18 +00:00
Michael Tüxen 6ce8546ecd This patch
* adds an encapsulation argument to pcap_write_phdr.
* writes the pseudo header when writing pcapng files.

This fixes a bug where you could not write pcapng files
when using encapsulations requiring pseudo headers.

svn path=/trunk/; revision=28859
2009-06-27 12:41:06 +00:00
Michael Tüxen 267df8e183 This commit
* adds an encap argument to pcap_process_pseudo_header.
* adds support for reading pseudo headers.
It fixes Bug 3560.
Thanks to Tyson Key for reporting the bug and providing
trace files. This fix will be scheduled for inclusion in
Wireshark 1.2.1 and higher.

svn path=/trunk/; revision=28857
2009-06-27 11:39:47 +00:00
Guy Harris 7d5afce08f When doing a seek-and-read, don't check the packet size, as we don't
have it (we have the size with the pseudo-header length already
removed); we've already read the packet, and thus have already checked
it.  Fixes bug 3501.

svn path=/trunk/; revision=28607
2009-06-02 19:06:05 +00:00
Guy Harris a60cae6935 Move pseudo-header routines from libpcap.c to pcap-common.c, for use
with pcap-NG files.

svn path=/trunk/; revision=28184
2009-04-27 19:39:06 +00:00
Guy Harris 18a3b0659c Have the libpcap and pcap-NG code share the LINKTYPE_-to-WTAP_ENCAP_
mapping table - they should be using the same values.  Share the mapping
routines as well.

svn path=/trunk/; revision=28173
2009-04-27 09:28:28 +00:00
Guy Harris ad33ca6c2f Clean up some 64-bit issues.
svn path=/trunk/; revision=28117
2009-04-22 03:07:37 +00:00
Guy Harris f6f84ae1dc Name changes to match libpcap name change of the corresponding DLT_
value.

svn path=/trunk/; revision=27113
2008-12-24 20:18:01 +00:00
Guy Harris d2cbbe0a2a Handle the new DLT_USB_LINUX_MMAP link-layer type.
svn path=/trunk/; revision=27099
2008-12-23 19:50:21 +00:00
Guy Harris 29a7854093 Move wtap_pcap_encap_to_wtap_encap() and wtap_wtap_encap_to_pcap_encap()
back to libwiretap for now, as it's inherently tied to reading libpcap
files; at some point we might want to have pcap-reading (and
pcap-ng-reading?) code in a separate library, for use by, for example,
dumpcap (and rawshark?).

svn path=/trunk/; revision=27076
2008-12-22 00:06:12 +00:00
Gerald Combs 62d20ccfb6 For libpcap captures with the DLT DLT_BLUETOOTH_HCI_H4, make sure we
initialize the P2P direction. This keeps Valgrind from complaining.

svn path=/trunk/; revision=26765
2008-11-13 00:36:52 +00:00
Anders Broman 637761d295 From Francesco Fusco:
Endace ERFII (extension header) support.

svn path=/trunk/; revision=26287
2008-09-29 16:20:24 +00:00