Skip to content
This repository has been archived by the owner on Aug 17, 2021. It is now read-only.

Commit

Permalink
teach fiche about binding to a specific address
Browse files Browse the repository at this point in the history
Add the -L <listen_addr> option which permits fiche to bind to a
specific local address rather than INADDR_ANY.
  • Loading branch information
larsks committed Feb 27, 2018
1 parent 9206dce commit 441debc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ To use fiche you have to have netcat installed. You probably already have it - t
```
usage: fiche [-D6epbsdSolBuw].
[-d domain] [-p port] [-s slug size]
[-d domain] [-L listen_addr ] [-p port] [-s slug size]
[-o output directory] [-B buffer size] [-u user name]
[-l log file] [-b banlist] [-w whitelist] [-S]
```
Expand Down
7 changes: 5 additions & 2 deletions fiche.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ void fiche_init(Fiche_Settings *settings) {
"example.com",
// output dir
"code",
// listen_addr
"0.0.0.0",
// port
9999,
// slug length
Expand Down Expand Up @@ -442,7 +444,7 @@ static int start_server(Fiche_Settings *settings) {
// Prepare address and port handler
struct sockaddr_in address;
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_addr.s_addr = inet_addr(settings->listen_addr);
address.sin_port = htons(settings->port);

// Bind to port
Expand All @@ -457,7 +459,8 @@ static int start_server(Fiche_Settings *settings) {
return -1;
}

print_status("Server started listening on port: %d.", settings->port);
print_status("Server started listening on: %s:%d.",
settings->listen_addr, settings->port);
print_separator();

// Run dispatching loop
Expand Down
5 changes: 5 additions & 0 deletions fiche.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ typedef struct Fiche_Settings {
*/
char *output_dir_path;

/**
* @brief Address on which fiche is waiting for connections
*/
char *listen_addr;

/**
* @brief Port on which fiche is waiting for connections
*/
Expand Down
13 changes: 10 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int main(int argc, char **argv) {

// Parse input arguments
int c;
while ((c = getopt(argc, argv, "D6eSp:b:s:d:o:l:B:u:w:")) != -1) {
while ((c = getopt(argc, argv, "D6eSL:p:b:s:d:o:l:B:u:w:")) != -1) {
switch (c) {

// domain
Expand All @@ -61,6 +61,13 @@ int main(int argc, char **argv) {
}
break;

// listen_addr
case 'L':
{
fs.listen_addr = optarg;
}
break;

// slug size
case 's':
{
Expand Down Expand Up @@ -120,8 +127,8 @@ int main(int argc, char **argv) {
// Display help in case of any unsupported argument
default:
{
printf("usage: fiche [-dpsSoBulbw].\n");
printf(" [-d domain] [-p port] [-s slug size]\n");
printf("usage: fiche [-dLpsSoBulbw].\n");
printf(" [-d domain] [-L listen_addr] [-p port] [-s slug size]\n");
printf(" [-o output directory] [-B buffer size] [-u user name]\n");
printf(" [-l log file] [-b banlist] [-w whitelist] [-S]\n");
return 0;
Expand Down

0 comments on commit 441debc

Please sign in to comment.