1 const char errlog_rcs[] = "$Id: errlog.c,v 2.1 2002/09/25 12:51:21 oes Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/src/errlog.c,v $
6 * Purpose : Log errors to a designated destination in an elegant,
9 * Copyright : Written by and Copyright (C) 2001 the SourceForge
10 * Privoxy team. http://www.privoxy.org/
12 * Based on the Internet Junkbuster originally written
13 * by and Copyright (C) 1997 Anonymous Coders and
14 * Junkbusters Corporation. http://www.junkbusters.com
16 * This program is free software; you can redistribute it
17 * and/or modify it under the terms of the GNU General
18 * Public License as published by the Free Software
19 * Foundation; either version 2 of the License, or (at
20 * your option) any later version.
22 * This program is distributed in the hope that it will
23 * be useful, but WITHOUT ANY WARRANTY; without even the
24 * implied warranty of MERCHANTABILITY or FITNESS FOR A
25 * PARTICULAR PURPOSE. See the GNU General Public
26 * License for more details.
28 * The GNU General Public License should be included with
29 * this file. If not, you can view it at
30 * http://www.gnu.org/copyleft/gpl.html
31 * or write to the Free Software Foundation, Inc., 59
32 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 * Revision 2.1 2002/09/25 12:51:21 oes
37 * Made log_error safe against NULL string arguments
39 * Revision 2.0 2002/06/04 14:34:21 jongfoster
40 * Moving source files to src/
42 * Revision 1.40 2002/05/22 01:27:27 david__schmidt
44 * Add os2_socket_strerr mirroring w32_socket_strerr.
46 * Revision 1.39 2002/04/03 17:15:27 gliptak
47 * zero padding thread ids in log
49 * Revision 1.38 2002/03/31 17:18:59 jongfoster
50 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
52 * Revision 1.37 2002/03/27 14:32:43 david__schmidt
53 * More compiler warning message maintenance
55 * Revision 1.36 2002/03/26 22:29:54 swa
56 * we have a new homepage!
58 * Revision 1.35 2002/03/24 15:23:33 jongfoster
61 * Revision 1.34 2002/03/24 13:25:43 swa
62 * name change related issues
64 * Revision 1.33 2002/03/13 00:27:04 jongfoster
67 * Revision 1.32 2002/03/07 03:46:17 oes
68 * Fixed compiler warnings
70 * Revision 1.31 2002/03/06 23:02:57 jongfoster
73 * Revision 1.30 2002/03/05 22:43:45 david__schmidt
74 * - Better error reporting on OS/2
75 * - Fix double-slash comment (oops)
77 * Revision 1.29 2002/03/04 23:45:13 jongfoster
78 * Printing thread ID if using Win32 native threads
80 * Revision 1.28 2002/03/04 17:59:59 oes
81 * Deleted deletePidFile(), cosmetics
83 * Revision 1.27 2002/03/04 02:08:01 david__schmidt
84 * Enable web editing of actions file on OS/2 (it had been broken all this time!)
86 * Revision 1.26 2002/01/09 19:05:45 steudten
87 * Fix big memory leak.
89 * Revision 1.25 2002/01/09 14:32:08 oes
90 * Added support for gmtime_r and localtime_r.
92 * Revision 1.24 2001/12/30 14:07:32 steudten
93 * - Add signal handling (unix)
94 * - Add SIGHUP handler (unix)
95 * - Add creation of pidfile (unix)
96 * - Add action 'top' in rc file (RH)
97 * - Add entry 'SIGNALS' to manpage
98 * - Add exit message to logfile (unix)
100 * Revision 1.23 2001/11/07 00:02:13 steudten
101 * Add line number in error output for lineparsing for
102 * actionsfile and configfile.
103 * Special handling for CLF added.
105 * Revision 1.22 2001/11/05 23:43:05 steudten
106 * Add time+date to log files.
108 * Revision 1.21 2001/10/25 03:40:47 david__schmidt
109 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
110 * threads to call select() simultaneously. So, it's time to do a real, live,
111 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
112 * (native). Both versions will work, but using __OS2__ offers multi-threading.
114 * Revision 1.20 2001/09/16 23:04:34 jongfoster
117 * Revision 1.19 2001/09/13 20:08:06 jongfoster
118 * Adding support for LOG_LEVEL_CGI
120 * Revision 1.18 2001/09/10 11:27:24 oes
121 * Declaration of w32_socket_strerr now conditional
123 * Revision 1.17 2001/09/10 10:17:13 oes
124 * Removed unused variable; Fixed sprintf format
126 * Revision 1.16 2001/07/30 22:08:36 jongfoster
127 * Tidying up #defines:
128 * - All feature #defines are now of the form FEATURE_xxx
129 * - Permanently turned off WIN_GUI_EDIT
130 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
132 * Revision 1.15 2001/07/29 17:41:10 jongfoster
133 * Now prints thread ID for each message (pthreads only)
135 * Revision 1.14 2001/07/19 19:03:48 haroon
136 * - Added case for LOG_LEVEL_POPUPS
138 * Revision 1.13 2001/07/13 13:58:58 oes
139 * - Added case for LOG_LEVEL_DEANIMATE
140 * - Removed all #ifdef PCRS
142 * Revision 1.12 2001/06/09 10:55:28 jongfoster
143 * Changing BUFSIZ ==> BUFFER_SIZE
145 * Revision 1.11 2001/06/01 18:14:49 jongfoster
146 * Changing the calls to strerr() to check HAVE_STRERR (which is defined
147 * in config.h if appropriate) rather than the NO_STRERR macro.
149 * Revision 1.10 2001/05/29 11:52:21 oes
150 * Conditional compilation of w32_socket_error
152 * Revision 1.9 2001/05/28 16:15:17 jongfoster
153 * Improved reporting of errors under Win32.
155 * Revision 1.8 2001/05/26 17:25:14 jongfoster
156 * Added support for CLF (Common Log Format) and fixed LOG_LEVEL_LOG
158 * Revision 1.7 2001/05/26 15:21:28 jongfoster
159 * Activity animation in Win32 GUI now works even if debug==0
161 * Revision 1.6 2001/05/25 21:55:08 jongfoster
162 * Now cleans up properly on FATAL (removes taskbar icon etc)
164 * Revision 1.5 2001/05/22 18:46:04 oes
166 * - Enabled filtering banners by size rather than URL
167 * by adding patterns that replace all standard banner
168 * sizes with the "Junkbuster" gif to the re_filterfile
170 * - Enabled filtering WebBugs by providing a pattern
171 * which kills all 1x1 images
173 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
174 * which is selected by the (nonstandard and therefore
175 * capital) letter 'U' in the option string.
176 * It causes the quantifiers to be ungreedy by default.
177 * Appending a ? turns back to greedy (!).
179 * - Added a new interceptor ijb-send-banner, which
180 * sends back the "Junkbuster" gif. Without imagelist or
181 * MSIE detection support, or if tinygif = 1, or the
182 * URL isn't recognized as an imageurl, a lame HTML
183 * explanation is sent instead.
185 * - Added new feature, which permits blocking remote
186 * script redirects and firing back a local redirect
188 * The feature is conditionally compiled, i.e. it
189 * can be disabled with --disable-fast-redirects,
190 * plus it must be activated by a "fast-redirects"
191 * line in the config file, has its own log level
192 * and of course wants to be displayed by show-proxy-args
193 * Note: Boy, all the #ifdefs in 1001 locations and
194 * all the fumbling with configure.in and acconfig.h
195 * were *way* more work than the feature itself :-(
197 * - Because a generic redirect template was needed for
198 * this, tinygif = 3 now uses the same.
200 * - Moved GIFs, and other static HTTP response templates
205 * - Removed some >400 CRs again (Jon, you really worked
208 * Revision 1.4 2001/05/21 19:32:54 jongfoster
209 * Added another #ifdef _WIN_CONSOLE
211 * Revision 1.3 2001/05/20 01:11:40 jongfoster
212 * Added support for LOG_LEVEL_FATAL
213 * Renamed LOG_LEVEL_FRC to LOG_LEVEL_FORCE,
214 * and LOG_LEVEL_REF to LOG_LEVEL_RE_FILTER
216 * Revision 1.2 2001/05/17 22:42:01 oes
217 * - Cleaned CRLF's from the sources and related files
218 * - Repaired logging for REF and FRC
220 * Revision 1.1.1.1 2001/05/15 13:58:51 oes
221 * Initial import of version 2.9.3 source tree
224 *********************************************************************/
228 #include "miscutil.h"
235 #if !defined(_WIN32) && !defined(__OS2__)
237 #endif /* !defined(_WIN32) && !defined(__OS2__) */
241 #ifdef FEATURE_PTHREAD
243 #endif /* def FEATURE_PTHREAD */
252 #endif /* ndef _WIN_CONSOLE */
253 #endif /* def _WIN32 */
256 #include <sys/socket.h> /* For sock_errno */
265 const char errlog_h_rcs[] = ERRLOG_H_VERSION;
269 * LOG_LEVEL_FATAL cannot be turned off. (There are
270 * some exceptional situations where we need to get a
271 * message to the user).
273 #define LOG_LEVEL_MINIMUM LOG_LEVEL_FATAL
275 /* where to log (default: stderr) */
276 static FILE *logfp = NULL;
278 /* logging detail level. */
279 static int debug = (LOG_LEVEL_FATAL | LOG_LEVEL_ERROR | LOG_LEVEL_INFO);
281 /* static functions */
282 static void fatal_error(const char * error_message);
284 static char *w32_socket_strerr(int errcode, char *tmp_buf);
287 static char *os2_socket_strerr(int errcode, char *tmp_buf);
290 /*********************************************************************
292 * Function : fatal_error
294 * Description : Displays a fatal error to standard error (or, on
295 * a WIN32 GUI, to a dialog box), and exits
296 * JunkBuster with status code 1.
299 * 1 : error_message = The error message to display.
301 * Returns : Does not return.
303 *********************************************************************/
304 static void fatal_error(const char * error_message)
306 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
307 MessageBox(g_hwndLogFrame, error_message, "Privoxy Error",
308 MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND | MB_TOPMOST);
310 /* Cleanup - remove taskbar icon etc. */
313 #else /* if !defined(_WIN32) || defined(_WIN_CONSOLE) */
314 fputs(error_message, stderr);
315 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
325 /*********************************************************************
327 * Function : init_error_log
329 * Description : Initializes the logging module. Must call before
333 * 1 : prog_name = The program name.
334 * 2 : logfname = The logfile name, or NULL for stderr.
335 * 3 : debuglevel = The debugging level.
339 *********************************************************************/
340 void init_error_log(const char *prog_name, const char *logfname, int debuglevel)
344 /* FIXME RACE HAZARD: should start critical section error_log_use here */
346 /* set the logging detail level */
347 debug = debuglevel | LOG_LEVEL_MINIMUM;
349 if ((logfp != NULL) && (logfp != stderr))
351 log_error(LOG_LEVEL_INFO, "(Re-)Open logfile %s", logfname ? logfname : "none");
356 /* set the designated log file */
359 if( NULL == (fp = fopen(logfname, "a")) )
361 log_error(LOG_LEVEL_FATAL, "init_error_log(): can't open logfile: %s", logfname);
364 /* set logging to be completely unbuffered */
370 log_error(LOG_LEVEL_INFO, "Privoxy version " VERSION);
371 if (prog_name != NULL)
373 log_error(LOG_LEVEL_INFO, "Program name: %s", prog_name);
376 /* FIXME RACE HAZARD: should end critical section error_log_use here */
378 } /* init_error_log */
381 /*********************************************************************
383 * Function : log_error
385 * Description : This is the error-reporting and logging function.
388 * 1 : loglevel = the type of message to be logged
389 * 2 : fmt = the main string we want logged, printf-like
390 * 3 : ... = arguments to be inserted in fmt (printf-like).
394 *********************************************************************/
395 void log_error(int loglevel, char *fmt, ...)
399 static char *outbuf_save = NULL;
402 long this_thread = 1; /* was: pthread_t this_thread;*/
408 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
410 * Irrespective of debug setting, a GET/POST/CONNECT makes
411 * the taskbar icon animate. (There is an option to disable
412 * this but checking that is handled inside LogShowActivity()).
414 if (loglevel == LOG_LEVEL_GPC)
418 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
420 /* verify if loglevel applies to current settings and bail out if negative */
421 if ((loglevel & debug) == 0)
426 /* FIXME get current thread id */
427 #ifdef FEATURE_PTHREAD
428 this_thread = (long)pthread_self();
431 * Mac OSX (and perhaps other Mach instances) doesn't have a debuggable
432 * value at the first 4 bytes of pthread_self()'s return value, a pthread_t.
433 * pthread_t is supposed to be opaque... but it's fairly random, though, so
434 * we make it mostly presentable.
436 this_thread = abs(this_thread % 1000);
437 #endif /* def __MACH__ */
438 #elif defined(_WIN32)
439 this_thread = GetCurrentThreadId();
440 #elif defined(__OS2__)
441 ulrc = DosGetInfoBlocks(&ptib, NULL);
443 this_thread = ptib -> tib_ptib2 -> tib2_ultid;
444 #endif /* def FEATURE_PTHREAD */
448 outbuf_save = outbuf = (char*)malloc(BUFFER_SIZE);
451 outbuf = outbuf_save;
455 * Write timestamp into tempbuf.
457 * Complex because not all OSs have tm_gmtoff or
458 * the %z field in strftime()
463 #ifdef HAVE_LOCALTIME_R
464 tm_now = *localtime_r(&now, &tm_now);
466 pthread_mutex_lock(&localtime_mutex);
467 tm_now = *localtime (&now);
468 pthread_mutex_unlock(&localtime_mutex);
470 tm_now = *localtime (&now);
472 strftime(outbuf, BUFFER_SIZE-6, "%b %d %H:%M:%S ", &tm_now);
473 outbuf += strlen( outbuf );
477 case LOG_LEVEL_ERROR:
478 outc = sprintf(outbuf, "Privoxy(%05ld) Error: ", this_thread);
480 case LOG_LEVEL_FATAL:
481 outc = sprintf(outbuf, "Privoxy(%05ld) Fatal error: ", this_thread);
484 outc = sprintf(outbuf, "Privoxy(%05ld) Request: ", this_thread);
486 case LOG_LEVEL_CONNECT:
487 outc = sprintf(outbuf, "Privoxy(%05ld) Connect: ", this_thread);
490 outc = sprintf(outbuf, "Privoxy(%05ld) Writing: ", this_thread);
492 case LOG_LEVEL_HEADER:
493 outc = sprintf(outbuf, "Privoxy(%05ld) Header: ", this_thread);
496 outc = sprintf(outbuf, "Privoxy(%05ld) Info: ", this_thread);
498 case LOG_LEVEL_RE_FILTER:
499 outc = sprintf(outbuf, "Privoxy(%05ld) Re-Filter: ", this_thread);
501 #ifdef FEATURE_FORCE_LOAD
502 case LOG_LEVEL_FORCE:
503 outc = sprintf(outbuf, "Privoxy(%05ld) Force: ", this_thread);
505 #endif /* def FEATURE_FORCE_LOAD */
506 #ifdef FEATURE_FAST_REDIRECTS
507 case LOG_LEVEL_REDIRECTS:
508 outc = sprintf(outbuf, "Privoxy(%05ld) Redirect: ", this_thread);
510 #endif /* def FEATURE_FAST_REDIRECTS */
511 case LOG_LEVEL_DEANIMATE:
512 outc = sprintf(outbuf, "Privoxy(%05ld) Gif-Deanimate: ", this_thread);
515 outbuf = outbuf_save;
519 #ifdef FEATURE_KILL_POPUPS
520 case LOG_LEVEL_POPUPS:
521 outc = sprintf(outbuf, "Privoxy(%05ld) Kill-Popups: ", this_thread);
523 #endif /* def FEATURE_KILL_POPUPS */
525 outc = sprintf(outbuf, "Privoxy(%05ld) CGI: ", this_thread);
528 outc = sprintf(outbuf, "Privoxy(%05ld) UNKNOWN LOG TYPE(%d): ", this_thread, loglevel);
532 /* get ready to scan var. args. */
535 /* build formatted message from fmt and var-args */
536 while ((*src) && (outc < BUFFER_SIZE-2))
538 char tempbuf[BUFFER_SIZE];
557 outbuf[outc++] = '%';
560 ival = va_arg( ap, int );
562 outc += sprintf(tempbuf, "%d", ival);
563 if (outc < BUFFER_SIZE-1)
565 strcpy(outbuf + oldoutc, tempbuf);
569 outbuf[oldoutc] = '\0';
573 uval = va_arg( ap, unsigned );
575 outc += sprintf(tempbuf, "%u", uval);
576 if (outc < BUFFER_SIZE-1)
578 strcpy(outbuf + oldoutc, tempbuf);
582 outbuf[oldoutc] = '\0';
586 /* this is a modifier that must be followed by u or d */
590 lval = va_arg( ap, long );
592 outc += sprintf(tempbuf, "%ld", lval);
596 ulval = va_arg( ap, unsigned long );
598 outc += sprintf(tempbuf, "%lu", ulval);
603 sprintf(outbuf, "Privoxy(%ld) Error: log_error(): Bad format string:\n"
605 "Exiting.", this_thread, fmt);
606 /* FIXME RACE HAZARD: should start critical section error_log_use here */
611 fputs(outbuf, logfp);
612 /* FIXME RACE HAZARD: should end critical section error_log_use here */
617 if (outc < BUFFER_SIZE-1)
619 strcpy(outbuf + oldoutc, tempbuf);
623 outbuf[oldoutc] = '\0';
628 * Note that char paramaters are converted to int, so we need to
629 * pass "int" to va_arg. (See K&R, 2nd ed, section A7.3.2, page 202)
631 outbuf[outc++] = (char) va_arg( ap, int );
634 sval = va_arg( ap, char * );
640 outc += strlen(sval);
641 if (outc < BUFFER_SIZE-1)
643 strcpy(outbuf + oldoutc, sval);
647 outbuf[oldoutc] = '\0';
651 /* Non-standard: Print a counted string. Takes 2 parameters:
652 * int length, const char * string
654 ival = va_arg( ap, int );
655 sval = va_arg( ap, char * );
666 if (outc < BUFFER_SIZE-1)
668 memcpy(outbuf + oldoutc, sval, (size_t) ival);
672 outbuf[oldoutc] = '\0';
676 /* Non-standard: Print error code from errno */
678 ival = WSAGetLastError();
679 sval = w32_socket_strerr(ival, tempbuf);
683 sval = os2_socket_strerr(ival, tempbuf);
687 sval = strerror(ival);
689 #else /* ifndef _WIN32 */
692 sval = strerror(ival);
693 #else /* ifndef HAVE_STRERROR */
695 #endif /* ndef HAVE_STRERROR */
698 sprintf(tempbuf, "(errno = %d)", ival);
701 #endif /* ndef _WIN32 */
703 outc += strlen(sval);
704 if (outc < BUFFER_SIZE-1)
706 strcpy(outbuf + oldoutc, sval);
710 outbuf[oldoutc] = '\0';
714 /* Non-standard: Print a Common Log File timestamp */
717 * Write timestamp into tempbuf.
719 * Complex because not all OSs have tm_gmtoff or
720 * the %z field in strftime()
725 #ifdef HAVE_LOCALTIME_R
731 gmt = *gmtime_r(&now, &gmt);
733 pthread_mutex_lock(&gmtime_mutex);
735 pthread_mutex_unlock(&gmtime_mutex);
739 #ifdef HAVE_LOCALTIME_R
740 tm_now = localtime_r(&now, &dummy);
742 pthread_mutex_lock(&localtime_mutex);
743 tm_now = localtime (&now);
744 pthread_mutex_unlock(&localtime_mutex);
746 tm_now = localtime (&now);
748 days = tm_now->tm_yday - gmt.tm_yday;
749 hrs = ((days < -1 ? 24 : 1 < days ? -24 : days * 24) + tm_now->tm_hour - gmt.tm_hour);
750 mins = hrs * 60 + tm_now->tm_min - gmt.tm_min;
751 strftime (tempbuf, BUFFER_SIZE-6, "%d/%b/%Y:%H:%M:%S ", tm_now);
752 sprintf (tempbuf + strlen(tempbuf), "%+03d%02d", mins / 60, abs(mins) % 60);
755 outc += strlen(tempbuf);
756 if (outc < BUFFER_SIZE-1)
758 strcpy(outbuf + oldoutc, tempbuf);
762 outbuf[oldoutc] = '\0';
766 sprintf(outbuf, "Privoxy(%ld) Error: log_error(): Bad format string:\n"
768 "Exiting.", this_thread, fmt);
769 /* FIXME RACE HAZARD: should start critical section error_log_use here */
774 fputs(outbuf_save, logfp);
775 /* FIXME RACE HAZARD: should end critical section error_log_use here */
776 fatal_error(outbuf_save);
784 /* done with var. args */
787 if (outc >= BUFFER_SIZE-2)
789 /* insufficient room for newline and trailing null. */
791 static const char warning[] = "... [too long, truncated]\n";
793 if (outc < BUFFER_SIZE)
795 /* Need to add terminating null in this case. */
799 /* Truncate output */
800 outbuf[BUFFER_SIZE - sizeof(warning)] = '\0';
803 strcat(outbuf, warning);
807 /* Add terminating newline and null */
808 outbuf[outc++] = '\n';
812 /* FIXME RACE HAZARD: should start critical section error_log_use here */
814 /* deal with glibc stupidity - it won't let you initialize logfp */
820 fputs(outbuf_save, logfp);
822 if (loglevel == LOG_LEVEL_FATAL)
824 fatal_error(outbuf_save);
828 /* FIXME RACE HAZARD: should end critical section error_log_use here */
830 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
831 /* Write to display */
832 LogPutString(outbuf_save);
833 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
839 /*********************************************************************
841 * Function : w32_socket_strerr
843 * Description : Translate the return value from WSAGetLastError()
847 * 1 : errcode = The return value from WSAGetLastError().
848 * 2 : tmp_buf = A temporary buffer that might be used to
851 * Returns : String representing the error code. This may be
852 * a global string constant or a string stored in
855 *********************************************************************/
856 static char *w32_socket_strerr(int errcode, char *tmp_buf)
858 #define TEXT_FOR_ERROR(code,text) \
859 if (errcode == code) \
861 return #code " - " text; \
864 TEXT_FOR_ERROR(WSAEACCES, "Permission denied")
865 TEXT_FOR_ERROR(WSAEADDRINUSE, "Address already in use.")
866 TEXT_FOR_ERROR(WSAEADDRNOTAVAIL, "Cannot assign requested address.");
867 TEXT_FOR_ERROR(WSAEAFNOSUPPORT, "Address family not supported by protocol family.");
868 TEXT_FOR_ERROR(WSAEALREADY, "Operation already in progress.");
869 TEXT_FOR_ERROR(WSAECONNABORTED, "Software caused connection abort.");
870 TEXT_FOR_ERROR(WSAECONNREFUSED, "Connection refused.");
871 TEXT_FOR_ERROR(WSAECONNRESET, "Connection reset by peer.");
872 TEXT_FOR_ERROR(WSAEDESTADDRREQ, "Destination address required.");
873 TEXT_FOR_ERROR(WSAEFAULT, "Bad address.");
874 TEXT_FOR_ERROR(WSAEHOSTDOWN, "Host is down.");
875 TEXT_FOR_ERROR(WSAEHOSTUNREACH, "No route to host.");
876 TEXT_FOR_ERROR(WSAEINPROGRESS, "Operation now in progress.");
877 TEXT_FOR_ERROR(WSAEINTR, "Interrupted function call.");
878 TEXT_FOR_ERROR(WSAEINVAL, "Invalid argument.");
879 TEXT_FOR_ERROR(WSAEISCONN, "Socket is already connected.");
880 TEXT_FOR_ERROR(WSAEMFILE, "Too many open sockets.");
881 TEXT_FOR_ERROR(WSAEMSGSIZE, "Message too long.");
882 TEXT_FOR_ERROR(WSAENETDOWN, "Network is down.");
883 TEXT_FOR_ERROR(WSAENETRESET, "Network dropped connection on reset.");
884 TEXT_FOR_ERROR(WSAENETUNREACH, "Network is unreachable.");
885 TEXT_FOR_ERROR(WSAENOBUFS, "No buffer space available.");
886 TEXT_FOR_ERROR(WSAENOPROTOOPT, "Bad protocol option.");
887 TEXT_FOR_ERROR(WSAENOTCONN, "Socket is not connected.");
888 TEXT_FOR_ERROR(WSAENOTSOCK, "Socket operation on non-socket.");
889 TEXT_FOR_ERROR(WSAEOPNOTSUPP, "Operation not supported.");
890 TEXT_FOR_ERROR(WSAEPFNOSUPPORT, "Protocol family not supported.");
891 TEXT_FOR_ERROR(WSAEPROCLIM, "Too many processes.");
892 TEXT_FOR_ERROR(WSAEPROTONOSUPPORT, "Protocol not supported.");
893 TEXT_FOR_ERROR(WSAEPROTOTYPE, "Protocol wrong type for socket.");
894 TEXT_FOR_ERROR(WSAESHUTDOWN, "Cannot send after socket shutdown.");
895 TEXT_FOR_ERROR(WSAESOCKTNOSUPPORT, "Socket type not supported.");
896 TEXT_FOR_ERROR(WSAETIMEDOUT, "Connection timed out.");
897 TEXT_FOR_ERROR(WSAEWOULDBLOCK, "Resource temporarily unavailable.");
898 TEXT_FOR_ERROR(WSAHOST_NOT_FOUND, "Host not found.");
899 TEXT_FOR_ERROR(WSANOTINITIALISED, "Successful WSAStartup not yet performed.");
900 TEXT_FOR_ERROR(WSANO_DATA, "Valid name, no data record of requested type.");
901 TEXT_FOR_ERROR(WSANO_RECOVERY, "This is a non-recoverable error.");
902 TEXT_FOR_ERROR(WSASYSNOTREADY, "Network subsystem is unavailable.");
903 TEXT_FOR_ERROR(WSATRY_AGAIN, "Non-authoritative host not found.");
904 TEXT_FOR_ERROR(WSAVERNOTSUPPORTED, "WINSOCK.DLL version out of range.");
905 TEXT_FOR_ERROR(WSAEDISCON, "Graceful shutdown in progress.");
907 * The following error codes are documented in the Microsoft WinSock
908 * reference guide, but don't actually exist.
910 * TEXT_FOR_ERROR(WSA_INVALID_HANDLE, "Specified event object handle is invalid.");
911 * TEXT_FOR_ERROR(WSA_INVALID_PARAMETER, "One or more parameters are invalid.");
912 * TEXT_FOR_ERROR(WSAINVALIDPROCTABLE, "Invalid procedure table from service provider.");
913 * TEXT_FOR_ERROR(WSAINVALIDPROVIDER, "Invalid service provider version number.");
914 * TEXT_FOR_ERROR(WSA_IO_PENDING, "Overlapped operations will complete later.");
915 * TEXT_FOR_ERROR(WSA_IO_INCOMPLETE, "Overlapped I/O event object not in signaled state.");
916 * TEXT_FOR_ERROR(WSA_NOT_ENOUGH_MEMORY, "Insufficient memory available.");
917 * TEXT_FOR_ERROR(WSAPROVIDERFAILEDINIT, "Unable to initialize a service provider.");
918 * TEXT_FOR_ERROR(WSASYSCALLFAILURE, "System call failure.");
919 * TEXT_FOR_ERROR(WSA_OPERATION_ABORTED, "Overlapped operation aborted.");
922 sprintf(tmp_buf, "(error number %d)", errcode);
925 #endif /* def _WIN32 */
929 /*********************************************************************
931 * Function : os2_socket_strerr
933 * Description : Translate the return value from sock_errno()
937 * 1 : errcode = The return value from sock_errno().
938 * 2 : tmp_buf = A temporary buffer that might be used to
941 * Returns : String representing the error code. This may be
942 * a global string constant or a string stored in
945 *********************************************************************/
946 static char *os2_socket_strerr(int errcode, char *tmp_buf)
948 #define TEXT_FOR_ERROR(code,text) \
949 if (errcode == code) \
951 return #code " - " text; \
954 TEXT_FOR_ERROR(SOCEPERM , "Not owner.")
955 TEXT_FOR_ERROR(SOCESRCH , "No such process.")
956 TEXT_FOR_ERROR(SOCEINTR , "Interrupted system call.")
957 TEXT_FOR_ERROR(SOCENXIO , "No such device or address.")
958 TEXT_FOR_ERROR(SOCEBADF , "Bad file number.")
959 TEXT_FOR_ERROR(SOCEACCES , "Permission denied.")
960 TEXT_FOR_ERROR(SOCEFAULT , "Bad address.")
961 TEXT_FOR_ERROR(SOCEINVAL , "Invalid argument.")
962 TEXT_FOR_ERROR(SOCEMFILE , "Too many open files.")
963 TEXT_FOR_ERROR(SOCEPIPE , "Broken pipe.")
964 TEXT_FOR_ERROR(SOCEWOULDBLOCK , "Operation would block.")
965 TEXT_FOR_ERROR(SOCEINPROGRESS , "Operation now in progress.")
966 TEXT_FOR_ERROR(SOCEALREADY , "Operation already in progress.")
967 TEXT_FOR_ERROR(SOCENOTSOCK , "Socket operation on non-socket.")
968 TEXT_FOR_ERROR(SOCEDESTADDRREQ , "Destination address required.")
969 TEXT_FOR_ERROR(SOCEMSGSIZE , "Message too long.")
970 TEXT_FOR_ERROR(SOCEPROTOTYPE , "Protocol wrong type for socket.")
971 TEXT_FOR_ERROR(SOCENOPROTOOPT , "Protocol not available.")
972 TEXT_FOR_ERROR(SOCEPROTONOSUPPORT, "Protocol not supported.")
973 TEXT_FOR_ERROR(SOCESOCKTNOSUPPORT, "Socket type not supported.")
974 TEXT_FOR_ERROR(SOCEOPNOTSUPP , "Operation not supported.")
975 TEXT_FOR_ERROR(SOCEPFNOSUPPORT , "Protocol family not supported.")
976 TEXT_FOR_ERROR(SOCEAFNOSUPPORT , "Address family not supported by protocol family.")
977 TEXT_FOR_ERROR(SOCEADDRINUSE , "Address already in use.")
978 TEXT_FOR_ERROR(SOCEADDRNOTAVAIL , "Can't assign requested address.")
979 TEXT_FOR_ERROR(SOCENETDOWN , "Network is down.")
980 TEXT_FOR_ERROR(SOCENETUNREACH , "Network is unreachable.")
981 TEXT_FOR_ERROR(SOCENETRESET , "Network dropped connection on reset.")
982 TEXT_FOR_ERROR(SOCECONNABORTED , "Software caused connection abort.")
983 TEXT_FOR_ERROR(SOCECONNRESET , "Connection reset by peer.")
984 TEXT_FOR_ERROR(SOCENOBUFS , "No buffer space available.")
985 TEXT_FOR_ERROR(SOCEISCONN , "Socket is already connected.")
986 TEXT_FOR_ERROR(SOCENOTCONN , "Socket is not connected.")
987 TEXT_FOR_ERROR(SOCESHUTDOWN , "Can't send after socket shutdown.")
988 TEXT_FOR_ERROR(SOCETOOMANYREFS , "Too many references: can't splice.")
989 TEXT_FOR_ERROR(SOCETIMEDOUT , "Operation timed out.")
990 TEXT_FOR_ERROR(SOCECONNREFUSED , "Connection refused.")
991 TEXT_FOR_ERROR(SOCELOOP , "Too many levels of symbolic links.")
992 TEXT_FOR_ERROR(SOCENAMETOOLONG , "File name too long.")
993 TEXT_FOR_ERROR(SOCEHOSTDOWN , "Host is down.")
994 TEXT_FOR_ERROR(SOCEHOSTUNREACH , "No route to host.")
995 TEXT_FOR_ERROR(SOCENOTEMPTY , "Directory not empty.")
996 TEXT_FOR_ERROR(SOCEOS2ERR , "OS/2 Error.")
998 sprintf(tmp_buf, "(error number %d)", errcode);
1001 #endif /* def __OS2__ */