From 58dca3d6b16c127784b96936328fe55869f03d8c Mon Sep 17 00:00:00 2001 From: Emil Mikulic Date: Sat, 16 Apr 2011 19:07:57 +1000 Subject: [PATCH] Default to --port 8080, or 80 if running as root. --- darkhttpd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/darkhttpd.c b/darkhttpd.c index 2506fa7..40f961c 100644 --- a/darkhttpd.c +++ b/darkhttpd.c @@ -256,7 +256,7 @@ static time_t now; /* Defaults can be overridden on the command-line */ static in_addr_t bindaddr = INADDR_ANY; -static uint16_t bindport = 80; +static uint16_t bindport = 8080; /* or 80 if running as root */ static int max_connections = -1; /* kern.ipc.somaxconn */ static const char *index_name = "index.html"; @@ -844,7 +844,7 @@ static void usage(void) { "usage: darkhttpd /path/to/wwwroot [options]\n\n" "options:\n\n"); printf( - "\t--port number (default: %u)\n" /* bindport */ + "\t--port number (default: %u, or 80 if running as root)\n" /* bindport */ "\t\tSpecifies which port to listen on for connections.\n" "\n", bindport); printf( @@ -917,6 +917,9 @@ static void parse_commandline(const int argc, char *argv[]) { exit(EXIT_FAILURE); } + if (getuid() == 0) + bindport = 80; + wwwroot = xstrdup(argv[1]); /* Strip ending slash. */ len = strlen(wwwroot);