Commit Graph

3721 Commits

Author SHA1 Message Date
Alexis La Goutte a3f9c6bc45 erf: Fix Dead Store (found by Clang Anlyzer)
Although the value stored to 'tagtotallength' is used in the enclosing expression, the value is never actually read from 'tagtotallength'
2021-07-30 20:43:55 +00:00
Guy Harris cb98aa3730 nettrace 3GPP 32.423: move the name related code together.
Initialize name_str right before we fill it in if the name is present,
and note what we're doing, to make it a bit clearer what the
initializing code is doing.
2021-07-25 13:34:11 -07:00
Moshe Kaplan 49ca5fa8ab libwiretap: Avoid using uninit variable
Within wiretap/nettrace_3gpp_32_423.c,
set the first byte of the buffer
to a null byte to avoid potentially
accessing uninitiliazed memory.
Fixes Coverity 1471685.
2021-07-25 17:25:44 +00:00
Gerald Combs 539ad8a91b CMake: Remove unneeded GLIB2_LIBRARIES.
GLib is part of wsutil's link interface, so we don't need to link to it
explictly.
2021-07-21 10:05:21 +00:00
David Perry dc7089e831 Carry drop count/packet ID/queue ID as options on packet block 2021-07-19 21:25:40 +00:00
Gerald Combs 50da270b8a BLF: Fix Win32 compilation issues.
Fix

```
wiretap\blf.c(368,73): error C2220: the following warning is treated as an error [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(368,73): error C2220:         unsigned char *compressed_data = g_try_malloc0(tmp.infile_length); [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(368,73): error C2220:                                                                         ^ [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(368,73): warning C4244: 'function': conversion from 'guint64' to 'gsize', possible loss of data [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(368,73): warning C4244:         unsigned char *compressed_data = g_try_malloc0(tmp.infile_length); [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(368,73): warning C4244:                                                                         ^ [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(375,59): warning C4244: 'function': conversion from 'guint64' to 'gsize', possible loss of data [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(375,59): warning C4244:         unsigned char *buf = g_try_malloc0(tmp.real_length); [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(375,59): warning C4244:                                                           ^ [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(654,23): warning C4018: '<': signed/unsigned mismatch [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(654,23): warning C4018:     if (object_length < (data_start - block_start) + sizeof(blf_ethernetframeheader_t)) { [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(654,23): warning C4018:                       ^ [build\wiretap\wiretap.vcxproj]
  busmaster.c
wiretap\blf.c(733,23): warning C4018: '<': signed/unsigned mismatch [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(733,23): warning C4018:     if (object_length < (data_start - block_start) + sizeof(blf_ethernetframeheader_ex_t)) { [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(733,23): warning C4018:                       ^ [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(818,23): warning C4018: '<': signed/unsigned mismatch [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(818,23): warning C4018:     if (object_length < (data_start - block_start) + sizeof(canheader)) { [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(818,23): warning C4018:                       ^ [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(859,27): warning C4018: '<': signed/unsigned mismatch [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(859,27): warning C4018:         if (object_length < (data_start - block_start) + sizeof(canheader) + payload_length_valid + sizeof(can2trailer)) { [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(859,27): warning C4018:                           ^ [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(894,23): warning C4018: '<': signed/unsigned mismatch [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(894,23): warning C4018:     if (object_length < (data_start - block_start) + sizeof(canheader)) { [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(894,23): warning C4018:                       ^ [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(966,23): warning C4018: '<': signed/unsigned mismatch [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(966,23): warning C4018:     if (object_length < (data_start - block_start) + sizeof(canheader)) { [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(966,23): warning C4018:                       ^ [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(1045,23): warning C4018: '<': signed/unsigned mismatch [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(1045,23): warning C4018:     if (object_length < (data_start - block_start) + sizeof(frheader)) { [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(1045,23): warning C4018:                       ^ [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(1126,23): warning C4018: '<': signed/unsigned mismatch [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(1126,23): warning C4018:     if (object_length < (data_start - block_start) + sizeof(frheader)) { [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(1126,23): warning C4018:                       ^ [build\wiretap\wiretap.vcxproj]
```
2021-07-18 17:05:31 -07:00
Guy Harris c64a9bbde7 erf: make a copy of the first SHB comment.
We free it, but what wtap_block_get_nth_string_option_value() returns is
what's stored in the block, and it might get freed up out from under us.
Save a copy of it, so that when we free it, we're not double-freeing.
2021-07-16 15:59:58 -07:00
Dr. Lars Völker 796819c955 BLF: Support for BLF file format
This patch adds first support for the BLF file format.
2021-07-16 07:37:43 +00:00
Developer Alexander 2a1ebd1e91 can: more specific dissector tables for CAN IDs and extended IDs
Introduces two new dissector tables can.id and can.extended_id to enable a
more precise control of subdissectors dependent on the can id which is often
used to identify the the payload.

Since standard CAN IDs and extended IDs can be used in the same network and
their ranges overlap it is necessary to have two different dissector tables.

Existing Decode as dissector table can.subdissector stays as is to prevent a
breaking change. But new dissector tables can.id and can.extended_id get
priority over can.subdissector since they are more specific. Id they get a
match can.subdissector won't be called.

New dissector tables can.id and can.extended_id are accessible in lua scripts
via DissectorTable:add() while can.subdissector unfortunately is not.

For related Discussion see MR !3405
2021-07-15 07:29:46 +00:00
Guy Harris cc36b74139 pcapng: shuffle functions that process various option types.
Define them in the order in which wiretap/wtap_opttypes.h defines the
corresponding enum values for wtap_opttype_e.
2021-07-14 01:01:27 -07:00
Guy Harris 7b0c4950a5 wiretap: clean up option definitions a bit.
Spell out "DESCRIPTION" for the IDB description option, as it's spelled
out in the pcapng spec.

Put the #defines for various options in the same order as the block
types for them are in the pcapng spec.
2021-07-14 06:55:12 +00:00
Guy Harris 23f19e4a5d wiretap: iptrace/Sniffer/Peek classic always have packet flags.
For iptrace files, there's always a direction indication (which also
means that the flags field will never be zero - "outbound" and "inbound"
both have non-zero values - so the test for non-zero always succeeds, so
it's not even a useful test).

For Sniffer Ethernet/FDDI/synchronous serial line files, and for Peek
classic files, there are always flags; they might be zero if there were
no errors, but that doesn't mean that the lack of errors shouldn't be
noted with a flags field.

While we're at it, shuffle creating of the block next to the setting of
the record type - the block and record type should match, so the two
operations are doing related things.
2021-07-14 00:31:03 +00:00
Guy Harris fa9ee0f37a pcapng: process OPT_COMMENT in pcapng_process_options().
That option applies to all pcapng blocks, so handle it in common code.
2021-07-12 18:06:38 -07:00
David Perry 06ed6930dc Carry EPB flags as an option on the packet block
As requested by [this comment][1] on !2859, move `pack_flags` from a
dedicated field in `wtap_rec` to a block option on the packet block in
`wtap_rec.block`.

[1]: https://gitlab.com/wireshark/wireshark/-/merge_requests/2859#note_615984624
2021-07-12 12:41:57 -04:00
Guy Harris dd5907d2a3 Consistently refer to blocks that have been modified as "modified".
"User" sounds as if the blocks belong to the user; at most, the current
user might have modified them directly, but they might also have, for
example, run a Lua script that, unknown to them, modified comments.
Also, a file might have "user comments" added by a previous user, who
them wrote the file and and provided it to the current user.

"Modified" seems a bit clearer than "changed".
2021-07-08 00:05:35 -07:00
David Perry 73087d6fb4 Use wtap_blocks for packet comments
Mostly functioning proof of concept for #14329. This work is intended to
allow Wireshark to support multiple packet comments per packet.

Uses and expands upon the `wtap_block` API in `wiretap/wtap_opttypes.h`.
It attaches a `wtap_block` structure to `wtap_rec` in place of its
current `opt_comment` and `packet_verdict` members to hold OPT_COMMENT
and OPT_PKT_VERDICT option values.
2021-07-07 18:40:24 +00:00
Guy Harris 5f596c1e82 wiretap: add the ZigBee secret types.
They're in the spec, they belong here as well.
2021-07-01 11:09:36 +00:00
Guy Harris 33cff8c95b wiretap: change some comments.
Note that OPT_CUSTOM_STR_COPY is, specifically, a UTF-8 string.

Fix the comment for OPT_CUSTOM_STR_NO_COPY to say it's a UTF-8 string,
not binary data.
2021-07-01 08:56:34 +00:00
Guy Harris 70d69d5f91 wiretap: add WTAP_BLOCK_SYSDIG_EVENT block type for future use. 2021-07-01 06:29:50 +00:00
Guy Harris 689ff5a3ad pcapng: centralize access to members of the wtap_optval_t union.
Have the "compute option size" and "write option" routines take a
wtap_optval_t * as an argument and choose the appropriate member of the
union.
2021-06-29 14:54:48 -07:00
Guy Harris c0dc9106dd pcapng: clean up some function names.
Consistently use pcapng_compute_XXX_option_size() for routines to
compute the size of an option of type XXX and pcapng_write_XXX_option()
for routins to write out an option of type XXX.

