Skip to content

Commit 7ff711b

Browse files
committed
Feature #878 - add -w / --suppress-warning option
Suppress warning if desired.
1 parent cd1718a commit 7ff711b

File tree

12 files changed

+66
-9
lines changed

12 files changed

+66
-9
lines changed

docs/CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
06/08/2024 Version 4.5.0-beta2
2+
- add -w (--suppress-warnings) option to suppress warning messages (#878)
23
- AF_XDP compile issue due to merge issue (#876)
34
- memory leak in tcpprep when using include/exclude (#869)
45
- memory leak in tcpprep when using RegEx (#867)

src/common/err.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
#include <stdlib.h>
5151
#include <string.h>
5252

53+
int print_warnings = 1;
54+
5355
/**
5456
* writes a notice message to stderr. Always forces a newline
5557
*/

src/common/err.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
#include "defines.h"
5151
#include <stdlib.h>
5252

53+
extern int print_warnings;
54+
5355
#ifdef DEBUG
5456
extern int debug;
5557
#endif
@@ -84,12 +86,14 @@ void notice(const char *fmt, ...);
8486
fprintf(stderr, "DEBUG%d in %s:%s() line %d: " y "\n", x, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__); \
8587
} \
8688
} while(0)
87-
88-
89-
#define warn(x) fprintf(stderr, "Warning in %s:%s() line %d:\n%s\n", __FILE__, __FUNCTION__, __LINE__, x)
9089

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

92-
#define warnx(x, ...) fprintf(stderr, "Warning in %s:%s() line %d:\n" x "\n", __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
94+
#define warnx(x, ...) \
95+
if (print_warnings) \
96+
fprintf(stderr, "Warning in %s:%s() line %d:\n" x "\n", __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
9397

9498
#define err(x, y) do { \
9599
fprintf(stderr, "\nFatal Error in %s:%s() line %d:\n%s\n", __FILE__, __FUNCTION__, __LINE__, y); \

src/tcpbridge.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ post_args(_U_ int argc, _U_ char *argv[])
149149
if (HAVE_OPT(DBUG))
150150
warn("not configured with --enable-debug. Debugging disabled.");
151151
#endif
152-
152+
if (HAVE_OPT(SUPPRESS_WARNINGS))
153+
print_warnings = 0;
153154
#ifdef ENABLE_VERBOSE
154155
if (HAVE_OPT(VERBOSE))
155156
options.verbose = 1;

src/tcpbridge_opts.def

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ autogen definitions options;
2323

2424

2525
copyright = {
26-
date = "2000-2022";
26+
date = "2000-2024";
2727
owner = "Aaron Turner and Fred Klassen";
2828
eaddr = "[email protected]";
2929
type = gpl;
@@ -411,3 +411,13 @@ flag = {
411411
EOHelp;
412412
doc = "";
413413
};
414+
415+
flag = {
416+
name = suppress-warnings;
417+
value = w;
418+
immediate;
419+
descrip = "suppress printing warning messages";
420+
settable;
421+
doc = "";
422+
};
423+

src/tcpprep.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ main(int argc, char *argv[])
125125
err(-1, "MAC mode splitting is only supported by DLT_EN10MB packet captures.");
126126
}
127127

128+
if (HAVE_OPT(SUPPRESS_WARNINGS))
129+
print_warnings = 0;
130+
128131
#ifdef ENABLE_VERBOSE
129132
if (HAVE_OPT(VERBOSE)) {
130133
tcpdump_open(&tcpprep->tcpdump, options->pcap);

src/tcpprep_api.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ tcpprep_post_args(tcpprep_t *ctx, int argc, char *argv[])
141141
debug = OPT_VALUE_DBUG;
142142
#endif
143143

144+
if (HAVE_OPT(SUPPRESS_WARNINGS))
145+
print_warnings = 0;
146+
144147
#ifdef ENABLE_VERBOSE
145148
if (HAVE_OPT(VERBOSE)) {
146149
ctx->options->verbose = 1;

src/tcpprep_opts.def

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
autogen definitions options;
2222

2323
copyright = {
24-
date = "2000-2022";
24+
date = "2000-2024";
2525
owner = "Aaron Turner and Fred Klassen";
2626
eaddr = "[email protected]";
2727
type = gpl;
@@ -644,3 +644,12 @@ flag = {
644644

645645
EOHelp;
646646
};
647+
648+
flag = {
649+
name = suppress-warnings;
650+
value = w;
651+
immediate;
652+
descrip = "suppress printing warning messages";
653+
settable;
654+
doc = "";
655+
};

src/tcpreplay_api.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ tcpreplay_post_args(tcpreplay_t *ctx, int argc)
209209
options->maxsleep.tv_nsec = (OPT_VALUE_MAXSLEEP % 1000) * 1000 * 1000;
210210
}
211211

212+
if (HAVE_OPT(SUPPRESS_WARNINGS))
213+
print_warnings = 0;
214+
212215
#ifdef ENABLE_VERBOSE
213216
if (HAVE_OPT(VERBOSE))
214217
options->verbose = 1;

src/tcpreplay_opts.def

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ autogen definitions options;
2222

2323

2424
copyright = {
25-
date = "2000-2022";
25+
date = "2000-2024";
2626
owner = "Aaron Turner and Fred Klassen";
2727
eaddr = "[email protected]";
2828
type = gpl;
@@ -719,3 +719,12 @@ flag = {
719719
EOHelp;
720720
doc = "";
721721
};
722+
723+
flag = {
724+
name = suppress-warnings;
725+
value = w;
726+
immediate;
727+
descrip = "suppress printing warning messages";
728+
settable;
729+
doc = "";
730+
};

src/tcprewrite.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ post_args(_U_ int argc, _U_ char *argv[])
193193
warn("not configured with --enable-debug. Debugging disabled.");
194194
#endif
195195

196+
if (HAVE_OPT(SUPPRESS_WARNINGS))
197+
print_warnings = 0;
198+
196199
#ifdef ENABLE_VERBOSE
197200
if (HAVE_OPT(VERBOSE))
198201
options.verbose = 1;

src/tcprewrite_opts.def

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
autogen definitions options;
2222

2323
copyright = {
24-
date = "2000-2022";
24+
date = "2000-2024";
2525
owner = "Aaron Turner and Fred Klassen";
2626
eaddr = "[email protected]";
2727
type = gpl;
@@ -300,3 +300,12 @@ flag = {
300300
EOHelp;
301301
doc = "";
302302
};
303+
304+
flag = {
305+
name = suppress-warnings;
306+
value = w;
307+
immediate;
308+
descrip = "suppress printing warning messages";
309+
settable;
310+
doc = "";
311+
};

0 commit comments

Comments
 (0)