1224090Sdougb/* 2224090Sdougb * Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC") 3224090Sdougb * 4224090Sdougb * Permission to use, copy, modify, and/or distribute this software for any 5224090Sdougb * purpose with or without fee is hereby granted, provided that the above 6224090Sdougb * copyright notice and this permission notice appear in all copies. 7224090Sdougb * 8224090Sdougb * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 9224090Sdougb * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10224090Sdougb * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 11224090Sdougb * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12224090Sdougb * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13224090Sdougb * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14224090Sdougb * PERFORMANCE OF THIS SOFTWARE. 15224090Sdougb */ 16224090Sdougb 17234010Sdougb/* $Id: gai_strerror.c,v 1.5 2009/09/02 23:48:02 tbox Exp $ */ 18224090Sdougb 19224090Sdougb/*! \file gai_strerror.c 20224090Sdougb * gai_strerror() returns an error message corresponding to an 21224090Sdougb * error code returned by getaddrinfo() and getnameinfo(). The following error 22224090Sdougb * codes and their meaning are defined in 23224090Sdougb * \link netdb.h include/irs/netdb.h.\endlink 24224090Sdougb * This implementation is almost an exact copy of lwres/gai_sterror.c except 25224090Sdougb * that it catches up the latest API standard, RFC3493. 26224090Sdougb * 27224090Sdougb * \li #EAI_ADDRFAMILY address family for hostname not supported 28224090Sdougb * \li #EAI_AGAIN temporary failure in name resolution 29224090Sdougb * \li #EAI_BADFLAGS invalid value for ai_flags 30224090Sdougb * \li #EAI_FAIL non-recoverable failure in name resolution 31224090Sdougb * \li #EAI_FAMILY ai_family not supported 32224090Sdougb * \li #EAI_MEMORY memory allocation failure 33224090Sdougb * \li #EAI_NODATA no address associated with hostname (obsoleted in RFC3493) 34224090Sdougb * \li #EAI_NONAME hostname nor servname provided, or not known 35224090Sdougb * \li #EAI_SERVICE servname not supported for ai_socktype 36224090Sdougb * \li #EAI_SOCKTYPE ai_socktype not supported 37224090Sdougb * \li #EAI_SYSTEM system error returned in errno 38224090Sdougb * \li #EAI_BADHINTS Invalid value for hints (non-standard) 39224090Sdougb * \li #EAI_PROTOCOL Resolved protocol is unknown (non-standard) 40224090Sdougb * \li #EAI_OVERFLOW Argument buffer overflow 41224090Sdougb * \li #EAI_INSECUREDATA Insecure Data (experimental) 42224090Sdougb * 43224090Sdougb * The message invalid error code is returned if ecode is out of range. 44224090Sdougb * 45224090Sdougb * ai_flags, ai_family and ai_socktype are elements of the struct 46224090Sdougb * addrinfo used by lwres_getaddrinfo(). 47224090Sdougb * 48224090Sdougb * \section gai_strerror_see See Also 49224090Sdougb * 50224090Sdougb * strerror(), getaddrinfo(), getnameinfo(), RFC3493. 51224090Sdougb */ 52224090Sdougb#include <config.h> 53224090Sdougb 54224090Sdougb#include <irs/netdb.h> 55224090Sdougb 56224090Sdougb/*% Text of error messages. */ 57224090Sdougbstatic const char *gai_messages[] = { 58224090Sdougb "no error", 59224090Sdougb "address family for hostname not supported", 60224090Sdougb "temporary failure in name resolution", 61224090Sdougb "invalid value for ai_flags", 62224090Sdougb "non-recoverable failure in name resolution", 63224090Sdougb "ai_family not supported", 64224090Sdougb "memory allocation failure", 65224090Sdougb "no address associated with hostname", 66224090Sdougb "hostname nor servname provided, or not known", 67224090Sdougb "servname not supported for ai_socktype", 68224090Sdougb "ai_socktype not supported", 69224090Sdougb "system error returned in errno", 70224090Sdougb "bad hints", 71224090Sdougb "bad protocol", 72224090Sdougb "argument buffer overflow", 73224090Sdougb "insecure data provided" 74224090Sdougb}; 75224090Sdougb 76224090Sdougb/*% 77224090Sdougb * Returns an error message corresponding to an error code returned by 78224090Sdougb * getaddrinfo() and getnameinfo() 79224090Sdougb */ 80224090SdougbIRS_GAISTRERROR_RETURN_T 81224090Sdougbgai_strerror(int ecode) { 82224090Sdougb union { 83224090Sdougb const char *const_ptr; 84224090Sdougb char *deconst_ptr; 85224090Sdougb } ptr; 86224090Sdougb 87224090Sdougb if ((ecode < 0) || 88224090Sdougb (ecode >= (int)(sizeof(gai_messages)/sizeof(*gai_messages)))) 89224090Sdougb ptr.const_ptr = "invalid error code"; 90224090Sdougb else 91224090Sdougb ptr.const_ptr = gai_messages[ecode]; 92224090Sdougb return (ptr.deconst_ptr); 93224090Sdougb} 94