1 /* 2 * %%% copyright-cmetz-97-bsd 3 * Copyright (c) 1997-1999, Craig Metz, All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by Craig Metz and 16 * by other contributors. 17 * 4. Neither the name of the author nor the names of contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Redistribution and use in source and binary forms, with or without 34 * modification, are permitted provided that the following conditions 35 * are met: 36 * 1. Redistributions of source code must retain the above copyright 37 * notice, this list of conditions and the following disclaimer. 38 * 2. Redistributions in binary form must reproduce the above copyright 39 * notice, this list of conditions and the following disclaimer in the 40 * documentation and/or other materials provided with the distribution. 41 * 3. All advertising materials mentioning features or use of this software 42 * must display the following acknowledgement: 43 * This product includes software developed by Craig Metz and 44 * by other contributors. 45 * 4. Neither the name of the author nor the names of contributors 46 * may be used to endorse or promote products derived from this software 47 * without specific prior written permission. 48 * 49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59 * SUCH DAMAGE. 60 */ 61 62 /* gai_strerror() v1.38 */ 63 64 #include <sys/types.h> 65 #include <netdb.h> 66 #include <errno.h> 67 68 #define THREAD_SAFE 0 69 70 #if !THREAD_SAFE 71 static char buffer[256]; 72 #endif /* !THREAD_SAFE */ 73 74 char *gai_strerror(int errnum) 75 { 76 switch(errnum) { 77 case 0: 78 return "no error"; 79 case EAI_BADFLAGS: 80 return "invalid value for ai_flags"; 81 case EAI_NONAME: 82 return "name or service is not known"; 83 case EAI_AGAIN: 84 return "temporary failure in name resolution"; 85 case EAI_FAIL: 86 return "non-recoverable failure in name resolution"; 87 case EAI_NODATA: 88 return "no address associated with name"; 89 case EAI_FAMILY: 90 return "ai_family not supported"; 91 case EAI_SOCKTYPE: 92 return "ai_socktype not supported"; 93 case EAI_SERVICE: 94 return "service not supported for ai_socktype"; 95 case EAI_ADDRFAMILY: 96 return "address family for name not supported"; 97 case EAI_MEMORY: 98 return "memory allocation failure"; 99 case EAI_SYSTEM: 100 #if THREAD_SAFE 101 return "system error"; 102 #else /* THREAD_SAFE */ 103 snprintf(buffer, sizeof(buffer)-1, "system error: %s(%d)", strerror(errno), errno); 104 buffer[sizeof(buffer)-1] = 0; 105 return buffer; 106 #endif /* THREAD_SAFE */ 107 default: 108 #if THREAD_SAFE 109 return "unknown/invalid error"; 110 #else /* THREAD_SAFE */ 111 snprintf(buffer, sizeof(buffer)-1, "unknown/invalid error %d", errnum); 112 buffer[sizeof(buffer)-1] = 0; 113 return buffer; 114 #endif /* THREAD_SAFE */ 115 }; 116 }; 117