aboutsummaryrefslogtreecommitdiff
path: root/lib
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 /lib
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 'lib')
-rw-r--r--lib/lib.h6
-rw-r--r--lib/net.c14
2 files changed, 16 insertions, 4 deletions
diff --git a/lib/lib.h b/lib/lib.h
index e354a82a..e744977f 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -348,8 +348,10 @@ int xsocket(int domain, int type, int protocol);
void xsetsockopt(int fd, int level, int opt, void *val, socklen_t len);
struct addrinfo *xgetaddrinfo(char *host, char *port, int family, int socktype,
int protocol, int flags);
-int xconnect(struct addrinfo *ai);
-int xbind(struct addrinfo *ai);
+void xbind(int fd, const struct sockaddr *sa, socklen_t len);
+void xconnect(int fd, const struct sockaddr *sa, socklen_t len);
+int xconnectany(struct addrinfo *ai);
+int xbindany(struct addrinfo *ai);
int xpoll(struct pollfd *fds, int nfds, int timeout);
int pollinate(int in1, int in2, int out1, int out2, int timeout, int shutdown_timeout);
char *ntop(struct sockaddr *sa);
diff --git a/lib/net.c b/lib/net.c
index 2bb720a4..be69c9a3 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -56,17 +56,27 @@ int xconnbind(struct addrinfo *ai_arg, int dobind)
return fd;
}
-int xconnect(struct addrinfo *ai)
+int xconnectany(struct addrinfo *ai)
{
return xconnbind(ai, 0);
}
-int xbind(struct addrinfo *ai)
+int xbindany(struct addrinfo *ai)
{
return xconnbind(ai, 1);
}
+void xbind(int fd, const struct sockaddr *sa, socklen_t len)
+{
+ if (bind(fd, sa, len)) perror_exit("bind");
+}
+
+void xconnect(int fd, const struct sockaddr *sa, socklen_t len)
+{
+ if (connect(fd, sa, len)) perror_exit("connect");
+}
+
int xpoll(struct pollfd *fds, int nfds, int timeout)
{
int i;