]> git.ipfire.org Git - thirdparty/strongswan.git/blob - lib/liblwres/herror.c
- import of strongswan-2.7.0
[thirdparty/strongswan.git] / lib / liblwres / herror.c
1 /*
2 * Portions Copyright (C) 2000, 2001 Internet Software Consortium.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
9 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
10 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
11 * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
13 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
14 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 /*
19 * Copyright (c) 1987, 1993
20 * The Regents of the University of California. All rights reserved.
21 *
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
24 * are met:
25 * 1. Redistributions of source code must retain the above copyright
26 * notice, this list of conditions and the following disclaimer.
27 * 2. Redistributions in binary form must reproduce the above copyright
28 * notice, this list of conditions and the following disclaimer in the
29 * documentation and/or other materials provided with the distribution.
30 * 3. All advertising materials mentioning features or use of this software
31 * must display the following acknowledgement:
32 * This product includes software developed by the University of
33 * California, Berkeley and its contributors.
34 * 4. Neither the name of the University nor the names of its contributors
35 * may be used to endorse or promote products derived from this software
36 * without specific prior written permission.
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
39 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
42 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
44 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
46 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
47 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48 * SUCH DAMAGE.
49 */
50
51 #if defined(LIBC_SCCS) && !defined(lint)
52 static const char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93";
53 static const char rcsid[] =
54 "$Id: herror.c,v 1.1 2004/03/15 20:35:25 as Exp $";
55 #endif /* LIBC_SCCS and not lint */
56
57 #include <config.h>
58
59 #include <stdio.h>
60
61 #include <lwres/netdb.h>
62 #include <lwres/platform.h>
63
64 LIBLWRES_EXTERNAL_DATA int lwres_h_errno;
65
66 /*
67 * these have never been declared in any header file so make them static
68 */
69
70 static const char *h_errlist[] = {
71 "Resolver Error 0 (no error)",
72 "Unknown host", /* 1 HOST_NOT_FOUND */
73 "Host name lookup failure", /* 2 TRY_AGAIN */
74 "Unknown server error", /* 3 NO_RECOVERY */
75 "No address associated with name", /* 4 NO_ADDRESS */
76 };
77
78 static int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
79
80
81 /*
82 * herror --
83 * print the error indicated by the h_errno value.
84 */
85 void
86 lwres_herror(const char *s) {
87 fprintf(stderr, "%s: %s\n", s, lwres_hstrerror(lwres_h_errno));
88 }
89
90 /*
91 * hstrerror --
92 * return the string associated with a given "host" errno value.
93 */
94 const char *
95 lwres_hstrerror(int err) {
96 if (err < 0)
97 return ("Resolver internal error");
98 else if (err < h_nerr)
99 return (h_errlist[err]);
100 return ("Unknown resolver error");
101 }