Default to --port 8080, or 80 if running as root.

This commit is contained in:
Emil Mikulic 2011-04-16 19:07:57 +10:00
parent 010d194180
commit 58dca3d6b1

View File

@ -256,7 +256,7 @@ static time_t now;
/* Defaults can be overridden on the command-line */ /* Defaults can be overridden on the command-line */
static in_addr_t bindaddr = INADDR_ANY; 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 int max_connections = -1; /* kern.ipc.somaxconn */
static const char *index_name = "index.html"; static const char *index_name = "index.html";
@ -844,7 +844,7 @@ static void usage(void) {
"usage: darkhttpd /path/to/wwwroot [options]\n\n" "usage: darkhttpd /path/to/wwwroot [options]\n\n"
"options:\n\n"); "options:\n\n");
printf( 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" "\t\tSpecifies which port to listen on for connections.\n"
"\n", bindport); "\n", bindport);
printf( printf(
@ -917,6 +917,9 @@ static void parse_commandline(const int argc, char *argv[]) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (getuid() == 0)
bindport = 80;
wwwroot = xstrdup(argv[1]); wwwroot = xstrdup(argv[1]);
/* Strip ending slash. */ /* Strip ending slash. */
len = strlen(wwwroot); len = strlen(wwwroot);