From 85629f08bcea5d4a44b6d511422fd608bbc3fc45 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Mon, 22 Jan 2007 09:36:41 +0000 Subject: [PATCH] comment out unused old networking API parts sockaddr2dotted: return IPV6 addrs in [addr]:port form (was addr:port) --- include/libbb.h | 22 +++++++++++----------- libbb/xconnect.c | 24 ++++++++++++++++-------- networking/ftpgetput.c | 2 +- networking/wget.c | 4 ++-- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index ede44526b..c1c9486c4 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -282,13 +282,10 @@ extern int xsocket(int domain, int type, int protocol); 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 @@ extern int xconnect_stream(const len_and_sockaddr *lsa); * 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 @@ USE_DESKTOP(long long) int uncompress(int fd_in, int fd_out); 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); diff --git a/libbb/xconnect.c b/libbb/xconnect.c index 377e0657e..62cab95a1 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c @@ -60,7 +60,7 @@ unsigned bb_lookup_port(const char *port, const char *protocol, unsigned default /* "Old" networking API - only IPv4 */ - +/* void bb_lookup_host(struct sockaddr_in *s_in, const char *host) { struct hostent *he; @@ -71,13 +71,14 @@ void bb_lookup_host(struct sockaddr_in *s_in, const char *host) 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 @@ int get_nport(len_and_sockaddr *lsa) if (lsa->sa.sa_family == AF_INET) { return lsa->sin.sin_port; } - return -1; /* What? UNIX socket? IPX?? :) */ + return -1; } void set_nport(len_and_sockaddr *lsa, unsigned port) @@ -111,7 +112,7 @@ void set_nport(len_and_sockaddr *lsa, unsigned port) /* 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 @@ static char* sockaddr2str(const struct sockaddr *sa, socklen_t salen, int flags) 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) diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c index 0e2d4173f..ccc0b5e46 100644 --- a/networking/ftpgetput.c +++ b/networking/ftpgetput.c @@ -347,7 +347,7 @@ int ftpgetput_main(int argc, char **argv) * 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)); } diff --git a/networking/wget.c b/networking/wget.c index 056d2c7fc..0e0268770 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -235,9 +235,9 @@ int wget_main(int argc, char **argv) * 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) { -- 2.25.1