summaryrefslogtreecommitdiff
path: root/tunnel.c
diff options
context:
space:
mode:
Diffstat (limited to 'tunnel.c')
-rw-r--r--tunnel.c31
1 files changed, 9 insertions, 22 deletions
diff --git a/tunnel.c b/tunnel.c
index 2e0718e..27b71ef 100644
--- a/tunnel.c
+++ b/tunnel.c
@@ -19,10 +19,14 @@ struct socket {
socklen_t salen;
};
+bool tunnel_daemon(int sock);
+
static bool socket_connect(struct socket *sock)
{
- if (connect(sock->fd, sock->sa, sock->salen) < 0)
+ if (connect(sock->fd, sock->sa, sock->salen) < 0) {
+ warn("connect");
return false;
+ }
return true;
}
@@ -101,41 +105,24 @@ bool tunnel_server(void)
defer { socket_free(sock); }
- if (! tunnel_listen(sock))
+ if (!tunnel_listen(sock))
return false;
- if (! tunnel_daemon(sock->fd))
+ if (!tunnel_daemon(sock->fd))
return false;
return true;
}
-bool tunnel_connect(struct socket *sock)
-{
- if (! socket_connect(sock)) {
- if (errno == ENOENT) {
- if (! tunnel_server())
- return false;
- }
-
- if (errno != ENOENT || ! socket_connect(sock)) {
- warn("connect");
- return false;
- }
- }
-
- return true;
-}
-
int tunnel_client(void)
{
struct socket *sock = tunnel_socket();
- if (! sock)
+ if (!sock)
return -1;
defer { socket_free(sock); }
- if (! tunnel_connect(sock))
+ if (!socket_connect(sock))
return -1;
return socket_detach_fd(sock);