]>
Commit | Line | Data |
---|---|---|
d7ce7006 | 1 | /*\r |
2 | * Copyright (c) 1987, 1993\r | |
39f4382a | 3 | * The Regents of the University of California. All rights reserved.\r |
d7ce7006 | 4 | *\r |
5 | * Portions copyright (c) 1999, 2000\r | |
6 | * Intel Corporation.\r | |
7 | * All rights reserved.\r | |
39f4382a | 8 | *\r |
d7ce7006 | 9 | * Redistribution and use in source and binary forms, with or without\r |
10 | * modification, are permitted provided that the following conditions\r | |
11 | * are met:\r | |
39f4382a | 12 | *\r |
d7ce7006 | 13 | * 1. Redistributions of source code must retain the above copyright\r |
14 | * notice, this list of conditions and the following disclaimer.\r | |
39f4382a | 15 | *\r |
d7ce7006 | 16 | * 2. Redistributions in binary form must reproduce the above copyright\r |
17 | * notice, this list of conditions and the following disclaimer in the\r | |
18 | * documentation and/or other materials provided with the distribution.\r | |
39f4382a | 19 | *\r |
d7ce7006 | 20 | * 3. All advertising materials mentioning features or use of this software\r |
21 | * must display the following acknowledgement:\r | |
39f4382a | 22 | *\r |
d7ce7006 | 23 | * This product includes software developed by the University of\r |
24 | * California, Berkeley, Intel Corporation, and its contributors.\r | |
39f4382a | 25 | *\r |
d7ce7006 | 26 | * 4. Neither the name of University, Intel Corporation, or their respective\r |
27 | * contributors may be used to endorse or promote products derived from\r | |
28 | * this software without specific prior written permission.\r | |
39f4382a | 29 | *\r |
d7ce7006 | 30 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND\r |
31 | * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r | |
32 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r | |
33 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,\r | |
34 | * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r | |
35 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r | |
36 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r | |
37 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r | |
38 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r | |
39 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r | |
40 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r | |
41 | *\r | |
42 | */\r | |
43 | \r | |
44 | /*\r | |
45 | * Portions Copyright (c) 1996 by Internet Software Consortium.\r | |
46 | *\r | |
47 | * Permission to use, copy, modify, and distribute this software for any\r | |
48 | * purpose with or without fee is hereby granted, provided that the above\r | |
49 | * copyright notice and this permission notice appear in all copies.\r | |
50 | *\r | |
51 | * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS\r | |
52 | * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES\r | |
53 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE\r | |
54 | * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL\r | |
55 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR\r | |
56 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\r | |
57 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\r | |
58 | * SOFTWARE.\r | |
d7ce7006 | 59 | \r |
39f4382a | 60 | herror.c 8.1 (Berkeley) 6/4/93\r |
61 | herror.c,v 1.1.1.1 2003/11/19 01:51:28 kyu3 Exp\r | |
62 | */\r | |
d7ce7006 | 63 | \r |
64 | #include <sys/types.h>\r | |
65 | #include <sys/uio.h>\r | |
66 | #include <netdb.h>\r | |
67 | #include <string.h>\r | |
68 | #include <stdio.h>\r | |
69 | #include <unistd.h>\r | |
70 | \r | |
71 | const char *h_errlist[] = {\r | |
39f4382a | 72 | "Resolver Error 0 (no error)",\r |
73 | "Unknown host", /* 1 HOST_NOT_FOUND */\r | |
74 | "Host name lookup failure", /* 2 TRY_AGAIN */\r | |
75 | "Unknown server error", /* 3 NO_RECOVERY */\r | |
76 | "No address associated with name", /* 4 NO_ADDRESS */\r | |
d7ce7006 | 77 | };\r |
39f4382a | 78 | int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };\r |
d7ce7006 | 79 | \r |
39f4382a | 80 | int h_errno;\r |
d7ce7006 | 81 | \r |
82 | const char *\r | |
83 | hstrerror(\r | |
84 | int err\r | |
85 | );\r | |
86 | \r | |
87 | /*\r | |
88 | * herror --\r | |
39f4382a | 89 | * print the error indicated by the h_errno value.\r |
d7ce7006 | 90 | */\r |
91 | void\r | |
92 | herror(\r | |
39f4382a | 93 | const char *s\r |
94 | )\r | |
d7ce7006 | 95 | {\r |
39f4382a | 96 | struct iovec iov[4];\r |
97 | register struct iovec *v = iov;\r | |
d7ce7006 | 98 | \r |
39f4382a | 99 | if (s && *s) {\r |
100 | v->iov_base = (char *)s;\r | |
101 | v->iov_len = strlen(s);\r | |
102 | v++;\r | |
103 | v->iov_base = ": ";\r | |
104 | v->iov_len = 2;\r | |
105 | v++;\r | |
106 | }\r | |
107 | v->iov_base = (char *)hstrerror(h_errno);\r | |
108 | v->iov_len = strlen(v->iov_base);\r | |
109 | v++;\r | |
110 | v->iov_base = "\n";\r | |
111 | v->iov_len = 1;\r | |
826f9005 | 112 | #if defined(_ORG_FREEBSD_) || defined(__GNUC__)\r |
39f4382a | 113 | writev(STDERR_FILENO, iov, (v - iov) + 1);\r |
d7ce7006 | 114 | #else\r |
826f9005 | 115 | {\r |
116 | int i;\r | |
117 | for (i = 0; i < (v - iov) + 1; i++)\r | |
118 | fprintf( stderr, iov[i].iov_base);\r | |
119 | }\r | |
d7ce7006 | 120 | #endif\r |
121 | \r | |
122 | }\r | |
123 | \r | |
124 | const char *\r | |
125 | hstrerror(\r | |
39f4382a | 126 | int err\r |
127 | )\r | |
d7ce7006 | 128 | {\r |
39f4382a | 129 | if (err < 0)\r |
130 | return ("Resolver internal error");\r | |
131 | else if (err < h_nerr)\r | |
132 | return (h_errlist[err]);\r | |
133 | return ("Unknown resolver error");\r | |
d7ce7006 | 134 | }\r |