Sort the routines by the order in which their option type values are
defined.
2021-06-28 17:20:26 -07:00
Guy Harris 73e058032f pcapng: have more common code for writing options.
Have common routines that iterate over all the options, processing
comment and custom options in common code (as they're defined
independently of particular block types), with callbacks to handle the
options for particular block types.
2021-06-28 15:14:36 -07:00
Joakim Andersson 9728438929 nordic_ble: Update display name of nordic_ble dissector
Replace all instances of "Nordic BLE Sniffer" with
"nRF Sniffer for Bluetooth LE" which is the name used by
nordic semiconductor for the development tool on the homepage.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-06-28 11:52:14 +00:00
Guy Harris c1082bd99e wiretap: have the "for each option" routine return a success/fail indication.
Have the routine it calls return a Boolean value, with "true" meaning
"keep going" and "false" meaning "stop iterating and return a failure
indication".  If the callback routine never returns "false", the routine
returns "true" as a success indication.
2021-06-27 13:25:16 -07:00
Guy Harris ae10f11212 wtap_opttypes: clean up comments. 2021-06-27 04:27:59 -07:00
Guy Harris 9e6aa424f1 pcapng: have a common routine to write the "end of options" option. 2021-06-27 03:14:14 -07:00
João Valverde 472eaf911b "config.h" need not and should not be included in any header
config.h is included in the source file before including the
header that uses it.
2021-06-25 23:53:53 +01:00
Martin Mathieson af57fb94ac DT2000: Fix buffer length in wiretap code
CID: 1477941
2021-06-25 09:44:35 +01:00
Michael Tuexen 1f0a16e472 pcapng: add support for custom options 2021-06-23 04:38:27 +00:00
Dario Lombardo f62138c0d5 Fix some includes. 2021-06-22 19:25:43 +00:00
Guy Harris 1fe3ed4940 erf: fix a comment to match reality.
It's not that Wireshark only supports one copy of some block options,
it's that *the pcapng specification* only supports one instance of some
block options, and it's not that wtap_block_set_*_value() fails on
non-string values, it's that the set_XXX_option_value routines currently
only support changing the value of an existing option, not adding a new
instance of an option - the latter requires the add_XXX_option_value
routine.
2021-06-19 15:37:43 -07:00
João Valverde 8cf9791679 Replace some lingering references to g_log() 2021-06-19 02:34:36 +00:00
Guy Harris 39315979c6 pcap-common: set the time stamp precision correctly for LINKTYPE_ERF.
LINKTYPE_ERF pcap files are really ERF files inside a thin pcap wrapper
(don't even ask what a pcapng file with some or all interfaces being
LINKTYPE_ERF is...), so the time stamp comes from the ERF record, not
from the pcap packet header or pcapng block header.

The time stamp reslution for the record should reflect that, so set it
to WTAP_TSPREC_NSEC (ERF time stamps are fractional-power-of-2, not
fractional-power-of-10, so that's the best we can do).
2021-06-18 17:43:36 -07:00
Guy Harris 02cffb51a9 erf: handle errors in some routines more completely.
Have them take error code and error information string arguments and,
for various failures, fill them in as "internal error" indications.

Check their return codes to see if they got an error.
2021-06-18 16:22:54 -07:00
Guy Harris d69d1271f0 libpcap: don't generate a fake interface for LINKTYPE_ERF files.
The ERF code will generate interfaces based on the ERF records in the
file, so don't bother adding an additional dummy interface.
2021-06-18 15:34:49 -07:00
Guy Harris 49ec11f5aa erf: set the tsprecision value of a newly-created IDB.
Don't assume the default is correct, because there's no guarantee of
that - in fact, there's currently a guarantee that it's not, as it's
initialized to 0, which is WTAP_TSPREC_SECS.
2021-06-18 01:24:41 -07:00
Guy Harris 5eda4c0128 pcapng: update a comment to reflect the name cleanups. 2021-06-17 15:55:18 -07:00
Guy Harris 9773b5a4a7 Just call the block type for custom blocks WTAP_BLOCK_CUSTOM.
No need to add a redundant "_BLOCK" at the end.
2021-06-17 15:04:44 -07:00
Guy Harris 6eb3703379 Make various names match the name of the systemd journal export block.
The name of the block, in the pcapng specification is the systemd
Journal Export Block; add "export" after "journal" in various
variable/enum/define names.
2021-06-17 13:52:45 -07:00
Guy Harris 2c9d262ed1 pcapng: indentation cleanups. 2021-06-16 20:03:00 -07:00
Guy Harris 8aceee774a pcapng: get rid of some now-redundant rounding up of the block length.
Now that it's being done in common code, we don't need to do it in the
routines to read sysdig event blocks, systemd journal export blocks, or
unknown blocks.

Add in a comment to match other comments while we're at it.
2021-06-16 18:59:34 -07:00
Guy Harris a16f65ab20 pcapng: have more common code for processing options.
Have a common loop for processing options, with a callback to process
options for a particular block type.
2021-06-16 16:50:22 -07:00
Guy Harris ea38a1d419 pcapng: round up block lengths to a multiple of 4 in common code.
Do it earlier in the reading process, rather than in the packet block
code.
2021-06-16 13:15:24 -07:00
João Valverde 39df3ae3c0 Replace g_log() calls with ws_log() 2021-06-16 12:50:27 +00:00
Guy Harris 8176a16798 pcapng: fix indentation. 2021-06-16 03:31:27 -07:00
Guy Harris 25a254823f wsutil: add a header that defines some "round to power of 2" macros.
Add macros to round to multiples of 2, 4, 8, 16, and 32.

Use them instead of independently defined macros.

(We don't define a general "round to a power of 2" macro to avoid the
risk of somebody passing something other than a power of 2 to it.)
2021-06-16 02:01:23 -07:00
Guy Harris 016f193111 pcapng: fix routine name.
This processes pcapng files, not pcap files, so call it
pcapng_process_unhandled_option(), not pcap_process_unhandled_option().
2021-06-12 14:08:16 -07:00
João Valverde dc7f0b88bb Refactor our logging and extend the wslog API
Experience has shown that:

  1. The current logging methods are not very reliable or practical.
A logging bitmask makes little sense as the user-facing interface (who
would want debug but not crtical messages for example?); it's
computer-friendly and user-unfriendly. More importantly the console
log level preference is initialized too late in the startup process
to be used for the logging subsystem and that fact raises a number
of annoying and hard-to-fix usability issues.

  2. Coding around G_MESSAGES_DEBUG to comply with our log level mask
and not clobber the user's settings or not create unexpected log misses
is unworkable and generally follows the principle of most surprise.
The fact that G_MESSAGES_DEBUG="all" can leak to other programs using
GLib is also annoying.

  3. The non-structured GLib logging API is very opinionated and lacks
configurability beyond replacing the log handler.

  4. Windows GUI has some special code to attach to a console,
but it would be nice to abstract away the rest under a single
interface.

  5. Using this logger seems to be noticeably faster.

Deprecate the console log level preference and extend our API to
implement a log handler in wsutil/wslog.h to provide easy-to-use,
flexible and dependable logging during all execution phases.

Log levels have a hierarchy, from most verbose to least verbose
(debug to error). When a given level is set everything above that
is also enabled.

The log level can be set with an environment variable or a command
line option (parsed as soon as possible but still later than the
environment). The default log level is "message".

Dissector logging is not included because it is not clear what log
domain they should use. An explosion to thousands of domains is
not desirable and putting everything in a single domain is probably
too coarse and noisy. For now I think it makes sense to let them do
their own thing using g_log_default_handler() and continue using the
G_MESSAGES_DEBUG mechanism with specific domains for each individual
dissector.

In the future a mechanism may be added to selectively enable these
domains at runtime while trying to avoid the problems introduced
by G_MESSAGES_DEBUG.
2021-06-11 09:40:28 +00:00
yuanjungong ca42e4a9ad Wiretap: Fix a resource leak
call destroy_k12_file_data to destory file_data before return.
2021-06-09 17:09:44 +00:00
Michael Tuexen 4ddae68508 pcapng: add support for custom blocks 2021-06-06 21:15:35 +00:00
João Valverde 4aff36d501 Replace g_assert() with ws_assert() in places 2021-06-06 20:05:26 +00:00
João Valverde 4e4bef09f9 wiretap: Remove some redundant debug information
It is not necessary to include the function name and/or locations,
ws_debug() includes that information,
2021-06-06 19:48:54 +00:00
Guy Harris 7477431325 wiretap: un-export some routines.
wtap_file_get_shb_for_new_file() and wtap_file_get_nrb_for_new_file()
are intended to be used only internally to libwiretap and by libwiretap
plugins.
2021-05-31 04:39:59 -07:00
Guy Harris 162251176a ascend: set rec->rec_type.
REC_TYPE_PACKET is 0, so if it's been initialized to 0, and never gets
overwritten, this fixes code withotu fixing a visible bug, but it should
be done anyway.
2021-05-31 02:44:57 -07:00
Guy Harris 883f159c8b pcapng: fix some more WTAP_ERR_BAD_FILE err_info strings.
Just say "pcapng:", rather than giving the function name, to match the
style used here and for other capture file formats.
2021-05-29 23:17:27 -07:00
Guy Harris 5827009e7a pcapng: remove a second colon from a debug message. 2021-05-29 22:52:59 -07:00
Guy Harris 82dcb9196a wiretap: clean up WTAP_ERR_BAD_FILE error messages.
Consistently give a file type name at the beginning of the message.
2021-05-29 18:08:24 -07:00
Michael Tuexen 86b28f0d4b wiretap: improve code consistency in pcapng.c 2021-05-30 01:08:14 +02:00
Guy Harris 48ba793ef6 erf: clean up handling the return value when getting and option value.
Make the variable into which we put the return value of
wtap_block_get_nth_string_option_value() a wtap_opttype_return_val, as
that's the type of the return value - it's not a boolean, it's a status
code with multiple values.

Explicitly check that value against WTAP_OPTTYPE_SUCCESS.  Yes,
WTAP_OPTTYPE_SUCCESS is 0, so

	if (xxx)

is equivalent to

	if (xxx != WTAP_OPTTYPE_SUCCESS)

but it's better to make it explict, so it's clear that it's checking for
failure.
2021-05-24 23:39:26 -07:00
Guy Harris 54e6b249c1 wiretap: change wtapng_mandatory_section_t to wtapng_section_mandatory_t.
This is consistent with other names for block mandatory data structures.
2021-05-24 04:06:20 -07:00
Guy Harris 7f6c5d0137 k12: plug a memory leak.
If the two putative number-of-records values don't match (meaning one of
them is presumably the number of records and the other one isn't - we
don't know which is the case), free up the private data structure we
allocated before returning an error.
2021-05-23 23:14:27 -07:00
Guy Harris 297b6c5407 erf: set USERAPPL if we have the application version but not the name.
Just say "(Unknown application) <version>".

This also means that we don't leak the app_version string if there's no
app_name string.
2021-05-23 19:37:09 -07:00
João Valverde 9ba97d12d6 Add ws_debug() and use it
Replace most instances of ws_debug_printf() except in
epan/dissectors and dissector plugins.

Some replacements use printf(), some use ws_debug(), and
some were removed because they were dead or judged to be
temporary.
2021-05-24 01:13:19 +00:00
João Valverde de00cdd512 pcapng: Fix debug statements 2021-05-24 01:13:19 +00:00
Guy Harris 976ccc9a00 netscaler: plug a memory leak.
Free the read buffer if the first read fails.
2021-05-23 17:56:18 -07:00
Martin Mathieson f54221b579 DCT2000: allow for longer lines/PDUs 2021-05-20 12:05:23 +00:00
Guy Harris bc8bb0152e commview: add support for newer NCFX file format. 2021-05-11 07:40:51 +00:00
Alexis La Goutte b4898e653a wtap_opttypes(wiretap): Fix Dead Store
Value stored to 'block_type' is never read
2021-05-06 07:18:22 +00:00
Guy Harris 57a1514ac7 Cast away the return value of g_strlcpy() and g_strlcat().
Most of the time, the return value tells us nothing useful, as we've
already decided that we're perfectly willing to live with string
truncation.  Hopefully this keeps Coverity from whining that those
routines could return an error code (NARRATOR: They don't) and thus that
we're ignoring the possibility of failure (as indicated, we've already
decided that we can live with string truncation, so truncation is *NOT*
a failure).
2021-04-30 03:19:19 -07:00
Guy Harris eb4d68033e Don't cast away upper bits when assigning to a nstime_t's secs field.
The secs field is a time_t, which is not necessarily 32 bits.  If it's
not, casting away the upper bits, by casting to guint32, introduces a
Y2.038K bug.

Either cast to time_t or, if you're assigning a time_t to it, don't
bother with the cast.
2021-04-28 21:31:15 +00:00
Guy Harris bdc878e2f7 wiretap: clean up freeing of if_filter options.
Use if_filter_free() in wtap_block_free_option(), don't duplicate it.

Move if_filter_dup() and if_filter_free() before the latter is first
used.
2021-04-27 10:22:00 -07:00
Daniel Dulaney e35efdee8d TIFF: Add a basic TIFF dissector 2021-04-24 10:42:59 +00:00
Gerald Combs e513ed41d2 Wiretap: Fix some compiler warnings.
Make various _dump_can_write_encap and _dump_open routines static. Add a
couple of casts.
2021-04-16 20:09:42 +00:00
Gerald Combs c92637bcd8 Add missing prototypes to lemon-generated code.
Add static prototypes for the parser interface functions. Fixes
-Wmissing-prototypes found by clang.
2021-04-16 18:38:26 +00:00
Tomasz Moń 4bd5830cda CMake: Add ENABLE_VLD option for MSVC
Calling cmake with -DENABLE_VLD=ON when building with Visual Studio,
results in debug configuration being linked to Visual Leak Detector.
By default, Visual Leak Detector outputs the leak summary to Visual
Studio debug window. When ENABLE_VLD is active, VLD is linked to all
wireshark libraries and executables.
2021-04-10 21:53:59 +00:00
Guy Harris 7de6b0822a pcapng: expand a comment and tweak the version test.
Drop in the comment from libpcap about version 1.2 (I wrote that
comment, and generously double-license it under the BSD license and the
GPL :-)).

