Commit Graph

1351 Commits

Author SHA1 Message Date
João Valverde 612c0cff60 wmem: Add ws_strdup_printf() convenience macros
The convention (for wmem) is that functions with ws_ use
malloc'ed memory. This is just a convenience to avoid having
to pass a NULL allocator.
2021-12-19 10:48:15 +00:00
João Valverde f75b79a59d Move wmem string utility functions to wsutil 2021-12-19 10:47:50 +00:00
João Valverde 8cc527cce3 wmem: Use vasprintf()
Use vasprintf(3) if available to optimize wmem_stdup_printf().
2021-12-18 23:16:38 +00:00
João Valverde 58c297ca81 wmem_test: Add more string performance test
Add some C99 stdio.h numbers to compare with GLib on platforms
(such as Windows) where they use different implementations.

Add a wmem string test with NULL allocator, to compare wmem and GLib
performance with roughly the same memory allocation.

Use the block allocator as being more representative of normal
wmem performance, instead of using strict, that is normally
used for wmem debugging.
2021-12-18 20:13:41 +00:00
João Valverde 9465c5c28d wmem_test: Disable performance tests by default
These are not pass/fail tests, so the automation cannot
validate them. They just slow down the CI builds. To
enable pass -m perf.

I think the --verbose comment is wrong, I did not detect
any difference in output with or without --verbose.
2021-12-18 20:13:41 +00:00
João Valverde f837dae4c4 Fix wmem_test.c indentation 2021-12-18 19:39:21 +00:00
João Valverde b83f264f7d Fix wsutil/time_util.c indentation 2021-12-18 19:39:21 +00:00
João Valverde 81de22e81a wslog: 'struct timespec' is C11, use that 2021-12-15 15:00:59 +00:00
João Valverde fe30cf2f8a wsutil: Add portability wrapper for clock_gettime(CLOCK_REALTIME) 2021-12-15 15:00:59 +00:00
João Valverde e877460a9e Revert "The function timespec_get() is C17 so assume we have it"
This reverts commit 8b15d0e641.
2021-12-15 15:00:59 +00:00
João Valverde fa41e2244c wmem: Optimize wmem_strdup_vprintf()
Because we already have the length of the output string after
calling vsnprintf(), we should avoid calling wmem_strdup(), which
will ignore that and recompute the length.

Increase the buffer size to a value that seems reasonable to
minimize the chance of a second call to vsnprintf().
2021-12-15 06:48:24 +00:00
João Valverde cf3cb3a695 wslog: Avoid logging any output to stdout
For historical reasons our logging inherited from GLib the logging of
some levels to stdout. Namely levels "info" and "debug" (to which we
added "noisy").

However this practice is discouraged because it mixes debug output
with application output for CLI tools and breaks many common usage
scenarios, like using tshark in pipes.

This change flips the logic on wslog to make logging to stderr the
default behavior.

Extcap subprocess have a hidden dependency on stdout so add that.

Some GUI users may also have a dependency on stdout. Because
GUI tools are unlikely to depend on stdout for programatic output
add another exception for wireshark GUI, to preserve backward
compatibility.
2021-12-14 12:05:41 +00:00
João Valverde 77b6bca387 Convert wmem I/O to use stdio.h 2021-12-14 11:23:05 +00:00
João Valverde 8b15d0e641 The function timespec_get() is C17 so assume we have it 2021-12-14 11:23:05 +00:00
João Valverde fb0e1a4907 regex: Remove requirement for ssize_t
The type ssize_t is not available on Windows. Because this is
used in the public API we must provide a definition for it.
To avoid having to add a header to fix this use a size_t in
the API instead, and assign SIZE_MAX to represent a null
terminated string.
2021-12-13 23:57:32 +00:00
João Valverde cace66d45d The macro 'va_copy' is C99, use that 2021-12-12 11:56:17 +00:00
João Valverde 53cded5062 wslog: Add backward compatibility with 'console.log.level'
This adds some custom logic to check if we were given
the obsolete 'console.log.level' setting from the CLI
arguments, that specified the log level using a bitmask
copied from GLib. If we find that map the bitmask to a
wslog log level.

In any case the option is not removed from the argv (unlike
other wslog arguments like --log-level, etc.).

Adds deprecation warning for 'console.log.level' printed to
the console.

Related to #17763.
2021-12-11 00:19:09 +00:00
João Valverde b6130cd970 extcap: Register log handler conditionally
This matches the original implementation and allows displaying
logs to the console, including debug information, when running
an extcap from the CLI for testing and development purposes.

This should make extcap logging bug-for-bug compatible with the
behavior before dc7f0b88bb.
2021-12-06 18:51:42 +00:00
João Valverde 25c7a1abc8 wslog: Use stdout for debug messages
Imitate the GLib logic for selecting the console output stream
according to the log level. Levels MESSAGE and above go to
stderr. INFO and below go to stdout, unless stderr is chosen
using ws_log_console_writer_set_use_stderr().

It turns out some old extcap code was subtly dependending
on this behavior.
2021-12-06 18:51:42 +00:00
AndersBroman 3e0506dbe9 Make wmem_print_tree public. 2021-12-06 16:06:13 +00:00
João Valverde e921b804d0 Fix logging with extcaps
Extcaps require a log file when invoked in child mode. It also has
a specific flag to enable debugging, other that the wslog options.

Fix the logging to:
  1. Enable debug log level if --debug is used.
  2. Do not emit messages to the stderr if debug is enabled.

This brings extcap logging to the same feature level it had before
wslog replaced GLib logging.
2021-12-03 12:30:53 +00:00
João Valverde fe9b1fb103 dfilter: Avoid dumping mangled UTF-8
We should not replace chars that cannot be represented
in ASCII, to avoid mangling UTF-8. This assumes every
string is UTF-8, of course.

This only affects the display of the compiled filter.

Before:

    Filter: http.user_agent == "João"

    Constants:
    00000 PUT_FVALUE	"Jo\xc3\xa3o" <FT_STRING> -> reg#1

After:

    Filter: http.user_agent == "João"

    Constants:
    00000 PUT_FVALUE	"João" <FT_STRING> -> reg#1
