Refactor the dns_open_connection code so that duplicate code is removed and ensure...