hstrerror.c revision 233294
1120441Sbms/*
2120441Sbms * Copyright (c) 1995 - 1999 Kungliga Tekniska H��gskolan
3120441Sbms * (Royal Institute of Technology, Stockholm, Sweden).
4120441Sbms * All rights reserved.
5120441Sbms *
6120441Sbms * Redistribution and use in source and binary forms, with or without
7120441Sbms * modification, are permitted provided that the following conditions
8120441Sbms * are met:
9120441Sbms *
10120441Sbms * 1. Redistributions of source code must retain the above copyright
11120441Sbms *    notice, this list of conditions and the following disclaimer.
12120441Sbms *
13120441Sbms * 2. Redistributions in binary form must reproduce the above copyright
14120441Sbms *    notice, this list of conditions and the following disclaimer in the
15120441Sbms *    documentation and/or other materials provided with the distribution.
16120441Sbms *
17120441Sbms * 3. Neither the name of the Institute nor the names of its contributors
18120441Sbms *    may be used to endorse or promote products derived from this software
19120441Sbms *    without specific prior written permission.
20120441Sbms *
21120441Sbms * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22120441Sbms * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23120441Sbms * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24120441Sbms * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25120441Sbms * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26120441Sbms * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27120441Sbms * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28120441Sbms * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29120441Sbms * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30131681Sru * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31120441Sbms * SUCH DAMAGE.
32120441Sbms */
33120441Sbms
34120441Sbms#include <config.h>
35120441Sbms
36120441Sbms#ifndef HAVE_HSTRERROR
37120441Sbms
38120441Sbms#if (defined(SunOS) && (SunOS >= 50))
39120441Sbms#define hstrerror broken_proto
40120441Sbms#endif
41120441Sbms#include "roken.h"
42120441Sbms#if (defined(SunOS) && (SunOS >= 50))
43120441Sbms#undef hstrerror
44120441Sbms#endif
45120441Sbms
46120441Sbms#if !(defined(HAVE_H_ERRLIST) && defined(HAVE_H_NERR))
47120441Sbmsstatic const char *const h_errlist[] = {
48120441Sbms    "Resolver Error 0 (no error)",
49120441Sbms    "Unknown host",		/* 1 HOST_NOT_FOUND */
50120441Sbms    "Host name lookup failure",	/* 2 TRY_AGAIN */
51120441Sbms    "Unknown server error",	/* 3 NO_RECOVERY */
52120441Sbms    "No address associated with name", /* 4 NO_ADDRESS */
53120441Sbms};
54120441Sbms
55120441Sbmsstatic
56120441Sbmsconst
57120441Sbmsint h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
58120441Sbms#else
59120441Sbms
60120441Sbms#if !HAVE_DECL_H_ERRLIST
61120441Sbmsextern const char *h_errlist[];
62120441Sbmsextern int h_nerr;
63120441Sbms#endif
64120441Sbms
65120441Sbms#endif
66120441Sbms
67120441SbmsROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
68120441Sbmshstrerror(int herr)
69120441Sbms{
70120441Sbms    if (0 <= herr && herr < h_nerr)
71120441Sbms	return h_errlist[herr];
72120441Sbms    else if(herr == -17)
73120441Sbms	return "unknown error";
74120441Sbms    else
75120441Sbms	return "Error number out of range (hstrerror)";
76120441Sbms}
77120441Sbms
78120441Sbms#endif
79120441Sbms