while seeking the reason why tsocks-1.8beta5 doesn't
NetBSD's stock ftp client (in passive mode), I found 1
problem about connect() implementation and 2 serious
bugs in poll()
1. poll() bug #1
tsocks assumes that flags in struct
compatible with flags in struct pollfd::events,
line 551 and line 675 directly assign these struct
members each other.
but the assumption is wrong as follows:
connreq::selectevents pollfd::events (on Solaris,
READ 0x01 POLLIN 0x1
WRITE 0x02 POLLOUT 0x4
EXCEPT 0x04 POLLPRI 0x2
also, POLLRDNORM should be treated as READ,
POLLWRNORM and POLLWRBAND should be treated as WRITE,
and POLLRDBAND should be treated as EXCEPT, as well.
the patch to tsocks.h in the attached file fixes this
2. poll() bug #2
if connection is established and the client polled
struct pollfd:revents doesn't correctly updated.
the patch to poll() implementation in the attached
file fixes this problem.
3. connect() portability problem
on NetBSD and some other operating systems, if once
called with non-blocking mode, subsequent connect(2)
call to same
descriptor doesn't return 0, rather it returns
(Operation now in progress) or EISCONN (Socket is
The connect() implementation in tsocks already deals
EINPROGRESS case, but doesn't deal with the EISCONN case.
the patch to connect_server() function in the
attached file fixes
perhaps it's better to use "#if defined(__NetBSD__)"
in this case,
but I guess this patch isn't so harmful on other OS.