aboutsummaryrefslogtreecommitdiff
path: root/toys/net/netcat.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-07-08 16:02:56 -0700
committerRob Landley <rob@landley.net>2019-07-11 22:02:12 -0500
commita57721d14642291696be4ffd5d8bb0915fbe861b (patch)
tree11a18894601df31ce1eb9c46c5d1faaa59e2f9e8 /toys/net/netcat.c
parent34f095fcbf0829719f9a130a359ebf2a3e223ca0 (diff)
downloadtoybox-a57721d14642291696be4ffd5d8bb0915fbe861b.tar.gz
bind/connect cleanup.
Rename the existing xbind/xconnect to xbindany/xconnectany, to make room for new xbind/xconnect that are more like 'x' versions of the regular bind and connect. Move explicit bind/connect callers over to xbind/xconnect. Of the affected commands, only netcat is actually used by Android. It was the most recent patch to netcat that made the lack of a more traditional xbind/xconnect apparent.
Diffstat (limited to 'toys/net/netcat.c')
-rw-r--r--toys/net/netcat.c19
1 files changed, 5 insertions, 14 deletions
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");