Package: dhttpd
Version: 1.02a-15
Severity: wishlist
Tags: patch

This patch adds -b option for binding to an alternate address.

-- System Information:
Debian Release: testing/unstable
  APT prefers testing
  APT policy: (500, 'testing'), (500, 'stable')
Architecture: amd64 (x86_64)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.8-12-amd64-k8
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) (ignored: LC_ALL 
set to en_US.UTF-8)

Versions of packages dhttpd depends on:
ii  libc6                         2.3.6-13   GNU C Library: Shared libraries
ii  libgcc1                       1:4.1.0-4  GCC support library
ii  libstdc++6                    4.1.0-4    The GNU Standard C++ Library v3

dhttpd recommends no packages.

-- no debconf information
diff -ur dhttpd-1.02a.old/debian/default dhttpd-1.02a/debian/default
--- dhttpd-1.02a.old/debian/default	2006-06-17 11:21:50.000000000 +0200
+++ dhttpd-1.02a/debian/default	2006-06-17 11:44:10.399171928 +0200
@@ -1,2 +1,2 @@
 # Change this value to set options for dhttpd startup
-#OPTIONS="-p80"
+#OPTIONS="-p80 -b 0.0.0.0"
diff -ur dhttpd-1.02a.old/src/config.hh dhttpd-1.02a/src/config.hh
--- dhttpd-1.02a.old/src/config.hh	2006-06-17 11:21:50.000000000 +0200
+++ dhttpd-1.02a/src/config.hh	2006-06-17 11:35:45.791883896 +0200
@@ -11,6 +11,9 @@
  * root, you must use a value >= 1024, such as 8080.             */
 #define DEFAULTPORT	80
 
+/* Set default address to listen to.  (0.0.0.0 for any)          */
+#define DEFAULTBINDADDR "0.0.0.0"
+
 /* This is the directory where the web pages are located.        */
 /* Note:  buffer overflow problems may exist if WEBDIRPREFIX is  *
  * longer than 150 characters or so.                             */
diff -ur dhttpd-1.02a.old/src/main.cc dhttpd-1.02a/src/main.cc
--- dhttpd-1.02a.old/src/main.cc	2006-06-17 11:21:50.000000000 +0200
+++ dhttpd-1.02a/src/main.cc	2006-06-17 11:41:51.657263904 +0200
@@ -99,11 +99,12 @@
 {
 	int o;
 	int portnum = DEFAULTPORT;
+	char *bind_addr = DEFAULTBINDADDR;
 	bool nofork=false;
 
 	for( ;; )
 	{
-		o = getopt( argc, argv, "p:hdr:" );
+		o = getopt( argc, argv, "p:b:hdr:" );
 		if( o==-1 )
 		{
 			break;
@@ -118,6 +119,7 @@
 			case 'h':
 				printf( "usage: %s [options]\n", argv[ 0 ] );
 				printf( "  -p (port)  Use a different port than the default of %i\n", DEFAULTPORT );
+				printf( "  -b         Bind to this address instead of ", DEFAULTBINDADDR, "\n" );
 				printf( "  -h         Help\n" );
 				printf( "  -d         Do not fork into Background on startup\n" );
 				return 0;
@@ -125,6 +127,9 @@
 			case 'p':
 				sscanf( optarg, "%i", &portnum );
 				break;
+			case 'b':
+				bind_addr = optarg;
+				break;
 			case 'r':
 			        if ( strlen(optarg) > ROOT_MAX_LEN )
 			        {
@@ -152,7 +157,7 @@
 		}
 	}
 
-	ListenSocket listen_socket( portnum );
+	ListenSocket listen_socket( portnum, bind_addr );
 	pid_t pid;
 	int s;
 
diff -ur dhttpd-1.02a.old/src/socket.cc dhttpd-1.02a/src/socket.cc
--- dhttpd-1.02a.old/src/socket.cc	2006-06-17 11:21:50.000000000 +0200
+++ dhttpd-1.02a/src/socket.cc	2006-06-17 11:40:09.404808640 +0200
@@ -29,6 +29,7 @@
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <arpa/inet.h>		/* inet_addr */
 
 #include "socket.hh"
 
@@ -77,7 +78,7 @@
  * ListenSocket::ListenSocket():
  *   Start up the socket listening routines
  */
-ListenSocket::ListenSocket( int port )
+ListenSocket::ListenSocket( int port, char *bind_addr )
 {
 	int status;
 	struct sockaddr_in s_in;
@@ -87,7 +88,7 @@
 	one = 1;
 	memset( &s_in, 0, sizeof( s_in ) );
 	s_in.sin_family = AF_INET;
-	s_in.sin_addr.s_addr = htonl( INADDR_ANY );
+	s_in.sin_addr.s_addr = inet_addr( bind_addr );
 	s_in.sin_port = htons( port );
 
 	sock = socket( AF_INET, SOCK_STREAM, 0 );
diff -ur dhttpd-1.02a.old/src/socket.hh dhttpd-1.02a/src/socket.hh
--- dhttpd-1.02a.old/src/socket.hh	2006-06-17 11:21:50.000000000 +0200
+++ dhttpd-1.02a/src/socket.hh	2006-06-17 11:32:55.627752776 +0200
@@ -43,6 +43,6 @@
 	int newsock();
 	int getfd() const { return sock; }
 
-	ListenSocket( int port );
+	ListenSocket( int port, char *bind_addr );
 	~ListenSocket();
 };

Reply via email to