Redo the version test as

    if (!({version is one we handle}))

to match the way it's done in libpcap.
2021-04-08 19:38:26 -07:00
Loris Degioanni 7894b1d0ea sysdig: a couple more fixes
- parse the number of system call arguments in a way that works for both V1 and V2 event blocks
- returned the correct error string when unable to read the nparams entry from a sysdig event block V2
2021-04-09 01:24:53 +00:00
Loris Degioanni cbbe660504 sysdig: implementation fixes
- make sure nparams is initialized
- validate block_total_length in the correct way for sysdig event blocks
2021-04-09 01:24:53 +00:00
Loris Degioanni 8c70dd8d17 sysdig: simplified the separate handling of the two different sysdig block types 2021-04-09 01:24:53 +00:00
Loris Degioanni fbe8d3a00f sysdig: support the most recent version of sysdig
Update the pcap-ng reader and sysdig event dissector to support the second version of the sysdig event block, which was introduced after Wireshark's original implementation
2021-04-09 01:24:53 +00:00
Guy Harris c01dd585c7 netmon: fill in all of the 802.11 pseudo-header in the dissector.
All the NetMon reading code does is initialize the pseudo-header; the
bulk of the work is done in the dissector.  Give the dissector its own
pseudo-header structure, and do the initialization there.

That's the way other packet formats in which the 802.11 radio metadata
is a header at the beginning of the packet data, such as radiotap, work.
2021-04-02 07:46:32 +00:00
João Valverde d7401147b4 CMake: Remove non existent '/codecs' include path
The '/codecs' dir was removed in g63af1da7e7.

Avoid using include_directories(), prefer target_include_directories().
Remove some unnecessary CMAKE_CURRENT_*_DIR includes and some other
small cleanups while at it.
2021-03-29 00:00:57 +00:00
Dario Lombardo ea929d6401 wsutils: add local implementation of g_memdup2.
g_memdup() was deprecated and replaced with g_memdup2() in GLib 2.68,
we provide our own copy of g_memdup2() for older GLib versions.
2021-03-25 09:38:10 +00:00
Guy Harris e434d404d0 Move even more headers outside extern "C".
If a header declares a function, or anything else requiring the extern
"C" decoration, have it wrap the declaration itself; don't rely on the
header itself being included inside extern "C".
2021-03-16 04:33:00 -07:00
Guy Harris a892a161d7 pcapng: add some comments warning not to cheat.
Add comments in various switch statements warning people *not* to add
standardized block types or option codes that aren't in the pcapng spec.
If you want a standardized block or option type, go through the
standards process.
2021-03-16 00:52:42 -07:00
Guy Harris 8f965899b3 Remove unnecessary includes of wiretap/pcap-encap.h. 2021-03-15 16:04:02 -07:00
Guy Harris ce20c00049 Remove unnecessary inclues of wiretap/pcapng.h. 2021-03-15 15:29:40 -07:00
Guy Harris 03d6f39a99 libwiretap: make wtap_wtap_encap_to_pcap_encap() private to the library.
Only a tiny amount of code outside libwiretap needs to know about
pcap/pcapng LINKTYPE_ values, and all that code needs to know is, for a
given LINKTYPE_ value, what the corresponding WTAP_ENCAP_ value is.
Nothing should need to know, for a given WTAP_ENCAP_ value, what its
LINKTYPE_ value is.

Make it the case that nothing *does* need to know, for a given
WTAP_ENCAP_ value, what its LINKTYPE_ value is.  Export
wtap_dump_can_write_encap() and use *that*, in the "import hex dump"
code, what formats can be written to a pcap file.
2021-03-14 14:22:16 -07:00
Guy Harris 610dffbb19 pcapng: make sure the packet encapsulation matches the interface encapsulation.
If an attempt is made to write a packet with one encapsulation for an
interface with a different encapsulation, report an internal error.
2021-03-13 22:00:21 -08:00
Guy Harris 5d39e36198 doc: Clean up lists of file types.
Add missing entries, regularize the descriptions, etc..

Note that pcap and pcapng are the native formats.

Fix various issues.

Update the editcap -F output to match urrent reality.

While we're at it, sort the libwiretap modules, putting observer.c in
the right place.
2021-03-13 10:02:02 +00:00
Guy Harris c473eba8dc observer: rename source and update name.
Name the source to the code to read Observer files after the file
format, not the company that created it, got bought by JDSU, and then
ended up in Viavi when JDSU split.

Refer to the file format as "Viavi Observer" to reflect that.
2021-03-11 16:01:27 -08:00
Guy Harris 2561f1e9f8 libwiretap: don't have a central table of file type/subtype name mappings.
Let individual file type/subtype modules register their
backwards-compatibility names, rather than having a centralized table
that would need to be updated along with the module.
2021-03-11 13:56:40 -08:00
Guy Harris 98485a1c27 pcapng: small cleanups in pcap_open().
We don't need to initialize first_section before calling
pcapng_read_section_header_block(); it doesn't depend on it being
initialized, and sets byte_swapped, version_major, and version_minor if
what it reads is a valid SHB, so we don't need to set those in
pcap_open().

We don't need to set shb_off until we've deemed this to be a pcapng
file, so do so at the same point that we initialize

We also don't need to initialize wblock until we call
pcapng_read_section_header_block(), so do so all in one place.
2021-03-11 12:49:24 -08:00
Guy Harris e0afa7f2a4 Observer is now a product of Viavi.
JDSU bought Network Instruments, and then split into Viavi and Lumentum,
with Viavi getting Observer.
2021-03-11 20:02:14 +00:00
Guy Harris aab0bd12a5 pcapng: clean up pcapng_block_read().
Instead of pcapng_open() calling pcap_block_read() to do all the work of
reading the initial SHB, have it do the read of the initial SHB itself,
by calling the same routines that pcap_block_read() calls.

That way, pcap_block_read() doesn't have to be prepared to be called to
read that block, so it can treat all issues with an SHB that it reads as
errors, rather than possibly reporting them as "not a pcapng file", and
it doesn't have to support being called without a pointer to the
pcapng_t for the file being read, as it no longer ever is.  It can now
just return a gboolean success/failure indication.

That makes pcapng_open() a little more complicated but it makes
pcap_block_read() less complicated.

Fix some use of : as ' in comments while we're at it.
2021-03-11 10:27:36 +00:00
Guy Harris f669bf2ec9 pcapng: ignore if_filter options with an unknown type.
We don't know how to process the type, so just ignore it.
2021-03-11 04:44:19 +00:00
Guy Harris 7446a16247 pcapng: get rid of the local pcapng_t in pcapng_open().
Pass a null pointer to pcapng_read_block(), instead.  In
pcapng_read_block(), treat that as the indication that we're trying to
read the purported first SHB, rather than treating a null section_info
pointer as that indication.

This addreses one, but not all, of the problems reported in issue #17281.
2021-03-10 22:06:58 +00:00
Guy Harris 598e32f933 commview: use the data rate to determine the modulation.
The band field of the header doesn't necessarily indicate the modulation
of the packet; use the data rate to determine the modulation.
2021-03-10 11:09:57 -08:00
Guy Harris dcd3e26a81 several: make the phy reflect the packet modulation.
Use the data rate and channel to determine 11b vs. 11g vs. 11a for:

