From 8336b7ef9d0432f6bdfcdc166d4db3aeca66b71a Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Wed, 30 Jan 2013 21:54:56 +0100 Subject: [PATCH] Also listen on IPv6 --- main.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index ef6866e..ec3cdff 100644 --- a/main.c +++ b/main.c @@ -357,7 +357,7 @@ void print_addresses(void) { } int main(int argc, char ** argv) { - struct MHD_Daemon *d; + struct MHD_Daemon *d, *d6; struct stat sBuf; int port; @@ -457,7 +457,24 @@ int main(int argc, char ** argv) { &request_completed, NULL, MHD_OPTION_END); if (d == NULL) { - LOG(LVL_FATAL, "Cannot start up libmicrohttpd."); + LOG(LVL_ERR, "Cannot start up libmicrohttpd listening on IPv4."); + } + + d6 = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_IPv6, + port, + NULL, + NULL, + &connection_handler, + NULL, + MHD_OPTION_NOTIFY_COMPLETED, + &request_completed, NULL, + MHD_OPTION_END); + if (d6 == NULL) { + LOG(LVL_ERR, "Cannot start up libmicrohttpd listening on IPv6."); + } + + if(d == NULL && d6 == NULL) { + LOG(LVL_FATAL, "Both IPv4 and IPv6 servers failed to start. Terminating."); return EXIT_FAILURE; } @@ -471,6 +488,7 @@ int main(int argc, char ** argv) { LOG(LVL_INFO, "Shutting down..."); MHD_stop_daemon(d); + MHD_stop_daemon(d6); MHD_destroy_response(error403Response); MHD_destroy_response(error404Response);