inetd: make it NOMMU-capable and IPv6-friendly. Lots of renames
of variable/function names Total: -2474 bytes text data bss dec hex filename 802215 661 7452 810328 c5d58 busybox_old 800120 661 7428 808209 c5511 busybox_unstripped
This commit is contained in:
		@@ -1,7 +1,7 @@
 | 
			
		||||
#
 | 
			
		||||
# Automatically generated make config: don't edit
 | 
			
		||||
# Busybox version: 1.10.0.svn
 | 
			
		||||
# Tue Mar  4 22:57:04 2008
 | 
			
		||||
# Thu Mar  6 20:18:05 2008
 | 
			
		||||
#
 | 
			
		||||
CONFIG_HAVE_DOT_CONFIG=y
 | 
			
		||||
 | 
			
		||||
@@ -653,13 +653,13 @@ CONFIG_IFUPDOWN_IFSTATE_PATH=""
 | 
			
		||||
# CONFIG_FEATURE_IFUPDOWN_IPV6 is not set
 | 
			
		||||
# CONFIG_FEATURE_IFUPDOWN_MAPPING is not set
 | 
			
		||||
# CONFIG_FEATURE_IFUPDOWN_EXTERNAL_DHCP is not set
 | 
			
		||||
# CONFIG_INETD is not set
 | 
			
		||||
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_ECHO is not set
 | 
			
		||||
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD is not set
 | 
			
		||||
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_TIME is not set
 | 
			
		||||
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DAYTIME is not set
 | 
			
		||||
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_CHARGEN is not set
 | 
			
		||||
# CONFIG_FEATURE_INETD_RPC is not set
 | 
			
		||||
CONFIG_INETD=y
 | 
			
		||||
CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_ECHO=y
 | 
			
		||||
CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD=y
 | 
			
		||||
CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_TIME=y
 | 
			
		||||
CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DAYTIME=y
 | 
			
		||||
CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_CHARGEN=y
 | 
			
		||||
CONFIG_FEATURE_INETD_RPC=y
 | 
			
		||||
CONFIG_IP=y
 | 
			
		||||
CONFIG_FEATURE_IP_ADDRESS=y
 | 
			
		||||
CONFIG_FEATURE_IP_LINK=y
 | 
			
		||||
 
 | 
			
		||||
@@ -390,6 +390,7 @@ typedef struct len_and_sockaddr {
 | 
			
		||||
	} u;
 | 
			
		||||
} len_and_sockaddr;
 | 
			
		||||
enum {
 | 
			
		||||
	LSA_LEN_SIZE = offsetof(len_and_sockaddr, u),
 | 
			
