aboutsummaryrefslogtreecommitdiff
path: root/toys/net
diff options
context:
space:
mode:
Diffstat (limited to 'toys/net')
-rw-r--r--toys/net/ftpget.c4
-rw-r--r--toys/net/netcat.c19
-rw-r--r--toys/net/ping.c2
-rw-r--r--toys/net/sntp.c2
4 files changed, 9 insertions, 18 deletions
diff --git a/toys/net/ftpget.c b/toys/net/ftpget.c
index ad3c3030..05c53509 100644
--- a/toys/net/ftpget.c
+++ b/toys/net/ftpget.c
@@ -105,7 +105,7 @@ void ftpget_main(void)
if (!remote) remote = toys.optargs[1];
// connect
- TT.fd = xconnect(xgetaddrinfo(*toys.optargs, TT.p, 0, SOCK_STREAM, 0,
+ TT.fd = xconnectany(xgetaddrinfo(*toys.optargs, TT.p, 0, SOCK_STREAM, 0,
AI_ADDRCONFIG));
if (getpeername(TT.fd, (void *)&si6, &sl)) perror_exit("getpeername");
@@ -147,7 +147,7 @@ void ftpget_main(void)
if (!s || port<1 || port>65535) error_exit_raw(toybuf);
si6.sin6_port = SWAP_BE16(port); // same field size/offset for v4 and v6
port = xsocket(si6.sin6_family, SOCK_STREAM, 0);
- if (connect(port, (void *)&si6, sizeof(si6))) perror_exit("connect");
+ xconnect(port, (void *)&si6, sizeof(si6));
// RETR blocks until file data read from data port, so use SIZE to check
// if file exists before creating local copy
diff --git a/toys/net/netcat.c b/toys/net/netcat.c
index 65c41ace..0a235d1e 100644
--- a/toys/net/netcat.c
+++ b/toys/net/netcat.c
@@ -111,16 +111,10 @@ void netcat_main(void)
sockaddr.sun_family = AF_UNIX;
sockfd = xsocket(AF_UNIX, type | SOCK_CLOEXEC, 0);
- if (connect(sockfd, (struct sockaddr*)&sockaddr,
- sizeof(sockaddr)) != 0) {
- perror_exit("could not bind to unix domain socket");
- }
-
+ xconnect(sockfd, (struct sockaddr*)&sockaddr, sizeof(sockaddr));
} else {
- struct addrinfo *addr = xgetaddrinfo(toys.optargs[0], toys.optargs[1],
- family, type, 0, 0);
-
- sockfd = xconnect(addr);
+ sockfd = xconnectany(xgetaddrinfo(toys.optargs[0], toys.optargs[1],
+ family, type, 0, 0));
}
// We have a connection. Disarm timeout.
@@ -145,13 +139,10 @@ void netcat_main(void)
sockaddr.sun_family = AF_UNIX;
sockfd = xsocket(AF_UNIX, type | SOCK_CLOEXEC, 0);
- if (bind(sockfd, (struct sockaddr*)&sockaddr,
- sizeof(struct sockaddr_un)) != 0) {
- perror_exit("unable to bind to UNIX domain socket");
- }
+ xbind(sockfd, (struct sockaddr*)&sockaddr, sizeof(sockaddr));
} else {
sprintf(toybuf, "%ld", TT.p);
- sockfd = xbind(xgetaddrinfo(TT.s, toybuf, family, type, 0, 0));
+ sockfd = xbindany(xgetaddrinfo(TT.s, toybuf, family, type, 0, 0));
}
if (listen(sockfd, 5)) error_exit("listen");
diff --git a/toys/net/ping.c b/toys/net/ping.c
index 81dca99f..9ae7c856 100644
--- a/toys/net/ping.c
+++ b/toys/net/ping.c
@@ -155,7 +155,7 @@ void ping_main(void)
}
xexit();
}
- if (TT.I && bind(TT.sock, sa, sizeof(srcaddr))) perror_exit("bind");
+ if (TT.I) xbind(TT.sock, sa, sizeof(srcaddr));
if (toys.optflags&FLAG_m) {
int mark = TT.m;
diff --git a/toys/net/sntp.c b/toys/net/sntp.c
index b1ecb1be..b1f3685f 100644
--- a/toys/net/sntp.c
+++ b/toys/net/sntp.c
@@ -88,7 +88,7 @@ void sntp_main(void)
// Act as server if necessary
if (FLAG(S)|FLAG(m)) {
- fd = xbind(ai);
+ fd = xbindany(ai);
if (TT.m) {
struct ip_mreq group;