Added error handling for gethostbyname()