Added support for httpd IP address binding, worksforme #108
[openwrt/svn-archive/archive.git] / openwrt / package / busybox / patches / 220-http_address_binding.patch
1 --- busybox-1.1.0-pre1.orig/networking/httpd.c 2005-11-01 00:55:15.000000000 +0100
2 +++ busybox-1.1.0-pre1/networking/httpd.c 2006-01-07 00:58:45.000000000 +0100
3 @@ -150,6 +150,7 @@
4
5 /* You can use this server as standalone, require libbb.a for linking */
6 //#define HTTPD_STANDALONE
7 +static const char address[16] = "127.0.0.1";
8
9 /* Config options, disable this for do very small module */
10 //#define CONFIG_FEATURE_HTTPD_CGI
11 @@ -184,7 +185,7 @@
12 void bb_show_usage(void)
13 {
14 fprintf(stderr, "Usage: %s [-p <port>] [-c configFile] [-d/-e <string>] "
15 - "[-r realm] [-u user] [-h homedir]\n", bb_applet_name);
16 + "[-l IP address] [-r realm] [-u user] [-h homedir]\n", bb_applet_name);
17 exit(1);
18 }
19 #endif
20 @@ -234,6 +235,7 @@
21 #endif
22 unsigned port; /* server initial port and for
23 set env REMOTE_PORT */
24 + char addr[16]; /* server initial IP address */
25 union HTTPD_FOUND {
26 const char *found_mime_type;
27 const char *found_moved_temporarily;
28 @@ -826,6 +828,13 @@
29 sprintf(buf, "%u", config->port);
30 addEnv(port_name, "PORT", buf);
31 }
32 +static void addEnvAddr(const char *addr_name)
33 +{
34 + char buf[16];
35 +
36 + sprintf(buf, "%s", config->addr);
37 + addEnv(addr_name, "ADDR", buf);
38 +}
39 #endif
40 #endif /* CONFIG_FEATURE_HTTPD_CGI */
41
42 @@ -910,7 +919,14 @@
43 /* inet_addr() returns a value that is already in network order */
44 memset(&lsocket, 0, sizeof(lsocket));
45 lsocket.sin_family = AF_INET;
46 - lsocket.sin_addr.s_addr = INADDR_ANY;
47 + if (inet_aton(config->addr, & (lsocket.sin_addr)) == 0) {
48 + if ((gethostbyname(config->addr)) == NULL) return -1;
49 + lsocket.sin_addr.s_addr = ((struct in_addr *) ((gethostbyname(config->addr))->h_addr))->s_addr;
50 + }
51 + else
52 + {
53 + lsocket.sin_addr.s_addr = htons(INADDR_ANY);
54 + }
55 lsocket.sin_port = htons(config->port) ;
56 fd = socket(AF_INET, SOCK_STREAM, 0);
57 if (fd >= 0) {
58 @@ -1943,7 +1959,7 @@
59 #define OPT_INC_2 0
60 #endif
61 #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
62 - "p:v"
63 + "p:v:l"
64 #ifdef CONFIG_FEATURE_HTTPD_SETUID
65 "u:"
66 #endif
67 @@ -1957,8 +1973,9 @@
68 #define OPT_REALM (1<<(3+OPT_INC_1))
69 #define OPT_MD5 (1<<(4+OPT_INC_1))
70 #define OPT_PORT (1<<(3+OPT_INC_1+OPT_INC_2))
71 -#define OPT_DEBUG (1<<(4+OPT_INC_1+OPT_INC_2))
72 -#define OPT_SETUID (1<<(5+OPT_INC_1+OPT_INC_2))
73 +#define OPT_ADDR (1<<(4+OPT_INC_1+OPT_INC_2))
74 +#define OPT_DEBUG (1<<(5+OPT_INC_1+OPT_INC_2))
75 +#define OPT_SETUID (1<<(6+OPT_INC_1+OPT_INC_2))
76
77
78 #ifdef HTTPD_STANDALONE
79 @@ -2014,6 +2031,7 @@
80 #endif
81 #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
82 , &s_port
83 + , &(config->addr)
84 #ifdef CONFIG_FEATURE_HTTPD_SETUID
85 , &s_uid
86 #endif