prioritize getaddrinfo() results matching bindaddr's address family
commit6ecc398072abf792088af2c90fc7252c05d7c94a
authorparke <parke.nexus@gmail.com>
Sun, 12 Dec 2021 21:50:26 +0000 (12 13:50 -0800)
committerrofl0r <rofl0r@users.noreply.github.com>
Mon, 13 Dec 2021 12:43:14 +0000 (13 12:43 +0000)
tree89660a682e23654984f2ee2afa434df51988b98c
parent9d463f4297794f3e8a29488af087fe93ddd1a60c
prioritize getaddrinfo() results matching bindaddr's address family

If `-b bindaddr` is used, then created sockets must be of the same address
family as `bindaddr`, otherwise, calls to `bind()` will fail.

This patch harmonizes the address family across the calls to `socket()`,
`bind()`, and `connect()`.

Prior to this patch, `microsocks` would use the first `addrinfo` record
returned by `getaddrinfo()`.
On systems with both IPv4 and IPv6, sometimes the address family of the
first record would be a mismatch with `bindaddr`, resulting in an error.

Fixes #30.  (And possibly #40)
sockssrv.c