Blame resolv/herror.c

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