* Aruba Networks encapsulated remote mirroring;
* Prism headers;
* *Peek remote protocol;
* Network Instruments^W^WViavi Observer;
* *Peek classic format;
* Shomiti Surveyor.

Note why we *don't* need to do that for NetMon captures.
2021-03-10 09:45:26 +00:00
Guy Harris 31dc280d25 radiotap, wlancap, wiretap: make the "phy" reflect the packet modulation.
Do more fixups of the "phy" based on the data rate, so that it reflects
the modulation used for the packet.

Note, in comments, why we're doing this, and that there's no reiable
way, in radiotap, to determine the type of channel on which capturing is
being done, as some packet providers use the channel field to indicate
the channel type and others use it to indicate the modulation.

Only provide the "short preamble" for "11b", as that's now being used to
mean "DSSS modulation" - packets on an 11g channel will be marked as
"11g" if they're OFDM or "11b" if they're DSSS.

Make some other cleanups while we're at it.
2021-03-08 18:40:32 -08:00
Guy Harris 6b830718d2 niobserver: some work.
Put all the TLV stuff together.  *If* some TLVs are only in the file
header and others are only in packets, thot should be the split; it
appears that the TLVS with a type with the 0x01 bit clear are for the
file header, so perhaps they can be split based on that.

Don't include the TLV header in the structure for the time_info TLV;
that matches other TLV structures.  Write the time_info TLV in two
parts, as we do with the comment TLV.

Consistently use _TO_LE macros in our _TO_LE_IN_PLACE macros.

Add _FROM_LE_IN_PLACE and _TO_LE_IN_PLACE macros for the network_load
TLV.

Use %z, now that we require C99-or-later.

Check the length of TLVs.

Note some things found in files while reverse engineering.
2021-03-05 18:08:10 -08:00
Guy Harris 2627bd4b84 snoop: expand a comment.
There's a bunch of information about the Shomiti wireless header that
would be Nice To Have.  Note it.
2021-03-04 20:40:30 -08:00
Guy Harris 8f700ab1f3 peektagged: guess the PHY for 11b/11g/11a.
FOr 11b and 11g, also set the metadata to provide the "short preamble"
indication.

Add some macros to wsutil/802_11-utils.h to help there, as I threatened
to do in the previous commit. :-)
2021-03-04 16:07:23 -08:00
Guy Harris 25d44cde11 wsutil: rename frequency-utils.[ch] to 802_11-utils.[ch].
It's 802.11-specific, and may include non-frequency/channel-related
items in the future.
2021-03-04 15:41:00 -08:00
Guy Harris b8d90bb548 netxray: update a comment.
Add additional information derived from more reverse engineering.
2021-03-03 15:19:18 -08:00
João Valverde e536166b38 Fix warnings with GCC and -O3
When building with GCC 10.2.0 and optimization level 3 some new
warnings turn up. Fix them.

./epan/crypt/dot11decrypt_util.c: In function ‘dot11decrypt_derive_pmk_r0’:
../epan/crypt/dot11decrypt_util.c:308:5: error: ‘sha256_res’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  308 |     memcpy(pmk_r0_name, sha256_res, 16);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../epan/crypt/dot11decrypt_util.c: In function ‘dot11decrypt_derive_pmk_r1’:
../epan/crypt/dot11decrypt_util.c:357:5: error: ‘sha256_res’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  357 |     memcpy(pmk_r1_name, sha256_res, 16);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../wiretap/wtap_opttypes.c: In function ‘wtap_block_add_if_filter_option’:
../wiretap/wtap_opttypes.c:782:12: error: ‘*((void *)&filter_dest+8)’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  782 |     return filter_dest;
      |            ^~~~~~~~~~~
../wiretap/wtap_opttypes.c: In function ‘wtap_block_set_if_filter_option_value’:
../wiretap/wtap_opttypes.c:782:12: error: ‘*((void *)&filter_dest+8)’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  782 |     return filter_dest;
      |            ^~~~~~~~~~~
2021-03-03 15:15:25 +00:00
Gerald Combs 481b490b82 Miscellaneous EditorConfig fixes
In the top-level .editorconfig, note that we don't use CMake's standard
indentation.

Remove ascendtext.[ch] from wiretap/.editorconfig since it's no longer
needed.
2021-03-02 19:13:54 +00:00
João Valverde 7f105d3981 CMake: Use CheckAPI's abort/termoutput with dissectors only
I believe this was the original intention, to use these API restricitons
with dissectors only (not that I necessarily agree with that policy either),
and through copy-paste and lack of clear guidelines it spread to other
parts of the build.

Rename the checkAPI groups to make it very clear that this is dissector-only.

This doesn't mean, of course, that good programming practices shouldn't be
followed everywhere. In particular assertions need to be used properly.
Don't use them to catch runtime errors or validate input data.

This commit will be followed by another removing the various ugly hacks
people have been using to get around the checkAPI hammer.
2021-03-01 20:59:39 +00:00
Guy Harris 7665075241 wiretap: make WTAP_FILE_TYPE_SUBTYPE_UNKNOWN -1 rather than an index.
And get rid of the entry for that type in the table of type/subtypes.
2021-02-24 17:30:47 -08:00
Guy Harris 9191746670 wiretap: add a block type for systemd journal entries.
Those are used by more than one file type, so we should provide a block
type for them.  (We don't *currently* use that block type, or the packet
block type, but this makes them available for future use.)
2021-02-24 03:09:03 -08:00
Guy Harris 7ffc11e38f wiretap: add some additional bounds checks for file type/subtype values.
Check to make sure the value is non-negative and less than the number of
file type/subtypes.

Make it clearer than one check is unnecessary:

* pull wtap_dump_open_check() into wtap_dump_init_dumper(), so it's
clear that wtap_dump_init_dumper() ensures the validity of the file
type/subtype value early on (wtap_dump_can_open() fails if it's not
valid);

* pull wtap_dump_alloc_wdh() into wtap_dump_init_dumper(), so that the
allocation and all the initialiation is done there - that makes it clear
that it sets the file_type_subtype member of the wtap_dumper structure
before wtap_dump_init_dumper() returns;

* have wtap_dump_open_finish() use that value rather than being passed
the type/subtype value explicitly, so it's clear that it's dealing with
a validated value.
2021-02-24 10:36:05 +00:00
Guy Harris ed86f51e49 wiretap: rename wtap_register_file_type_subtypes().
It only registers one file type/subtype, so rename it to
wtap_register_file_type_subtype().

That will also force plugins to be recompiled; that will produce compile
errors for some plugins that didn't change to match the new contents of
the file_type_subtype_info structure.

Also check to make sure that the registered file type/subtype supports
at least one type of block; a file type/subtype that doesn't return
*any* blocks and doesn't permit *any* block types to be written is not
very useful.  That should also catch most if not all other plugins that
didn't change to match the new contents of the file_type_subtype_info
structure.

Don't make errors registering a file type/subtype fatal; just complain,
don't register the bogus file type/subtype, and drive on.
2021-02-23 20:39:16 -08:00
Guy Harris 166159f15d wiretap: eliminate the pcap/nspcap/pcapng WTAP_FILE_TYPE_SUBTYPE_ values.
Register the pcap and pcapng file types/subtypes rather than hardwiring
them into the table.

Call the registration routines for them directly, rather than through a
generated table; they're always supposed to be there, as some code in
Wireshark either writes only one of those formats or defaults to writing
one of those formats.  Don't run their source code through the
registration-routine-finder script.

Have the file type/subtype codes for them be directly exported to the
libwiretap core, and provide routines to return each of them, to be used
by the aforementioned code.

When reporting errors with cfile_write_failure_message(), use
wtap_dump_file_type_subtype() to get the file type/subtype value for the
wtap_dumper to which we're writing, rather than hardcoding it.

Have the "export PDU" code capable of supporting arbitrary file
types/subtypes, although we currently only use pcapng.

Get rid of declarations of now-static can_write_encap and
dump_open routines in various headers.
2021-02-23 21:56:20 +00:00
Guy Harris d50f712a85 wiretap: fix use of wrong index as array subscript.
"i" and "j" are too similar, so it's easy to use the wrong one if you're
using both as array indices and not easy enough to notice the mistake.

Use somewhat more meaningful names when we fix the index.

Fixes #17252.
2021-02-22 12:55:35 -08:00
Guy Harris 00d2661459 wiretap: fix dependency in CMakeLists.txt.
wtap_modules.c depends on ${WIRETAP_MODULE_FILES} rather than
${WIRETAP_NONGENERATED_FILES}.
2021-02-22 19:45:44 +00:00
Guy Harris 842a7cccf9 wiretap: have file handlers advertise blocks and options supported.
Instead of a "supports name resolution" Boolean and bitflags for types of
comments supported, provide a list of block types that the file
type/subtype supports, with each block type having a list of options
supported.  Indicate whether "supported" means "one instance" or
"multiple instances".

"Supports" doesn't just mean "can be written", it also means "could be
read".

Rename WTAP_BLOCK_IF_DESCRIPTION to WTAP_BLOCK_IF_ID_AND_INFO, to
indicate that it provides, in addition to information about the
interface, an ID (implicitly, in pcapng files, by its ordinal number)
that is associated with every packet in the file.  Emphasize that in
comments - just because your capture file format can list the interfaces
on which a capture was done, that doesn't mean it supports this; it
doesn't do so if the file doesn't indicate, for every packet, on which
of those interfaces it was captured (I'm looking at *you*, Microsoft
Network Monitor...).

Use APIs to query that information to do what the "does this file
type/subtype support name resolution information", "does this file
type/subtype support all of these comment types", and "does this file
type/subtype support - and require - interface IDs" APIs did.

Provide backwards compatibility for Lua.

This allows us to eliminate the WTAP_FILE_TYPE_SUBTYPE_ values for IBM's
iptrace; do so.
2021-02-21 23:18:35 +00:00
Martin Mathieson cd77e5aa5f Some more spelling fixes.
Also add more words to dictionary file.
2021-02-21 09:59:04 +00:00
Guy Harris 1f595c435c BER: get rid of WTAP_FILE_TYPE_SUBTYPE_BER.
Save a copy of the pathname used to open a file in the wtap structure.
This allows the BER file reader to put a pointer to it in the
pseudo-header; it also would allow file readers to attempt to read
"associated" files that have the same name as the file, but with a
different extension.

