comment out unused old networking API parts

sockaddr2dotted: return IPV6 addrs in [addr]:port form (was addr:port)
This commit is contained in:
Denis Vlasenko 2007-01-22 09:36:41 +00:00
parent 3c99a59915
commit 85629f08bc
4 changed files with 30 additions and 22 deletions

View File

@ -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);

View File

@ -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)

View File

@ -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));
}

View File

@ -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) {