2021-12-02 16:04:48 +00:00
John Thacker aadf4efcbe epan: Add ENC_ISO_8601_DATE_TIME_BASIC
Add the ISO 8601 Basic date time format as another string time
option. This could be used for e.g. ASN.1 GeneralizedTime.
Add tests for it.
2021-12-02 14:19:49 +00:00
John Thacker cf0ecc4fe1 nstime: Support ISO 8601 basic format
Add support in iso8601_to_nstime for the ISO 8601 Basic date/time
format that lacks the - and : separators.
2021-12-01 20:50:37 -05:00
Moshe Kaplan e45ad9dcef wsutil: Add header files to Doxygen
Add @file markers for wsutil
headers so that Doxygen will
generate documentation for them.
2021-11-30 07:30:34 +00:00
Moshe Kaplan 40016daeb3 Add files with WS_DLL_PUBLIC to Doxygen part2
Add @file markers for remaining non-dissector
files that contain functions exported with
WS_DLL_PUBLIC so that Doxygen will
generate documentation for them.
2021-11-30 06:47:35 +00:00
João Valverde 504de90a3c wsutil: Split format_size() enum
Use an enum to select units and a bit flag for the other options,
currently only prefix type.
2021-11-29 22:13:32 +00:00
João Valverde 51f2a56b7c wsutil/str_util: Fix indentation
This file has mixed space and tabs indentation, use the standard
4-space C indentation everywhere.
2021-11-29 22:13:31 +00:00
Moshe Kaplan 1c3a9af869 Add files with WS_DLL_PUBLIC to Doxygen
Add @file markers for most files that
contain functions exported with
WS_DLL_PUBLIC so that Doxygen will
generate documentation for them.
2021-11-29 21:27:45 +00:00
João Valverde 37f2a86207 Move string_or_null() to wsutil 2021-11-29 18:37:03 +00:00
João Valverde 9c61142195 wsutil: Add more character escapes to ws_escape_string()
Add whitespace and other escapes for a better display of strings
in the UI.
2021-11-29 17:47:53 +00:00
João Valverde 54bdc20e45 epan: Rewrite ws_escape_string() to use wmem
Return a wmem-allocated string.

Add boolean argument to enable/disable adding double quotes.
2021-11-29 17:47:53 +00:00
João Valverde 44121e2c3b Move escape_string() to wsutil
Move this utility function to wsutil. Rename to
ws_escape_string().

Also add tests.
2021-11-29 17:47:53 +00:00
Uli Heilmeier c8c9ef0c1c OS Version Info: Improve Windows detection
Figuring out the right Windows version for 10/11 or Server 2016/2019/2022
by using the build number.
2021-11-28 22:16:19 +00:00
João Valverde ef8125e3ae Move two functions from epan to wsutil/str_util
Move epan_memmem() and epan_strcasestr() to wsutil/str_util.
Rename to ws_memmem() and ws_strcasestr(). Add compile time
check for a system implementation and use that if available.

We invoke those functions using a wrapper to avoid exposing
_GNU_SOURCE outside of the implementation.
2021-11-28 12:32:51 +00:00
João Valverde f5d8d9e306 wmem: Use better names in the API 2021-11-27 19:39:27 +00:00
John Thacker ba85d8ef4d wustil: Fix timezone handling in iso8601_to_nstime
Convert the tm struct to nstime first, then apply the timezone
offset, because applying the offset to the hours and minutes fields
directly can require carrying or borrowing in base 24 and 60 arithmetic.
2021-11-26 22:07:11 -05:00
John Thacker 9413658b7c wsutil: Clarify NT epoch explanation in comment 2021-11-27 00:53:38 +00:00
John Thacker 9da9c4e388 wsutil: Prevent buffer overflow in iso8601_to_nstime
Don't blindly examine the fifth byte in the input string without testing
earlier bytes.  Instead, process the year by hand before calling sscanf.

ISO 8601 times don't switch between Basic and Extended format in the
middle, so for the later possible buffer overflows just use the
previously determined format.
2021-11-26 13:06:27 +00:00
John Thacker a839ee1c2b wmem: Fix filename in header comment
If the name is going to be in the header, might as well spell it
correctly
2021-11-26 07:46:11 -05:00
Uli Heilmeier 8d03eae346 OS Version Info: Update Windows 10/11 2016/2019
Windows Server 2016 and 2019 have both dwMajorVersion==10 and dwMinorVersion==0
It seems this is the same for Windows 10 and Windows 11.

See also https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/ns-wdm-_osversioninfoexw

As we don't know if we running on 10 or 11, 2016 or 2019 we should report
both OS names.
2021-11-24 07:36:16 +00:00
John Thacker b5917d0182 wmem: Add a multimap
A number of protocols have IDs that can be reused that are used as
lookup keys. In most cases the frame number should be used as well
to differentiate repeat appearances of an ID. For response/request
matching, it is frequently useful to find the most recent frame number
(greatest value less than or equal to the current one) that contained
an ID.

We can achieve that by using a multimap that stores values with a given
ID in a tree keyed with the frame number. This works better than using
a map or a tree alone:

1) A map isn't ordered, so doesn't allow for less than or equal comparison.
2) Using a tree requires an ordering on all the ID components, and then
   having to test all the components other than the frame number separately
   for equality after retrieval.

Currently the multimap does not support inserting items without specifying
the tree key (and having the multimap generate a key), because the total
capacity of trees (including deleted nodes) is not tracked. If other use
cases are needed, this could be added later along with more generic
multimap support.

Use a multimap in ANSI MAP, ANSI TCAP, and GSM SMS, all of which need to
match lookup IDs that can be reused. Fix #7653.
2021-11-21 07:16:55 -05:00
Gerald Combs e2703507c2 Update a bunch of GLib documentation links.
Change our developer.gnome.org/glib URLs to
developer-old.gnome.org/glib. The official documentation for GLib
appears to be at https://docs.gtk.org/glib/, but it has a different
layout than the gnome.org content (and is surprisingly resistant to
exploration IMHO). We can switch to developer-old.gnome.org using a
simple substitution and it still seems to be updated, so do that for
now.
2021-11-20 21:33:17 +00:00
João Valverde c92e4ff7c6 wslog: Remove (part of) a special case for the default level
Instead of removing extra log information in the log handler
for the default log level, do it in the ws_message() macro.

This means ws_log_full() will work as expected.
2021-11-15 09:22:06 +00:00
João Valverde b30a2112e8 regex: Prefer C99/POSIX types
Replace 'gssize' with 'ssize_t'.

Add a CMake configure check for ssize_t.

Fix missing "config.h" includes.
2021-11-15 02:41:59 +00:00
João Valverde b59980bbff regex: Add a diagnostic message
Add a debug log message if pcre2_match() errors out.

Minor optimization with the use of pcre2_match_data_create().

