1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "nacl_io/ossocket.h" 6 7 #ifdef PROVIDES_SOCKET_API 8 9 #include <sstream> 10 #include <string> 11 #include "sdk_util/macros.h" 12 13 EXTERN_C_BEGIN 14 15 const char* hstrerror(int err) { 16 // These error message texts are taken straight from the man page 17 const char* host_not_found_msg = 18 "The specified host is unknown."; 19 const char* no_address_msg = 20 "The requested name is valid but does not have an IP address."; 21 const char* no_recovery_msg = 22 "A nonrecoverable name server error occurred."; 23 const char* try_again_msg = 24 "A temporary error occurred on an authoritative name server. " 25 "Try again later."; 26 const char* internal_msg = 27 "Internal error in gethostbyname."; 28 const char* unknown_msg_base = 29 "Unknown error in gethostbyname: "; 30 31 switch (err) { 32 case HOST_NOT_FOUND: 33 return host_not_found_msg; 34 case NO_ADDRESS: 35 return no_address_msg; 36 case NO_RECOVERY: 37 return no_recovery_msg; 38 case TRY_AGAIN: 39 return try_again_msg; 40 case NETDB_INTERNAL: 41 return internal_msg; 42 default: 43 std::stringstream msg; 44 msg << unknown_msg_base << err << "."; 45 46 static std::string unknown_msg; 47 unknown_msg.assign(msg.str()); 48 return unknown_msg.c_str(); 49 } 50 } 51 52 EXTERN_C_END 53 54 #endif // PROVIDES_SOCKET_API 55