diff --git a/CMakeLists.txt b/CMakeLists.txt index 2710960b0..d3a5c9b81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -723,6 +723,7 @@ if (NOT LWS_HAVE_GETIFADDRS) set(LWS_BUILTIN_GETIFADDRS 1) endif() +CHECK_INCLUDE_FILE(getopt.h LWS_HAS_GETOPT_LONG) CHECK_INCLUDE_FILE(dlfcn.h LWS_HAVE_DLFCN_H) CHECK_INCLUDE_FILE(fcntl.h LWS_HAVE_FCNTL_H) CHECK_INCLUDE_FILE(in6addr.h LWS_HAVE_IN6ADDR_H) @@ -817,6 +818,14 @@ CHECK_C_SOURCE_COMPILES("#define _GNU_SOURCE return 0; }" LWS_HAS_PTHREAD_SETNAME_NP) +CHECK_C_SOURCE_COMPILES(" + #include + int main(void) { + void *p = (void *)getopt_long; + return p != NULL; + }" LWS_HAS_GETOPT_LONG) + + if (NOT PID_T_SIZE) set(pid_t int) endif() diff --git a/cmake/lws_config.h.in b/cmake/lws_config.h.in index 255bdf447..254799dc5 100644 --- a/cmake/lws_config.h.in +++ b/cmake/lws_config.h.in @@ -21,12 +21,14 @@ #cmakedefine LWS_BUILTIN_GETIFADDRS #cmakedefine LWS_FALLBACK_GETHOSTBYNAME #cmakedefine LWS_HAS_INTPTR_T +#cmakedefine LWS_HAS_GETOPT_LONG #cmakedefine LWS_HAVE__ATOI64 #cmakedefine LWS_HAVE_ATOLL #cmakedefine LWS_HAVE_BN_bn2binpad #cmakedefine LWS_HAVE_ECDSA_SIG_set0 #cmakedefine LWS_HAVE_EVP_MD_CTX_free #cmakedefine LWS_HAVE_EVP_aes_128_wrap +#cmakedefine LWS_HAS_GETOPT_LONG #cmakedefine LWS_HAVE_LIBCAP #cmakedefine LWS_HAVE_MALLOC_H #cmakedefine LWS_HAVE_mbedtls_net_init diff --git a/lib/core/adopt.c b/lib/core/adopt.c index c21e196d9..17d4013b6 100644 --- a/lib/core/adopt.c +++ b/lib/core/adopt.c @@ -348,7 +348,10 @@ lws_create_adopt_udp(struct lws_vhost *vhost, int port, int flags, h.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ h.ai_socktype = SOCK_DGRAM; h.ai_protocol = IPPROTO_UDP; - h.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; + h.ai_flags = AI_PASSIVE; +#ifdef AI_ADDRCONFIG + h.ai_flags |= AI_ADDRCONFIG; +#endif lws_snprintf(buf, sizeof(buf), "%u", port); n = getaddrinfo(NULL, buf, &h, &r); diff --git a/lib/roles/http/server/lejp-conf.c b/lib/roles/http/server/lejp-conf.c index bdb4a2e2f..005b5c935 100644 --- a/lib/roles/http/server/lejp-conf.c +++ b/lib/roles/http/server/lejp-conf.c @@ -960,7 +960,7 @@ lwsws_get_config_d(void *user, const char *d, const char * const *paths, char path[256]; int n, i, ret = 0; - n = scandir(d, &namelist, filter, alphasort); + n = scandir((char *) d, &namelist, filter, alphasort); if (n < 0) { lwsl_err("Scandir on %s failed\n", d); return 1; diff --git a/lwsws/main.c b/lwsws/main.c index d3962d8d5..59bcbca27 100644 --- a/lwsws/main.c +++ b/lwsws/main.c @@ -21,7 +21,9 @@ #include #include +#if defined(LWS_HAS_GETOPT_LONG) || defined(WIN32) #include +#endif #include #include #include @@ -75,12 +77,14 @@ static const char * const plugin_dirs[] = { NULL }; +#if defined(LWS_HAS_GETOPT_LONG) || defined(WIN32) static struct option options[] = { { "help", no_argument, NULL, 'h' }, { "debug", required_argument, NULL, 'd' }, { "configdir", required_argument, NULL, 'c' }, { NULL, 0, 0, 0 } }; +#endif void signal_cb(uv_signal_t *watcher, int signum) { @@ -216,7 +220,11 @@ int main(int argc, char **argv) strcpy(config_dir, "/etc/lwsws"); while (n >= 0) { +#if defined(LWS_HAS_GETOPT_LONG) || defined(WIN32) n = getopt_long(argc, argv, "hd:c:", options, NULL); +#else + n = getopt(argc, argv, "hd:c:"); +#endif if (n < 0) continue; switch (n) { diff --git a/minimal-examples/api-tests/api-test-fts/main.c b/minimal-examples/api-tests/api-test-fts/main.c index bc0123c8d..e599d4f1e 100644 --- a/minimal-examples/api-tests/api-test-fts/main.c +++ b/minimal-examples/api-tests/api-test-fts/main.c @@ -8,9 +8,12 @@ */ #include +#if defined(LWS_HAS_GETOPT_LONG) || defined(WIN32) #include +#endif #include +#if defined(LWS_HAS_GETOPT_LONG) || defined(WIN32) static struct option options[] = { { "help", no_argument, NULL, 'h' }, { "createindex", no_argument, NULL, 'c' }, @@ -20,6 +23,7 @@ static struct option options[] = { { "lines", required_argument, NULL, 'l' }, { NULL, 0, 0, 0 } }; +#endif static const char *index_filepath = "/tmp/lws-fts-test-index"; static char filepath[256]; @@ -35,7 +39,11 @@ int main(int argc, char **argv) char buf[16384]; do { +#if defined(LWS_HAS_GETOPT_LONG) || defined(WIN32) n = getopt_long(argc, argv, "hd:i:cfl", options, NULL); +#else + n = getopt(argc, argv, "hd:i:cfl"); +#endif if (n < 0) continue; switch (n) { diff --git a/minimal-examples/http-server/minimal-http-server-form-post-file/minimal-http-server-form-post-file.c b/minimal-examples/http-server/minimal-http-server-form-post-file/minimal-http-server-form-post-file.c index 9c500edae..a9d80071f 100644 --- a/minimal-examples/http-server/minimal-http-server-form-post-file/minimal-http-server-form-post-file.c +++ b/minimal-examples/http-server/minimal-http-server-form-post-file/minimal-http-server-form-post-file.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include diff --git a/test-apps/test-client.c b/test-apps/test-client.c index 675affadc..b3dd1d97b 100644 --- a/test-apps/test-client.c +++ b/test-apps/test-client.c @@ -22,7 +22,9 @@ #include #include +#if defined(LWS_HAS_GETOPT_LONG) || defined(WIN32) #include +#endif #include #include @@ -526,6 +528,7 @@ void sighandler(int sig) force_exit = 1; } +#if defined(LWS_HAS_GETOPT_LONG) || defined(WIN32) static struct option options[] = { { "help", no_argument, NULL, 'h' }, { "debug", required_argument, NULL, 'd' }, @@ -550,6 +553,7 @@ static struct option options[] = { #endif { NULL, 0, 0, 0 } }; +#endif static int ratelimit_connects(unsigned int *last, unsigned int secs) { @@ -589,8 +593,11 @@ int main(int argc, char **argv) goto usage; while (n >= 0) { - n = getopt_long(argc, argv, "Sjnuv:hsp:d:lC:K:A:P:moeO", options, - NULL); +#if defined(LWS_HAS_GETOPT_LONG) || defined(WIN32) + n = getopt_long(argc, argv, "Sjnuv:hsp:d:lC:K:A:P:moeO", options, NULL); +#else + n = getopt(argc, argv, "Sjnuv:hsp:d:lC:K:A:P:moeO"); +#endif if (n < 0) continue; switch (n) { diff --git a/test-apps/test-server.c b/test-apps/test-server.c index 5c2f085bc..97e552da0 100644 --- a/test-apps/test-server.c +++ b/test-apps/test-server.c @@ -21,7 +21,9 @@ #include #include #include +#if defined(LWS_HAS_GETOPT_LONG) || defined(WIN32) #include +#endif #include int close_testing; @@ -298,6 +300,7 @@ static const struct lws_protocol_vhost_options pvo = { "" /* ignored */ }; +#if defined(LWS_HAS_GETOPT_LONG) || defined(WIN32) static struct option options[] = { { "help", no_argument, NULL, 'h' }, { "debug", required_argument, NULL, 'd' }, @@ -323,6 +326,7 @@ static struct option options[] = { { "pingpong-secs", required_argument, NULL, 'P' }, { NULL, 0, 0, 0 } }; +#endif int main(int argc, char **argv) { @@ -353,7 +357,11 @@ int main(int argc, char **argv) info.port = 7681; while (n >= 0) { +#if defined(LWS_HAS_GETOPT_LONG) || defined(WIN32) n = getopt_long(argc, argv, "eci:hsap:d:DC:K:A:R:vu:g:P:kU:n", options, NULL); +#else + n = getopt(argc, argv, "eci:hsap:d:DC:K:A:R:vu:g:P:kU:n"); +#endif if (n < 0) continue; switch (n) {