Instead of having cf_open() special-case BER files, and calling a
routine in the BER dissector to specify the file name to the dissector,
have separate dissectors for "dissect packet payload as BER" and
"dissect a file as BER", and have the latter get the pathname of the
file from the pseudo-header and determine the ASN.1 syntax from that.

(Side-effect - this means that you can now dissect a BER file, and have
the syntax be determined by the file extension, in TShark as well; the
above cf_open() special-casing was *not* done in TShark, so it didn't
work before.  Now the application code doesn't need to do any of that,
so it works in TShark as well as Wireshark.)
2021-02-20 01:36:26 -08:00
Guy Harris c80c16759b wiretap: eliminate two WTAP_FILE_TYPE_SUBTYPE_ values.
Eliminate WTAP_FILE_TYPE_SUBTYPE_ERF and
WTAP_FILE_TYPE_SUBTYPE_SYSTEMD_JOURNAL - instead, fetch the values by
name, using wtap_name_to_file_type_subtype().

This requires that wtap_init() be called before epan_init(); that's
currently the case, but put in comments to indicate why it must continue
to be the case.
2021-02-19 23:20:24 +00:00
Guy Harris 8b775000bc wiretap: register BUSMASTER log and candump file formats.
*Don't* use WTAP_FILE_TYPE_SUBTYPE_UNKNOWN for the file type/subtype.
2021-02-18 07:48:11 +00:00
Guy Harris a931d73e64 wiretap: fix return value of wtap_register_file_type_subtypes().
It was returning the length of the array *after* we added the new entry,
which is the index that would be used for the *next* entry added.
Return, instead, the length of the array *before* we add the new entry.
2021-02-17 21:40:21 -08:00
Guy Harris edc17b6589 wiretap: update the count of builtin types early.
We need to update the count of builtin types after copying over the
entries from the fixed table; otherwise, slot 0, for
WTAP_FILE_TYPE_SUBTYPE_UNKNOWN, will get assigned to the first
non-fixed-table builtin module.

Fix a comment (is a "builtin plugin" like a "square circle"?).
2021-02-17 19:43:11 -08:00
Guy Harris ba9b08a710 netscaler: fix a comment. 2021-02-17 16:37:04 -08:00
Guy Harris a7256d50b5 wiretap: more work on file type/subtypes.
Provide a wiretap routine to get an array of all savable file
type/subtypes, sorted with pcap and pcapng at the top, followed by the
other types, sorted either by the name or the description.

Use that routine to list options for the -F flag for various commands

Rename wtap_get_savable_file_types_subtypes() to
wtap_get_savable_file_types_subtypes_for_file(), to indicate that it
provides an array of all file type/subtypes in which a given file can be
saved.  Have it sort all types, other than the default type/subtype and,
if there is one, the "other" type (both of which are put at the top), by
the name or the description.

Don't allow wtap_register_file_type_subtypes() to override any existing
registrations; have them always register a new type.  In that routine,
if there are any emply slots in the table, due to an entry being
unregistered, use it rather than allocating a new slot.

Don't allow unregistration of built-in types.

Rename the "dump open table" to the "file type/subtype table", as it has
entries for all types/subtypes, even if we can't write them.

Initialize that table in a routine that pre-allocates the GArray before
filling it with built-in types/subtypes, so it doesn't keep getting
reallocated.

Get rid of wtap_num_file_types_subtypes - it's just a copy of the size
of the GArray.

Don't have wtap_file_type_subtype_description() crash if handed an
file type/subtype that isn't a valid array index - just return NULL, as
we do with wtap_file_type_subtype_name().

In wtap_name_to_file_type_subtype(), don't use WTAP_FILE_TYPE_SUBTYPE_
names for the backwards-compatibility names - map those names to the
current names, and then look them up.  This reduces the number of
uses of hardwired WTAP_FILE_TYPE_SUBTYPE_ values.

Clean up the type of wtap_module_count - it has no need to be a gulong.

Have built-in wiretap file handlers register names to be used for their
file type/subtypes, rather than building the table in init.lua.

Add a new Lua C function get_wtap_filetypes() to construct the
wtap_filetypes table, based on the registered names, and use it in
init.lua.

Add a #define WSLUA_INTERNAL_FUNCTION to register functions intended
only for internal use in init.lua, so they can be made available from
Lua without being documented.

Get rid of WTAP_NUM_FILE_TYPES_SUBTYPES - most code has no need to use
it, as it can just request arrays of types, and the space of
type/subtype codes can be sparse due to registration in any case, so
code has to be careful using it.

