Commit Graph

3548 Commits

Author SHA1 Message Date
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