tag rc6
[openwrt/svn-archive/openwrt.git] / package / busybox / patches / 330-httpd_address_binding.patch
1 --- busybox-1.00.orig/networking/httpd.c 2006-02-06 15:46:15.000000000 +0100
2 +++ busybox-1.00/networking/httpd.c 2006-02-06 15:49:06.000000000 +0100
3 @@ -109,6 +109,7 @@
4 #include <sys/types.h>
5 #include <sys/socket.h> /* for connect and socket*/
6 #include <netinet/in.h> /* for sockaddr_in */
7 +#include <arpa/inet.h> /* for inet_aton */
8 #include <sys/time.h>
9 #include <sys/stat.h>
10 #include <sys/wait.h>
11 @@ -183,8 +184,8 @@
12
13 void bb_show_usage(void)
14 {
15 - fprintf(stderr, "Usage: %s [-p <port>] [-c configFile] [-d/-e <string>] "
16 - "[-r realm] [-u user] [-h homedir]\n", bb_applet_name);
17 + fprintf(stderr, "Usage: %s [-p <port>] [-l <IP address>] [-c configFile]
18 + [-d/-e <string>] [-r realm] [-u user] [-h homedir]\n", bb_applet_name);
19 exit(1);
20 }
21 #endif
22 @@ -235,6 +236,7 @@
23 #endif
24 unsigned port; /* server initial port and for
25 set env REMOTE_PORT */
26 + char *address; /* server initial address */
27 union HTTPD_FOUND {
28 const char *found_mime_type;
29 const char *found_moved_temporarily;
30 @@ -911,7 +913,10 @@
31 /* inet_addr() returns a value that is already in network order */
32 memset(&lsocket, 0, sizeof(lsocket));
33 lsocket.sin_family = AF_INET;
34 - lsocket.sin_addr.s_addr = INADDR_ANY;
35 + if (inet_aton(config->address, &(lsocket.sin_addr)) == 1) {
36 + if (config->address != NULL) lsocket.sin_addr.s_addr = ((struct in_addr *) ((gethostbyname(config->address))->h_addr))->s_addr;
37 + else lsocket.sin_addr.s_addr = htons(INADDR_ANY);
38 + }
39 lsocket.sin_port = htons(config->port) ;
40 fd = socket(AF_INET, SOCK_STREAM, 0);
41 if (fd >= 0) {
42 @@ -1943,7 +1948,7 @@
43 #define OPT_INC_2 0
44 #endif
45 #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
46 - "p:v"
47 + "p:l:v"
48 #ifdef CONFIG_FEATURE_HTTPD_SETUID
49 "u:"
50 #endif
51 @@ -1957,8 +1962,9 @@
52 #define OPT_REALM (1<<(3+OPT_INC_1))
53 #define OPT_MD5 (1<<(4+OPT_INC_1))
54 #define OPT_PORT (1<<(3+OPT_INC_1+OPT_INC_2))
55 -#define OPT_DEBUG (1<<(4+OPT_INC_1+OPT_INC_2))
56 -#define OPT_SETUID (1<<(5+OPT_INC_1+OPT_INC_2))
57 +#define OPT_ADDRESS (1<<(4+OPT_INC_1+OPT_INC_2))
58 +#define OPT_DEBUG (1<<(5+OPT_INC_1+OPT_INC_2))
59 +#define OPT_SETUID (1<<(6+OPT_INC_1+OPT_INC_2))
60
61
62 #ifdef HTTPD_STANDALONE
63 @@ -1975,6 +1981,7 @@
64 #endif
65 #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
66 const char *s_port;
67 + const char *s_addr;
68 #endif
69
70 #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
71 @@ -1997,6 +2004,7 @@
72
73 #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
74 config->port = 80;
75 + config->address = "";
76 #endif
77
78 config->ContentLength = -1;
79 @@ -2014,6 +2022,7 @@
80 #endif
81 #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
82 , &s_port
83 + , &s_addr
84 #ifdef CONFIG_FEATURE_HTTPD_SETUID
85 , &s_uid
86 #endif
87 @@ -2039,6 +2048,8 @@
88 #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
89 if(opt & OPT_PORT)
90 config->port = bb_xgetlarg(s_port, 10, 1, 0xffff);
91 + if (opt & OPT_ADDRESS)
92 + config->address = (char *) s_addr;
93 config->debugHttpd = opt & OPT_DEBUG;
94 #ifdef CONFIG_FEATURE_HTTPD_SETUID
95 if(opt & OPT_SETUID) {