mirror of
https://github.com/emikulic/darkhttpd.git
synced 2023-08-10 21:13:08 +03:00
. Changed argument --bind' ->
--addr'
. Implemented arg parsing for port, addr, maxconn, log, chroot . init_sockin() prints the addr:port that sockin is bound to
This commit is contained in:
parent
79e52dfae2
commit
7a8ff37bb3
@ -10,6 +10,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -17,13 +18,16 @@
|
||||
|
||||
|
||||
/* defaults can be overridden on the command-line */
|
||||
static u_int32_t bindaddr = INADDR_ANY;
|
||||
static in_addr_t bindaddr = INADDR_ANY;
|
||||
static u_int16_t bindport = 80;
|
||||
static int max_connections = -1; /* kern.ipc.somaxconn */
|
||||
|
||||
static int sockin;
|
||||
static int sockin; /* socket to accept connections from */
|
||||
/*@null@*/
|
||||
static char *wwwroot = NULL;
|
||||
static char *wwwroot = NULL; /* a path name */
|
||||
/*@null@*/
|
||||
static char *logfile_name = NULL; /* NULL = no logging */
|
||||
static int want_chroot = 0;
|
||||
|
||||
|
||||
|
||||
@ -55,6 +59,8 @@ static void init_sockin(void)
|
||||
sizeof(struct sockaddr)) == -1)
|
||||
err(1, "bind(port %u)", bindport);
|
||||
|
||||
printf("listening on %s:%u\n", inet_ntoa(addrin.sin_addr), bindport);
|
||||
|
||||
/* listen on socket */
|
||||
if (listen(sockin, max_connections) == -1)
|
||||
err(1, "listen()");
|
||||
@ -72,9 +78,9 @@ static void usage(void)
|
||||
"\t--port number (default: %u)\n" /* DEFAULT_PORT */
|
||||
"\t\tSpecifies which port to listen on for connections.\n"
|
||||
"\n"
|
||||
"\t--bind ip (default: all)\n"
|
||||
"\t\tIf multiple interfaces are present,\n"
|
||||
"\t\tspecifies which one to bind the listening port to.\n"
|
||||
"\t--addr ip (default: all)\n"
|
||||
"\t\tIf multiple interfaces are present, specifies\n"
|
||||
"\t\twhich one to bind the listening port to.\n"
|
||||
"\n"
|
||||
"\t--maxconn number (default: system maximum)\n"
|
||||
"\t\tSpecifies how many concurrent connections to accept.\n"
|
||||
@ -85,7 +91,7 @@ static void usage(void)
|
||||
"\t--chroot (default: don't chroot)\n"
|
||||
"\t\tLocks server into wwwroot directory for added security.\n"
|
||||
"\n"
|
||||
"\t--uid blah, --gid blah\n" /* FIXME */
|
||||
/* "\t--uid blah, --gid blah\n" FIXME */
|
||||
, bindport);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@ -105,7 +111,33 @@ static void parse_commandline(const int argc, char *argv[])
|
||||
/* walk through the remainder of the arguments (if any) */
|
||||
for (i=2; i<argc; i++)
|
||||
{
|
||||
/* FIXME */
|
||||
if (strcmp(argv[i], "--port") == 0)
|
||||
{
|
||||
if (++i >= argc) errx(1, "missing number after --port");
|
||||
bindport = (u_int16_t)atoi(argv[i]);
|
||||
}
|
||||
else if (strcmp(argv[i], "--addr") == 0)
|
||||
{
|
||||
if (++i >= argc) errx(1, "missing ip after --addr");
|
||||
bindaddr = inet_addr(argv[i]);
|
||||
if (bindaddr == (in_addr_t)INADDR_NONE)
|
||||
errx(1, "malformed --addr argument");
|
||||
}
|
||||
else if (strcmp(argv[i], "--maxconn") == 0)
|
||||
{
|
||||
if (++i >= argc) errx(1, "missing number after --maxconn");
|
||||
max_connections = atoi(argv[i]);
|
||||
}
|
||||
else if (strcmp(argv[i], "--log") == 0)
|
||||
{
|
||||
if (++i >= argc) errx(1, "missing filename after --log");
|
||||
logfile_name = argv[i];
|
||||
}
|
||||
else if (strcmp(argv[i], "--chroot") == 0)
|
||||
{
|
||||
want_chroot = 1;
|
||||
}
|
||||
else
|
||||
errx(1, "unknown argument `%s'", argv[i]);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user