Fix: socket() type check SOCK_STREAM

Even though connect() makes a check, deny socket creation that are
INET/INET6 but NOT of type SOCK_STREAM. This fix makes our wrapper
handle socket type flags that can be passed to the kernel such as
SOCK_NONBLOCK and SOCK_CLOEXEC.

Furthermore, the type check was *not* right since having a type set to
SOCK_DGRAM also matches SOCK_STREAM when using the & operator.

A unit test is added for the IS_SOCK_STREAM(type) macro that test if a
socket type is a SOCK_STREAM.

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Fix: socketpair() denied for INET[6] socket

The SOCK_STREAM check was wrong since you could pass SOCK_DGRAM and
match the check so the socketpair() now denies INET/INET6 socket.

Note that socketpair() only supports AF_UNIX and AF_LOCAL on most *nix
system.

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Tests: add socket() test

Add unit test for socket() and socketpair().

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Tests: add connect() test

Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Refactor the connect() code flow for clarity

This adds a "validate_socket()" function that is called first to make
sure all criteria of a valid socket that torsocks can handle are met.
This has been done to have a single callsite that can do this validation
thus improving the clarity and flow of the code.

It now also returns EPERM for things that we deny instead of EINVAL or
EBADF. Because of that, the connect test has been changed to handle this
new errno value.

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