aboutsummaryrefslogtreecommitdiffstats
path: root/sharkd_daemon.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 /sharkd_daemon.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 'sharkd_daemon.c')
-rw-r--r--sharkd_daemon.c31
1 files changed, 10 insertions, 21 deletions
diff --git a/sharkd_daemon.c b/sharkd_daemon.c
index 0c9363301f..d5bda8da61 100644
--- a/sharkd_daemon.c
+++ b/sharkd_daemon.c
@@ -30,18 +30,7 @@
#include <wsutil/inet_addr.h>
#include <wsutil/please_report_bug.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>
#ifndef _WIN32
#include <sys/un.h>
@@ -295,29 +284,29 @@ sharkd_init(int argc, char **argv)
*/
do {
- if (optind > (argc - 1))
+ if (ws_optind > (argc - 1))
break;
- opt = getopt_long(argc, argv, optstring, long_options, NULL);
+ opt = ws_getopt_long(argc, argv, optstring, long_options, NULL);
switch (opt) {
case 'C': /* Configuration Profile */
- if (profile_exists(optarg, FALSE)) {
- set_profile_name(optarg); // In Daemon Mode, we may need to do this again in the child process
+ if (profile_exists(ws_optarg, FALSE)) {
+ set_profile_name(ws_optarg); // In Daemon Mode, we may need to do this again in the child process
}
else {
- fprintf(stderr, "Configuration Profile \"%s\" does not exist\n", optarg);
+ fprintf(stderr, "Configuration Profile \"%s\" does not exist\n", ws_optarg);
return -1;
}
break;
case 'a':
- fd = socket_init(optarg);
+ fd = socket_init(ws_optarg);
if (fd == INVALID_SOCKET)
return -1;
_server_fd = fd;
- fprintf(stderr, "Sharkd listening on: %s\n", optarg);
+ fprintf(stderr, "Sharkd listening on: %s\n", ws_optarg);
mode = SHARKD_MODE_GOLD_DAEMON;
break;
@@ -338,8 +327,8 @@ sharkd_init(int argc, char **argv)
break;
default:
- if (!optopt)
- fprintf(stderr, "This option isn't supported: %s\n", argv[optind]);
+ if (!ws_optopt)
+ fprintf(stderr, "This option isn't supported: %s\n", argv[ws_optind]);
fprintf(stderr, "Use sharkd -h for details of supported options\n");
exit(0);
break;