Use signal SIGUSR1 instead of SIGHUP to detect when to rotate the pcap dump file.
Use signal SIGHUP instead of SIGCONT to detect when the controlling terminal closed.
This signal usage provides that sngrep closes cleanly when its controlling (SSH) terminal closes.
'device' and 'outfile' are initialized from 'settings' in the later code,
but 'text_outfile' is not initialized, which may lead to writing to an unknown file.
* add siplify command for saving pcap to txt file
* remove unnecessary printf and commented code
* Refactor siplify into text; minor changes according to pull request review
strings.h required for strncasecmp, fixes an implicit function
declaration
config.h needed for the actual configuration, it sets -D_GNU_SOURCE that
is needed for strsep.
libpcap doesn't directly support this, so this is implemented using the
Linux call fopencookie which rereoutes the read,write,seek,close functions.
*BSD seems to have something similar (funopen) which is not implemented in
this patch because I'm not familiar enough with BSD.
gzip detection for read is done by first directly opening the given file
like before. If this fails, we retry with gzip.
gzip detection for write is done by looking at the filename to write to.
If it ends in ".gz" we activate gzip compression.
This currently just works for the commandline option --output because only
there you get to set the filename suffix freely. To make this usable in
the curses gui, the save dialog would have to be extended to allow setting
a .pcap.gz filename extension.
gzip compression must be compiled in to be active. This is done with the
--with-zlib configure option.
Before this patch the process was just terminated by the default signal
handler. This could lead for example to incompletely written pcap files.
So proper shutdown like in this patch is always a good idea. But it becomes
mandadory when implementing more complex file I/O with buffering, for
example with gzip streaming.
To not conflict with the threading used in sngrep, the signal handler
just sets a atomic flag. This flag is then checked in one of the two
main loops (with/without curses UI).
When using --no-interface without --quiet, a dialog counter
is shown and continously updated. Without this patch this
counter just shows the number of calls that are stored in RAM.
When rotation is used, it never shows more calls than the
rotation limit.
Since the --no-interface option is usually just used for
capturing, using it with a small number for rotation (down to 1)
is recommended to not waste RAM. This means the shown value
is useless.
This patch introduces the function sip_calls_count_unrotated() that
can be used to get the full number of calls since program start.
This is then used in the shown dialog count.
The #elifdef preprocessor directive will only become available with the
upcoming C2x standard.
I do not think that using it already is a good idea, since support for
it is very sparse and no long-term-stable distro has support for it.
Also replacing it with "#elif defined()" doesn't really complicate the code.
- the addrlen parameter must be filled with the size available for src_addr before
calling recvfrom()
- the size of the src_addr isn't really known before calling recvfrom, it can be
of different types. So use struct sockaddr_storage for it which is large enough
to allow different actual address types
Fix the following build failure with libressl >= 3.5.0:
capture_openssl.c: In function 'P_hash':
capture_openssl.c:101:18: error: storage size of 'hm' isn't known
101 | HMAC_CTX hm;
| ^~
Fixes:
- http://autobuild.buildroot.org/results/f1e8cdb3ac35a30055ab79d41e6cc038e5339c37
Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
`ncuses-6.3` added printf-style function attributes and now makes
it easier to catch cases when user input is used in palce of format
string when built with CFLAGS=-Werror=format-security:
curses/ui_msg_diff.c: In function 'msg_diff_draw_message':
curses/ui_msg_diff.c:190:5: error: format not a string literal and no format arguments [-Werror=format-security]
190 | mvwprintw(win, 0, 0, sip_get_msg_header(msg, header));
| ^~~~~~~~~
Let's wrap all the missing places with "%s" format.