2c2d517c60e841e9627d3d987e916bcf1270694d
[openwrt/svn-archive/archive.git] / openwrt / package / busybox / patches / 320-httpd_address_binding.patch
1 --- busybox-1.1.0.orig/networking/httpd.c 2006-02-06 16:02:30.000000000 +0100
2 +++ busybox-1.1.0/networking/httpd.c 2006-02-06 16:25:34.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 @@ -201,8 +202,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 @@ -256,6 +257,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 @@ -942,7 +944,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 @@ -1985,7 +1990,7 @@
43 #define OPT_INC_3 ENABLE_FEATURE_HTTPD_AUTH_MD5
44
45 #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
46 - "p:"
47 + "p:l:"
48 #endif
49 #ifdef CONFIG_FEATURE_HTTPD_SETUID
50 "u:"
51 @@ -1999,7 +2004,8 @@
52 #define OPT_REALM (1<<(2+OPT_INC_1+OPT_INC_2)) /* r */
53 #define OPT_MD5 (1<<(2+OPT_INC_1+OPT_INC_2+OPT_INC_3)) /* m */
54 #define OPT_PORT (1<<(3+OPT_INC_1+OPT_INC_2+OPT_INC_3)) /* p */
55 -#define OPT_SETUID (1<<(4+OPT_INC_1+OPT_INC_2+OPT_INC_3)) /* u */
56 +#define OPT_ADDRESS (1<<(4+OPT_INC_1+OPT_INC_2+OPT_INC_3)) /* l */
57 +#define OPT_SETUID (1<<(5+OPT_INC_1+OPT_INC_2+OPT_INC_3)) /* u */
58
59
60 #ifdef HTTPD_STANDALONE
61 @@ -2016,6 +2022,7 @@
62 #endif
63 #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
64 const char *s_port;
65 + const char *s_addr;
66 int server;
67 #endif
68
69 @@ -2035,6 +2042,7 @@
70
71 #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
72 config->port = 80;
73 + config->address = "";
74 #endif
75
76 config->ContentLength = -1;
77 @@ -2052,6 +2060,7 @@
78 #endif
79 #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
80 , &s_port
81 + , &s_addr
82 #endif
83 #ifdef CONFIG_FEATURE_HTTPD_SETUID
84 , &s_uid
85 @@ -2077,6 +2086,8 @@
86 #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
87 if(opt & OPT_PORT)
88 config->port = bb_xgetlarg(s_port, 10, 1, 0xffff);
89 + if (opt & OPT_ADDRESS)
90 + if (s_addr) config->address = (char *) s_addr;
91 #ifdef CONFIG_FEATURE_HTTPD_SETUID
92 if(opt & OPT_SETUID) {
93 char *e;