wtap_get_num_file_types_subtypes() is no longer used, so remove it.  It
returns the number of elements in the file type/subtype array, which is
not necessarily the name of known file type/subtypes, as there may have
been some deregistered types, and those types do *not* get removed from
the array, they just get cleared so that they're available for future
allocation (we don't want the indices of any registered types to changes
if another type is deregistered, as those indicates are the type/subtype
values, so we can't shrink the array).

Clean up white space and remove some comments that shouldn't have been
added.
2021-02-17 21:54:28 +00:00
Guy Harris 3387eef836 wiretap: remove duplicate declaration of wtap_block_get_type(). 2021-02-14 20:06:21 +00:00
Guy Harris b8b3531883 wiretap: register most built-in file types from its module.
Remove most of the built-in file types from the table in
wiretap/file_access.c and, instead, have the file types register
themselves, using wtap_register_file_type_subtypes().

This reduces the source code changes needed to add a new file type from
three (add the handler, add the file type to the table in file_access.c,
add a #define for the file type in wiretap/wtap.h) to one (add the
handler).  (It also requires adding the handler's source file to
wiretap/CMakeLists.txt, but that's required in both cases.)

A few remain because the WTAP_FILE_TYPE_SUBTYPE_ #define is used
elsewhere; that needs to be fixed.

Fix the wiretap/CMakefile.txt file to scan k12text.l, as that now
contains a registration routine.  In the process, avoid scanning files
that don't implement a file type and won't ever have a registration
routine.

Add a Lua routine to fetch the total number of file types; we use that
in some code to construct the wtap_filetypes table, which we need to do
in order to continue to have all the values that used to come from the
WTAP_FILE_TYPE_SUBTYPE_ types.

While we're at it, add modelines to a file that lacked them.
2021-02-14 00:58:46 -08:00
Guy Harris 8ec5906fd6 iseries: report Unicode files as Unicode rather than ASCII.
While we're at it, that's "Unicode", not "UNICODE" - it's not an
initialism, and isn't all-caps.
2021-02-13 20:23:08 -08:00
Guy Harris 8bba6ebe5c wiretap: remove spaces from file format names.
File format names are used on the command line, so don't require them to
be quoted - replace the space in "systemd journal" with an underscore.
2021-02-13 10:35:58 -08:00
Guy Harris 24acef0885 wiretap: file types have a name and a description.
The "short name" is really just the name, used to look it up.  The
"name" is really a description intended solely for human consumption.
Rename the fields, and the functions that access them, to match.

The "description" maintained by Lua for file type handlers is used
*only* for one debugging message; we should probably just eliminate it.
Call it an "internal description" for now.
2021-02-13 01:25:39 -08:00
Guy Harris a1e03ea89e Remove the existing "custom block" mechanism:
For most file types, blocks for which we don't have a wtap_block_type_t
aren't "custom", they're just "file-type specific".  Add
WTAP_BLOCK_FT_SPECIFIC_REPORT and WTAP_BLOCK_FT_SPECIFIC_EVENT block
types; the "mandatory" part of those blocks includes a
file-type-specific block type value, with specific values assigned to
specific block types (either as part of the file type's definition, or
by us if necessary).

For pcapng files, blocks for which we don't have a wtap_block_type_t are
either "local" (block type has the high-order bit set), are defined in
the current spec but aren't supported yet (which we should fix), or are
*not* defined in the current spec and are *not* "local" (in which case
whoever's using the block number should submit a pull request to the
spec to register the block type *and* give it a specification, so we can
add support).  For "local" block types and for not-yet-supported
non-"local" block types, they should be handled as file-type-specific
blocks with the file-type-specific block value being the pcapng block
type code, with plugin support in the pcapng code to read *and* write
those blocks.

Move the structures for the "mandatory" parts of blocks to
wiretap/wtap_opttypes.h, right after the definition of
wtap_block_type_t.
2021-02-10 09:05:41 +00:00
Guy Harris f0c54cc480 wiretap: add an API to get the type of a block.
When registering a custom block type, set the block type field of the
wtap_blocktype_t structure.  (We may do custom blocks differently, so
this is just for now.)

When registering a standard block type, don't pass in the block type, as
we can just use the type in the wtap_blocktype_t structure.
2021-02-09 21:23:44 -08:00
Guy Harris 09684644ee wiretap: clean up WTAP_BLOCK_ names.
Remove NG from the names - it adds nothing.

Don't use the abbreviations for pcapng block names, spell out what the
block does (e.g. "WTAP_BLOCK_DECRYPTION_SECRETS" rather than
"WTAP_BLOCK_DSB"), to make it more obvious what the block does.

Spell out some other abbreviations.

Add WTAP_BLOCK_PACKET for future use for packet blocks; there's no need
to distinguish between the Enhanced Packet Block, the Simple Packet
Block, and the deprecated Packet Block here.
2021-02-09 22:32:57 +00:00
Guy Harris 85de5ed784 btsnoop: fix writing of btsnoop files.
In answer to the question "How do we support multiple backends?", this
is the answer - what they mean is "how do we support multiple
encapsulation types for the *same* file format", and the answer is "you
have one dump open routine that writes the appropriate encapsulation
type in the header, depending on the encapulation type, and you have one
dump write routine that generates the appropriate packet header and
writes out the packet, depending on the encapsulation type".

Fix the generation of the packet header when writing H1 and H4 packets,
and *don't* strip off the first octet of the packet data when writing H1
packets - that octet isn't generated when reading H1 packets, it's read
from the file.

Tested by running several H1 and H4 captures through "editcap -F
btsnoop" and making sure that the files are identical.
2021-02-07 09:58:39 +00:00
Guy Harris 1cbafa47b9 wiretap: add a mechanism for built-in modules to have a register routine.
Currently, only pcapng has one, and it does nothing, but this mechanism
will be used more in the future.

Update comments in epan/dissectors/CMakeLists.txt and ui/taps.h while
we're at it.
2021-02-06 17:54:19 -08:00
Guy Harris 12960c81c4 pcapng: write out the FCS length IDB option. 2021-02-06 13:50:30 -08:00
Guy Harris 910c489a4a pcapng: fix build without plugins.
Just remove some HAVE_PLUGINS checks.  Those tables will eventually
handle built-in block and option types as well.
2021-02-06 13:07:12 -08:00
João Valverde 89fee9321e Avoid exposing HAVE_PLUGINS in the public API
Instead *_register_plugin() is turned into a noop (with a warning).

The test suit is failing with ENABLE_PLUGINS=Off (it was already failing
before and this patch didn't affect that).

Closes #17202.
2021-02-06 16:35:51 +00:00
Guy Harris eb066c6091 wiretap: use a hash table for option types.
Option types aren't guaranteed to be small integers, so store option
types for a block type in a hash table, so we don't need to have a big
array to handle the custom option types (the type values of which aren't
small integers) and with local-use option types (the type values of
which also aren't small integers).

Make all the option type structures const while we're at it.
2021-02-04 22:09:23 -08:00
Guy Harris 44abff6934 pcapng: expand the plugin option handlers to support writing options.
The options get unmarshalled (deserialized) when you read them; they
need to get marshalled (serialized) when you write them.  This requires
an option handler to have more than one function.

While we're at it, in the declarations for function types for *block*
reader and writer plugins, add names to the prototype function
arguments, to make it a bit clearer what those arguments are.
2021-02-05 01:34:04 +00:00
Guy Harris 712490f214 pcapng: have common code to handle otherwise-unhandled options.
That code looks for a plugin handler if there's no built-in handler.

Change the handler signature so that it can add an option.
2021-02-04 21:37:53 +00:00
Guy Harris 42dc21a346 pcapng: pull common processing code into subroutines. 2021-02-04 00:59:16 -08:00
Guy Harris fbdd2446e1 pcapng: Fix copy-and-pasteo.
Found by Coverity; fixes Coverity CID 1472770.

(At least *this* Coverity report doesn't use that tainted word
"tainted", which, most of the time, means "ZOMG UR PROGRAM READS
EXTERNAL FILEZ!!!!111ONE!!!")
2021-02-02 21:33:24 -08:00
Guy Harris 0773147a55 wiretap: redo the way we handle if_filter IDB options.
Change the data structure for that option to have a type field,
indicating that it's either a pcap filter string or a BPF program,
followed by a union with a string-pointer member for pcap filter strings
and an instruction-count-and-pointer-to-instructions structure for BPF
programs.

Have routines to add, set, and fetch that option that handle that
structure; discard the "generic structured option" routines.  That means
there's more type checking possible at compile time.

Add more code to handle BPF programs.

When writing pcapng files, check, both for that option and for string
options, whether the option length is too big for the data to fit in a
pcapng option, and don't write it if it is.  (XXX - truncate the data?
Report an error?)
2021-02-01 16:50:01 -08:00
Richard Sharpe fb2a0b4a71 ieee80211: Add support for S1G including PV1.
S1G adapters should be shipping soon since Silex America has a dev-kit
available, so it is about time to add support for this.

Change-Id: I0225d87f78efbcbe88476921d4fce3d56a3ce0cd
2021-02-01 19:34:55 +00:00
Guy Harris 8c83f31063 wiretap: fix indentation. 2021-01-30 12:05:54 -08:00
Guy Harris 3db10d02e9 wiretap: add wtap_block_set_nth_string_option_value_format().
We have wtap_block_set_string_option_value(),
wtap_block_set_string_option_value_format(), and
wtap_block_set_nth_string_option_value(); complete the collection and
win valuable prizes.
2021-01-30 18:45:03 +00:00
Guy Harris b8e2005653 wiretap: clean up comments.
Remove a trailing blank line while we're at it.
2021-01-30 09:13:52 +00:00
Guy Harris ca85c516fe Refer to options whose data isn't a simple data type as "structured".
"Custom", as in "requires custom handling of the option data, collides
with "custom", as in pcapng custom options.
2021-01-30 00:12:11 -08:00
Guy Harris 8e1e28623b Add an encap_table entry for WTAP_ENCAP_ETW.
Fixes #17183.
2021-01-27 23:23:37 +00:00
Guy Harris 93a472575d Rename WTAP_ENCAP_ETL to WTAP_ENCAP_ETW.
It corresponds to LINKTYPE_ETW in pcap and pcapng files; the structures
in the record format come from the Event Tracing for Windows (ETW) API
rather than directly from Event Trace Log files.

While we're at it, explain what extcap/etl does.
2021-01-27 14:33:09 -08:00
Gerald Combs cd278f5fd9 wiretap: Fixup the sdjournal block length in pcapng.
Fix our entry length check and put our trailing '\0' in the right
location. Fixes #17174.
2021-01-27 02:23:24 +00:00
Guy Harris 64f1d09ef3 Make various max packet sizes unsigned, and clean up from that.
Make some packet size variables unsigned.

Leave some others signed, because they're read with sscanf(), and
sscanf() handles string-to-unsigned conversions in the same crazy way
strtouX() routines do, wherein a leading sign is *not* an error.
Instead, cast them to unsigned after we make sure they're not negative.
2021-01-19 19:02:01 -08:00
David Perry b758fdaede Add iso8601_to_nstime() for editcap and nettrace
This adds a function to parse a string date-time in ISO 8601 format into
a `nstime_t` structure. It's based on code from epan/tvbuff.c and
wiretap/nettrace_3gpp_32_423.c and meant to eventually replace both.
(Currently only replaces the latter.)

Since most of Wireshark expects ISO 8601 date-times to fit a fairly
strict pattern, iso8601_to_nstime() currently rejects date-times without
separators between the components, even though ISO 8601 actually permits
this. This could be revisited later.

Also uses iso8601_to_nstime in editcap to parse the -A/-B options,
thus allowing the user to specify a time zone if desired. (See #17110)
2021-01-08 09:18:39 +00:00
David Perry 718cff5264 Initial refactor of nettrace reader (#17009)
Old behaviour is to read the entire file into memory at once; provide
the XML tree as the first packet; and then individual `<msg>` elements
as subsequent packets. It did this by writing to a temporary pcapng
file.

This change causes the XML file to only be read a chunk at a time (and
be read directly, not through an intermediate pcapng). This means much
larger files can be loaded, at the cost of no longer showing the raw XML
as the first packet. This is not a loss because the file can be loaded
in MIME Files Format (or a text editor) to see the XML.

Much of the logic from the old functions `create_temp_pcapng_file()` and
`write_packet_data()` has been relocated into the new function
`nettrace_msg_to_packet()`, and is used to directly generate packet data
for wiretap instead of writing it to a temporary file.

Also includes some initial "code smell" fixes:

- Removed some duplicate `#define`s from epan/exported_pdu.h
- Replaces some magic numbers with macros from epan/exported_pdu.h
- Replaces other magic numbers with the CLEN() macro to make it easier
  to see (and debug) where sizes/offsets come from
- Use `g_strstr_len()` instead of `strstr()` to remove the need to
  insert string terminators
- Uses direct pointer math instead of indexing into a byte array

This compiles and runs, and seems to produce the same results as the old
reader (except for the XML packet). Consider it a proof of concept; it
needs further revision before being review-ready.
2021-01-04 15:20:27 +00:00
Michael Tuexen a5822f6792 Cleanup debug output and fix indentation 2020-12-27 21:37:39 +00:00
Moshe Kaplan 5778b2403e wiretap/k12text.l: replace g_malloc with g_new
Replace `g_malloc` with `g_new` to improve
source code readability.
2020-12-27 09:58:01 +00:00
Moshe Kaplan 180b5e5dc0 Replace more g_malloc with g_new
Replace g_malloc with g_new to improve
source code readability.
2020-12-23 11:47:17 +00:00
Moshe Kaplan e16166a74c Detect and replace bad allocation patterns
Adds a pre-commit hook for detecting and replacing
occurrences of `g_malloc()` and `wmem_alloc()` with
`g_new()` and `wmem_new()`, to improve the
readability of Wireshark's code, and
occurrences of
`g_malloc(sizeof(struct myobj) * foo)`
with
`g_new(struct myobj, foo)`
to prevent integer overflows

Also fixes all existing occurrences across
the codebase.
2020-12-22 14:56:38 +00:00
Jim Young 2e137f31fa Update comments: From wtap_pkthdr to wtap_rec.
Fixup some overlooked comments to reflect refactoring made back
in 2018 with commit 1f5f63f8ef.
2020-12-17 13:23:14 +00:00
Jose Rubio 270561ade1 DCT2000: Allow any PDU to be dissected.
There are traffic dumps that only include the PDU payload
without lower layer information.  This commit allows any
dissector to be embedded in the DCT2000 as a protocol name.
tshark/wireshark will decode it despite having no lower
layer information.

The change allows a DCT2000 protocol field to look for a
dissector.

The change can be enabled or disabled with the preference
dct2000.use_protocol_name_as_dissector_name and it defaults
to FALSE.

Example:

Session Transcript (format 3.1)
December 6, 2020     16:45:20.5185
LTE-RRC.1/lte_rrc.dl_dcch/1/// r tm 22.5695 l $2c02
S1AP.1/s1ap/1/// s tm 23.3926 l
$001700130000020063000608023d7c00830002400202a0
2020-12-13 11:17:42 +00:00
Peter Eszlari 42a09ad02e Linux: rename metadata according to spec
https://www.freedesktop.org/software/appstream/docs/sect-Metadata-Application.html

https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s02.html#desktop-file-id
2020-12-10 18:11:12 +00:00
Moshe Kaplan c4d19650d5 wiretap/erf: Use memmove instead of memcpy
It's possible for memcpy's source and destination
to be the same address, and so therefore
'overlap'. Use memmove instead, which
is safe for overlapping regions.
This fixes Coverity 1450802.
2020-12-09 00:24:58 +00:00
Guy Harris ed6a2c156b Add a documentation comment for wtap_dump_add_idb(). 2020-12-04 23:23:27 -08:00
Odysseus Yang 2a5b34d8b0 MBIM: Update dissector to support DLT_ETW
New link type DLT_ETW is added for write and read Event Trace on Windows.
This change updates MBIM dissector to decode a MBIM message from
a DLT_ETW packet.
2020-12-02 09:05:11 +00:00
Gerald Combs f21cd2e23f wiretap: Convert ascend.y to Lemon.
Convert wiretap/ascend.y.in from Bison/YACC to Lemon and rename it to
wiretap/ascend_parser.lemon. Tighten up some of our scanning and
parsing. Make the indentation in it and related files consistent. Aside
from the recent IPv4 fragment offset changes, this produces identical
output to the 3.4 branch for the Ascend trace files I have here.

Remove the comment about supporting other commands. Another timeline
might have an Ascend that successfully pivoted to DSL or 15625B+1D
gigabit ISDN, but this one has neither.

This was our last/only Bison/YACC file, so remove Bison/YACC as a
development and packaging dependency and remove references to it from
the documentation.
2020-11-30 08:15:43 +00:00
Gerald Combs 51145c62e6 wiretap: Update pcapng systemd timestamp handling.
It's easy to create systemd blocks with a missing or invalid
__REALTIME_TIMESTAMP= field when fuzz testing. If that's the case, leave
WTAP_HAS_TS unset instead of returning an error. Fixes #16965.
2020-11-07 17:53:14 +00:00
Andre Luyer 18365c16a1 Nettrace: correct conversion from ISO 8601 to time stamp
A nettrace 3gpp capture contains the 'beginTime' in ISO 8601 format.
This patch corrects the conversion for the following steps:
- the UTC offset must be subtracted from the given time,
- given time must be converted to UTC time when an offset is provided (localtime otherwise)
- sub-seconds conversion fixed (i.e. .0012 was converted to .12).

Closes #16888
2020-11-02 13:19:55 +00:00
Guy Harris 889e0d5cb6 Add a new record type REC_TYPE_SYSTEMD_JOURNAL.
Systemd journal entries aren't file-type-specific; they're found in both
systemd journal entry blocks in pcapng files and in systemd journal
export files.  Give it a record type, for use with both file types.

This fixes #16955.

It also means that you can open a systemd journal export file and save
it as a pcapng file.
2020-10-27 20:06:26 -07:00
Guy Harris 4740f01134 Use wtap_uses_interface_ids() to check if IDBs are necessary.
Use that, rather than specifically checking for pcapng.
2020-10-22 10:42:25 -07:00
Guy Harris d0270415a9 editcap, tshark: process IDBs in the middle of input files.
Instead of grabbing the set of IDBs found at open time, have a loop
using wtap_get_next_interface_description() to read all unread IDBs run
after opening the input file, after reading a packet from the input
file, and after getting an EOF on the input file.

Add a routine wtap_uses_interface_ids() to check whether the file type
and subtype for a dump file uses interface IDs and requires IDBs.  If
so, in the aforementioned loop, add the IDBs to the dump stream.

Add a routine wtap_dump_add_idb() to add IDBs to a dump stream.  Have it
call a file-format-specific routine to add the IDBs; the only file type
that supports it is pcapng, and it 1) writes out the IDB and 2) adds it
to the set of IDBs for the stream.

Add a wtap_dump_params_init_no_idbs() routine that prevents the IDBs
from the input file from being used to initialize the output file; use
it in cases where we're using the aforementioned loop to copy over IDBs.

Don't require any IDBs to be present when opening a pcapng file for
writing; 1) the simplest pcapng file has just an SHB in it, 2) that
requirement causes dumps that don't provide IDBs at open time to fail,
and 3) the real issue is that we don't want packets with an interface ID
not corresponding to a known IDB, and we already have a check for that.

(There are some hacks here; eventually, when everything processes the
IDBs in such a loop, we may be able to get rid of the "two favors of
dump parameter initialization" hack.)

Fixes #15844.

Addresses the same issue in #15502, but there are other issues there
that also need to be addressed.

In addition, the merge code also needs to be changed to handle this.
2020-10-22 02:58:07 -07:00
Guy Harris 7c488e4c71 Add a routine to make a newly-allocated copy of a block.
It currently wraps wtap_block_create() and wtap_block_copy(); if there
are no remaining use cases for wtap_block_copy() at some point, it can
just *replace* wtap_block_copy().
2020-10-21 19:10:49 -07:00
Guy Harris b478e60b29 Add a routine to get the next as-yet-unfetched interface description.
In a wtap, keep track of the first interface description not yet fetched
with wtap_get_next_interface_description() and, when
wtap_get_next_interface_description() is called, have it return that
description, as a wtap_block_t for its IDB.  If there are no
as-yet-unfetched interface descriptions, return NULL; there may, in the
future, be more interface descriptions for the file, so this should be
called:

* after the file is opened;

* after wtap_read() returns TRUE, indicating that it's returned a
record (and *before* you process the record that wtap_read()
returns, as it might be the interface description for the
interface on which the packet in that record arrived);

* after wtap_read() returns FALSE, indicating an EOF or an error
return (as there might have been interfaces at the end of the
file or before the error point).

At each of those points, the caller should loop until
wtap_get_next_interface_description() returns NULL.

Not used yet (but tested with capinfos, which found a reason why you
have to wait until the end of the file before processing the interface
information - there's now a comment in the code giving that reason).

This will probably be used in the future.
2020-10-21 17:57:17 +00:00
Guy Harris a11b9fb7a0 Add an API to determine whether a file type uses interface IDs.
Currently, the only file types that use them are pcapng and IBM's
iptrace; we don't support writing the latter, so this is mainly of
interest for pcapng.

This makes it a bit more obvious what some "is this pcapng?" tests are
really trying to determine, and allows them to automatically support any
new file types that use them.

(With regard to interface descriptions, tere are three types of file:

1) files that contain no interface information;

2) files that contain "just FYI" interface information but that don't
tie packets or other records to particular interfaces;

3) files that contain interface information and tie all packets (and
possibly other records) to an interface.

This tests for files of type 3.)
2020-10-20 00:39:37 -07:00
Guy Harris 0d2277bca5 Include <stdint.h> in YACC/Bison parsers if necessary.
MSVC doesn't, by default, define __STDC_VERSION__, which means that the
code generated by newer versions of winflexbison3's Bison end up
defining YYPTRDIFF_T as long, which is wrong on 64-bit Windows, as
that's an LLP64 platform, not an LP64 platform, and causes warnings to
be generated.  Those warnings turn into errors.

