diff options
Diffstat (limited to 'src/lib/libc/net/herror.c')
| -rw-r--r-- | src/lib/libc/net/herror.c | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/src/lib/libc/net/herror.c b/src/lib/libc/net/herror.c index 41adbf1055..7787115a9d 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.8 2005/08/06 20:30:03 espie 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 |
| @@ -53,29 +51,21 @@ | |||
| 53 | * --Copyright-- | 51 | * --Copyright-- |
| 54 | */ | 52 | */ |
| 55 | 53 | ||
| 56 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 57 | #if 0 | ||
| 58 | static char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93"; | ||
| 59 | static char rcsid[] = "$Id: herror.c,v 4.9.1.1 1993/05/02 23:14:35 vixie Rel "; | ||
| 60 | #else | ||
| 61 | static char rcsid[] = "$NetBSD: herror.c,v 1.5 1995/02/25 06:20:39 cgd Exp $"; | ||
| 62 | #endif | ||
| 63 | #endif /* LIBC_SCCS and not lint */ | ||
| 64 | |||
| 65 | #include <sys/types.h> | 54 | #include <sys/types.h> |
| 55 | #include <sys/param.h> | ||
| 66 | #include <sys/uio.h> | 56 | #include <sys/uio.h> |
| 67 | #include <netdb.h> | 57 | #include <netdb.h> |
| 68 | #include <unistd.h> | 58 | #include <unistd.h> |
| 69 | #include <string.h> | 59 | #include <string.h> |
| 70 | 60 | ||
| 71 | char *h_errlist[] = { | 61 | const char * const h_errlist[] = { |
| 72 | "Error 0", | 62 | "Resolver Error 0 (no error)", |
| 73 | "Unknown host", /* 1 HOST_NOT_FOUND */ | 63 | "Unknown host", /* 1 HOST_NOT_FOUND */ |
| 74 | "Host name lookup failure", /* 2 TRY_AGAIN */ | 64 | "Host name lookup failure", /* 2 TRY_AGAIN */ |
| 75 | "Unknown server error", /* 3 NO_RECOVERY */ | 65 | "Unknown server error", /* 3 NO_RECOVERY */ |
| 76 | "No address associated with name", /* 4 NO_ADDRESS */ | 66 | "No address associated with name", /* 4 NO_ADDRESS */ |
| 77 | }; | 67 | }; |
| 78 | int h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) }; | 68 | const int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] }; |
| 79 | 69 | ||
| 80 | extern int h_errno; | 70 | extern int h_errno; |
| 81 | 71 | ||
| @@ -84,11 +74,10 @@ extern int h_errno; | |||
| 84 | * print the error indicated by the h_errno value. | 74 | * print the error indicated by the h_errno value. |
| 85 | */ | 75 | */ |
| 86 | void | 76 | void |
| 87 | herror(s) | 77 | herror(const char *s) |
| 88 | const char *s; | ||
| 89 | { | 78 | { |
| 90 | struct iovec iov[4]; | 79 | struct iovec iov[4]; |
| 91 | register struct iovec *v = iov; | 80 | struct iovec *v = iov; |
| 92 | 81 | ||
| 93 | if (s && *s) { | 82 | if (s && *s) { |
| 94 | v->iov_base = (char *)s; | 83 | v->iov_base = (char *)s; |
| @@ -98,8 +87,7 @@ herror(s) | |||
| 98 | v->iov_len = 2; | 87 | v->iov_len = 2; |
| 99 | v++; | 88 | v++; |
| 100 | } | 89 | } |
| 101 | v->iov_base = (u_int)h_errno < h_nerr ? | 90 | v->iov_base = (char *)hstrerror(h_errno); |
| 102 | h_errlist[h_errno] : "Unknown error"; | ||
| 103 | v->iov_len = strlen(v->iov_base); | 91 | v->iov_len = strlen(v->iov_base); |
| 104 | v++; | 92 | v++; |
| 105 | v->iov_base = "\n"; | 93 | v->iov_base = "\n"; |
| @@ -107,9 +95,12 @@ herror(s) | |||
| 107 | writev(STDERR_FILENO, iov, (v - iov) + 1); | 95 | writev(STDERR_FILENO, iov, (v - iov) + 1); |
| 108 | } | 96 | } |
| 109 | 97 | ||
| 110 | char * | 98 | const char * |
| 111 | hstrerror(err) | 99 | hstrerror(int err) |
| 112 | int err; | ||
| 113 | { | 100 | { |
| 114 | return (u_int)err < h_nerr ? h_errlist[err] : "Unknown resolver error"; | 101 | if (err < 0) |
| 102 | return ("Resolver internal error"); | ||
| 103 | else if (err < h_nerr) | ||
| 104 | return (h_errlist[err]); | ||
| 105 | return ("Unknown resolver error"); | ||
| 115 | } | 106 | } |
