Blame resolv/herror.c

Packit Service 82fcde
/*
Packit Service 82fcde
 * Copyright (c) 1987, 1993
Packit Service 82fcde
 *    The Regents of the University of California.  All rights reserved.
Packit Service 82fcde
 *
Packit Service 82fcde
 * Redistribution and use in source and binary forms, with or without
Packit Service 82fcde
 * modification, are permitted provided that the following conditions
Packit Service 82fcde
 * are met:
Packit Service 82fcde
 * 1. Redistributions of source code must retain the above copyright
Packit Service 82fcde
 *    notice, this list of conditions and the following disclaimer.
Packit Service 82fcde
 * 2. Redistributions in binary form must reproduce the above copyright
Packit Service 82fcde
 *    notice, this list of conditions and the following disclaimer in the
Packit Service 82fcde
 *    documentation and/or other materials provided with the distribution.
Packit Service 82fcde
 * 4. Neither the name of the University nor the names of its contributors
Packit Service 82fcde
 *    may be used to endorse or promote products derived from this software
Packit Service 82fcde
 *    without specific prior written permission.
Packit Service 82fcde
 *
Packit Service 82fcde
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
Packit Service 82fcde
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit Service 82fcde
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit Service 82fcde
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
Packit Service 82fcde
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit Service 82fcde
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit Service 82fcde
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit Service 82fcde
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit Service 82fcde
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit Service 82fcde
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit Service 82fcde
 * SUCH DAMAGE.
Packit Service 82fcde
 */
Packit Service 82fcde
Packit Service 82fcde
/*
Packit Service 82fcde
 * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
Packit Service 82fcde
 *
Packit Service 82fcde
 * Permission to use, copy, modify, and distribute this software for any
Packit Service 82fcde
 * purpose with or without fee is hereby granted, provided that the above
Packit Service 82fcde
 * copyright notice and this permission notice appear in all copies.
Packit Service 82fcde
 *
Packit Service 82fcde
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
Packit Service 82fcde
 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
Packit Service 82fcde
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
Packit Service 82fcde
 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
Packit Service 82fcde
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
Packit Service 82fcde
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
Packit Service 82fcde
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
Packit Service 82fcde
 * SOFTWARE.
Packit Service 82fcde
 */
Packit Service 82fcde
Packit Service 82fcde
#include <sys/types.h>
Packit Service 82fcde
#include <sys/param.h>
Packit Service 82fcde
#include <sys/uio.h>
Packit Service 82fcde
Packit Service 82fcde
#include <netinet/in.h>
Packit Service 82fcde
#include <arpa/nameser.h>
Packit Service 82fcde
Packit Service 82fcde
#include <netdb.h>
Packit Service 82fcde
#include <resolv.h>
Packit Service 82fcde
#include <string.h>
Packit Service 82fcde
#include <unistd.h>
Packit Service 82fcde
Packit Service 82fcde
#include <libintl.h>
Packit Service 82fcde
#include <not-cancel.h>
Packit Service 82fcde
Packit Service 82fcde
const char *const h_errlist[] = {
Packit Service 82fcde
	N_("Resolver Error 0 (no error)"),
Packit Service 82fcde
	N_("Unknown host"),			/* 1 HOST_NOT_FOUND */
Packit Service 82fcde
	N_("Host name lookup failure"),		/* 2 TRY_AGAIN */
Packit Service 82fcde
	N_("Unknown server error"),		/* 3 NO_RECOVERY */
Packit Service 82fcde
	N_("No address associated with name"),	/* 4 NO_ADDRESS */
Packit Service 82fcde
};
Packit Service 82fcde
const int	h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
Packit Service 82fcde
Packit Service 82fcde
/*
Packit Service 82fcde
 * herror --
Packit Service 82fcde
 *	print the error indicated by the h_errno value.
Packit Service 82fcde
 */
Packit Service 82fcde
void
Packit Service 82fcde
herror(const char *s) {
Packit Service 82fcde
	struct iovec iov[4], *v = iov;
Packit Service 82fcde
Packit Service 82fcde
	if (s != NULL && *s != '\0') {
Packit Service 82fcde
		v->iov_base = (/*noconst*/ char *)s;
Packit Service 82fcde
		v->iov_len = strlen(s);
Packit Service 82fcde
		v++;
Packit Service 82fcde
		v->iov_base = (char *) ": ";
Packit Service 82fcde
		v->iov_len = 2;
Packit Service 82fcde
		v++;
Packit Service 82fcde
	}
Packit Service 82fcde
	v->iov_base = (char *)hstrerror(h_errno);
Packit Service 82fcde
	v->iov_len = strlen(v->iov_base);
Packit Service 82fcde
	v++;
Packit Service 82fcde
	v->iov_base = (char *) "\n";
Packit Service 82fcde
	v->iov_len = 1;
Packit Service 82fcde
	__writev_nocancel_nostatus(STDERR_FILENO, iov, (v - iov) + 1);
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
/*
Packit Service 82fcde
 * hstrerror --
Packit Service 82fcde
 *	return the string associated with a given "host" errno value.
Packit Service 82fcde
 */
Packit Service 82fcde
const char *
Packit Service 82fcde
hstrerror(int err) {
Packit Service 82fcde
	if (err < 0)
Packit Service 82fcde
		return _("Resolver internal error");
Packit Service 82fcde
	else if (err < h_nerr)
Packit Service 82fcde
		return _(h_errlist[err]);
Packit Service 82fcde
	return _("Unknown resolver error");
Packit Service 82fcde
}
Packit Service 82fcde
libc_hidden_def (hstrerror)