With MSVC, if __STDC_VERSION__ isn't defined, Forcibly include
<stdint.h> here to work around that.

Fixes #16924.
2020-10-19 11:17:43 -07:00
Gerald Combs 1a244f9de5 CMake: Configure our .y files for different Bison/YACC flavors.
Bison 3.4 and later generate deprecation warnings for the "%pure-parser"
directive. As https://git.savannah.gnu.org/cgit/bison.git/tree/NEWS says,

----
** Deprecated features

  The %pure-parser directive is deprecated in favor of '%define api.pure'
  since Bison 2.3b (2008-05-27), but no warning was issued; there is one
  now.  Note that since Bison 2.7 you are strongly encouraged to use
  '%define api.pure full' instead of '%define api.pure'.
----

Rename our .y files to .y.in, and modify FindYACC.cmake to detect newer
versions of Bison and configure our .y files with "%pure-parser" or
"%define api.pure" as needed. Squelches warnings from Bison in #16924.
2020-10-19 08:46:32 -07:00
Guy Harris 6e6233521a Have WTAP_ERR_INTERNAL include an err_info string giving details.
That way, users won't just see "You got an internal error", the details
will be given, so they can report them in a bug.
2020-10-14 04:51:45 +00:00
Роман Донченко 69e1aa860b Fix many spelling errors 2020-10-11 08:35:55 +00:00
Guy Harris a883081b70 Update URLs pointing to the bug database.
Switch from bugs.wireshark.org to the GitLab issues list.
2020-10-03 07:54:12 -07:00
Guy Harris e02229250d Nettrace: Fix fix to calculation of changetime
A long time ago, in a galaxy far far away, C had arithmetic/logical-
plus-assignment operators, so that

	a = a {op} x;

could be written as

	a ={op} x;

Unfortunately, if {op} is -, that meant that you could have, for
example:

	a =- 17;

which could be interpreted as

	a = -17;

so they changed the operators to be

	a {op}= x;

I.e., if you want to subtract 1000 from a variable, do

	elapsed_ms -= 1000;

not

	elapsed_ms =- 1000;
2020-10-03 07:21:40 -07:00
Anders Broman 79bf1f7d99 Nettrace: Fix calculation of changetime
Closes #16869 (closed)
2020-10-03 07:23:55 +00:00
Guy Harris e013c5ec7f Clean up URLs.
Add ui/urls.h to define some URLs on various of our websites.  Use the
GitLab URL for the wiki.  Add a macro to generate wiki URLs.

Update wiki URLs in comments etc.

Use the #defined URL for the docs page in
WelcomePage::on_helpLabel_clicked; that removes the last user of
topic_online_url(), so get rid of it and swallow it up into
topic_action_url().
2020-10-02 20:13:42 -07:00
Martin Mathieson d461bf3025 Yet more spelling fixes.
Includes small updates to the script and wireshark dictionary.
Probably the last spelling fixes from me for a while.
2020-09-07 16:35:13 +01:00
Gerald Combs 7ab6440416 Tools: Clean up checkAPI and add ui/qt.
Remove the --check-addtext and --build flags. They were used for
checkAddTextCalls, which was removed in e2735ecfdd.

Add the sources in ui/qt except for qcustomplot.{cpp,h}. Fix issues in
main.cpp, rtp_audio_stream.cpp, and wireshark_zip_helper.cpp.

