Code deduplication

* Deduplicate the code that prepares the socket address (from an
nc_host_t and an nc_port_t structure) to perform a bind(2) or connect(2)
call. This code appeared three times in network.c (for TCP connections)
and supports IPv4 and IPv6.
* Also use the same new functions in netcore.c for UDP bind/connect. The
existing code was written only for IPv4, so that this change should
(partially) implement IPv6 support for UDP.