Refactor sock_open a bit and make windows happy