X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=lib%2Ftlsproxyhelper.c;h=1281dd86590bb6f09306cb15acbba3e516ebfde9;hb=ea87309935747eebc7cf8f5b46ed37975d1ebb09;hp=a37e0224dc9eac6332a1a0a11b3dd5a3f61531c1;hpb=3cb7193721894ec9c064bc22e09078e8c5cd3dd8;p=tlsproxy%2Ftlsproxy.git diff --git a/lib/tlsproxyhelper.c b/lib/tlsproxyhelper.c index a37e022..1281dd8 100644 --- a/lib/tlsproxyhelper.c +++ b/lib/tlsproxyhelper.c @@ -1,3 +1,16 @@ +/* + * Simple LD_PRELOAD wrapper for connect() which uses tlsproxy as proxy for + * programs which don't support setting a TLS proxy. + * + * The following environment variables can be used: + * + * - TLSPROXYHELPER_PORT: port where tlsproxy is running (default 9000) + * + * If an error occurs -1 is returned and errno is set (either EAFNOSUPPORT if + * another protocol besides IPv4/IPv6 was used, or EINVAL if another error + * occurred). The error is written to stderr with "tlsproxyhelper:" as prefix. + */ + /* * Copyright (C) 2011-2013 Simon Ruderich * @@ -172,7 +185,7 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { return -1; } if (optval != 0) { - fprintf(stderr, LOG_PREFIX "connect() failed (SO_ERROR)"); + fprintf(stderr, LOG_PREFIX "connect() failed (SO_ERROR)\n"); errno = EINVAL; return -1; } @@ -241,9 +254,9 @@ static int poll_for(int sockfd, int mode) { fds[0].fd = sockfd; fds[0].events = POLLERR | POLLHUP; /* Either poll for read or write possibility. */ - if (1 == mode) { + if (mode == 1) { fds[0].events |= POLLIN | POLLPRI; - } else if (0 == mode) { + } else if (mode == 0) { fds[0].events |= POLLOUT; } else { abort(); @@ -259,8 +272,12 @@ static int poll_for(int sockfd, int mode) { return -1; } - if (fds[0].revents & POLLERR || fds[0].revents & POLLHUP) { - fprintf(stderr, LOG_PREFIX "poll(): POLLERR | POLLHUP\n"); + if (fds[0].revents & POLLERR) { + fprintf(stderr, LOG_PREFIX "poll(): POLLERR\n"); + return -1; + } + if (fds[0].revents & POLLHUP) { + fprintf(stderr, LOG_PREFIX "poll(): POLLHUP\n"); return -1; }