aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-08-05 20:32:49 -0500
committerRob Landley <rob@landley.net>2015-08-05 20:32:49 -0500
commit35dafc7b17ce23da62dcce2195bed9b370680e65 (patch)
tree944ab9be2d5e1a614d9682556e42eaf562011edd /lib
parentea75e752f930df7b740a773294b997f46927c716 (diff)
downloadtoybox-35dafc7b17ce23da62dcce2195bed9b370680e65.tar.gz
Tweak xconnect: socket can be a string (ala "ftp") from /etc/services.
Still need a rethink on how to handle socket/bind/connect sequence.
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.h2
-rw-r--r--lib/net.c8
2 files changed, 4 insertions, 6 deletions
diff --git a/lib/lib.h b/lib/lib.h
index 8e6a8e2a..1b3f9575 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -205,7 +205,7 @@ void tty_sigreset(int i);
// net.c
int xsocket(int domain, int type, int protocol);
void xsetsockopt(int fd, int level, int opt, void *val, socklen_t len);
-int xconnect(char *host, int port, int family, int socktype, int protocol,
+int xconnect(char *host, char *port, int family, int socktype, int protocol,
int flags);
// password.c
diff --git a/lib/net.c b/lib/net.c
index fc97a262..7be66b67 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -13,10 +13,9 @@ void xsetsockopt(int fd, int level, int opt, void *val, socklen_t len)
if (-1 == setsockopt(fd, level, opt, val, len)) perror_exit("setsockopt");
}
-int xconnect(char *host, int port, int family, int socktype, int protocol,
+int xconnect(char *host, char *port, int family, int socktype, int protocol,
int flags)
{
- char buf[32];
struct addrinfo info, *ai;
int fd;
@@ -26,11 +25,10 @@ int xconnect(char *host, int port, int family, int socktype, int protocol,
info.ai_protocol = protocol;
info.ai_flags = flags;
- sprintf(buf, "%d", port);
- fd = getaddrinfo(host, port ? buf : 0, &info, &ai);
+ fd = getaddrinfo(host, port, &info, &ai);
if (fd || !ai)
- error_exit("Connect '%s:%d': %s", host, port,
+ error_exit("Connect '%s%s%s': %s", host, port ? ":" : "", port ? port : "",
fd ? gai_strerror(fd) : "not found");
fd = xsocket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);