]> git.ipfire.org Git - thirdparty/dhcp.git/blob - omapip/errwarn.c
- Provide information on how to get support (and how not to) if the server
[thirdparty/dhcp.git] / omapip / errwarn.c
1 /* errwarn.c
2
3 Errors and warnings... */
4
5 /*
6 * Copyright (c) 1995 RadioMail Corporation.
7 * Copyright (c) 1996-2000 Internet Software Consortium.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
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 The Internet Software Consortium nor the names
20 * of its contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
24 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
31 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
34 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
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.
41 */
42
43 #ifndef lint
44 static char copyright[] =
45 "$Id: errwarn.c,v 1.6 2000/09/01 23:04:37 mellon Exp $ Copyright (c) 1996 The Internet Software Consortium. All rights reserved.\n";
46 #endif /* not lint */
47
48 #include <omapip/omapip_p.h>
49 #include <errno.h>
50
51 #ifdef DEBUG
52 int log_perror = -1;
53 #else
54 int log_perror = 1;
55 #endif
56 int log_priority;
57 void (*log_cleanup) (void);
58
59 static char mbuf [1024];
60 static char fbuf [1024];
61
62 /* Log an error message, then exit... */
63
64 void log_fatal (const char * fmt, ... )
65 {
66 va_list list;
67
68 do_percentm (fbuf, fmt);
69
70 va_start (list, fmt);
71 vsnprintf (mbuf, sizeof mbuf, fbuf, list);
72 va_end (list);
73
74 #ifndef DEBUG
75 syslog (log_priority | LOG_ERR, "%s", mbuf);
76 #endif
77
78 /* Also log it to stderr? */
79 if (log_perror) {
80 write (2, mbuf, strlen (mbuf));
81 write (2, "\n", 1);
82 }
83
84 #if !defined (NOMINUM)
85 log_error ("If you did not get this software from ftp.isc.org, please");
86 log_error ("get the latest from ftp.isc.org and install that before");
87 log_error ("requesting help.");
88 log_error ("If you did get this software from ftp.isc.org and have not");
89 log_error ("yet read the README, please read it before requesting help.");
90 log_error ("If you intend to request help from the dhcp-server@isc.org");
91 log_error ("mailing list, please read the section on the README about");
92 log_error ("submitting bug reports and requests for help.");
93 log_error ("");
94 log_error ("exiting.");
95 #endif
96 if (log_cleanup)
97 (*log_cleanup) ();
98 exit (1);
99 }
100
101 /* Log an error message... */
102
103 int log_error (const char * fmt, ...)
104 {
105 va_list list;
106
107 do_percentm (fbuf, fmt);
108
109 va_start (list, fmt);
110 vsnprintf (mbuf, sizeof mbuf, fbuf, list);
111 va_end (list);
112
113 #ifndef DEBUG
114 syslog (log_priority | LOG_ERR, "%s", mbuf);
115 #endif
116
117 if (log_perror) {
118 write (2, mbuf, strlen (mbuf));
119 write (2, "\n", 1);
120 }
121
122 return 0;
123 }
124
125 /* Log a note... */
126
127 int log_info (const char *fmt, ...)
128 {
129 va_list list;
130
131 do_percentm (fbuf, fmt);
132
133 va_start (list, fmt);
134 vsnprintf (mbuf, sizeof mbuf, fbuf, list);
135 va_end (list);
136
137 #ifndef DEBUG
138 syslog (log_priority | LOG_INFO, "%s", mbuf);
139 #endif
140
141 if (log_perror) {
142 write (2, mbuf, strlen (mbuf));
143 write (2, "\n", 1);
144 }
145
146 return 0;
147 }
148
149 /* Log a debug message... */
150
151 int log_debug (const char *fmt, ...)
152 {
153 va_list list;
154
155 do_percentm (fbuf, fmt);
156
157 va_start (list, fmt);
158 vsnprintf (mbuf, sizeof mbuf, fbuf, list);
159 va_end (list);
160
161 #ifndef DEBUG
162 syslog (log_priority | LOG_DEBUG, "%s", mbuf);
163 #endif
164
165 if (log_perror) {
166 write (2, mbuf, strlen (mbuf));
167 write (2, "\n", 1);
168 }
169
170 return 0;
171 }
172
173 /* Find %m in the input string and substitute an error message string. */
174
175 void do_percentm (obuf, ibuf)
176 char *obuf;
177 const char *ibuf;
178 {
179 const char *s = ibuf;
180 char *p = obuf;
181 int infmt = 0;
182 const char *m;
183
184 while (*s)
185 {
186 if (infmt)
187 {
188 if (*s == 'm')
189 {
190 #ifndef __CYGWIN32__
191 m = strerror (errno);
192 #else
193 m = pWSAError ();
194 #endif
195 if (!m)
196 m = "<unknown error>";
197 strcpy (p - 1, m);
198 p += strlen (p);
199 ++s;
200 }
201 else
202 *p++ = *s++;
203 infmt = 0;
204 }
205 else
206 {
207 if (*s == '%')
208 infmt = 1;
209 *p++ = *s++;
210 }
211 }
212 *p = 0;
213 }
214
215 #ifdef NO_STRERROR
216 char *strerror (err)
217 int err;
218 {
219 extern char *sys_errlist [];
220 extern int sys_nerr;
221 static char errbuf [128];
222
223 if (err < 0 || err >= sys_nerr) {
224 sprintf (errbuf, "Error %d", err);
225 return errbuf;
226 }
227 return sys_errlist [err];
228 }
229 #endif /* NO_STRERROR */
230
231 #ifdef _WIN32
232 char *pWSAError ()
233 {
234 int err = WSAGetLastError ();
235
236 switch (err)
237 {
238 case WSAEACCES:
239 return "Permission denied";
240 case WSAEADDRINUSE:
241 return "Address already in use";
242 case WSAEADDRNOTAVAIL:
243 return "Cannot assign requested address";
244 case WSAEAFNOSUPPORT:
245 return "Address family not supported by protocol family";
246 case WSAEALREADY:
247 return "Operation already in progress";
248 case WSAECONNABORTED:
249 return "Software caused connection abort";
250 case WSAECONNREFUSED:
251 return "Connection refused";
252 case WSAECONNRESET:
253 return "Connection reset by peer";
254 case WSAEDESTADDRREQ:
255 return "Destination address required";
256 case WSAEFAULT:
257 return "Bad address";
258 case WSAEHOSTDOWN:
259 return "Host is down";
260 case WSAEHOSTUNREACH:
261 return "No route to host";
262 case WSAEINPROGRESS:
263 return "Operation now in progress";
264 case WSAEINTR:
265 return "Interrupted function call";
266 case WSAEINVAL:
267 return "Invalid argument";
268 case WSAEISCONN:
269 return "Socket is already connected";
270 case WSAEMFILE:
271 return "Too many open files";
272 case WSAEMSGSIZE:
273 return "Message too long";
274 case WSAENETDOWN:
275 return "Network is down";
276 case WSAENETRESET:
277 return "Network dropped connection on reset";
278 case WSAENETUNREACH:
279 return "Network is unreachable";
280 case WSAENOBUFS:
281 return "No buffer space available";
282 case WSAENOPROTOOPT:
283 return "Bad protocol option";
284 case WSAENOTCONN:
285 return "Socket is not connected";
286 case WSAENOTSOCK:
287 return "Socket operation on non-socket";
288 case WSAEOPNOTSUPP:
289 return "Operation not supported";
290 case WSAEPFNOSUPPORT:
291 return "Protocol family not supported";
292 case WSAEPROCLIM:
293 return "Too many processes";
294 case WSAEPROTONOSUPPORT:
295 return "Protocol not supported";
296 case WSAEPROTOTYPE:
297 return "Protocol wrong type for socket";
298 case WSAESHUTDOWN:
299 return "Cannot send after socket shutdown";
300 case WSAESOCKTNOSUPPORT:
301 return "Socket type not supported";
302 case WSAETIMEDOUT:
303 return "Connection timed out";
304 case WSAEWOULDBLOCK:
305 return "Resource temporarily unavailable";
306 case WSAHOST_NOT_FOUND:
307 return "Host not found";
308 #if 0
309 case WSA_INVALID_HANDLE:
310 return "Specified event object handle is invalid";
311 case WSA_INVALID_PARAMETER:
312 return "One or more parameters are invalid";
313 case WSAINVALIDPROCTABLE:
314 return "Invalid procedure table from service provider";
315 case WSAINVALIDPROVIDER:
316 return "Invalid service provider version number";
317 case WSA_IO_PENDING:
318 return "Overlapped operations will complete later";
319 case WSA_IO_INCOMPLETE:
320 return "Overlapped I/O event object not in signaled state";
321 case WSA_NOT_ENOUGH_MEMORY:
322 return "Insufficient memory available";
323 #endif
324 case WSANOTINITIALISED:
325 return "Successful WSAStartup not yet performer";
326 case WSANO_DATA:
327 return "Valid name, no data record of requested type";
328 case WSANO_RECOVERY:
329 return "This is a non-recoverable error";
330 #if 0
331 case WSAPROVIDERFAILEDINIT:
332 return "Unable to initialize a service provider";
333 case WSASYSCALLFAILURE:
334 return "System call failure";
335 #endif
336 case WSASYSNOTREADY:
337 return "Network subsystem is unavailable";
338 case WSATRY_AGAIN:
339 return "Non-authoritative host not found";
340 case WSAVERNOTSUPPORTED:
341 return "WINSOCK.DLL version out of range";
342 case WSAEDISCON:
343 return "Graceful shutdown in progress";
344 #if 0
345 case WSA_OPERATION_ABORTED:
346 return "Overlapped operation aborted";
347 #endif
348 }
349 return "Unknown WinSock error";
350 }
351 #endif /* _WIN32 */