[BusyBox-cvs] busybox/networking ftpgetput.c, 1.13, 1.14 inetd.c, 1.11, 1.12 nc.c, 1.21, 1.22 telnet.c, 1.40, 1.41 tftp.c, 1.20, 1.21 wget.c, 1.64, 1.65

Glenn McGrath bug1 at busybox.net
Sat Jan 17 05:03:34 UTC 2004


Update of /var/cvs/busybox/networking
In directory nail:/tmp/cvs-serv356/networking

Modified Files:
	ftpgetput.c inetd.c nc.c telnet.c tftp.c wget.c 
Log Message:
Modify bb_lookup_port to allow the protocol to be specified, allowing 
/etc/services support for inetd, netcat and tftp.


Index: telnet.c
===================================================================
RCS file: /var/cvs/busybox/networking/telnet.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- telnet.c	20 Dec 2003 01:47:18 -0000	1.40
+++ telnet.c	17 Jan 2004 05:03:31 -0000	1.41
@@ -599,7 +599,7 @@
 		bb_show_usage();
 	
 	bb_lookup_host(&s_in, argv[1]);
-	s_in.sin_port = bb_lookup_port((argc == 3) ? argv[2] : "telnet", 23);
+	s_in.sin_port = bb_lookup_port((argc == 3) ? argv[2] : "telnet", "tcp", 23);
 	
 	G.netfd = xconnect(&s_in);
 

Index: wget.c
===================================================================
RCS file: /var/cvs/busybox/networking/wget.c,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- wget.c	27 Dec 2003 00:21:47 -0000	1.64
+++ wget.c	17 Jan 2004 05:03:31 -0000	1.65
@@ -537,11 +537,11 @@
 	char *cp, *sp, *up, *pp;
 
 	if (strncmp(url, "http://", 7) == 0) {
-		h->port = bb_lookup_port("http", 80);
+		h->port = bb_lookup_port("http", "tcp", 80);
 		h->host = url + 7;
 		h->is_ftp = 0;
 	} else if (strncmp(url, "ftp://", 6) == 0) {
-		h->port = bb_lookup_port("ftp", 21);
+		h->port = bb_lookup_port("ftp", "tfp", 21);
 		h->host = url + 6;
 		h->is_ftp = 1;
 	} else

Index: ftpgetput.c
===================================================================
RCS file: /var/cvs/busybox/networking/ftpgetput.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- ftpgetput.c	20 Dec 2003 05:43:34 -0000	1.13
+++ ftpgetput.c	17 Jan 2004 05:03:31 -0000	1.14
@@ -349,7 +349,7 @@
 	 * and we want to connect to only one IP... */
 	server->s_in = &s_in;
 	bb_lookup_host(&s_in, argv[optind]);
-	s_in.sin_port = bb_lookup_port(port, 21);
+	s_in.sin_port = bb_lookup_port(port, "tcp", 21);
 	if (verbose_flag) {
 		printf("Connecting to %s[%s]:%d\n",
 				argv[optind], inet_ntoa(s_in.sin_addr), ntohs(s_in.sin_port));

Index: inetd.c
===================================================================
RCS file: /var/cvs/busybox/networking/inetd.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- inetd.c	17 Jan 2004 03:20:46 -0000	1.11
+++ inetd.c	17 Jan 2004 05:03:31 -0000	1.12
@@ -610,19 +610,13 @@
 			sep->se_ctrladdr_in.sin_family = AF_INET;
 			sep->se_ctrladdr_size = sizeof sep->se_ctrladdr_in;
 			{
-				u_short port = htons(atoi(sep->se_service));
+				u_short port = bb_lookup_port(sep->se_service, sep->se_proto, 0);
 
-				if (!port) {
-					struct servent *sp;
-					sp = getservbyname(sep->se_service,
-								sep->se_proto);
-					if (sp == 0) {
-						syslog(LOG_ERR,
-						    "%s/%s: unknown service",
-						    sep->se_service, sep->se_proto);
-						continue;
-					}
-					port = sp->s_port;
+				if (port == 0) {
+					syslog(LOG_ERR,
+					    "%s/%s: unknown service",
+					    sep->se_service, sep->se_proto);
+					continue;
 				}
 				if (port != sep->se_ctrladdr_in.sin_port) {
 					sep->se_ctrladdr_in.sin_port = port;

Index: nc.c
===================================================================
RCS file: /var/cvs/busybox/networking/nc.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- nc.c	19 Mar 2003 09:12:38 -0000	1.21
+++ nc.c	17 Jan 2004 05:03:31 -0000	1.22
@@ -61,7 +61,7 @@
 				do_listen++;
 				break;
 			case 'p':
-				lport = atoi(optarg);
+				lport = bb_lookup_port(optarg, "tcp", 0);
 				break;
 			case 'i':
 				delay = atoi(optarg);
@@ -96,7 +96,7 @@
 
 	if (lport != 0) {
 		memset(&address.sin_addr, 0, sizeof(address.sin_addr));
-		address.sin_port = htons(lport);
+		address.sin_port = lport;
 
 		if (bind(sfd, (struct sockaddr *) &address, sizeof(address)) < 0)
 			bb_perror_msg_and_die("bind");
@@ -117,7 +117,7 @@
 		hostinfo = xgethostbyname(argv[optind]);
 
 		address.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list;
-		address.sin_port = htons(atoi(argv[optind+1]));
+		address.sin_port = bb_lookup_port(argv[optind+1], "tcp", 0);
 
 		if (connect(sfd, (struct sockaddr *) &address, sizeof(address)) < 0)
 			bb_perror_msg_and_die("connect");

Index: tftp.c
===================================================================
RCS file: /var/cvs/busybox/networking/tftp.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- tftp.c	30 Jul 2003 07:16:39 -0000	1.20
+++ tftp.c	17 Jan 2004 05:03:31 -0000	1.21
@@ -138,7 +138,7 @@
 #endif
 
 static inline int tftp(const int cmd, const struct hostent *host,
-	const char *remotefile, int localfd, const int port, int tftp_bufsize)
+	const char *remotefile, int localfd, const unsigned short port, int tftp_bufsize)
 {
 	const int cmd_get = cmd & tftp_cmd_get;
 	const int cmd_put = cmd & tftp_cmd_put;
@@ -179,7 +179,7 @@
 	bind(socketfd, (struct sockaddr *)&sa, len);
 
 	sa.sin_family = host->h_addrtype;
-	sa.sin_port = htons(port);
+	sa.sin_port = port;
 	memcpy(&sa.sin_addr, (struct in_addr *) host->h_addr,
 		   sizeof(sa.sin_addr));
 
@@ -332,7 +332,7 @@
 
 				timeout = 0;
 
-				if (sa.sin_port == htons(port)) {
+				if (sa.sin_port == port) {
 					sa.sin_port = from.sin_port;
 				}
 				if (sa.sin_port == from.sin_port) {
@@ -487,7 +487,7 @@
 	struct hostent *host = NULL;
 	char *localfile = NULL;
 	char *remotefile = NULL;
-	int port = 69;
+	int port;
 	int cmd = 0;
 	int fd = -1;
 	int flags = 0;
@@ -564,10 +564,7 @@
 	}
 
 	host = xgethostbyname(argv[optind]);
-
-	if (optind + 2 == argc) {
-		port = atoi(argv[optind + 1]);
-	}
+	port = bb_lookup_port(argv[optind + 1], "udp", 69);
 
 #ifdef CONFIG_FEATURE_TFTP_DEBUG
 	printf("using server \"%s\", remotefile \"%s\", "




More information about the busybox-cvs mailing list