diff --git a/src/main.c b/src/main.c index 01d67e2..cfdfbef 100644 --- a/src/main.c +++ b/src/main.c @@ -608,7 +608,12 @@ int parse_cmdline(int argc, char **argv, int *port, int *enableUpload, char **sh } int main(int argc, char ** argv) { - struct MHD_Daemon *d, *d6; + struct MHD_Daemon *d; + +#if MHD_VERSION <= 0x00092100 + struct MHD_Daemon *d6; +#endif + struct stat sBuf; int port; @@ -702,6 +707,8 @@ int main(int argc, char ** argv) { // static response for favicon faviconResponse = create_favicon_response(); + // start daemons +#if MHD_VERSION <= 0x00092100 d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION, port, NULL, @@ -713,6 +720,8 @@ int main(int argc, char ** argv) { MHD_OPTION_END); if (d == NULL) { LOG(LVL_ERR, "Cannot start up libmicrohttpd listening on IPv4."); + } else { + LOG(LVL_DEBUG, "IPv4 daemon startup successful."); } d6 = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_IPv6, @@ -726,12 +735,32 @@ int main(int argc, char ** argv) { MHD_OPTION_END); if (d6 == NULL) { LOG(LVL_ERR, "Cannot start up libmicrohttpd listening on IPv6."); + } else { + LOG(LVL_DEBUG, "IPv6 daemon startup successful."); } if(d == NULL && d6 == NULL) { LOG(LVL_FATAL, "Both IPv4 and IPv6 servers failed to start. Terminating."); return EXIT_FAILURE; } +#else + d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DUAL_STACK, + port, + NULL, + NULL, + &connection_handler, + NULL, + MHD_OPTION_NOTIFY_COMPLETED, + &request_completed, NULL, + MHD_OPTION_END); + + if (d == NULL) { + LOG(LVL_FATAL, "Cannot start up libmicrohttpd listening on dual stack socket."); + return EXIT_FAILURE; + } else { + LOG(LVL_DEBUG, "Dual stack daemon startup successful."); + } +#endif // MHD_VERSION LOG(LVL_INFO, "Startup successful. Here are the IP addresses for this computer:"); print_urls(port); @@ -743,7 +772,10 @@ int main(int argc, char ** argv) { LOG(LVL_INFO, "Shutting down..."); MHD_stop_daemon(d); + +#if MHD_VERSION <= 0x00092100 MHD_stop_daemon(d6); +#endif MHD_destroy_response(error403Response); MHD_destroy_response(error404Response);