Added code to handle situations where gethostbyname() is not properly returning the IP - fixes #269