		||||
	LSA_SIZEOF_SA = sizeof(
 | 
			
		||||
		union {
 | 
			
		||||
			struct sockaddr sa;
 | 
			
		||||
@@ -405,7 +406,12 @@ enum {
 | 
			
		||||
 * af == AF_UNSPEC will result in trying to create IPv6 socket,
 | 
			
		||||
 * and if kernel doesn't support it, IPv4.
 | 
			
		||||
 */
 | 
			
		||||
int xsocket_type(len_and_sockaddr **lsap, USE_FEATURE_IPV6(int af,) int sock_type);
 | 
			
		||||
#if ENABLE_FEATURE_IPV6
 | 
			
		||||
int xsocket_type(len_and_sockaddr **lsap, int af, int sock_type);
 | 
			
		||||
#else
 | 
			
		||||
int xsocket_type(len_and_sockaddr **lsap, int sock_type);
 | 
			
		||||
#define xsocket_type(lsap, af, sock_type) xsocket_type((lsap), (sock_type))
 | 
			
		||||
#endif
 | 
			
		||||
int xsocket_stream(len_and_sockaddr **lsap);
 | 
			
		||||
/* Create server socket bound to bindaddr:port. bindaddr can be NULL,
 | 
			
		||||
 * numeric IP ("N.N.N.N") or numeric IPv6 address,
 | 
			
		||||
@@ -430,14 +436,13 @@ len_and_sockaddr* host2sockaddr(const char *host, int port);
 | 
			
		||||
/* Version which dies on error */
 | 
			
		||||
len_and_sockaddr* xhost2sockaddr(const char *host, int port);
 | 
			
		||||
len_and_sockaddr* xdotted2sockaddr(const char *host, int port);
 | 
			
		||||
#if ENABLE_FEATURE_IPV6
 | 
			
		||||
/* Same, useful if you want to force family (e.g. IPv6) */
 | 
			
		||||
#if !ENABLE_FEATURE_IPV6
 | 
			
		||||
#define host_and_af2sockaddr(host, port, af) host2sockaddr((host), (port))
 | 
			
		||||
#define xhost_and_af2sockaddr(host, port, af) xhost2sockaddr((host), (port))
 | 
			
		||||
#else
 | 
			
		||||
len_and_sockaddr* host_and_af2sockaddr(const char *host, int port, sa_family_t af);
 | 
			
		||||
len_and_sockaddr* xhost_and_af2sockaddr(const char *host, int port, sa_family_t af);
 | 
			
		||||
#else
 | 
			
		||||
/* [we evaluate af: think about "host_and_af2sockaddr(..., af++)"] */
 | 
			
		||||
#define host_and_af2sockaddr(host, port, af) ((void)(af), host2sockaddr((host), (port)))
 | 
			
		||||
#define xhost_and_af2sockaddr(host, port, af) ((void)(af), xhost2sockaddr((host), (port)))
 | 
			
		||||
#endif
 | 
			
		||||
/* Assign sin[6]_port member if the socket is an AF_INET[6] one,
 | 
			
		||||
 * otherwise no-op. Useful for ftp.
 | 
			
		||||
 
 | 
			
		||||
@@ -1597,7 +1597,7 @@ USE_FEATURE_BRCTL_FANCY("\n" \
 | 
			
		||||
       "	-a	De/configure all interfaces automatically\n" \
 | 
			
		||||
       "	-i FILE	Use FILE for interface definitions\n" \
 | 
			
		||||
       "	-n	Print out what would happen, but don't do it\n" \
 | 
			
		||||
       "		(note that this option doesn't disable mappings)\n" \
 | 
			
		||||
       "		(note: doesn't disable mappings)\n" \
 | 
			
		||||
       "	-v	Print out what would happen before doing it\n" \
 | 
			
		||||
       "	-m	Don't run any mappings\n" \
 | 
			
		||||
       "	-f	Force de/configuration"
 | 
			
		||||
@@ -1609,19 +1609,21 @@ USE_FEATURE_BRCTL_FANCY("\n" \
 | 
			
		||||
       "	-a	De/configure all interfaces automatically\n" \
 | 
			
		||||
       "	-i FILE	Use FILE for interface definitions\n" \
 | 
			
		||||
       "	-n	Print out what would happen, but don't do it\n" \
 | 
			
		||||
       "		(note that this option doesn't disable mappings)\n" \
 | 
			
		||||
       "		(note: doesn't disable mappings)\n" \
 | 
			
		||||
       "	-v	Print out what would happen before doing it\n" \
 | 
			
		||||
       "	-m	Don't run any mappings\n" \
 | 
			
		||||
       "	-f	Force de/configuration"
 | 
			
		||||
 | 
			
		||||
#define inetd_trivial_usage \
 | 
			
		||||
       "[-f] [-q len] [conf]"
 | 
			
		||||
       "[-fe] [-q N] [-R N] [CONFFILE]"
 | 
			
		||||
#define inetd_full_usage \
 | 
			
		||||
       "Listen for network connections and launch programs" \
 | 
			
		||||
       "\n\nOptions:\n" \
 | 
			
		||||
       "	-f	Run in foreground\n" \
 | 
			
		||||
       "	-q N	Set the size of the socket listen queue to N\n" \
 | 
			
		||||
       "		(default: 128)"
 | 
			
		||||
       "Listen for network connections and launch programs\n" \
 | 
			
		||||
     "\nOptions:" \
 | 
			
		||||
     "\n	-f	Run in foreground" \
 | 
			
		||||
     "\n	-e	Log to stderr" \
 | 
			
		||||
     "\n	-q N    Socket listen queue (default: 128)" \
 | 
			
		||||
     "\n	-R N	Pause services after N connects/min" \
 | 
			
		||||
     "\n		(default: 0 - disabled)"
 | 
			
		||||
 | 
			
		||||
#define init_trivial_usage \
 | 
			
		||||
       ""
 | 
			
		||||
 
 | 
			
		||||
@@ -2,27 +2,26 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Utility routines.
 | 
			
		||||
 *
 | 
			
		||||
 * create raw socket for icmp (IPv6 version) protocol test permission
 | 
			
		||||
 * create raw socket for icmp (IPv6 version) protocol
 | 
			
		||||
 * and drop root privileges if running setuid
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
//#include <sys/types.h>
 | 
			
		||||
//#include <netdb.h>
 | 
			
		||||
//#include <sys/socket.h>
 | 
			
		||||
#include "libbb.h"
 | 
			
		||||
 | 
			
		||||
#if ENABLE_FEATURE_IPV6
 | 
			
		||||
int create_icmp6_socket(void)
 | 
			
		||||
{
 | 
			
		||||
	struct protoent *proto;
 | 
			
		||||
	int sock;
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
	struct protoent *proto;
 | 
			
		||||
	proto = getprotobyname("ipv6-icmp");
 | 
			
		||||
	/* if getprotobyname failed, just silently force
 | 
			
		||||
	 * proto->p_proto to have the correct value for "ipv6-icmp" */
 | 
			
		||||
	sock = socket(AF_INET6, SOCK_RAW,
 | 
			
		||||
			(proto ? proto->p_proto : IPPROTO_ICMPV6));
 | 
			
		||||
#else
 | 
			
		||||
	sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
 | 
			
		||||
#endif
 | 
			
		||||
	if (sock < 0) {
 | 
			
		||||
		if (errno == EPERM)
 | 
			
		||||
			bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
 | 
			
		||||
 
 | 
			
		||||
@@ -2,26 +2,25 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Utility routines.
 | 
			
		||||
 *
 | 
			
		||||
 * create raw socket for icmp protocol test permission
 | 
			
		||||
 * create raw socket for icmp protocol
 | 
			
		||||
 * and drop root privileges if running setuid
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
//#include <sys/types.h>
 | 
			
		||||
//#include <netdb.h>
 | 
			
		||||
//#include <sys/socket.h>
 | 
			
		||||
#include "libbb.h"
 | 
			
		||||
 | 
			
		||||
int create_icmp_socket(void)
 | 
			
		||||
{
 | 
			
		||||
	struct protoent *proto;
 | 
			
		||||
	int sock;
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
	struct protoent *proto;
 | 
			
		||||
	proto = getprotobyname("icmp");
 | 
			
		||||
	/* if getprotobyname failed, just silently force
 | 
			
		||||
	 * proto->p_proto to have the correct value for "icmp" */
 | 
			
		||||
	sock = socket(AF_INET, SOCK_RAW,
 | 
			
		||||
			(proto ? proto->p_proto : 1)); /* 1 == ICMP */
 | 
			
		||||
#else
 | 
			
		||||
	sock = socket(AF_INET, SOCK_RAW, 1); /* 1 == ICMP */
 | 
			
		||||
#endif
 | 
			
		||||
	if (sock < 0) {
 | 
			
		||||
		if (errno == EPERM)
 | 
			
		||||
			bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
 | 
			
		||||
 
 | 
			
		||||
@@ -132,11 +132,15 @@ USE_FEATURE_IPV6(sa_family_t af,)
 | 
			
		||||
 | 
			
		||||
	/* Ugly parsing of host:addr */
 | 
			
		||||
	if (ENABLE_FEATURE_IPV6 && host[0] == '[') {
 | 
			
		||||
		/* Even uglier parsing of [xx]:nn */
 | 
			
		||||
		host++;
 | 
			
		||||
		cp = strchr(host, ']');
 | 
			
		||||
		if (!cp || cp[1] != ':') /* Malformed: must have [xx]:nn */
 | 
			
		||||
			bb_error_msg_and_die("bad address '%s'", org_host);
 | 
			
		||||
			//return r; /* return NULL */
 | 
			
		||||
		if (!cp || cp[1] != ':') { /* Malformed: must have [xx]:nn */
 | 
			
		||||
			bb_error_msg("bad address '%s'", org_host);
 | 
			
		||||
			if (ai_flags & DIE_ON_ERROR)
 | 
			
		||||
				xfunc_die();
 | 
			
		||||
			return NULL;
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		cp = strrchr(host, ':');
 | 
			
		||||
		if (ENABLE_FEATURE_IPV6 && cp && strchr(host, ':') != cp) {
 | 
			
		||||
@@ -144,13 +148,19 @@ USE_FEATURE_IPV6(sa_family_t af,)
 | 
			
		||||
			cp = NULL; /* it's not a port spec */
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if (cp) {
 | 
			
		||||
	if (cp) { /* points to ":" or "]:" */
 | 
			
		||||
		int sz = cp - host + 1;
 | 
			
		||||
		host = safe_strncpy(alloca(sz), host, sz);
 | 
			
		||||
		if (ENABLE_FEATURE_IPV6 && *cp != ':')
 | 
			
		||||
			cp++; /* skip ']' */
 | 
			
		||||
		cp++; /* skip ':' */
 | 
			
		||||
		port = xatou16(cp);
 | 
			
		||||
		port = bb_strtou(cp, NULL, 10);
 | 
			
		||||
		if (errno || (unsigned)port > 0xffff) {
 | 
			
		||||
			bb_error_msg("bad port spec '%s'", org_host);
 | 
			
		||||
			if (ai_flags & DIE_ON_ERROR)
 | 
			
		||||
				xfunc_die();
 | 
			
		||||
			return NULL;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	memset(&hint, 0 , sizeof(hint));
 | 
			
		||||
@@ -221,6 +231,7 @@ len_and_sockaddr* xdotted2sockaddr(const char *host, int port)
 | 
			
		||||
	return str2sockaddr(host, port, AF_UNSPEC, AI_NUMERICHOST | DIE_ON_ERROR);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#undef xsocket_type
 | 
			
		||||
int xsocket_type(len_and_sockaddr **lsap, USE_FEATURE_IPV6(int family,) int sock_type)
 | 
			
		||||
{
 | 
			
		||||
	SKIP_FEATURE_IPV6(enum { family = AF_INET };)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1794
									
								
								networking/inetd.c
									
									
									
									
									
								
							
							
						
						
									
										1794
									
								
								networking/inetd.c
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -756,7 +756,7 @@ int nc_main(int argc, char **argv)
 | 
			
		||||
		/* We try IPv6, then IPv4, unless addr family is
 | 
			
		||||
		 * implicitly set by way of remote addr/port spec */
 | 
			
		||||
		x = xsocket_type(&ouraddr,
 | 
			
		||||
				USE_FEATURE_IPV6((themaddr ? themaddr->u.sa.sa_family : AF_UNSPEC),)
 | 
			
		||||
				(themaddr ? themaddr->u.sa.sa_family : AF_UNSPEC),
 | 
			
		||||
				x);
 | 
			
		||||
		if (o_lport)
 | 
			
		||||
			set_nport(ouraddr, htons(o_lport));
 | 
			
		||||
 
 | 
			
		||||
@@ -127,7 +127,7 @@ static int tftp( USE_GETPUT(const int cmd,)
 | 
			
		||||
	char *cp;
 | 
			
		||||
 | 
			
		||||
	unsigned org_port;
 | 
			
		||||
	len_and_sockaddr *const from = alloca(offsetof(len_and_sockaddr, u.sa) + peer_lsa->len);
 | 
			
		||||
	len_and_sockaddr *const from = alloca(LSA_LEN_SIZE + peer_lsa->len);
 | 
			
		||||
 | 
			
		||||
	/* Can't use RESERVE_CONFIG_BUFFER here since the allocation
 | 
			
		||||
	 * size varies meaning BUFFERS_GO_ON_STACK would fail */
 | 
			
		||||
 
 | 
			
		||||
@@ -171,8 +171,8 @@ static void limit(int what, long l)
 | 
			
		||||
{
 | 
			
		||||
	struct rlimit r;
 | 
			
		||||
 | 
			
		||||
	if (getrlimit(what, &r) == -1)
 | 
			
		||||
		bb_perror_msg_and_die("getrlimit");
 | 
			
		||||
	/* Never fails under Linux (except if you pass it bad arguments) */
 | 
			
		||||
	getrlimit(what, &r);
 | 
			
		||||
	if ((l < 0) || (l > r.rlim_max))
 | 
			
		||||
		r.rlim_cur = r.rlim_max;
 | 
			
		||||
	else
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user