Minor cleanup.
2021-11-14 23:05:53 +00:00
João Valverde 274531820a Move regex code to wsutil 2021-11-14 21:00:59 +00:00
João Valverde 6630fd5260 wsutil: Rename ws_return_ptr_if_null() macro
Rename to ws_return_val_if_null() because the name needs to be more
generic to indicate it should be used to return any kind of value,
not just pointers.

Increase the log level to something more appropriate because failing
any of these checks is considered to be a programming error.

Add the faulty variable name to the output message.

Add the macro ws_return_val_if_zero() for completeness.
2021-11-14 20:58:14 +00:00
João Valverde 6f1b814e25 Fix some narrowing compiler warnings
C:\Development\wireshark\wireshark\epan\ftypes\ftype-integer.c(448,47): warning C4267: 'function': conversion from 'size_t' to 'int', possible loss of data [C:\Development\wsbuild-msvc\epan\ftypes\ftypes.vcxproj]
C:\Development\wireshark\wireshark\epan\ftypes\ftype-integer.c(448,47): warning C4267:          guint32_to_str_buf(fv->value.uinteger, buf, size); [C:\Development\wsbuild-msvc\epan\ftypes\ftypes.vcxproj]
C:\Development\wireshark\wireshark\epan\ftypes\ftype-integer.c(448,47): warning C4267:                                                      ^ [C:\Development\wsbuild-msvc\epan\ftypes\ftypes.vcxproj]
C:\Development\wireshark\wireshark\epan\ftypes\ftype-integer.c(793,31): warning C4267: 'function': conversion from 'size_t' to 'int', possible loss of data [C:\Development\wsbuild-msvc\epan\ftypes\ftypes.vcxproj]
C:\Development\wireshark\wireshark\epan\ftypes\ftype-integer.c(793,31): warning C4267:  guint64_to_str_buf(val, buf, size); [C:\Development\wsbuild-msvc\epan\ftypes\ftypes.vcxproj]
C:\Development\wireshark\wireshark\epan\ftypes\ftype-integer.c(793,31): warning C4267:                               ^ [C:\Development\wsbuild-msvc\epan\ftypes\ftypes.vcxproj]
C:\Development\wireshark\wireshark\rawshark.c(1140,24): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data [C:\Development\wsbuild-msvc\rawshark.vcxproj]
C:\Development\wireshark\wireshark\rawshark.c(1140,24): warning C4267:         fs_len = strlen(fs_buf); [C:\Development\wsbuild-msvc\rawshark.vcxproj]
C:\Development\wireshark\wireshark\rawshark.c(1140,24): warning C4267:                        ^ [C:\Development\wsbuild-msvc\rawshark.vcxproj]
2021-11-10 16:13:17 +00:00
João Valverde 5680d1ae0b wsutil: Improve bytes_to_str_max() API
Have these functions accept a zero max length to mean "display
the whole byte array". Change the max length parameter to receive a
number of bytes to print, not the length of the output character
string.

Adjust the macros bytes_to_str() and bytes_to_string_punct() to
produce the same output. Add more tests. Rename the functions to
bytes_to_str_maxlen() and bytes_to_str_punct_maxlen() because this is
an API break.
2021-11-09 20:57:05 +00:00
Gerald Combs 6ae87c7cf1 wslog: Add a NULL check.
Fixes Coverity CID 1485996.
2021-11-09 09:22:53 -08:00
João Valverde 8c9019a155 wireshark.h: Remove wmem dependency.
Start smaller. Remove the return macros from wslog.h because
that pulls in a wmem dependency and the interface is not very
stable yet.
2021-10-22 06:41:44 +00:00
João Valverde 59c082c046 Add new global header wireshark.h with guideline
Remove ws_diag_control.h from config.h because that was a workaround
for the lack of a public global header. Fix the resultant build errors.
2021-10-22 06:41:44 +00:00
Nardi Ivan 763247c2b3 QUIC: fix compilation on Raspberry 2021-10-19 20:04:17 +00:00
Brian Sipos e63f8d8daa wsutil: install missing public header wsgcrypt.h 2021-10-18 09:55:50 +00:00
João Valverde a975d478ba dfilter: Require double-quoted strings with "matches"
Matches is a special case that looks on the RHS and tries
to convert every unparsed value to a string, regardless
of the LHS type. This is not how types work in the display
filter. Require double-quotes to avoid ambiguity, because
matches doesn't follow normal Wireshark display filter
type rules. It doesn't need nor benefit from the flexibility
provided by unparsed strings in the syntax.

For matches the RHS is always a literal strings except
if the RHS is also a field name, then it complains of an
incompatible type. This is confusing. No type can be compatible
because no type rules are ever considered. Every unparsed value is
a text string except if it happens to coincide with a field
name it also requires double-quoting or it throws a syntax error,
just to be difficult. We could remove this odd quirk but requiring
double-quotes for regular expressions is a better, more elegant
fix.

Before:
  Filter: tcp matches "udp"

  Constants:
  00000 PUT_PCRE	udp -> reg#1

  Instructions:
  00000 READ_TREE		tcp -> reg#0
  00001 IF-FALSE-GOTO	3
  00002 ANY_MATCHES	reg#0 matches reg#1
  00003 RETURN

  Filter: tcp matches udp

  Constants:
  00000 PUT_PCRE	udp -> reg#1

  Instructions:
  00000 READ_TREE		tcp -> reg#0
  00001 IF-FALSE-GOTO	3
  00002 ANY_MATCHES	reg#0 matches reg#1
  00003 RETURN

  Filter: tcp matches udp.srcport
  dftest: tcp and udp.srcport are not of compatible types.

  Filter: tcp matches udp.srcportt

  Constants:
  00000 PUT_PCRE	udp.srcportt -> reg#1

  Instructions:
  00000 READ_TREE		tcp -> reg#0
  00001 IF-FALSE-GOTO	3
  00002 ANY_MATCHES	reg#0 matches reg#1
  00003 RETURN

After:
  Filter: tcp matches "udp"

  Constants:
  00000 PUT_PCRE	udp -> reg#1

  Instructions:
  00000 READ_TREE		tcp -> reg#0
  00001 IF-FALSE-GOTO	3
  00002 ANY_MATCHES	reg#0 matches reg#1
  00003 RETURN

  Filter: tcp matches udp
  dftest: "udp" was unexpected in this context.

  Filter: tcp matches udp.srcport
  dftest: "udp.srcport" was unexpected in this context.

  Filter: tcp matches udp.srcportt
  dftest: "udp.srcportt" was unexpected in this context.

