Fix: add missing errno to handle non-blocking connect()

Fixes #16

Reported-by: adrelanos <adrelanos@riseup.net>
Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: fix localhost resolution address

Every DNS resolving call now will query the local host table (usually
/etc/hosts) before trying through Tor. Thus this fixes the issue of
localhost resolution.

If the application tries to connect to localhost, it is refused since it
might be a TCP DNS query to a local DNS server.

Adds a test for localhost resolution with getaddrinfo().

Fixes #14

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: reject IPv6 socket creation

Since Tor does not yet handle IPv6 DNS resolution or traffic, simply
reject any socket creation with AF_INET6 type.

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: set loopback check in host byte order

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: put utils_is_ipv4_local static inline

Also remove the assert() since 0.0.0.0 is valid :)

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: check if address is local after onion lookup

Make the .onion address lookup before we check if the address is local
(in the loopback network range). By default, onion cookies are in that
range (127.42.42.x).

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: change non TCP socket warning to debug

A fat comment is added to explain why this is done. :)

CC: adrelanos <adrelanos@riseup.net>
Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: bad include and duplicate syscall values

First, for the unistd.h include, remove the i386 and s390/x defined to
include asm-generic/unistd.h since this header is x64 specific! If some
syscall's values are missing, they will be nullified and handled
accordingly.

The second issue is that we set different bad values to an unknown
syscall value so we don't end up with duplicates in the torsocks syscall
wrapper switch case.

Fixes #18

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: lookup libc name and pass it to dlopen()

The configure process now looks up the libc file name on a per OS basis
and this value is passed to dlopen() that handles the library lookup in
the system like stated in dlopen(3).

Fixes #12

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: overload _exit and _Exit to cleanup library

Some application directly calls _exit (or exit_group on Linux) like SSH
does when a DNS name resolution fails. Those two functions don't call
the library destructor thus not cleaning the library cleanly.

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: add a library cleanup flag

This flag is used to make sure we don't cleanup torsocks twice which
could lead to out of bound memory access.

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: typo in exit.c comment

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: cleanup configure.ac and add missing headers/functions

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Add hardening compile and linker flags

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Add --version to torsocks.in

Fixes #19

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: quote torsocks script shell arguments

Reported-by: Jérémy Bobbio <lunar@debian.org>
Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Tests: add travis build status image to README

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Add portable is localhost function

This removes the utils_is_ipv4_local() call and move to a generic
portable way of checking if the sockaddr is localhost (both ipv4 and
ipv6 are supported).

Reported-by: Nick Mathewson <nickm@torproject.org>
Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: bad libc detection on system with libcap.so

The binary "yes" is much more generic and has a standard path in BSD,
Linux and OS X. Furthermore, it cannot be linked with libcap.so. But
this patch improves the grep regex to only detect "libc.so".

Fixes #21

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: README typos

Corrected some mistakes in the README file.

Closes #22

Signed-off-by: David Goulet <dgoulet@ev0ke.net>