Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/chm_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@

int config_port = 8080;
char config_bind[65536] = "0.0.0.0";
char config_quiet = 0;

static void usage(const char *argv0)
{
#ifdef CHM_HTTP_SIMPLE
fprintf(stderr, "usage: %s <filename>\n", argv0);
fprintf(stderr, "usage: %s [--quiet] <filename>\n", argv0);
#else
fprintf(stderr, "usage: %s [--port=PORT] [--bind=IP] <filename>\n", argv0);
fprintf(stderr, "usage: %s [--quiet] [--port=PORT] [--bind=IP] <filename>\n", argv0);
#endif
exit(1);
}
Expand All @@ -80,14 +81,15 @@ int main(int c, char **v)
{
{ "port", required_argument, 0, 'p' },
{ "bind", required_argument, 0, 'b' },
{ "quiet", no_argument, 0, 'q' },
{ "help", no_argument, 0, 'h' },
{ 0, 0, 0, 0 }
};

while (1)
{
int o;
o = getopt_long (c, v, "n:b:h", longopts, &optindex);
o = getopt_long (c, v, "n:b:qh", longopts, &optindex);
if (o < 0)
{
break;
Expand All @@ -109,6 +111,10 @@ int main(int c, char **v)
config_bind[65535] = '\0';
break;

case 'q':
config_quiet = 1;
break;

case 'h':
usage (v[0]);
break;
Expand Down Expand Up @@ -182,6 +188,12 @@ static void chmhttp_server(const char *filename)
exit(3);
}

/* Display URL for server */
if (!config_quiet)
{
printf("Server running at http://%s:%d/\n", config_bind, config_port);
}

/* listen for connections */
listen(server.socket, 75);
addrLen = sizeof(struct sockaddr);
Expand Down