The error message could still be improved.
2021-10-17 22:53:36 +00:00
Balint Reczey 9f92da75b8 wsutil: Provide static inline g_memdup2 in glib-compat.h to not export it
Shared libraries should not export symbols exported by other libraries to avoid
collisions.

Fixes #17645.
2021-10-11 21:51:35 +02:00
Adrian Granados da11ef5770 ieee80211: Add 6E support when converting freq. to channel number.
Converting from freq to channel only needed the 6 GHz freq. range
to be added, however, converting from channel to freq. will require
the function ieee80211_chan_to_mhz to take a starting frequency as
there's overlap in the channel numbering between 2.4/5 GHz and 6 GHz
bands. This may not be possible in some cases, so for now the
function will continue to do the conversion based on the order
on which the freq. ranges are defined. Specifically, it will favor
2.4/5 GHz over 6 GHz.
2021-10-03 10:03:45 +00:00
João Valverde 3ea2a61f2a dfilter: Display syntax tree for debugging
Use wslog to output debug information. Being able to control
it at runtime is a big advantage.

We extend the syntax tree nodes with a method to return a
canonical string representation.

Add a routine to walk the tree and return an textual representation
for debugging purposes.
2021-09-30 16:29:11 +01:00
João Valverde 1883487241 ws_getopt: Add a test for optional parameter 2021-09-30 14:24:52 +00:00
João Valverde 5362d0c31b ws_getopt: Rename struct and macros
This is part of the API and should also be renamed to avoid conflicts.
2021-09-30 13:59:28 +00:00
João Valverde e6a1225611 wslog: Alias --log-domain to --log-domains
I keep mistyping this if there is only one domain and it's annoying.
2021-09-30 13:08:32 +00:00
João Valverde acffc56148 test_wsutil: Use 'static' linkage 2021-09-25 19:44:40 +01:00
Stig Bjørlykke 533d859499 Qt: Register import_hexdump.json as a profile file
Profile files which is only used in Qt is not automatically registered
during startup and must be explicit registered.

Add profile_register_persconffile() to handle this registration.
2021-09-21 18:20:34 +00:00
João Valverde b2691b8f6c file_util: Fix declaration is not a prototype [-Wstrict-prototypes] 2021-09-21 14:52:32 +00:00
João Valverde b054286744 ws_getopt: Cleaner better __getopt_msg()
This is more readable and the extra error checking is functionally
the same as the original upstream code too, that trigerred some
compiler warnings.

Add missing 'static' qualifier.

Add a test for 'ws_opterr'.
2021-09-19 13:48:09 +01:00
João Valverde a34a234cf2 wslog: Add ws_log_buffer()
Use the new API with dot11decrypt debug.
2021-09-18 10:59:10 +01:00
João Valverde dd59d1fcf9 ws_getopt: Add test suite skeleton with some basic tests 2021-09-17 14:15:55 +00:00
João Valverde fea994855d Revert "ws_getopt: Disable MSVC warning C4244"
This reverts commit ac3a30f61b.

Clang build also has this warning enabled. Fixed in
3c484f278b.
2021-09-17 02:45:50 +01:00
Gerald Combs 3c484f278b ws_getopt: Fix some clang warnings.
Fix

wsutil/ws_getopt.c:93:21: error: possible misuse of comma operator here [-Werror,-Wcomma]
                return ws_optind++, -1;
                                  ^
wsutil/ws_getopt.c:93:10: note: cast expression to void to silence warning
                return ws_optind++, -1;
                       ^~~~~~~~~~~
                       (void)(    )
wsutil/ws_getopt.c:188:11: error: possible misuse of comma operator here [-Werror,-Wcomma]
                                name++, opt++;
                                      ^
wsutil/ws_getopt.c:188:5: note: cast expression to void to silence warning
                                name++, opt++;
                                ^~~~~~
                                (void)( )
wsutil/ws_getopt.c:199:15: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
                        int l = arg-start;
                            ~   ~~~^~~~~~

Add a .editorconfig entry for ws_getopt.[ch].
2021-09-16 18:07:02 -07:00
João Valverde ac3a30f61b ws_getopt: Disable MSVC warning C4244 2021-09-17 00:43:54 +01:00
João Valverde 2deb1c95d9 Merge ws_getopt source files
No need to keep a separate ws_getopt_long.c file.
2021-09-17 00:43:54 +01:00
João Valverde 8df2a73594 Use the musl in-tree getopt_long() everywhere
Besides the obvious limitation of being unavailable on Windows,
the standard is vague about getopt() and getopt_long() has many
non-portable pitfalls and buggy implementations, that increase
the maintainance cost a lot. Also the GNU libc code currently
in the tree is not suited for embedding and is unmaintainable.

Own maintainership for getopt_long() and use the musl implementation
everywhere. This way we don't need to worry if optreset is available,
or if the $OPERATING_SYSTEM version behaves in subtly different ways.

The API is under the Wireshark namespace to avoid conflicts with
system headers.

Side-note, the Mingw-w64 9.0 getopt_long() implementation is buggy
with opterr and known to crash. In my experience it's a headache to
use the embedded getopt implementation if the system provides one.
2021-09-17 00:43:54 +01:00
João Valverde 7462e76884 Add musl getopt_long() source files to project
Copied verbatim from musl 1.2.2.

