summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/herror.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/herror.c')
-rw-r--r--src/lib/libc/net/herror.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/lib/libc/net/herror.c b/src/lib/libc/net/herror.c
index 41adbf1055..e8f6fa28fc 100644
--- a/src/lib/libc/net/herror.c
+++ b/src/lib/libc/net/herror.c
@@ -1,9 +1,11 @@
1/* $NetBSD: herror.c,v 1.5 1995/02/25 06:20:39 cgd Exp $ */ 1/* $OpenBSD: herror.c,v 1.5 2003/06/02 20:18:35 millert Exp $ */
2 2
3/*- 3/*
4 * ++Copyright++ 1987, 1993
5 * -
4 * Copyright (c) 1987, 1993 6 * Copyright (c) 1987, 1993
5 * The Regents of the University of California. All rights reserved. 7 * The Regents of the University of California. All rights reserved.
6 * 8 *
7 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
9 * are met: 11 * are met:
@@ -12,14 +14,10 @@
12 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 16 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software 17 * 3. Neither the name of the University nor the names of its contributors
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software 18 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission. 19 * without specific prior written permission.
22 * 20 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -56,26 +54,27 @@
56#if defined(LIBC_SCCS) && !defined(lint) 54#if defined(LIBC_SCCS) && !defined(lint)
57#if 0 55#if 0
58static char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93"; 56static char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93";
59static char rcsid[] = "$Id: herror.c,v 4.9.1.1 1993/05/02 23:14:35 vixie Rel "; 57static char rcsid[] = "$From: herror.c,v 8.3 1996/08/05 08:31:35 vixie Exp $";
60#else 58#else
61static char rcsid[] = "$NetBSD: herror.c,v 1.5 1995/02/25 06:20:39 cgd Exp $"; 59static char rcsid[] = "$OpenBSD: herror.c,v 1.5 2003/06/02 20:18:35 millert Exp $";
62#endif 60#endif
63#endif /* LIBC_SCCS and not lint */ 61#endif /* LIBC_SCCS and not lint */
64 62
65#include <sys/types.h> 63#include <sys/types.h>
64#include <sys/param.h>
66#include <sys/uio.h> 65#include <sys/uio.h>
67#include <netdb.h> 66#include <netdb.h>
68#include <unistd.h> 67#include <unistd.h>
69#include <string.h> 68#include <string.h>
70 69
71char *h_errlist[] = { 70const char *h_errlist[] = {
72 "Error 0", 71 "Resolver Error 0 (no error)",
73 "Unknown host", /* 1 HOST_NOT_FOUND */ 72 "Unknown host", /* 1 HOST_NOT_FOUND */
74 "Host name lookup failure", /* 2 TRY_AGAIN */ 73 "Host name lookup failure", /* 2 TRY_AGAIN */
75 "Unknown server error", /* 3 NO_RECOVERY */ 74 "Unknown server error", /* 3 NO_RECOVERY */
76 "No address associated with name", /* 4 NO_ADDRESS */ 75 "No address associated with name", /* 4 NO_ADDRESS */
77}; 76};
78int h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) }; 77int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
79 78
80extern int h_errno; 79extern int h_errno;
81 80
@@ -98,8 +97,7 @@ herror(s)
98 v->iov_len = 2; 97 v->iov_len = 2;
99 v++; 98 v++;
100 } 99 }
101 v->iov_base = (u_int)h_errno < h_nerr ? 100 v->iov_base = (char *)hstrerror(h_errno);
102 h_errlist[h_errno] : "Unknown error";
103 v->iov_len = strlen(v->iov_base); 101 v->iov_len = strlen(v->iov_base);
104 v++; 102 v++;
105 v->iov_base = "\n"; 103 v->iov_base = "\n";
@@ -107,9 +105,13 @@ herror(s)
107 writev(STDERR_FILENO, iov, (v - iov) + 1); 105 writev(STDERR_FILENO, iov, (v - iov) + 1);
108} 106}
109 107
110char * 108const char *
111hstrerror(err) 109hstrerror(err)
112 int err; 110 int err;
113{ 111{
114 return (u_int)err < h_nerr ? h_errlist[err] : "Unknown resolver error"; 112 if (err < 0)
113 return ("Resolver internal error");
114 else if (err < h_nerr)
115 return (h_errlist[err]);
116 return ("Unknown resolver error");
115} 117}