Rename "index"es in packet-usb-hid.c.
2020-09-05 07:41:29 +00:00
Mikhail Gusarov ab4ef189ae wiretap: add Z-Wave Serial API frame type and pcap link-layer header
This header type was added to pcap registry a year ago:
https://lists.sandelman.ca/pipermail/tcpdump-workers/2019-July/001268.html
2020-08-24 19:34:07 +00:00
Jakub Pawlowski 2364968cd6 Bluetooth: simple HCI ISO Data packet dissector
Change-Id: I2da85d4ebe069a566943896fddb31e9a095d67b5
Reviewed-on: https://code.wireshark.org/review/38007
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-08-10 10:29:09 +00:00
Guy Harris 74e917fc6c wiretap: have wtap_dump_flush(), and its callers, check for errors.
Change-Id: Ibcddf1a949f775afa49d36a2d165c3685556035d
Reviewed-on: https://code.wireshark.org/review/38104
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-08-09 23:08:51 +00:00
Guy Harris b711b300cc netmon: handle non-monitor-mode 802.11 packets differently.
Microsoft Network Monitor lets you capture on an 802.11 adapter either
in monitor mode or in non-monitor mode; frames captured in non-monitor
mode may have the Protected bit set in the 802.11 header, but are
decrypted and don't incclude encryption information, and may have the
A-MSDU Present flag set in the QoS Control field, but have just a
regular frame payload, not a sequence of A-MSDUs, in the payload field.

Dissect those frames correctly.

Bug: 16758
Change-Id: I42b7e9ce52faa80222692403fa7276c039644343
Reviewed-on: https://code.wireshark.org/review/38082
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-08-07 18:07:57 +00:00
Guy Harris a381adfe12 wiretap: fix an internal routine's name.
generate_merged_idb() can generate multiple IDBs, so rename it to
generate_merged_idbs().

Change-Id: I4c54326f69ff0de16f0a716b7c82beefdda99cbd
Reviewed-on: https://code.wireshark.org/review/38040
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-08-04 00:31:17 +00:00
Gerald Combs e387a4752c wiretap: Adjust the pcapng systemd Journal length check.
Reduce the minimum systemd journal block size from 212 to 35. The larger
minimum was based on the Journal Export Format file reader, but we don't
need to be as strict here.

Update some comments.

Bug: 16734
Change-Id: Iad7227f29ff22f908e2fd49be0f11c9ad03fa7b9
Reviewed-on: https://code.wireshark.org/review/38035
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-08-03 06:48:21 +00:00
Guy Harris c68d36b173 wiretap: have the file's time stamp resolution be a dump parameter.
Add a tsprec value to the wtap_dump_params structure, giving the
per-file time stamp precision.

In wtap_dump_init_dumper(), when constructing a dummy IDB for files that
don't have one, fill in the tsprecision and time_units_per_second values
based on the tsprec value in the wtap_dump_params structure.

Change-Id: I3708b144d4d0ac0dfbe32bd1c16768a75c942141
Reviewed-on: https://code.wireshark.org/review/37979
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-07-29 13:49:09 +00:00
Guy Harris f8efccc3cc wiretap: generate fake IDBs for more capture file types.
That makes them work as input to a mergecap that writes pcapng files.

File types that don't have a single per-file encapsulation type need
more work, with multiple fake IDBs, one for each packet encapsulation
type seen in the file, unless we can generate real IDBs.

Change-Id: I2859e4f7fb15ec0c0f31a4044dc15638e5db7826
Reviewed-on: https://code.wireshark.org/review/37983
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-07-29 09:05:24 +00:00
Guy Harris 12621c5b64 wiretap: add a routine to add a "fake" IDB.
It generates a fake IDB for files that don't have interface information
and that have a per-file encapsulation type, snapshot length, and time
stamp precision, and adds it to the file's list of IDBs.

Use it for libpcap.

We will use it later for other file formats, so that code such as the
mergecap code to merge into a pcapng file can handle input files that
don't have interface information.

(We should have a way to indicate whether the IDBs are real or fake, so
that capinfos and Statistics > Capture File Properties don't report
meaningless IDB information and make it look as if it's known that the
capture was done on one interface with the properties in question.)

Change-Id: Iec124bf3c7cbd4c69ec2ac7d0dd776e5287f8576
Reviewed-on: https://code.wireshark.org/review/37982
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-07-29 07:03:02 +00:00
Guy Harris 8c0c27e590 iptrace: supply packet direction.
Change-Id: If28f04a34be6ec35e4fc60b2add129ca916d5ebd
Reviewed-on: https://code.wireshark.org/review/37976
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Jaap Keuter <jaap.keuter@xs4all.nl>
2020-07-27 14:59:56 +00:00
Guy Harris c099892700 iptrace: generate IDBs.
The packet information for a packet includes an interface name prefix
and an interface unit number (e.g., "en0", with a prefix of "en" and a
unit number of 0).  Keep a hash table of prefixes, unit numbers, and
link-layer header types (as an interface must have only one link-layer
header type), and, for each packet, look up that information from the
packet information to get the interface ID; if that fails, construct a
new entry, with a new interface ID, and an IDB for the interface.

Change-Id: I3f2dafcc8926fe96fe4ffd6875f583397b1582b6
Reviewed-on: https://code.wireshark.org/review/37975
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-07-27 10:10:57 +00:00
Guy Harris a4ebc98fa4 iptrace: various cleanups.
Call the "iptrace X.Y" string we read in the version string, rather than
the name.

Get rid of the structures defining various parts of the file format.
Instead, have #defines for offsets.

Read the record header - the first 8 octets - first.  Check the record
length, to make sure it's large enough to include the packet information
structure, before we try to read that structure.

Note that one octet in the packet information structure is the unit
number for the interface on which the packet arrived, the field that was
called the name is the prefix of the name (in the sense that, for
example, in "en0", "en" is the prefix and "0" is the unit number), and
that what was called the "description" isn't as simple as a description
of the interface on which the packet arrived.

Pass the field that was called the "description" to
fill_in_pseudo_header(), as, for ATM PDUs, it contains, among other
things, an indication of the VPI and VCI for the PDU, as well as a
direction indication.

Change-Id: I8703b046142dd41ca96bda00c2fa3d2edb66b837
Reviewed-on: https://code.wireshark.org/review/37974
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-07-27 09:21:08 +00:00
Guy Harris 75c739e4b7 ISDN, LAPD: clean up the way they connect to other dissectors.
Have the ISDN dissector take the ISDN pseudo-header through its data
argument, rather than assuming it's in pinfo->pseudo_header, so it can
be used if the link-layer type of the capture isn't ISDN.

Have it add the direction to its protocol tree, so it's there for all
ISDN packets.

Have more versions of the LAPD dissector:

	one where the ISDN direction information is available through
	an ISDN pseudo-header passed as its data argument;

	one for use when the link-layer type *is* LAPD, where the ISDN
	direction information may be available through the direction
	part of the packet flags.

Pass more flags to the routine that does LAPD dissection to indicate the
direction (user->network or network->user) and whether the user or
network side is on another machine; set those appropriately in the
dissector routines that call it.  To set those flags:

	in the routine that handles WTAP_ENCAP_LAPD, check the direction
	flags in pinfo->rec->rec_header.packet_header.pack_flags;

	in the routine that handles WTAP_ENCAP_LINUX_LAPD, check the SLL
	header;

	in the routine that's called from the ISDN dissector and other
	dissectors that can supply an ISDN pseudo-header, check the
	struct isdn_phdr passed to it via the data argument;

	for the routine that's to be called from L2TP pseudowire type
	and SCTP dissector tables, pass nothing, as there's currently
	no direction indication supplied - if that information is
	available from the encapsulating protocol in some fashion, we
	should make changes to supply that information.

Have the AudioCodes Trunk trace protocol dissector call the
LAPD-with-pseudoheader dissector, handing it an ISDN pseudo-header with
a direction indication from the direction field (and a channel of 0 to
indicate the D channel).

Have the Ascend text dump reader in libwiretap use WTAP_ENCAP_ASCEND for
all packets, even Ethernet and ISDN packets, and have the Ascend text
dump dissector handle that, calling the "no FCS" version of the Ethernet
dissector and calling the LAPD-with-pseudoheader dissector with a
pseudo-header filled in with the direction (and a channel of 0).

Have the Catapult DCT 2000 text dump dissector call the
LAPD-with-pseudoheader dissector with the pseudo-header supplied by
libwireshark.

Have the V5 envelope function frame get its ISDN pseudo-header from its
data argument, and call the LAPD-with-pseudoheader dissector with that
pseudo-header.

Have the ISDN dissector treat its data argument as pointing to the ISDN
pseudo-header, rather than assuming it's the one in
pinfo->pseudo_header->isdn - the latter is the one supplied by
libwiretap, but there's no guarantee that an ISDN pseudo-header was
supplied by libwiretap, as the lowest-level protocol layer might not
have been ISDN.

Change-Id: I9f702b879bbc3fb42bcb43c28f797bfc327562c6
Reviewed-on: https://code.wireshark.org/review/37953
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-07-25 18:31:34 +00:00
Guy Harris 9db3ce11eb ascend: update a comment.
Change-Id: I652a033132a90b10421e763cfbe4b47ae4e6087a
Reviewed-on: https://code.wireshark.org/review/37924
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-07-22 07:15:10 +00:00
Guy Harris 8cf626bf16 nettl: user IDs are 32-bit in HP-UX.
Also note that the record header might have additional stuff at the end,
although not all record headers do (the header length will indicate
what's there).

Change-Id: I5a9ff1f9cd592448bcc45d18808f4b651cdb2f0d
Reviewed-on: https://code.wireshark.org/review/37921
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-07-21 22:48:21 +00:00
Gerald Combs 4a4c8bdfea Systemd journal: Fix timestamp conversions.
Use ws_strtou64 to convert __REALTIME_TIMESTAMP= and other timestamps,
which should work across platforms.

Bug: 16664
Change-Id: I371f2b60e1957e57dbbdbbc3ded5ad49e8eb79d1
Reviewed-on: https://code.wireshark.org/review/37849
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-07-14 04:02:35 +00:00
Anders Broman f0158ea131 Nettrace: Try to fix -Wpointer-sign warnings.
Change-Id: Ib2fe089939513f2fa32235312cdc70c9148cdfc3
Reviewed-on: https://code.wireshark.org/review/37723
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-07-06 10:40:52 +00:00