aboutsummaryrefslogtreecommitdiffstats
path: root/randpkt.c
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2021-07-26 17:22:36 +0100
committerJoão Valverde <j@v6e.pt>2021-09-17 00:43:54 +0100
commit8df2a73594fbcc812f4ea22a72ab7a79bfb63dc3 (patch)
tree7d30bc5be8e85c52c0dd295cb15cd717d5770dcb /randpkt.c
parent7462e76884942258bae110ead925f25ffa54e2a8 (diff)
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.
Diffstat (limited to 'randpkt.c')
-rw-r--r--randpkt.c25
1 files changed, 7 insertions, 18 deletions
diff --git a/randpkt.c b/randpkt.c
index 1c81db4f9c..dcfa1f0f73 100644
--- a/randpkt.c
+++ b/randpkt.c
@@ -31,18 +31,7 @@
#include <wsutil/report_message.h>
#include <wsutil/wslog.h>
-/*
- * If we have getopt_long() in the system library, include <getopt.h>.
- * Otherwise, we're using our own getopt_long() (either because the
- * system has getopt() but not getopt_long(), as with some UN*Xes,
- * or because it doesn't even have getopt(), as with Windows), so
- * include our getopt_long()'s header.
- */
-#ifdef HAVE_GETOPT_LONG
-#include <getopt.h>
-#else
-#include <wsutil/wsgetopt.h>
-#endif
+#include <wsutil/ws_getopt.h>
#include "randpkt_core/randpkt_core.h"
@@ -171,10 +160,10 @@ main(int argc, char *argv[])
create_app_running_mutex();
#endif /* _WIN32 */
- while ((opt = getopt_long(argc, argv, "b:c:ht:r", long_options, NULL)) != -1) {
+ while ((opt = ws_getopt_long(argc, argv, "b:c:ht:r", long_options, NULL)) != -1) {
switch (opt) {
case 'b': /* max bytes */
- produce_max_bytes = get_positive_int(optarg, "max bytes");
+ produce_max_bytes = get_positive_int(ws_optarg, "max bytes");
if (produce_max_bytes > 65536) {
cmdarg_err("max bytes is > 65536");
ret = INVALID_OPTION;
@@ -183,11 +172,11 @@ main(int argc, char *argv[])
break;
case 'c': /* count */
- produce_count = get_positive_int(optarg, "count");
+ produce_count = get_positive_int(ws_optarg, "count");
break;
case 't': /* type of packet to produce */
- type = g_strdup(optarg);
+ type = g_strdup(ws_optarg);
break;
case 'h':
@@ -208,8 +197,8 @@ main(int argc, char *argv[])
}
/* any more command line parameters? */
- if (argc > optind) {
- produce_filename = argv[optind];
+ if (argc > ws_optind) {
+ produce_filename = argv[ws_optind];
} else {
usage(TRUE);
ret = INVALID_OPTION;