2 Copyright (C) 2006 OpenWrt.org
4 --- busybox-1.1.1/networking/httpd.c 2006-03-22 22:16:19.000000000 +0100
5 +++ busybox-1.1.1.new/networking/httpd.c 2006-04-01 19:41:42.150744624 +0200
8 #include <sys/socket.h> /* for connect and socket*/
9 #include <netinet/in.h> /* for sockaddr_in */
10 +#include <arpa/inet.h>
16 void bb_show_usage(void)
18 - fprintf(stderr, "Usage: %s [-p <port>] [-c configFile] [-d/-e <string>] "
19 - "[-r realm] [-u user] [-h homedir]\n", bb_applet_name);
20 + fprintf(stderr, "Usage: %s [-p <port>] [-l <IP address>] [-c configFile]"
21 + "[-d/-e <string>] [-r realm] [-u user] [-h homedir]\n", bb_applet_name);
27 unsigned port; /* server initial port and for
28 set env REMOTE_PORT */
31 const char *found_mime_type;
32 const char *found_moved_temporarily;
34 /* inet_addr() returns a value that is already in network order */
35 memset(&lsocket, 0, sizeof(lsocket));
36 lsocket.sin_family = AF_INET;
37 - lsocket.sin_addr.s_addr = INADDR_ANY;
38 + if (inet_aton(config->address, &(lsocket.sin_addr)) == 1) {
39 + if (config->address != NULL) lsocket.sin_addr.s_addr = ((struct in_addr *) ((gethostbyname(config->address))->h_addr))->s_addr;
40 + else lsocket.sin_addr.s_addr = htons(INADDR_ANY);
42 lsocket.sin_port = htons(config->port) ;
43 fd = socket(AF_INET, SOCK_STREAM, 0);
46 USE_FEATURE_HTTPD_AUTH_MD5(m_opt_md5,)
47 USE_FEATURE_HTTPD_SETUID(u_opt_setuid,)
48 SKIP_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY(p_opt_port,)
49 + SKIP_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY(l_opt_addr,)
52 static const char httpd_opts[]="c:d:h:"
54 USE_FEATURE_HTTPD_BASIC_AUTH("r:")
55 USE_FEATURE_HTTPD_AUTH_MD5("m:")
56 USE_FEATURE_HTTPD_SETUID("u:")
57 - SKIP_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY("p:");
58 + SKIP_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY("p:l:");
60 #define OPT_CONFIG_FILE (1<<c_opt_config_file)
61 #define OPT_DECODE_URL (1<<d_opt_decode_url)
63 #define OPT_PORT SKIP_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY((1<<p_opt_port)) \
64 USE_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY(0)
66 +#define OPT_ADDRESS SKIP_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY((1<<l_opt_addr)) \
67 + USE_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY(0)
69 #ifdef HTTPD_STANDALONE
70 int main(int argc, char *argv[])
73 USE_FEATURE_HTTPD_ENCODE_URL_STR(const char *url_for_encode;)
74 SKIP_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY(const char *s_port;)
75 + SKIP_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY(const char *s_addr;)
76 SKIP_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY(int server;)
78 USE_FEATURE_HTTPD_SETUID(const char *s_uid;)
81 #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
83 + config->address = "";
86 config->ContentLength = -1;
88 USE_FEATURE_HTTPD_AUTH_MD5(, &pass)
89 USE_FEATURE_HTTPD_SETUID(, &s_uid)
90 SKIP_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY(, &s_port)
91 + SKIP_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY(, &s_addr)
94 if(opt & OPT_DECODE_URL) {
96 #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
98 config->port = bb_xgetlarg(s_port, 10, 1, 0xffff);
99 + if (opt & OPT_ADDRESS)
100 + if (s_addr) config->address = (char *) s_addr;
101 #ifdef CONFIG_FEATURE_HTTPD_SETUID
102 if(opt & OPT_SETUID) {