From 1457915afcb8fb0697f441dce1697b278d25f4a5 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Thu, 26 Oct 2006 01:09:46 +0000 Subject: xconnect is non-conforming to "xfunc like libc" rule. Fixing --- include/libbb.h | 4 +++- libbb/xconnect.c | 18 ++++++++++++------ networking/ftpgetput.c | 4 ++-- networking/telnet.c | 2 +- networking/wget.c | 2 +- util-linux/rdate.c | 2 +- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index 7b8327f..a2267f9 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -452,7 +452,9 @@ extern struct hostent *xgethostbyname(const char *name); extern struct hostent *xgethostbyname2(const char *name, int af); extern int create_icmp_socket(void); extern int create_icmp6_socket(void); -extern int xconnect(struct sockaddr_in *s_addr); +extern void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen); +extern int xconnect_tcp_v4(struct sockaddr_in *s_addr); + extern unsigned short bb_lookup_port(const char *port, const char *protocol, unsigned short default_port); extern void bb_lookup_host(struct sockaddr_in *s_in, const char *host); diff --git a/libbb/xconnect.c b/libbb/xconnect.c index f88136a..7cf9d00 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c @@ -49,14 +49,20 @@ 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(struct sockaddr_in *s_addr) +void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) { - int s = xsocket(AF_INET, SOCK_STREAM, 0); - if (connect(s, (struct sockaddr *)s_addr, sizeof(struct sockaddr_in)) < 0) - { + if (connect(s, s_addr, addrlen) < 0) { if (ENABLE_FEATURE_CLEAN_UP) close(s); - bb_perror_msg_and_die("unable to connect to remote host (%s)", - inet_ntoa(s_addr->sin_addr)); + if (s_addr->sa_family == AF_INET) + bb_perror_msg_and_die("unable to connect to remote host (%s)", + inet_ntoa(((struct sockaddr_in *)s_addr)->sin_addr)); + bb_perror_msg_and_die("unable to connect to remote host"); } +} + +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; } diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c index aafeaf6..6608e68 100644 --- a/networking/ftpgetput.c +++ b/networking/ftpgetput.c @@ -67,7 +67,7 @@ static int xconnect_ftpdata(ftp_host_info_t *server, const char *buf) port_num += xatoul_range(buf_ptr + 1, 0, 255) * 256; server->s_in->sin_port = htons(port_num); - return xconnect(server->s_in); + return xconnect_tcp_v4(server->s_in); } static FILE *ftp_login(ftp_host_info_t *server) @@ -76,7 +76,7 @@ static FILE *ftp_login(ftp_host_info_t *server) char buf[512]; /* Connect to the command socket */ - control_stream = fdopen(xconnect(server->s_in), "r+"); + control_stream = fdopen(xconnect_tcp_v4(server->s_in), "r+"); if (control_stream == NULL) { bb_perror_msg_and_die("cannot open control stream"); } diff --git a/networking/telnet.c b/networking/telnet.c index cd4c33a..5b8c885 100644 --- a/networking/telnet.c +++ b/networking/telnet.c @@ -639,7 +639,7 @@ int telnet_main(int argc, char** argv) s_in.sin_port = bb_lookup_port((argc == 3) ? argv[2] : "telnet", "tcp", 23); #endif - G.netfd = xconnect(&s_in); + G.netfd = xconnect_tcp_v4(&s_in); setsockopt(G.netfd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof one); diff --git a/networking/wget.c b/networking/wget.c index 090b58d..425abc1 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -585,7 +585,7 @@ static FILE *open_socket(struct sockaddr_in *s_in) { FILE *fp; - fp = fdopen(xconnect(s_in), "r+"); + fp = fdopen(xconnect_tcp_v4(s_in), "r+"); if (fp == NULL) bb_perror_msg_and_die("fdopen"); diff --git a/util-linux/rdate.c b/util-linux/rdate.c index 6ad0554..645b0b9 100644 --- a/util-linux/rdate.c +++ b/util-linux/rdate.c @@ -42,7 +42,7 @@ static time_t askremotedate(const char *host) alarm(10); signal(SIGALRM, socket_timeout); - fd = xconnect(&s_in); + fd = xconnect_tcp_v4(&s_in); if (safe_read(fd, (void *)&nett, 4) != 4) /* read time from server */ bb_error_msg_and_die("%s did not send the complete time", host); -- cgit v1.1