3 Errors and warnings... */
6 * Copyright (c) 1996 The Internet Software Consortium.
8 * Copyright (c) 1995 RadioMail Corporation. All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of RadioMail Corporation, the Internet Software
20 * Consortium nor the names of its contributors may be used to endorse
21 * or promote products derived from this software without specific
22 * prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY RADIOMAIL CORPORATION, THE INTERNET
25 * SOFTWARE CONSORTIUM AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL RADIOMAIL CORPORATION OR CONTRIBUTORS
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
35 * OF THE POSSIBILITY OF SUCH DAMAGE.
37 * This software was written for RadioMail Corporation by Ted Lemon
38 * under a contract with Vixie Enterprises. Further modifications have
39 * been made for the Internet Software Consortium under a contract
40 * with Vixie Laboratories.
44 static char copyright[] =
45 "$Id: errwarn.c,v 1.15 1997/05/09 08:03:44 mellon Exp $ Copyright (c) 1996 The Internet Software Consortium. All rights reserved.\n";
51 static void do_percentm PROTO ((char *obuf, char *ibuf));
53 static char mbuf [1024];
54 static char fbuf [1024];
56 int warnings_occurred;
58 /* Log an error message, then exit... */
60 void error (ANSI_DECL(char *) fmt, VA_DOTDOTDOT)
67 do_percentm (fbuf, fmt);
70 vsnprintf (mbuf, sizeof mbuf, fbuf, list);
74 syslog (log_priority | LOG_ERR, mbuf);
77 /* Also log it to stderr? */
79 write (2, mbuf, strlen (mbuf));
83 syslog (LOG_CRIT, "exiting.");
85 fprintf (stderr, "exiting.\n");
92 /* Log a warning message... */
94 int warn (ANSI_DECL (char *) fmt, VA_DOTDOTDOT)
100 do_percentm (fbuf, fmt);
102 VA_start (list, fmt);
103 vsnprintf (mbuf, sizeof mbuf, fbuf, list);
107 syslog (log_priority | LOG_ERR, mbuf);
111 write (2, mbuf, strlen (mbuf));
120 int note (ANSI_DECL (char *) fmt, VA_DOTDOTDOT)
126 do_percentm (fbuf, fmt);
128 VA_start (list, fmt);
129 vsnprintf (mbuf, sizeof mbuf, fbuf, list);
133 syslog (log_priority | LOG_INFO, mbuf);
137 write (2, mbuf, strlen (mbuf));
144 /* Log a debug message... */
146 int debug (ANSI_DECL (char *) fmt, VA_DOTDOTDOT)
152 do_percentm (fbuf, fmt);
154 VA_start (list, fmt);
155 vsnprintf (mbuf, sizeof mbuf, fbuf, list);
159 syslog (log_priority | LOG_DEBUG, mbuf);
163 write (2, mbuf, strlen (mbuf));
170 /* Find %m in the input string and substitute an error message string. */
172 static void do_percentm (obuf, ibuf)
188 m = strerror (errno);
193 m = "<unknown error>";
213 int parse_warn (ANSI_DECL (char *) fmt, VA_DOTDOTDOT)
218 static char spaces [] = " ";
220 do_percentm (mbuf, fmt);
222 snprintf (fbuf, sizeof fbuf, "%s line %d: %s",
223 tlname, lexline, mbuf);
225 sprintf (fbuf, "%s line %d: %s",
226 tlname, lexline, mbuf);
229 VA_start (list, fmt);
230 vsnprintf (mbuf, sizeof mbuf, fbuf, list);
234 syslog (log_priority | LOG_ERR, mbuf);
235 syslog (log_priority | LOG_ERR, token_line);
237 syslog (log_priority | LOG_ERR,
238 "%s^", &spaces [sizeof spaces - lexchar]);
242 write (2, mbuf, strlen (mbuf));
244 write (2, token_line, strlen (token_line));
246 write (2, spaces, lexchar - 1);
250 warnings_occurred = 1;
259 extern char *sys_errlist [];
261 static char errbuf [128];
263 if (err < 0 || err >= sys_nerr) {
264 sprintf (errbuf, "Error %d", err);
267 return sys_errlist [err];
269 #endif /* NO_STRERROR */
274 int err = WSAGetLastError ();
279 return "Permission denied";
281 return "Address already in use";
282 case WSAEADDRNOTAVAIL:
283 return "Cannot assign requested address";
284 case WSAEAFNOSUPPORT:
285 return "Address family not supported by protocol family";
287 return "Operation already in progress";
288 case WSAECONNABORTED:
289 return "Software caused connection abort";
290 case WSAECONNREFUSED:
291 return "Connection refused";
293 return "Connection reset by peer";
294 case WSAEDESTADDRREQ:
295 return "Destination address required";
297 return "Bad address";
299 return "Host is down";
300 case WSAEHOSTUNREACH:
301 return "No route to host";
303 return "Operation now in progress";
305 return "Interrupted function call";
307 return "Invalid argument";
309 return "Socket is already connected";
311 return "Too many open files";
313 return "Message too long";
315 return "Network is down";
317 return "Network dropped connection on reset";
319 return "Network is unreachable";
321 return "No buffer space available";
323 return "Bad protocol option";
325 return "Socket is not connected";
327 return "Socket operation on non-socket";
329 return "Operation not supported";
330 case WSAEPFNOSUPPORT:
331 return "Protocol family not supported";
333 return "Too many processes";
334 case WSAEPROTONOSUPPORT:
335 return "Protocol not supported";
337 return "Protocol wrong type for socket";
339 return "Cannot send after socket shutdown";
340 case WSAESOCKTNOSUPPORT:
341 return "Socket type not supported";
343 return "Connection timed out";
345 return "Resource temporarily unavailable";
346 case WSAHOST_NOT_FOUND:
347 return "Host not found";
349 case WSA_INVALID_HANDLE:
350 return "Specified event object handle is invalid";
351 case WSA_INVALID_PARAMETER:
352 return "One or more parameters are invalid";
353 case WSAINVALIDPROCTABLE:
354 return "Invalid procedure table from service provider";
355 case WSAINVALIDPROVIDER:
356 return "Invalid service provider version number";
358 return "Overlapped operations will complete later";
359 case WSA_IO_INCOMPLETE:
360 return "Overlapped I/O event object not in signaled state";
361 case WSA_NOT_ENOUGH_MEMORY:
362 return "Insufficient memory available";
364 case WSANOTINITIALISED:
365 return "Successful WSAStartup not yet performer";
367 return "Valid name, no data record of requested type";
369 return "This is a non-recoverable error";
371 case WSAPROVIDERFAILEDINIT:
372 return "Unable to initialize a service provider";
373 case WSASYSCALLFAILURE:
374 return "System call failure";
377 return "Network subsystem is unavailable";
379 return "Non-authoritative host not found";
380 case WSAVERNOTSUPPORTED:
381 return "WINSOCK.DLL version out of range";
383 return "Graceful shutdown in progress";
385 case WSA_OPERATION_ABORTED:
386 return "Overlapped operation aborted";
389 return "Unknown WinSock error";