1 # Copyright (C) 2006 OpenWrt.org
3 # This is free software, licensed under the GNU General Public License v2.
4 # See /LICENSE for more information.
6 diff -ruN busybox-1.2.0-old/networking/httpd.c busybox-1.2.0-new/networking/httpd.c
7 --- busybox-1.2.0-old/networking/httpd.c 2006-07-01 00:42:02.000000000 +0200
8 +++ busybox-1.2.0-new/networking/httpd.c 2006-08-01 10:06:58.000000000 +0200
10 #include <sys/types.h>
11 #include <sys/socket.h> /* for connect and socket*/
12 #include <netinet/in.h> /* for sockaddr_in */
13 +#include <arpa/inet.h>
16 #include <fcntl.h> /* for open modes */
19 unsigned port; /* server initial port and for
20 set env REMOTE_PORT */
23 const char *found_mime_type;
24 const char *found_moved_temporarily;
26 /* inet_addr() returns a value that is already in network order */
27 memset(&lsocket, 0, sizeof(lsocket));
28 lsocket.sin_family = AF_INET;
29 - lsocket.sin_addr.s_addr = INADDR_ANY;
30 + if (inet_aton(config->address, &(lsocket.sin_addr)) == 1) {
31 + if (config->address != NULL) lsocket.sin_addr.s_addr = ((struct in_addr *) ((gethostbyname(config->address))->h_addr))->s_addr;
32 + else lsocket.sin_addr.s_addr = htons(INADDR_ANY);
34 lsocket.sin_port = htons(config->port);
35 fd = bb_xsocket(AF_INET, SOCK_STREAM, 0);
36 /* tell the OS it's OK to reuse a previous address even though */
38 USE_FEATURE_HTTPD_AUTH_MD5(m_opt_md5,)
39 USE_FEATURE_HTTPD_SETUID(u_opt_setuid,)
40 USE_FEATURE_HTTPD_WITHOUT_INETD(p_opt_port,)
41 + USE_FEATURE_HTTPD_WITHOUT_INETD(l_opt_addr,)
44 static const char httpd_opts[]="c:d:h:"
46 USE_FEATURE_HTTPD_BASIC_AUTH("r:")
47 USE_FEATURE_HTTPD_AUTH_MD5("m:")
48 USE_FEATURE_HTTPD_SETUID("u:")
49 - USE_FEATURE_HTTPD_WITHOUT_INETD("p:");
50 + USE_FEATURE_HTTPD_WITHOUT_INETD("p:l:");
52 #define OPT_CONFIG_FILE (1<<c_opt_config_file)
53 #define OPT_DECODE_URL (1<<d_opt_decode_url)
55 #define OPT_PORT USE_FEATURE_HTTPD_WITHOUT_INETD((1<<p_opt_port)) \
56 SKIP_FEATURE_HTTPD_WITHOUT_INETD(0)
58 +#define OPT_ADDRESS USE_FEATURE_HTTPD_WITHOUT_INETD((1<<l_opt_addr)) \
59 + SKIP_FEATURE_HTTPD_WITHOUT_INETD(0)
61 int httpd_main(int argc, char *argv[])
65 USE_FEATURE_HTTPD_ENCODE_URL_STR(const char *url_for_encode;)
66 USE_FEATURE_HTTPD_WITHOUT_INETD(const char *s_port;)
67 + USE_FEATURE_HTTPD_WITHOUT_INETD(const char *s_addr;)
68 USE_FEATURE_HTTPD_WITHOUT_INETD(int server;)
70 USE_FEATURE_HTTPD_SETUID(const char *s_uid;)
73 #ifdef CONFIG_FEATURE_HTTPD_WITHOUT_INETD
75 + config->address = "";
78 config->ContentLength = -1;
80 USE_FEATURE_HTTPD_AUTH_MD5(, &pass)
81 USE_FEATURE_HTTPD_SETUID(, &s_uid)
82 USE_FEATURE_HTTPD_WITHOUT_INETD(, &s_port)
83 + USE_FEATURE_HTTPD_WITHOUT_INETD(, &s_addr)
86 if(opt & OPT_DECODE_URL) {
88 #ifdef CONFIG_FEATURE_HTTPD_WITHOUT_INETD
90 config->port = bb_xgetlarg(s_port, 10, 1, 0xffff);
91 + if (opt & OPT_ADDRESS)
92 + if (s_addr) config->address = (char *) s_addr;
93 #ifdef CONFIG_FEATURE_HTTPD_SETUID
94 if(opt & OPT_SETUID) {