[PATCH]: Add -l option to only bind to loopback Add -l|--loopback option to only bind to the loopback interface. Signed-off-by: Peter Korsgaard --- src/didi.c | 14 ++++++++++---- src/http.c | 4 ++-- src/http.h | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) Index: didiwiki/src/http.c =================================================================== --- didiwiki.orig/src/http.c +++ didiwiki/src/http.c @@ -451,7 +451,7 @@ ** Implement an HTTP server daemon. */ HttpRequest* -http_server(int iPort) +http_server(unsigned int address, int iPort) { int listener; /* The server socket */ int connection; /* A socket for each connection */ @@ -466,7 +466,7 @@ memset(&inaddr, 0, sizeof(inaddr)); inaddr.sin_family = AF_INET; - inaddr.sin_addr.s_addr = INADDR_ANY; + inaddr.sin_addr.s_addr = htonl(address); inaddr.sin_port = htons(iPort); listener = socket(AF_INET, SOCK_STREAM, 0); Index: didiwiki/src/http.h =================================================================== --- didiwiki.orig/src/http.h +++ didiwiki/src/http.h @@ -6,7 +6,7 @@ typedef struct HttpRequestParam HttpRequestParam; HttpRequest* -http_server(int iPort); +http_server(unsigned int address, int iPort); HttpRequest* http_request_new(void); Index: didiwiki/src/didi.c =================================================================== --- didiwiki.orig/src/didi.c +++ didiwiki/src/didi.c @@ -14,6 +14,7 @@ HttpRequest *req = NULL; int port = 8000; int c; + unsigned int address = INADDR_ANY; char *didiwiki_home = NULL; debug = 0; @@ -23,6 +24,7 @@ static struct option long_options[] = { {"debug", no_argument, 0, 'd'}, + {"loopback", no_argument, 0, 'l'}, {"port", required_argument, 0, 'p'}, {"home", required_argument, 0, 'h'}, {0, 0, 0, 0} @@ -31,7 +33,7 @@ /* getopt_long stores the option index here */ int option_index = 0; - c = getopt_long (argc, argv, "dp:h:", long_options, &option_index); + c = getopt_long (argc, argv, "dlp:h:", long_options, &option_index); /* detect the end of the options */ if (c == -1) @@ -45,7 +47,11 @@ case 'd': debug = 1; break; - + + case 'l': + address = INADDR_LOOPBACK; + break; + case 'p': port = atoi(optarg); break; @@ -55,7 +61,7 @@ break; default: - abort (); + abort(); } } @@ -66,7 +72,7 @@ req = http_request_new(); /* reads request from stdin */ } else { - req = http_server(port); /* forks here */ + req = http_server(address, port); /* forks here */ } wiki_handle_http_request(req);