Commit Graph

1145 Commits

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