mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-02 15:45:25 +00:00
1084. [cleanup] libbind: gai_strerror() re-written.
This commit is contained in:
2
CHANGES
2
CHANGES
@@ -1,3 +1,5 @@
|
|||||||
|
1084. [cleanup] libbind: gai_strerror() re-written.
|
||||||
|
|
||||||
1083. [bug] The default control channel listened on the
|
1083. [bug] The default control channel listened on the
|
||||||
wildcard adress, not the loopback as documented.
|
wildcard adress, not the loopback as documented.
|
||||||
[RT #1975]
|
[RT #1975]
|
||||||
|
@@ -1,44 +1,86 @@
|
|||||||
/*
|
/*
|
||||||
%%% copyright-cmetz-97
|
* Copyright (c) 2001 by Internet Software Consortium.
|
||||||
This software is Copyright 1997-1998 by Craig Metz, All Rights Reserved.
|
*
|
||||||
The Inner Net License Version 2 applies to this software.
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
You should have received a copy of the license with this software. If
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
you didn't get a copy, you may request one from <license@inner.net>.
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
*/
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <port_before.h>
|
#include <port_before.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <port_after.h>
|
#include <port_after.h>
|
||||||
|
|
||||||
|
#ifdef DO_PTHREADS
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static const char *gai_errlist[] = {
|
||||||
|
"no error",
|
||||||
|
"address family not supported for name",/* EAI_ADDRFAMILY */
|
||||||
|
"temporary failure", /* EAI_AGAIN */
|
||||||
|
"invalid flags", /* EAI_BADFLAGS */
|
||||||
|
"permanent failure", /* EAI_FAIL */
|
||||||
|
"address family not supported", /* EAI_FAMILY */
|
||||||
|
"memory failure", /* EAI_MEMORY */
|
||||||
|
"no address", /* EAI_NODATA */
|
||||||
|
"unknown name or service", /* EAI_NONAME */
|
||||||
|
"service not supported for socktype", /* EAI_SERVICE */
|
||||||
|
"socktype not supported", /* EAI_SOCKTYPE */
|
||||||
|
"system failure", /* EAI_SYSTEM */
|
||||||
|
"bad hints", /* EAI_BADHINTS */
|
||||||
|
"bad protocol", /* EAI_PROTOCOL */
|
||||||
|
|
||||||
|
"unknown error" /* Must be last. */
|
||||||
|
};
|
||||||
|
|
||||||
|
static const int gai_nerr = (sizeof(gai_errlist)/sizeof(*gai_errlist));
|
||||||
|
|
||||||
|
#define EAI_BUFSIZE 128
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
gai_strerror(int errnum) {
|
gai_strerror(int ecode) {
|
||||||
switch(errnum) {
|
#ifndef DO_PTHREADS
|
||||||
case 0:
|
static char buf[EAI_BUFSIZE];
|
||||||
return "no error";
|
#else DO_PTHREADS
|
||||||
case EAI_BADFLAGS:
|
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
return "invalid value for ai_flags";
|
static pthread_key_t key;
|
||||||
case EAI_NONAME:
|
static int once = 0;
|
||||||
return "name or service is not known";
|
char *buf;
|
||||||
case EAI_AGAIN:
|
#endif
|
||||||
return "temporary failure in name resolution";
|
|
||||||
case EAI_FAIL:
|
if (ecode >= 0 && ecode < (gai_nerr - 1))
|
||||||
return "non-recoverable failure in name resolution";
|
return (gai_errlist[ecode]);
|
||||||
case EAI_NODATA:
|
|
||||||
return "no address associated with name";
|
#ifdef DO_PTHREADS
|
||||||
case EAI_FAMILY:
|
if (!once) {
|
||||||
return "ai_family not supported";
|
pthread_mutex_lock(&lock);
|
||||||
case EAI_SOCKTYPE:
|
if (!once++)
|
||||||
return "ai_socktype not supported";
|
pthread_key_create(&key, free);
|
||||||
case EAI_SERVICE:
|
pthread_mutex_unlock(&lock);
|
||||||
return "service not supported for ai_socktype";
|
}
|
||||||
case EAI_ADDRFAMILY:
|
|
||||||
return "address family for name not supported";
|
buf = pthread_getspecific(key);
|
||||||
case EAI_MEMORY:
|
if (buf == NULL) {
|
||||||
return "memory allocation failure";
|
buf = malloc(EAI_BUFSIZE);
|
||||||
case EAI_SYSTEM:
|
if (buf == NULL)
|
||||||
return "system error";
|
return ("unknown error");
|
||||||
default:
|
pthread_setspecific(key, buf);
|
||||||
return "unknown error";
|
}
|
||||||
};
|
#endif
|
||||||
|
/*
|
||||||
|
* XXX This really should be snprintf(buf, EAI_BUFSIZE, ...).
|
||||||
|
* It is safe until message catalogs are used.
|
||||||
|
*/
|
||||||
|
sprintf(buf, "%s: %d", gai_errlist[gai_nerr - 1], ecode);
|
||||||
|
return (buf);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user