f57cf8a2706c15bcb5fc1cb19faa0260b5111b0bMark Andrews/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2000, 2001, 2004-2007, 2014, 2016 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
1378841691ad112fce2376d9f2e54e02676057d3Michael Sawyer */
f57cf8a2706c15bcb5fc1cb19faa0260b5111b0bMark Andrews
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater/* $Id: gai_strerror.c,v 1.22 2007/06/19 23:47:22 tbox Exp $ */
f57cf8a2706c15bcb5fc1cb19faa0260b5111b0bMark Andrews
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*! \file gai_strerror.c
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * lwres_gai_strerror() returns an error message corresponding to an
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * error code returned by getaddrinfo(). The following error codes and
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * their meaning are defined in \link netdb.h include/lwres/netdb.h.\endlink
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #EAI_ADDRFAMILY address family for hostname not supported
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #EAI_AGAIN temporary failure in name resolution
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #EAI_BADFLAGS invalid value for #ai_flags
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #EAI_FAIL non-recoverable failure in name resolution
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #EAI_FAMILY ai_family not supported
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #EAI_MEMORY memory allocation failure
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #EAI_NODATA no address associated with hostname
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #EAI_NONAME hostname or servname not provided, or not known
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #EAI_SERVICE servname not supported for ai_socktype
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #EAI_SOCKTYPE ai_socktype not supported
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #EAI_SYSTEM system error returned in errno
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * The message invalid error code is returned if ecode is out of range.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * ai_flags, ai_family and ai_socktype are elements of the struct
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * addrinfo used by lwres_getaddrinfo().
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \section gai_strerror_see See Also
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * strerror, lwres_getaddrinfo(), getaddrinfo(), RFC2133.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein */
c7817270552b2faab56466b89731b6f290b352a4Mark Andrews
c7817270552b2faab56466b89731b6f290b352a4Mark Andrews#include <config.h>
c7817270552b2faab56466b89731b6f290b352a4Mark Andrews
f57cf8a2706c15bcb5fc1cb19faa0260b5111b0bMark Andrews#include <lwres/netdb.h>
f57cf8a2706c15bcb5fc1cb19faa0260b5111b0bMark Andrews
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*% Text of error messages. */
1378841691ad112fce2376d9f2e54e02676057d3Michael Sawyerstatic const char *gai_messages[] = {
1378841691ad112fce2376d9f2e54e02676057d3Michael Sawyer "no error",
1378841691ad112fce2376d9f2e54e02676057d3Michael Sawyer "address family for hostname not supported",
1378841691ad112fce2376d9f2e54e02676057d3Michael Sawyer "temporary failure in name resolution",
1378841691ad112fce2376d9f2e54e02676057d3Michael Sawyer "invalid value for ai_flags",
1378841691ad112fce2376d9f2e54e02676057d3Michael Sawyer "non-recoverable failure in name resolution",
1378841691ad112fce2376d9f2e54e02676057d3Michael Sawyer "ai_family not supported",
1378841691ad112fce2376d9f2e54e02676057d3Michael Sawyer "memory allocation failure",
1378841691ad112fce2376d9f2e54e02676057d3Michael Sawyer "no address associated with hostname",
1378841691ad112fce2376d9f2e54e02676057d3Michael Sawyer "hostname nor servname provided, or not known",
1378841691ad112fce2376d9f2e54e02676057d3Michael Sawyer "servname not supported for ai_socktype",
1378841691ad112fce2376d9f2e54e02676057d3Michael Sawyer "ai_socktype not supported",
dd0fdd442633c66003c996ddf7dd229c8630ddc9Brian Wellington "system error returned in errno",
dd0fdd442633c66003c996ddf7dd229c8630ddc9Brian Wellington "bad hints",
e177c7b81414417858b5d4816946b1b9d72fbf1cMark Andrews "bad protocol",
e177c7b81414417858b5d4816946b1b9d72fbf1cMark Andrews "overflow"
c062bee4953be00fc5a04f023d5304810a171254Andreas Gustafsson};
50bd180f4bd49cd6d6483e9b39e7f8165cd1dd8fDavid Lawrence
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*% Returns an error message corresponding to an error code returned by getaddrinfo() */
b6007467ebe8aaf72a1507d5da1b65b3ead5c7f3Andreas Gustafssonchar *
57b3597444bc8716459f0fb3022b2c12f4eee2aeAndreas Gustafssonlwres_gai_strerror(int ecode) {
1378841691ad112fce2376d9f2e54e02676057d3Michael Sawyer union {
1378841691ad112fce2376d9f2e54e02676057d3Michael Sawyer const char *const_ptr;
1378841691ad112fce2376d9f2e54e02676057d3Michael Sawyer char *deconst_ptr;
1378841691ad112fce2376d9f2e54e02676057d3Michael Sawyer } ptr;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
552a117791c17878c5c1b94b0fc3ac4e8491543eMark Andrews if ((ecode < 0) ||
552a117791c17878c5c1b94b0fc3ac4e8491543eMark Andrews (ecode >= (int)(sizeof(gai_messages)/sizeof(*gai_messages))))
c062bee4953be00fc5a04f023d5304810a171254Andreas Gustafsson ptr.const_ptr = "invalid error code";
1378841691ad112fce2376d9f2e54e02676057d3Michael Sawyer else
1378841691ad112fce2376d9f2e54e02676057d3Michael Sawyer ptr.const_ptr = gai_messages[ecode];
c062bee4953be00fc5a04f023d5304810a171254Andreas Gustafsson return (ptr.deconst_ptr);
f57cf8a2706c15bcb5fc1cb19faa0260b5111b0bMark Andrews}