revert between 56095 -> 55830 in arch
[AROS.git] / workbench / network / stacks / AROSTCP / dhcp / omapip / errwarn.c
blobf1ee6fe5462c1a68d69ebcd9a19aacdd6eee8fb9
1 /* errwarn.c
3 Errors and warnings... */
5 /*
6 * Copyright (c) 1995 RadioMail Corporation.
7 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
8 * Copyright (c) 1996-2003 by Internet Software Consortium
10 * Permission to use, copy, modify, and distribute this software for any
11 * purpose with or without fee is hereby granted, provided that the above
12 * copyright notice and this permission notice appear in all copies.
14 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
15 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
17 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
20 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 * Internet Systems Consortium, Inc.
23 * 950 Charter Street
24 * Redwood City, CA 94063
25 * <info@isc.org>
26 * http://www.isc.org/
28 * This software was written for RadioMail Corporation by Ted Lemon
29 * under a contract with Vixie Enterprises. Further modifications have
30 * been made for Internet Systems Consortium under a contract
31 * with Vixie Laboratories.
34 #if 0
35 static char copyright[] =
36 "$Id$ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n";
37 #endif
39 #include <omapip/omapip_p.h>
40 #include <errno.h>
42 #ifdef DEBUG
43 int log_perror = -1;
44 #else
45 int log_perror = 1;
46 #endif
47 int log_priority;
48 void (*log_cleanup) (void);
50 #define CVT_BUF_MAX 1023
51 static char mbuf [CVT_BUF_MAX + 1];
52 static char fbuf [CVT_BUF_MAX + 1];
54 /* Log an error message, then exit... */
56 void log_fatal (const char * fmt, ... )
58 va_list list;
60 do_percentm (fbuf, fmt);
62 /* %Audit% This is log output. %2004.06.17,Safe%
63 * If we truncate we hope the user can get a hint from the log.
65 va_start (list, fmt);
66 vsnprintf (mbuf, sizeof mbuf, fbuf, list);
67 va_end (list);
69 #ifndef DEBUG
70 syslog (log_priority | LOG_ERR, "%s", mbuf);
71 #endif
73 /* Also log it to stderr? */
74 if (log_perror) {
75 write (STDERR_FILENO, mbuf, strlen (mbuf));
76 write (STDERR_FILENO, "\n", 1);
79 #if !defined (NOMINUM)
80 log_error ("%s", "");
81 log_error ("If you did not get this software from ftp.isc.org, please");
82 log_error ("get the latest from ftp.isc.org and install that before");
83 log_error ("requesting help.");
84 log_error ("%s", "");
85 log_error ("If you did get this software from ftp.isc.org and have not");
86 log_error ("yet read the README, please read it before requesting help.");
87 log_error ("If you intend to request help from the dhcp-server@isc.org");
88 log_error ("mailing list, please read the section on the README about");
89 log_error ("submitting bug reports and requests for help.");
90 log_error ("%s", "");
91 log_error ("Please do not under any circumstances send requests for");
92 log_error ("help directly to the authors of this software - please");
93 log_error ("send them to the appropriate mailing list as described in");
94 log_error ("the README file.");
95 log_error ("%s", "");
96 log_error ("exiting.");
97 #endif
98 if (log_cleanup)
99 (*log_cleanup) ();
100 exit (1);
103 /* Log an error message... */
105 int log_error (const char * fmt, ...)
107 va_list list;
109 do_percentm (fbuf, fmt);
111 /* %Audit% This is log output. %2004.06.17,Safe%
112 * If we truncate we hope the user can get a hint from the log.
114 va_start (list, fmt);
115 vsnprintf (mbuf, sizeof mbuf, fbuf, list);
116 va_end (list);
118 #ifndef DEBUG
119 syslog (log_priority | LOG_ERR, "%s", mbuf);
120 #endif
122 if (log_perror) {
123 write (STDERR_FILENO, mbuf, strlen (mbuf));
124 write (STDERR_FILENO, "\n", 1);
127 return 0;
130 /* Log a note... */
132 int log_info (const char *fmt, ...)
134 va_list list;
136 do_percentm (fbuf, fmt);
138 /* %Audit% This is log output. %2004.06.17,Safe%
139 * If we truncate we hope the user can get a hint from the log.
141 va_start (list, fmt);
142 vsnprintf (mbuf, sizeof mbuf, fbuf, list);
143 va_end (list);
145 #ifndef DEBUG
146 syslog (log_priority | LOG_INFO, "%s", mbuf);
147 #endif
149 if (log_perror) {
150 write (STDERR_FILENO, mbuf, strlen (mbuf));
151 write (STDERR_FILENO, "\n", 1);
154 return 0;
157 /* Log a debug message... */
159 int log_debug (const char *fmt, ...)
161 va_list list;
163 do_percentm (fbuf, fmt);
165 /* %Audit% This is log output. %2004.06.17,Safe%
166 * If we truncate we hope the user can get a hint from the log.
168 va_start (list, fmt);
169 vsnprintf (mbuf, sizeof mbuf, fbuf, list);
170 va_end (list);
172 #ifndef DEBUG
173 syslog (log_priority | LOG_DEBUG, "%s", mbuf);
174 #endif
176 if (log_perror) {
177 write (STDERR_FILENO, mbuf, strlen (mbuf));
178 write (STDERR_FILENO, "\n", 1);
181 return 0;
184 /* Find %m in the input string and substitute an error message string. */
186 void do_percentm (obuf, ibuf)
187 char *obuf;
188 const char *ibuf;
190 const char *s = ibuf;
191 char *p = obuf;
192 int infmt = 0;
193 const char *m;
194 int len = 0;
196 while (*s) {
197 if (infmt) {
198 if (*s == 'm') {
199 #ifndef __CYGWIN32__
200 m = strerror (errno);
201 #else
202 m = pWSAError ();
203 #endif
204 if (!m)
205 m = "<unknown error>";
206 len += strlen (m);
207 if (len > CVT_BUF_MAX)
208 goto out;
209 strcpy (p - 1, m);
210 p += strlen (p);
211 ++s;
212 } else {
213 if (++len > CVT_BUF_MAX)
214 goto out;
215 *p++ = *s++;
217 infmt = 0;
218 } else {
219 if (*s == '%')
220 infmt = 1;
221 if (++len > CVT_BUF_MAX)
222 goto out;
223 *p++ = *s++;
226 out:
227 *p = 0;
230 #ifdef NO_STRERROR
231 char *strerror (err)
232 int err;
234 extern char *sys_errlist [];
235 extern int sys_nerr;
236 static char errbuf [128];
238 if (err < 0 || err >= sys_nerr) {
239 sprintf (errbuf, "Error %d", err);
240 return errbuf;
242 return sys_errlist [err];
244 #endif /* NO_STRERROR */
246 #ifdef _WIN32
247 char *pWSAError ()
249 int err = WSAGetLastError ();
251 switch (err)
253 case WSAEACCES:
254 return "Permission denied";
255 case WSAEADDRINUSE:
256 return "Address already in use";
257 case WSAEADDRNOTAVAIL:
258 return "Cannot assign requested address";
259 case WSAEAFNOSUPPORT:
260 return "Address family not supported by protocol family";
261 case WSAEALREADY:
262 return "Operation already in progress";
263 case WSAECONNABORTED:
264 return "Software caused connection abort";
265 case WSAECONNREFUSED:
266 return "Connection refused";
267 case WSAECONNRESET:
268 return "Connection reset by peer";
269 case WSAEDESTADDRREQ:
270 return "Destination address required";
271 case WSAEFAULT:
272 return "Bad address";
273 case WSAEHOSTDOWN:
274 return "Host is down";
275 case WSAEHOSTUNREACH:
276 return "No route to host";
277 case WSAEINPROGRESS:
278 return "Operation now in progress";
279 case WSAEINTR:
280 return "Interrupted function call";
281 case WSAEINVAL:
282 return "Invalid argument";
283 case WSAEISCONN:
284 return "Socket is already connected";
285 case WSAEMFILE:
286 return "Too many open files";
287 case WSAEMSGSIZE:
288 return "Message too long";
289 case WSAENETDOWN:
290 return "Network is down";
291 case WSAENETRESET:
292 return "Network dropped connection on reset";
293 case WSAENETUNREACH:
294 return "Network is unreachable";
295 case WSAENOBUFS:
296 return "No buffer space available";
297 case WSAENOPROTOOPT:
298 return "Bad protocol option";
299 case WSAENOTCONN:
300 return "Socket is not connected";
301 case WSAENOTSOCK:
302 return "Socket operation on non-socket";
303 case WSAEOPNOTSUPP:
304 return "Operation not supported";
305 case WSAEPFNOSUPPORT:
306 return "Protocol family not supported";
307 case WSAEPROCLIM:
308 return "Too many processes";
309 case WSAEPROTONOSUPPORT:
310 return "Protocol not supported";
311 case WSAEPROTOTYPE:
312 return "Protocol wrong type for socket";
313 case WSAESHUTDOWN:
314 return "Cannot send after socket shutdown";
315 case WSAESOCKTNOSUPPORT:
316 return "Socket type not supported";
317 case WSAETIMEDOUT:
318 return "Connection timed out";
319 case WSAEWOULDBLOCK:
320 return "Resource temporarily unavailable";
321 case WSAHOST_NOT_FOUND:
322 return "Host not found";
323 #if 0
324 case WSA_INVALID_HANDLE:
325 return "Specified event object handle is invalid";
326 case WSA_INVALID_PARAMETER:
327 return "One or more parameters are invalid";
328 case WSAINVALIDPROCTABLE:
329 return "Invalid procedure table from service provider";
330 case WSAINVALIDPROVIDER:
331 return "Invalid service provider version number";
332 case WSA_IO_PENDING:
333 return "Overlapped operations will complete later";
334 case WSA_IO_INCOMPLETE:
335 return "Overlapped I/O event object not in signaled state";
336 case WSA_NOT_ENOUGH_MEMORY:
337 return "Insufficient memory available";
338 #endif
339 case WSANOTINITIALISED:
340 return "Successful WSAStartup not yet performer";
341 case WSANO_DATA:
342 return "Valid name, no data record of requested type";
343 case WSANO_RECOVERY:
344 return "This is a non-recoverable error";
345 #if 0
346 case WSAPROVIDERFAILEDINIT:
347 return "Unable to initialize a service provider";
348 case WSASYSCALLFAILURE:
349 return "System call failure";
350 #endif
351 case WSASYSNOTREADY:
352 return "Network subsystem is unavailable";
353 case WSATRY_AGAIN:
354 return "Non-authoritative host not found";
355 case WSAVERNOTSUPPORTED:
356 return "WINSOCK.DLL version out of range";
357 case WSAEDISCON:
358 return "Graceful shutdown in progress";
359 #if 0
360 case WSA_OPERATION_ABORTED:
361 return "Overlapped operation aborted";
362 #endif
364 return "Unknown WinSock error";
366 #endif /* _WIN32 */