svn commit: trunk/busybox: include libbb networking

vda at busybox.net vda at busybox.net
Mon Jan 22 09:36:42 UTC 2007


Author: vda
Date: 2007-01-22 01:36:41 -0800 (Mon, 22 Jan 2007)
New Revision: 17456

Log:
comment out unused old networking API parts
sockaddr2dotted: return IPV6 addrs in [addr]:port form (was addr:port)


Modified:
   trunk/busybox/include/libbb.h
   trunk/busybox/libbb/xconnect.c
   trunk/busybox/networking/ftpgetput.c
   trunk/busybox/networking/wget.c


Changeset:
Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2007-01-22 09:20:55 UTC (rev 17455)
+++ trunk/busybox/include/libbb.h	2007-01-22 09:36:41 UTC (rev 17456)
@@ -282,13 +282,10 @@
 extern void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
 extern void xlisten(int s, int backlog);
 extern void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen);
-extern int xconnect_tcp_v4(struct sockaddr_in *s_addr);
-extern struct hostent *xgethostbyname(const char *name);
-extern struct hostent *xgethostbyname2(const char *name, int af);
 extern int setsockopt_reuseaddr(int fd);
 extern int setsockopt_broadcast(int fd);
-
-/* "new" (ipv4+ipv6) API */
+/* NB: returns port in host byte order */
+unsigned bb_lookup_port(const char *port, const char *protocol, unsigned default_port);
 typedef struct len_and_sockaddr {
 	int len;
 	union {
@@ -320,13 +317,20 @@
  * UNIX socket address being returned, IPX sockaddr etc... */
 extern len_and_sockaddr* host2sockaddr(const char *host, int port);
 /* Assign sin[6]_port member if the socket is of corresponding type,
- * otherwise noop. Useful for ftp.
+ * otherwise no-op. Useful for ftp.
  * NB: does NOT do htons() internally, just direct assignment. */
 extern void set_nport(len_and_sockaddr *lsa, unsigned port);
-/* Retrieve sin[6]_port or return -1 for non-inet lsa's */
+/* Retrieve sin[6]_port or return -1 for non-INET[6] lsa's */
 extern int get_nport(len_and_sockaddr *lsa);
 extern char* xmalloc_sockaddr2host(const struct sockaddr *sa, socklen_t salen);
 extern char* xmalloc_sockaddr2dotted(const struct sockaddr *sa, socklen_t salen);
+// "old" (ipv4 only) API
+//void bb_lookup_host(struct sockaddr_in *s_in, const char *host);
+//extern int xconnect_tcp_v4(struct sockaddr_in *s_addr);
+// users: traceroute.c hostname.c ifconfig.c ping.c
+extern struct hostent *xgethostbyname(const char *name);
+// ping6 is the only user - convert to new API
+extern struct hostent *xgethostbyname2(const char *name, int af);
 
 
 extern char *xstrdup(const char *s);
@@ -536,10 +540,6 @@
 int inflate(int in, int out);
 
 
-/* NB: returns port in host byte order */
-unsigned bb_lookup_port(const char *port, const char *protocol, unsigned default_port);
-void bb_lookup_host(struct sockaddr_in *s_in, const char *host);
-
 int bb_make_directory(char *path, long mode, int flags);
 
 int get_signum(const char *name);

Modified: trunk/busybox/libbb/xconnect.c
===================================================================
--- trunk/busybox/libbb/xconnect.c	2007-01-22 09:20:55 UTC (rev 17455)
+++ trunk/busybox/libbb/xconnect.c	2007-01-22 09:36:41 UTC (rev 17456)
@@ -60,7 +60,7 @@
 
 /* "Old" networking API - only IPv4 */
 
-
+/*
 void bb_lookup_host(struct sockaddr_in *s_in, const char *host)
 {
 	struct hostent *he;
@@ -71,14 +71,15 @@
 	memcpy(&(s_in->sin_addr), he->h_addr_list[0], he->h_length);
 }
 
+
 int xconnect_tcp_v4(struct sockaddr_in *s_addr)
 {
 	int s = xsocket(AF_INET, SOCK_STREAM, 0);
 	xconnect(s, (struct sockaddr*) s_addr, sizeof(*s_addr));
 	return s;
 }
+*/
 
-
 /* "New" networking API */
 
 
@@ -92,8 +93,8 @@
 	if (lsa->sa.sa_family == AF_INET) {
 		return lsa->sin.sin_port;
 	}
+	/* What? UNIX socket? IPX?? :) */
 	return -1;
-	/* What? UNIX socket? IPX?? :) */
 }
 
 void set_nport(len_and_sockaddr *lsa, unsigned port)
@@ -111,7 +112,7 @@
 	/* What? UNIX socket? IPX?? :) */
 }
 
-/* peer: "1.2.3.4[:port]", "www.google.com[:port]"
+/* host: "1.2.3.4[:port]", "www.google.com[:port]"
  * port: if neither of above specifies port #
  */
 static len_and_sockaddr* str2sockaddr(const char *host, int port, int ai_flags)
@@ -252,11 +253,18 @@
 	int rc = getnameinfo(sa, salen,
 			host, sizeof(host),
 			serv, sizeof(serv),
-			flags | NI_NUMERICSERV /* do not resolve port# */
+			/* do not resolve port# into service _name_ */
+			flags | NI_NUMERICSERV
 	);
-	if (rc) return NULL;
-// We probably need to use [%s]:%s for IPv6...
-	return xasprintf("%s:%s", host, serv);
+	if (rc)
+		return NULL;
+#if ENABLE_FEATURE_IPV6
+	if (sa->sa_family == AF_INET6)
+		return xasprintf("[%s]:%s", host, serv);
+#endif
+	/* For now we don't support anything else, so it has to be INET */
+	/*if (sa->sa_family == AF_INET)*/
+		return xasprintf("%s:%s", host, serv);
 }
 
 char* xmalloc_sockaddr2host(const struct sockaddr *sa, socklen_t salen)

Modified: trunk/busybox/networking/ftpgetput.c
===================================================================
--- trunk/busybox/networking/ftpgetput.c	2007-01-22 09:20:55 UTC (rev 17455)
+++ trunk/busybox/networking/ftpgetput.c	2007-01-22 09:36:41 UTC (rev 17456)
@@ -347,7 +347,7 @@
 	 * and we want to connect to only one IP... */
 	server->lsa = host2sockaddr(argv[0], bb_lookup_port(port, "tcp", 21));
 	if (verbose_flag) {
-		printf("Connecting to %s [%s]\n", argv[0],
+		printf("Connecting to %s (%s)\n", argv[0],
 			xmalloc_sockaddr2dotted(&server->lsa->sa, server->lsa->len));
 	}
 

Modified: trunk/busybox/networking/wget.c
===================================================================
--- trunk/busybox/networking/wget.c	2007-01-22 09:20:55 UTC (rev 17455)
+++ trunk/busybox/networking/wget.c	2007-01-22 09:36:41 UTC (rev 17456)
@@ -235,9 +235,9 @@
 	 * and we want to connect to only one IP... */
 	lsa = host2sockaddr(server.host, server.port);
 	if (!(opt & WGET_OPT_QUIET)) {
-		fprintf(stderr, "Connecting to %s [%s]\n", server.host,
+		fprintf(stderr, "Connecting to %s (%s)\n", server.host,
 				xmalloc_sockaddr2dotted(&lsa->sa, lsa->len));
-		/* We leak xmalloc_sockaddr2dotted result */
+		/* We leak result of xmalloc_sockaddr2dotted */
 	}
 
 	if (use_proxy || !target.is_ftp) {




More information about the busybox-cvs mailing list