tcp: factor common bind/connect code