https://www.musl-libc.org
2021-09-17 00:28:06 +01:00
João Valverde 4d873d4ce2 wsutil/to_str: Use a macro to check buffer size 2021-09-17 00:08:41 +01:00
João Valverde 18c155a3ca wsutil: Remove ip6_to_str_buf_with_pfx()
Writing a string prefix shouldn't require a specialized function here.
2021-09-17 00:08:41 +01:00
João Valverde 364df939ea wsutil: Rewrite ip6_to_str_buf() 2021-09-17 00:08:40 +01:00
João Valverde d4c7978f68 wsutil: Add ip_to_str() 2021-09-16 23:18:53 +01:00
João Valverde 8c4a479c52 Move more numerical functions to wsutil/to_str.h 2021-09-16 20:55:03 +01:00
João Valverde 8304ced0e6 wsutil: Add some tests for word_to_hex() 2021-09-16 18:21:14 +01:00
João Valverde 24fd8c6740 Move more numerical epan/*to_str() routines to wsutil 2021-09-16 18:21:14 +01:00
João Valverde 44538f6e4d wsutil: Add tests for to_str_back() 2021-09-16 15:53:14 +00:00
João Valverde 8b70e24889 wsutil/to_str: Rename some functions for consistency 2021-09-16 15:53:14 +00:00
João Valverde 8a584222f1 Move epan/*to_str_back() functions to wsutil 2021-09-16 15:53:14 +00:00
João Valverde bd33320521 wslog: Add macro to validate arguments and return
Similar to g_return_if_fail(), etc.
2021-09-15 18:19:07 +00:00
João Valverde 20dc422550 wsutil: Add test for bytes_to_str_punct() 2021-09-15 18:38:57 +01:00
Graham Bloice 58207d2f8d Windows: Update displayed OS version info
MS has changed the registry key that holds the version for display
from 20H2 onwards.
2021-09-11 14:27:21 +00:00
Jorge Mora 981ec7f3c7 iwarp_mpa: fix iWarp MPA for NFS-over-RDMA
On the first packet of the conversation, the MPA layer is
dissected correctly followed by the DDP, RDMAP, RPC-over-RDMA,
RPC and NFS layers. The MPA layer sets the TCP conversation as
MPA protocol but when it dissects the RPC layer it also sets
the TCP conversation as RPC protocol thus overwriting the previous
protocol.

Added new port type PT_IWARP_MPA so that when the RPC layer
is dissected it does not overwrite the default protocol for
the TCP conversation which has already been set to MPA.

Fixes #15869.
2021-08-31 08:14:31 +00:00
Guy Harris e490f93072 wmem: don't check whether sizeof(type) is <= 0.
This should fix the cppcheck warning "The unsigned expression
'sizeof(struct _PKT_INFO)' will never be negative so it is either
pointless or an error to check if it is."

wmem_safe_mult() was only used to do an overflow-safe multiplication of
a type size and a count of elements of that type; replace it with
wmem_safe_mult_type_size(), which takes the type as the first argument,
and checks only whether the count of elements is <= 0.
2021-08-24 20:58:00 -07:00
Guy Harris 4de9f6ef83 Fix some issues with Exported PDUs.
Fix the description in wsutil/exported_pdu_tlvs.h to reflect reality
(i.e., to match what the code in Wireshark that reads the exported PDU
TLVs, and all code that writes them, does).

In the code that dissects them, treat all strings as FT_STRINGZPAD, as
any null bytes at the end of the string are padding, not part of the
string.

See merge request !3895 and issue #17535.
2021-08-21 02:31:45 -07:00
Guy Harris 4e80643cc0 Move LINKTYPE_WIRESHARK_UPPER_PDU definitions to a separate header.
Have wsutil/exported_pdu_tlvs.h define the LINKTYPE_WIRESHARK_UPPER_PDU
TLV type and length values, as well as the port type values written to
files in EXP_PDU_TAG_PORT_TYPE TLVs.

Update the comment that describes the LINKTYPE_WIRESHARK_UPPER_PDU TLVs
to more completely and correctly reflect reality (it was moved from
epan/exported_pdu.h to wsutil/exported_pdu_tlvs.h).

Rename those port type values from OLD_PT_ to EXP_PDU_PT_; there is
nothing "old" about them - yes, they originally had the same numerical
values as the PT_ enum values in libwireshark, but that's no longer the
case, and the two are now defined independently.  Rename routines that
map between libwireshark PT_ values and EXP_PDU_PT_ values to remove
"old" from the name while we're at it.

Don't include epan/exported_pdu.h if we only need the
LINKTYPE_WIRESHARK_UPPER_PDU definitions - just include
wsutil/exported_pdu_tlvs.h.

In extcap/udpdump.c, include wsutil/exported_pdu_tlvs.h rather than
defining the TLV types ourselves.
2021-08-20 02:18:19 -07:00
Alexis La Goutte 17f474406a nstime: Fix Dead Store (found by Clang Analyzer)
Although the value stored to 'n_scanned' is used in the enclosing expression, the value is never actually read from 'n_scanned'
2021-07-30 20:43:55 +00:00
João Valverde 0693674494 wslog: Add function to log directly without filtering
Used to write custom logging functions.
2021-07-29 20:17:44 +01:00
João Valverde 7b845e7194 wsutil: rename bytestring_to_str() -> bytes_to_str_punct() 2021-07-29 17:23:05 +00:00
João Valverde 177e5cda1f wsutil: Clean up unit test namespaces
Remove implicit root and separate tests for proper coverage.
2021-07-29 17:23:05 +00:00
João Valverde f0b02dd0ff wsutil: Add max length argument to bytes_to_str() 2021-07-29 17:23:04 +00:00
João Valverde 1ff6cc7b27 wsutil: Add some tests for bytes_to_str() 2021-07-29 17:23:04 +00:00
João Valverde c3bd5c9d91 Move bytes_to_str() to wsutil
This utility function is useful outside of epan. Move it to wsutil
and export the interface.

The move isn't completely clean as it requires duplicating two small
inline functions but that was necessary to avoiding moving too much at
once.
2021-07-29 17:23:04 +00:00
João Valverde 0983eb2456 wslog: Avoid macro duplication 2021-07-29 01:52:39 +01:00
João Valverde 925e01b23f Remove duplicate format_size() function
We have two format_size()s, with and without wmem scoped memory.
Move the wmem version to wsutil and add a convenience macro to
use g_malloc()ed memory.
2021-07-26 14:56:11 +00:00
João Valverde 7f9c1f5f92 Move wmem to wsutil
This allows wmem to be used from other libraries, namely wsutil.
It is often the case that a funtion exists in wsutil and cannot
be used with a wmem scope, requiring some code duplication or
extra memory allocations, or vice-versa, code in epan cannot be
moved to wsutil because it has a wmem dependency.

To this end wmem is moved to wsutil. Scope management remains part
of epan because those scope semantics are specific to dissection.
2021-07-26 14:56:11 +00:00
João Valverde 6ab67e2aa6 wslog: Minor fixes and cleanups 2021-07-25 18:21:31 +00:00
Gerald Combs 34ef2066e5 CMake: Don't bother checking for fcntl.h or floorl.
fcntl.h appears to be available on all of our supported platforms,
including Windows. We've also been including it without HAVE_FCNTL_H
guards in a few places (e.g. sshdump.c) without any issues for some
time.

floorl is part of C99.
2021-07-15 06:41:05 +00:00
Gerald Combs ff60fcf92d CMake: Adjust wsutil includes and linking.
Mark wsutil's includes SYSTEM PRIVATE. This exposed a lot of targets
that were indirectly picking up include paths via the wsutil target, so
add direct includes where needed. The G.722 and G.726 codecs were
implicilty including tiffio.h; find it explicitly instead.

Mark some of wsutil's libraries PRIVATE, but leave commonly-used ones
PUBLIC.

Ping #17477.
2021-07-14 03:56:05 +00:00
João Valverde 89acb935bc wsutil: Start adding a test suite 2021-07-11 14:39:13 +00:00
João Valverde 396d560744 wsutil: Revert some changes to format_size()
Revert change to format_size() added in
f509a83381. This commit broke formatting
with spaces and introduced some dead code.

Also replace unnecessary call to format_size_wmem() and remove
unnecessary casts (since our warning settings were fixed in the
mean time).
2021-07-11 14:39:13 +00:00
João Valverde 6498f1fce5 wslog: Fix representation of null domain
Map "" to "(none)", besides NULL.
2021-07-09 23:43:49 +01:00
João Valverde de59975fc1 wslog: fixup copyright 2021-07-09 18:25:02 +01:00
João Valverde cb61645941 wslog: Fix comment 2021-07-09 18:24:39 +01:00
João Valverde 4124986a9c wslog: Prefer more modern time APIs
Functions clock_gettime() and timespec_get() cover all the platforms
we support with sub-second resolution in a a portable manner. Fallback
to using time().

Pass a struct timespec to the log writer callback for maximum
flexibility.
2021-06-29 14:19:55 +00:00
Guy Harris c125236e57 wslog: don't assume how big struct timeval's tv_usec is.
At least according to the Single UNIX Standard, it merely has to be big
enough to hold a value in the range [-1, 1000000], and there must be
*an* environment in which it's no *larger* than a long.

Just cast it to long, and continue to print the result of dividing it by
1000 with %03ld.
2021-06-28 07:59:33 +00:00
João Valverde 3fc5eb3f1f wslog: Replace g_date_time_format()
Calling GLib functions inside the log writer is not safe,
it might infinitely recurse or abort if g_date_time_* logs
warnings because we registered our log handler for GLib itself.
2021-06-28 00:09:30 +01:00
João Valverde ceedd7b334 wslog: Update API documentation and improve code formatting 2021-06-26 00:44:23 +01:00
João Valverde c6a920686c wslog: Check environment initialization for errors
Initialiaze the cmdarg error stream earlier.

Dumpcap also needs to know earlier if it is running in capture
child mode.
2021-06-26 00:18:26 +01:00
João Valverde c2c256f0d8 wslog: Fatal messages should always be active 2021-06-26 00:18:26 +01: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
João Valverde 7aae691f7d wsutil: Rewrite ws_assert() to minimize dependencies
This includes as little as possible in the assertion header, so
that it can be included globally in every file without pulling
any unwanted definitions. In particular pulling stdlib.h is
avoided because that can have side effects if it wants to
include non-portable extensions.

It is possible to have side-effects from include glib.h too, for
example because of G_LOG_DOMAIN.

These side-effects are usually avoidable with careful ordering
of pre-processor directives but with multiple levels of indirections
it can be hard to track. Better to make it robust to these kinds
of failures in the first place.

Also integrate with our logger for a cohesive experience (but
keep it a private dependency).
2021-06-25 22:06:32 +00:00
João Valverde 53704fb971 wsutil: Rewrite ws_log() to minimize dependencies
Minimizing the dependencies on other wsutil and GLib functions
reduces the chance that we will have a weird recursion pattern
in wslog and makes the code easier to analyze.
2021-06-25 22:06:32 +00:00
João Valverde 129046b518 wsutil: Fix incorrect header include
wsutil should not have any dependency on epan, replace the
extraneous header.
2021-06-25 03:14:22 +00:00
João Valverde cd05ec7232 wslog: Register log handler with GLib
This avoids having to manage two different implementations.
For example with this change GLib functions will terminate
if Wireshark's fatal log level is set to a matching level
and the --log-file option will also output messages from
GLib itself.
2021-06-24 02:31:42 +01:00
João Valverde a370024ca9 wslog: Fix initialization with invalid environment
We can't write to stderr outside of the default writer context.
Wireshark and tshark will block if we do that and dumpcap is
running as capture child.
2021-06-24 02:26:28 +01:00
João Valverde eb3417e38f wslog: Slight color and format change
This changes color use to be the very similar with GLib to
maintain familiarity. The only difference is that Message
and Info use a different color than Debug.

Also use the more familiar format of <domain> <level> instead
of <level> <domain>.
2021-06-24 00:06:19 +01:00
João Valverde 752b0fc320 Debug: Lower priority to "noisy" for pipe spawn output
Spawn output can include very long multiline extcap arguments.
2021-06-23 17:45:44 +00:00
João Valverde 7bc3a5629e wslog: Fix crash using a custom log file
Add missing va_copy() call.
2021-06-23 17:09:24 +00:00
Dario Lombardo f62138c0d5 Fix some includes. 2021-06-22 19:25:43 +00:00
João Valverde 2080661e88 wslog: Documentation fixups 2021-06-21 22:39:54 +01:00
João Valverde 585ddc9283 wslog: Format and color amendments 2021-06-21 22:25:47 +01:00
João Valverde 759bb234d0 wslog: Check if we are initialized and add missing inits
Instead of receiving the program name from GLib, pass it explicitly
to ws_log_init() instead  and use that to initialize the GLib program
name.

ws_log_parse_args() will now exit the program when it encounters an
argument error if exit_failure >= 0.
2021-06-21 16:03:29 +00:00
João Valverde c216bb85e7 wslog: Reverse order for level priority
Consistently speaking of ascending priority for higher levels
seems slightly more intuitive. Use that instead.
2021-06-21 16:03:29 +00:00
João Valverde b23d2f8519 wslog: Cleanup the filter/match logic 2021-06-21 16:03:29 +00:00
João Valverde 3256e45b4e wslog: Critical and error are always active.
The intention was that "error" and "critical" are *always*
active (always...). Do that.
2021-06-21 16:03:29 +00:00
João Valverde 256f5f6e30 wslog: "Warning" can also be set as fatal 2021-06-21 16:03:29 +00:00
Pascal Quantin 3ea51dba87 NGAP: fix dissection of multiple NGAP messages in the same HTTP2 packet
Also add dissection for more containers
2021-06-21 13:33:55 +00:00
João Valverde 7dea683bf1 wslog: Shorten ws_log_message_is_active() name 2021-06-21 00:07:21 +00:00
Guy Harris 72b2cf6672 ws_assert: remove a stray semicolon at the end of an inline function. 2021-06-19 03:04:49 +00:00
João Valverde b4eddd32c1 wslog: Set registered name earlier 2021-06-19 02:07:34 +01:00
João Valverde dddb33e398 wslog: Be more obvious in the log that the domain is unset
Currently we are not filtering the unset (NULL) domain, on
the assumption that every log call should belong to a defined
domain.

However there are still many places in the codebase where this isn't
true and the fact that the null/default domain name is omitted from
the output and never filtered is probably surprising and user-unfriendly.
Users might understandably assume the filtering is buggy.

Give an indication, such as (none)-MESSAGE, to make this more
obvious.
2021-06-19 02:07:34 +01:00
João Valverde 7f17d18012 wslog: Fix domain filtering
Fixes 051a74378d.
2021-06-19 01:17:05 +01:00
João Valverde a6738d72a0 wslog: Add support for inverted debug matches
The --log-debug and --log-noisy now accepts a '!' to invert the
match and disable the debug (noisy respectively) log level for
the listed domains.

Note this is different from --log-domains, that option
enables/disables the entire log domain itself, regardless of log
level.
2021-06-18 10:43:39 +01:00
João Valverde 051a74378d wslog: Use NULL for empty/default domain 2021-06-18 10:43:39 +01:00
João Valverde c5b3842639 wslog: Add more documentation 2021-06-17 12:00:10 +01:00
João Valverde ff9acff6f2 Replace usage of GLogLevel flags everywhere
ws_log_domains.h needs to be included before wslog.h to be used
to define WS_LOG_DOMAIN. Also the definition for enum ws_log_level
needs to be exported for other APIs so move that to ws_log_domains.h
and rename the file to ws_log_defs.h to reflect the new scope.
2021-06-17 12:00:10 +01:00
João Valverde 02e34357bc wslog: Add a noisy debug level
This is intended to replace logging in dissectors that has a
debug level with #ifdef DEBUG_foo and an extra level guarded
by a #ifdef DEBUG_EXTRA_foo.

But generally it can be used as another level of granularity
for debugging output, to avoid flooding the log with too
much information with typical usage.

Rename the filter functions without the unnecessary 'str'
suffix.
2021-06-17 12:00:09 +01:00
João Valverde ac50926d6f wslog: Add a new log-debug option
Option --log-debug or WIRESHARK_LOG_DEBUG is a list
of domains that are set to a "debug" log level. This
takes precedence over the normal log level and domain
filter options.
2021-06-17 12:00:09 +01:00
João Valverde 01001485b9 wslog: Add a new log-fatal option
Enviroment variable WIRESHARK_LOG_FATAL and command line
option --log-fatal set the fatal log level. Messages with
fatal or highr priority cause the program to abort. By
default the fatal level is "error", but it can be set to
"critical" or "warning" with this option.
2021-06-17 12:00:09 +01:00
João Valverde 36c32de869 wslog: Add support for inverted domain matches
Domain filter expressions starting with '!' invert the match.
Only domains that do not match become active. Note that '!'
must be the first character in the filter and applies to the
whole expression.
2021-06-17 12:00:09 +01:00
João Valverde 05ed76d4c0 wslog: Use plain format with "message" level
Try out a simpler format with the default log level.

Don't display process and file/function information with "message"
level (experimental).
2021-06-17 12:00:09 +01:00
João Valverde 39df3ae3c0 Replace g_log() calls with ws_log() 2021-06-16 12:50:27 +00: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
João Valverde 2c6d897b58 wslog: Add ws_logv_full() 2021-06-15 18:51:40 +01:00
João Valverde e37b2ae637 wslog: Remove unused macro 2021-06-15 18:51:40 +01:00
João Valverde 477e7f7300 wslog: Do not filter default domain 2021-06-15 18:51:40 +01:00
João Valverde bec7b0c609 wslog: Fixup color support 2021-06-15 18:51:38 +01:00
João Valverde ac4a0c056b wslog: Use g_date_time_format() 2021-06-15 18:28:02 +01:00
João Valverde 41fd46310f wslog: Change log format to display everything
Revert from alternating between function name and file name,
show both instead.
2021-06-14 22:05:35 +00:00
João Valverde 95396973e7 wslog: Add basic color support
This is just a basic framework to improve on, if desired.
2021-06-14 22:05:35 +00:00
João Valverde 69a217b95b wslog: Use buffered I/O
Use standard buffered I/O instead of printing to a string.
This is more efficient, cleaner and allows custom output per stream.
2021-06-14 22:05:35 +00:00
João Valverde 59eff63794 wslog: Rename default log level 2021-06-14 22:05:35 +00:00
João Valverde 42c6c4781f wslog: Add a diagnostic message. 2021-06-14 22:05:35 +00:00
João Valverde b91801a870 wslog: Add a --log-file cmd line option 2021-06-14 22:05:35 +00:00
João Valverde e86ac706ca wslog: Parse cmd line options in one pass 2021-06-14 22:05:35 +00:00
João Valverde 2d2cfa8d14 wslog: Make a variable static 2021-06-14 22:05:35 +00:00
João Valverde 5ddc007023 wslog: Include pid in format 2021-06-14 14:18:38 +01:00
João Valverde 675c428dca wslog: Fix shadow variable 2021-06-14 13:13:12 +01:00
João Valverde 55f0fba85d wslog: Make error and critical levels not conditional 2021-06-14 13:13:12 +01:00
João Valverde 700d8e34db wslog: Rename environment vars to according to our conventions 2021-06-14 13:13:12 +01:00
João Valverde 5a662ba3fb wslog: Add support for domain filtering
A domain filter can be given in the environment variable
'WS_LOG_DOMAINS' or in a command-line options "--log-domains".

The filter is specified as a comma separated case insensitive list,
for example:

    ./tshark  --log-domains=main,capture

Domain data type switches from an enum to a string. There is no
constaint on adding new domains, neither in code or at runtime.
The string format is arbitrary, only positive matches will produce
output.
2021-06-14 13:13:12 +01:00
João Valverde 82739fc4f5 wslog: Improve code modularity and efficiency
Also tweak format for readability.
2021-06-14 13:13:12 +01: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
João Valverde 70cea91c8a wsutil: argv[] is a NULL terminated array 2021-06-10 16:22:12 +00:00
João Valverde af2a88cd18 CMake: Reverse logic to handle debug code
Only enabling debug code by default with Debug build type
seems overly restrictive; debug output is still conditional
on the log level.
2021-06-10 00:57:49 +01:00
João Valverde 1a702e5430 Try to avoid -Wunused with vanishing macros 2021-06-10 00:51:59 +01:00
Stig Bjørlykke 5dbaa8d3b2 wsutil: Add filesystem write_file_binary_mode()
Add a generic function to write content to file. Use this on write
TLS session keys from UI and tshark, and for export objects.

Remove the now unused export_object_ui.[ch].
2021-06-07 06:24:28 +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 ef0f022f86 wslog: Add a comment 2021-06-06 19:48:54 +00:00
João Valverde c015257c9f wslog: Include function name in ws_debug() output format
The GLib documentation says G_STRLOC includes the function name
but that is a lie[1]. Change ws_debug() to not use G_STRLOC and receive
__FILE__, __LINE__ and G_STRFUNC separately instead.

[1]https://bugzilla.gnome.org/show_bug.cgi?id=69097
2021-06-06 19:48:53 +00:00
John Thacker 4371474cc3 ip: Reassemble across VLANs for publicly routable IPv4 addresses
Default to taking the VLAN ID into account when reassembling only
for private IPv4 addresses as defined by RFC 1918 and for link-local
addresses. Otherwise, do not take the VLAN ID into account unless
the "Enable stricter conversation tracking heuristics" preference
is enabled. Fixes #14356.
2021-05-25 20:09:25 -04:00
João Valverde c4aa583d8e wsutil: Rename ws_assert_bounds()
It is not necessary to categorize every assertion that
is not conditional to WS_DISABLE_ASSERT.
2021-05-24 01:35:30 +00: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 cee1b443b5 wsutil: Add ws_assert_bounds() 2021-05-20 03:01:05 +01:00
João Valverde adfb0b99c2 wsutil: Avoid using g_abort()
g_abort() requires GLib 2.50, our minimum required version
is 2.38.
2021-05-20 03:01:05 +01:00
João Valverde cf0cb5819f Fixup ws_assert() macro
Use a void expression instead of removing the expression
entirely. Under certain conditions, for example as the only
statement in an if() conditional, removing the assertion
will generate compiler warnings.
2021-05-20 03:01:05 +01:00
João Valverde 8eacd615c8 Disable assertions for release builds
Currently our build generates very many warnings if
G_DISABLE_ASSERT is defined.

Add ws_assert() and ws_assert_not_reached() to incrementally
replace existing assertions and then disable them using
WS_DISABLE_ASSERT.

Assertions are disabled with CMake build type Release.
By default the build type is RelWithDebInfo so the current
behaviour of enabling assertions by default is (for now) preserved.

Add some notes to README.Developer.
2021-05-19 03:52:45 +01: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
Alexis La Goutte 38d279326a Fix -Wdocumentation warning 2021-04-14 14:01:49 +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
Tomasz Moń 98cf147b19 glib-compat: Fix build on Windows
Include string.h to make the memcpy() function available.
2021-03-26 09:52:56 +01: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 c33e2f7b51 Add more error-reporting routines that call through a function pointer.
Have routines to report capture-file errors, using libwireshark error
codes and strings, that call through a pointer, so they can pop up
dialogs in GUI apps, print a message to the standard error on
command-line apps, and possibly do something different on server
programs.

Have init_report_message() take a pointer to structure containing those
function pointers, rather than the function pointers themselves, as
arguments.

Make other API changes to make that work.
2021-03-15 12:17:59 -07:00
João Valverde b2bb8bf4e0 Replace g_assert(0) with g_assert_not_reached() 2021-03-05 14:54:58 +00: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
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
João Valverde 73d793788c Remove and replace obsolete ws_snprintf() definition
Since fe94133f0d ws_snprintf()
and ws_vsnprintf() don't actually do anything anymore.

The return value of ws_[v]snprintf was discarded before,
now it too conforms to C99.
2021-02-28 22:03:42 +00:00
Michal Ruprich c8246c9973 Moving glib.h out of extern C 2021-02-10 17:49:09 +00: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
João Valverde 10178fdb09 Don't include config.h in system headers
Config.h must not be installed so configuration must be performed by client code.

Fixes #17190.
2021-01-30 10:06:20 +00:00
Gerald Combs dfd7ae3b74 nstime: Remove an unneeded check. 2021-01-14 21:42:31 +00:00
Chema Gonzalez 03baf65ae7 editcap: add support for epoch timestamps in `-A` and `-B` options
Inspired in https://gitlab.com/wireshark/wireshark/-/merge_requests/1618.

Tested:

Timestamps on file used for comparison:
```
$ tshark -r test/captures/snakeoil-dtls.pcap -T fields -e frame.time_epoch
1150121069.248818000
1150121069.249193000
1150121069.251152000
1150121069.251384000
1150121069.293686000
1150121069.319315000
1150121075.230753000
1150121105.510885000
1150121105.510934000
```

Before:
```
$ ./build/run/editcap -B 1150121069.3 test/captures/snakeoil-dtls.pcap -
editcap: "1150121069.3" isn't a valid date and time
$ ./build/run/editcap -A 1150121069.3 test/captures/snakeoil-dtls.pcap -
editcap: "1150121069.3" isn't a valid date and time
$ ./build/run/editcap -A 1150121069 test/captures/snakeoil-dtls.pcap -
editcap: "1150121069" isn't a valid date and time
$ ./build/run/editcap -B 1150121069 test/captures/snakeoil-dtls.pcap -
editcap: "1150121069" isn't a valid date and time
```

After:
```
$ ./build/run/editcap -A 1150121069.3 test/captures/snakeoil-dtls.pcap - | tshark -r - -T fields -e frame.time_epoch
1150121069.319315000
1150121075.230753000
1150121105.510885000
1150121105.510934000
$ ./build/run/editcap -A 1150121069 test/captures/snakeoil-dtls.pcap - | tshark -r - -T fields -e frame.time_epoch
1150121069.248818000
1150121069.249193000
1150121069.251152000
1150121069.251384000
1150121069.293686000
1150121069.319315000
1150121075.230753000
1150121105.510885000
1150121105.510934000
$ ./build/run/editcap -B 1150121069.3 test/captures/snakeoil-dtls.pcap - | tshark -r - -T fields -e frame.time_epoch
1150121069.248818000
1150121069.249193000
1150121069.251152000
1150121069.251384000
1150121069.293686000
$ ./build/run/editcap -B 1150121069 test/captures/snakeoil-dtls.pcap - | tshark -r - -T fields -e frame.time_epoch
```
2021-01-11 18:01:08 +00:00