1 /* $NetBSD: gai_strerror.c,v 1.5 2014/12/10 04:37:59 christos Exp $ */ 2 3 /* 4 * Copyright (C) 2009, 2014 Internet Systems Consortium, Inc. ("ISC") 5 * 6 * Permission to use, copy, modify, and/or distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 /* Id: gai_strerror.c,v 1.5 2009/09/02 23:48:02 tbox Exp */ 20 21 /*! \file gai_strerror.c 22 * gai_strerror() returns an error message corresponding to an 23 * error code returned by getaddrinfo() and getnameinfo(). The following error 24 * codes and their meaning are defined in 25 * \link netdb.h include/irs/netdb.h.\endlink 26 * This implementation is almost an exact copy of lwres/gai_sterror.c except 27 * that it catches up the latest API standard, RFC3493. 28 * 29 * \li #EAI_ADDRFAMILY address family for hostname not supported 30 * \li #EAI_AGAIN temporary failure in name resolution 31 * \li #EAI_BADFLAGS invalid value for ai_flags 32 * \li #EAI_FAIL non-recoverable failure in name resolution 33 * \li #EAI_FAMILY ai_family not supported 34 * \li #EAI_MEMORY memory allocation failure 35 * \li #EAI_NODATA no address associated with hostname (obsoleted in RFC3493) 36 * \li #EAI_NONAME hostname nor servname provided, or not known 37 * \li #EAI_SERVICE servname not supported for ai_socktype 38 * \li #EAI_SOCKTYPE ai_socktype not supported 39 * \li #EAI_SYSTEM system error returned in errno 40 * \li #EAI_BADHINTS Invalid value for hints (non-standard) 41 * \li #EAI_PROTOCOL Resolved protocol is unknown (non-standard) 42 * \li #EAI_OVERFLOW Argument buffer overflow 43 * \li #EAI_INSECUREDATA Insecure Data (experimental) 44 * 45 * The message invalid error code is returned if ecode is out of range. 46 * 47 * ai_flags, ai_family and ai_socktype are elements of the struct 48 * addrinfo used by lwres_getaddrinfo(). 49 * 50 * \section gai_strerror_see See Also 51 * 52 * strerror(), getaddrinfo(), getnameinfo(), RFC3493. 53 */ 54 #include <config.h> 55 56 #include <isc/net.h> 57 58 #include <irs/netdb.h> 59 60 /*% Text of error messages. */ 61 static const char *gai_messages[] = { 62 "no error", 63 "address family for hostname not supported", 64 "temporary failure in name resolution", 65 "invalid value for ai_flags", 66 "non-recoverable failure in name resolution", 67 "ai_family not supported", 68 "memory allocation failure", 69 "no address associated with hostname", 70 "hostname nor servname provided, or not known", 71 "servname not supported for ai_socktype", 72 "ai_socktype not supported", 73 "system error returned in errno", 74 "bad hints", 75 "bad protocol", 76 "argument buffer overflow", 77 "insecure data provided" 78 }; 79 80 /*% 81 * Returns an error message corresponding to an error code returned by 82 * getaddrinfo() and getnameinfo() 83 */ 84 IRS_GAISTRERROR_RETURN_T 85 gai_strerror(int ecode) { 86 union { 87 const char *const_ptr; 88 char *deconst_ptr; 89 } ptr; 90 91 if ((ecode < 0) || 92 (ecode >= (int)(sizeof(gai_messages)/sizeof(*gai_messages)))) 93 ptr.const_ptr = "invalid error code"; 94 else 95 ptr.const_ptr = gai_messages[ecode]; 96 return (ptr.deconst_ptr); 97 } 98