Skip to content

Commit

Permalink
Feature #878 - add -w / --suppress-warning option
Browse files Browse the repository at this point in the history
Suppress warning if desired.
  • Loading branch information
fklassen committed Jun 9, 2024
1 parent cd1718a commit 7ff711b
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
06/08/2024 Version 4.5.0-beta2
- add -w (--suppress-warnings) option to suppress warning messages (#878)
- AF_XDP compile issue due to merge issue (#876)
- memory leak in tcpprep when using include/exclude (#869)
- memory leak in tcpprep when using RegEx (#867)
Expand Down
2 changes: 2 additions & 0 deletions src/common/err.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
#include <stdlib.h>
#include <string.h>

int print_warnings = 1;

Check warning on line 53 in src/common/err.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/common/err.c:53:5 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'print_warnings' is non-const and globally accessible, consider making it const

/**
* writes a notice message to stderr. Always forces a newline
*/
Expand Down
12 changes: 8 additions & 4 deletions src/common/err.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
#include "defines.h"

Check failure on line 50 in src/common/err.h

View workflow job for this annotation

GitHub Actions / cpp-linter

src/common/err.h:50:10 [clang-diagnostic-error]

'defines.h' file not found
#include <stdlib.h>

extern int print_warnings;

Check warning on line 53 in src/common/err.h

View workflow job for this annotation

GitHub Actions / cpp-linter

src/common/err.h:53:12 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'print_warnings' is non-const and globally accessible, consider making it const

#ifdef DEBUG
extern int debug;
#endif
Expand Down Expand Up @@ -84,12 +86,14 @@ void notice(const char *fmt, ...);
fprintf(stderr, "DEBUG%d in %s:%s() line %d: " y "\n", x, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__); \
} \
} while(0)


#define warn(x) fprintf(stderr, "Warning in %s:%s() line %d:\n%s\n", __FILE__, __FUNCTION__, __LINE__, x)

#define warn(x) \
if (print_warnings) \
fprintf(stderr, "Warning in %s:%s() line %d:\n%s\n", __FILE__, __FUNCTION__, __LINE__, x)

#define warnx(x, ...) fprintf(stderr, "Warning in %s:%s() line %d:\n" x "\n", __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
#define warnx(x, ...) \
if (print_warnings) \
fprintf(stderr, "Warning in %s:%s() line %d:\n" x "\n", __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)

#define err(x, y) do { \
fprintf(stderr, "\nFatal Error in %s:%s() line %d:\n%s\n", __FILE__, __FUNCTION__, __LINE__, y); \
Expand Down
3 changes: 2 additions & 1 deletion src/tcpbridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ post_args(_U_ int argc, _U_ char *argv[])
if (HAVE_OPT(DBUG))
warn("not configured with --enable-debug. Debugging disabled.");
#endif

if (HAVE_OPT(SUPPRESS_WARNINGS))

Check warning on line 152 in src/tcpbridge.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpbridge.c:152:37 [readability-braces-around-statements]

statement should be inside braces
print_warnings = 0;
#ifdef ENABLE_VERBOSE
if (HAVE_OPT(VERBOSE))
options.verbose = 1;
Expand Down
12 changes: 11 additions & 1 deletion src/tcpbridge_opts.def
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ autogen definitions options;


copyright = {
date = "2000-2022";
date = "2000-2024";
owner = "Aaron Turner and Fred Klassen";
eaddr = "[email protected]";
type = gpl;
Expand Down Expand Up @@ -411,3 +411,13 @@ flag = {
EOHelp;
doc = "";
};

flag = {
name = suppress-warnings;
value = w;
immediate;
descrip = "suppress printing warning messages";
settable;
doc = "";
};

3 changes: 3 additions & 0 deletions src/tcpprep.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ main(int argc, char *argv[])
err(-1, "MAC mode splitting is only supported by DLT_EN10MB packet captures.");
}

if (HAVE_OPT(SUPPRESS_WARNINGS))

Check warning on line 128 in src/tcpprep.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpprep.c:128:37 [readability-braces-around-statements]

statement should be inside braces
print_warnings = 0;

#ifdef ENABLE_VERBOSE
if (HAVE_OPT(VERBOSE)) {
tcpdump_open(&tcpprep->tcpdump, options->pcap);
Expand Down
3 changes: 3 additions & 0 deletions src/tcpprep_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ tcpprep_post_args(tcpprep_t *ctx, int argc, char *argv[])
debug = OPT_VALUE_DBUG;
#endif

if (HAVE_OPT(SUPPRESS_WARNINGS))

Check warning on line 144 in src/tcpprep_api.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpprep_api.c:144:37 [readability-braces-around-statements]

statement should be inside braces
print_warnings = 0;

#ifdef ENABLE_VERBOSE
if (HAVE_OPT(VERBOSE)) {
ctx->options->verbose = 1;
Expand Down
11 changes: 10 additions & 1 deletion src/tcpprep_opts.def
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
autogen definitions options;

copyright = {
date = "2000-2022";
date = "2000-2024";
owner = "Aaron Turner and Fred Klassen";
eaddr = "[email protected]";
type = gpl;
Expand Down Expand Up @@ -644,3 +644,12 @@ flag = {

EOHelp;
};

flag = {
name = suppress-warnings;
value = w;
immediate;
descrip = "suppress printing warning messages";
settable;
doc = "";
};
3 changes: 3 additions & 0 deletions src/tcpreplay_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ tcpreplay_post_args(tcpreplay_t *ctx, int argc)
options->maxsleep.tv_nsec = (OPT_VALUE_MAXSLEEP % 1000) * 1000 * 1000;
}

if (HAVE_OPT(SUPPRESS_WARNINGS))

Check warning on line 212 in src/tcpreplay_api.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpreplay_api.c:212:37 [readability-braces-around-statements]

statement should be inside braces
print_warnings = 0;

#ifdef ENABLE_VERBOSE
if (HAVE_OPT(VERBOSE))
options->verbose = 1;
Expand Down
11 changes: 10 additions & 1 deletion src/tcpreplay_opts.def
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ autogen definitions options;


copyright = {
date = "2000-2022";
date = "2000-2024";
owner = "Aaron Turner and Fred Klassen";
eaddr = "[email protected]";
type = gpl;
Expand Down Expand Up @@ -719,3 +719,12 @@ flag = {
EOHelp;
doc = "";
};

flag = {
name = suppress-warnings;
value = w;
immediate;
descrip = "suppress printing warning messages";
settable;
doc = "";
};
3 changes: 3 additions & 0 deletions src/tcprewrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ post_args(_U_ int argc, _U_ char *argv[])
warn("not configured with --enable-debug. Debugging disabled.");
#endif

if (HAVE_OPT(SUPPRESS_WARNINGS))

Check warning on line 196 in src/tcprewrite.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcprewrite.c:196:37 [readability-braces-around-statements]

statement should be inside braces
print_warnings = 0;

#ifdef ENABLE_VERBOSE
if (HAVE_OPT(VERBOSE))
options.verbose = 1;
Expand Down
11 changes: 10 additions & 1 deletion src/tcprewrite_opts.def
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
autogen definitions options;

copyright = {
date = "2000-2022";
date = "2000-2024";
owner = "Aaron Turner and Fred Klassen";
eaddr = "[email protected]";
type = gpl;
Expand Down Expand Up @@ -300,3 +300,12 @@ flag = {
EOHelp;
doc = "";
};

flag = {
name = suppress-warnings;
value = w;
immediate;
descrip = "suppress printing warning messages";
settable;
doc = "";
};

0 comments on commit 7ff711b

Please sign in to comment.