[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#536787: didiwiki: option to bind only to loopback or to specific ip



Package: didiwiki
Version: 0.5-6
Severity: wishlist

*** Please type your report below this line ***

didiwiki listens on any ip address (0.0.0.0). It would be useful an option to bind it only to loopback or to a specific ip address.
The patch attached adds this option:

- "-l": only to localhost
- "-l <ip>": only to specific ip
- no option (default): to any ip

Carlo

-- System Information:
Debian Release: 5.0.2
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: i386 (i686)

Kernel: Linux 2.6.26-2-686 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages didiwiki depends on:
ii  adduser                       3.110      add and remove users and groups
ii  libc6                         2.7-18     GNU C Library: Shared libraries

didiwiki recommends no packages.

didiwiki suggests no packages.

-- no debconf information
--- didi.c.orig	2009-07-13 09:11:42.000000000 +0200
+++ didi.c	2009-07-13 14:57:39.000000000 +0200
@@ -12,6 +12,7 @@
 main(int argc, char **argv)
 {
   HttpRequest  *req  = NULL;
+  char         *address = "0.0.0.0";
   int           port = 8000;
   int           c;
   char          *didiwiki_home = NULL;
@@ -22,16 +23,17 @@
     {
       static struct option long_options[] = 
 	{
-	  {"debug", no_argument,       0, 'd'},
-	  {"port",  required_argument, 0, 'p'},
-	  {"home",  required_argument, 0, 'h'},
+	  {"debug", no_argument,        0, 'd'},
+          {"listen", optional_argument, 0, 'l'},
+	  {"port",  required_argument,  0, 'p'},
+	  {"home",  required_argument,  0, 'h'},
 	  {0, 0, 0, 0}
 	};
 
       /* 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, "dl::p:h:", long_options, &option_index);
 
       /* detect the end of the options */
       if (c == -1)
@@ -46,6 +48,17 @@
 	  debug = 1;
 	  break;
 	  
+        case 'l':
+	  if (optarg == NULL)
+		address = "127.0.0.1";
+	  else
+		{
+        	unsigned int n1,n2,n3,n4;
+		if (sscanf(optarg,"%u.%u.%u.%u", &n1, &n2, &n3, &n4) == 4 && n1 <= 255 && n2 <= 255 && n3 <= 255 && n4 <= 255) 
+			address = optarg;
+		}
+          break;
+
 	case 'p':
 	  port = atoi(optarg);
 	  break;
@@ -66,7 +79,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);
--- http.h.orig	2009-07-13 09:11:36.000000000 +0200
+++ http.h	2009-07-13 14:26:59.000000000 +0200
@@ -6,7 +6,7 @@
 typedef struct HttpRequestParam HttpRequestParam;
 
 HttpRequest*
-http_server(int iPort);
+http_server(char *address, int iPort);
 
 HttpRequest*
 http_request_new(void);
--- http.c.orig	2009-07-13 09:11:27.000000000 +0200
+++ http.c	2009-07-13 14:28:03.000000000 +0200
@@ -443,7 +443,7 @@
 ** Implement an HTTP server daemon.
 */
 HttpRequest*
-http_server(int iPort)
+http_server(char *address, int iPort)
 {
   int                listener;      /* The server socket */
   int                connection;    /* A socket for each connection */
@@ -457,7 +457,7 @@
 
   memset(&inaddr, 0, sizeof(inaddr));
   inaddr.sin_family = AF_INET;
-  inaddr.sin_addr.s_addr = INADDR_ANY;
+  inaddr.sin_addr.s_addr = inet_addr(address);
   inaddr.sin_port = htons(iPort);
   listener = socket(AF_INET, SOCK_STREAM, 0);
 

Reply to: