add struct socket_pass to avoid global variable

The socket_pass structure is a helper data item to be passed to each
socket separately, so that they do not mix up nor need a variable in too
wide scope.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
move initializations to variable declaration when possible

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
replace strcpy() with xstrdup() or memcpy() when it is easy

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
remove duplicate line

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
add more error checking to socket operations

Signed-off-by: Sami Kerola <kerolasa@iki.fi>