Refactor inet_connect_opts function