diff options
Diffstat (limited to 'src/lib/libc/net/herror.c')
| -rw-r--r-- | src/lib/libc/net/herror.c | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/lib/libc/net/herror.c b/src/lib/libc/net/herror.c index 41adbf1055..737bb115a7 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.4 1997/03/13 19:07:28 downsj 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: |
| @@ -14,12 +16,12 @@ | |||
| 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. All advertising materials mentioning features or use of this software |
| 16 | * must display the following acknowledgement: | 18 | * must display the following acknowledgement: |
| 17 | * This product includes software developed by the University of | 19 | * This product includes software developed by the University of |
| 18 | * California, Berkeley and its contributors. | 20 | * California, Berkeley and its contributors. |
| 19 | * 4. Neither the name of the University nor the names of its contributors | 21 | * 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 | 22 | * may be used to endorse or promote products derived from this software |
| 21 | * without specific prior written permission. | 23 | * without specific prior written permission. |
| 22 | * | 24 | * |
| 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| @@ -56,26 +58,27 @@ | |||
| 56 | #if defined(LIBC_SCCS) && !defined(lint) | 58 | #if defined(LIBC_SCCS) && !defined(lint) |
| 57 | #if 0 | 59 | #if 0 |
| 58 | static char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93"; | 60 | 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 "; | 61 | static char rcsid[] = "$From: herror.c,v 8.3 1996/08/05 08:31:35 vixie Exp $"; |
| 60 | #else | 62 | #else |
| 61 | static char rcsid[] = "$NetBSD: herror.c,v 1.5 1995/02/25 06:20:39 cgd Exp $"; | 63 | static char rcsid[] = "$OpenBSD: herror.c,v 1.4 1997/03/13 19:07:28 downsj Exp $"; |
| 62 | #endif | 64 | #endif |
| 63 | #endif /* LIBC_SCCS and not lint */ | 65 | #endif /* LIBC_SCCS and not lint */ |
| 64 | 66 | ||
| 65 | #include <sys/types.h> | 67 | #include <sys/types.h> |
| 68 | #include <sys/param.h> | ||
| 66 | #include <sys/uio.h> | 69 | #include <sys/uio.h> |
| 67 | #include <netdb.h> | 70 | #include <netdb.h> |
| 68 | #include <unistd.h> | 71 | #include <unistd.h> |
| 69 | #include <string.h> | 72 | #include <string.h> |
| 70 | 73 | ||
| 71 | char *h_errlist[] = { | 74 | const char *h_errlist[] = { |
| 72 | "Error 0", | 75 | "Resolver Error 0 (no error)", |
| 73 | "Unknown host", /* 1 HOST_NOT_FOUND */ | 76 | "Unknown host", /* 1 HOST_NOT_FOUND */ |
| 74 | "Host name lookup failure", /* 2 TRY_AGAIN */ | 77 | "Host name lookup failure", /* 2 TRY_AGAIN */ |
| 75 | "Unknown server error", /* 3 NO_RECOVERY */ | 78 | "Unknown server error", /* 3 NO_RECOVERY */ |
| 76 | "No address associated with name", /* 4 NO_ADDRESS */ | 79 | "No address associated with name", /* 4 NO_ADDRESS */ |
| 77 | }; | 80 | }; |
| 78 | int h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) }; | 81 | int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] }; |
| 79 | 82 | ||
| 80 | extern int h_errno; | 83 | extern int h_errno; |
| 81 | 84 | ||
| @@ -98,8 +101,7 @@ herror(s) | |||
| 98 | v->iov_len = 2; | 101 | v->iov_len = 2; |
| 99 | v++; | 102 | v++; |
| 100 | } | 103 | } |
| 101 | v->iov_base = (u_int)h_errno < h_nerr ? | 104 | v->iov_base = (char *)hstrerror(h_errno); |
| 102 | h_errlist[h_errno] : "Unknown error"; | ||
| 103 | v->iov_len = strlen(v->iov_base); | 105 | v->iov_len = strlen(v->iov_base); |
| 104 | v++; | 106 | v++; |
| 105 | v->iov_base = "\n"; | 107 | v->iov_base = "\n"; |
| @@ -107,9 +109,13 @@ herror(s) | |||
| 107 | writev(STDERR_FILENO, iov, (v - iov) + 1); | 109 | writev(STDERR_FILENO, iov, (v - iov) + 1); |
| 108 | } | 110 | } |
| 109 | 111 | ||
| 110 | char * | 112 | const char * |
| 111 | hstrerror(err) | 113 | hstrerror(err) |
| 112 | int err; | 114 | int err; |
| 113 | { | 115 | { |
| 114 | return (u_int)err < h_nerr ? h_errlist[err] : "Unknown resolver error"; | 116 | if (err < 0) |
| 117 | return ("Resolver internal error"); | ||
| 118 | else if (err < h_nerr) | ||
| 119 | return (h_errlist[err]); | ||
| 120 | return ("Unknown resolver error"); | ||
| 115 | } | 121 | } |
