1 const char errlog_rcs[] = "$Id: errlog.c,v 2.0 2002/06/04 14:34:21 jongfoster 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.0 2002/06/04 14:34:21 jongfoster
37 * Moving source files to src/
39 * Revision 1.40 2002/05/22 01:27:27 david__schmidt
41 * Add os2_socket_strerr mirroring w32_socket_strerr.
43 * Revision 1.39 2002/04/03 17:15:27 gliptak
44 * zero padding thread ids in log
46 * Revision 1.38 2002/03/31 17:18:59 jongfoster
47 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
49 * Revision 1.37 2002/03/27 14:32:43 david__schmidt
50 * More compiler warning message maintenance
52 * Revision 1.36 2002/03/26 22:29:54 swa
53 * we have a new homepage!
55 * Revision 1.35 2002/03/24 15:23:33 jongfoster
58 * Revision 1.34 2002/03/24 13:25:43 swa
59 * name change related issues
61 * Revision 1.33 2002/03/13 00:27:04 jongfoster
64 * Revision 1.32 2002/03/07 03:46:17 oes
65 * Fixed compiler warnings
67 * Revision 1.31 2002/03/06 23:02:57 jongfoster
70 * Revision 1.30 2002/03/05 22:43:45 david__schmidt
71 * - Better error reporting on OS/2
72 * - Fix double-slash comment (oops)
74 * Revision 1.29 2002/03/04 23:45:13 jongfoster
75 * Printing thread ID if using Win32 native threads
77 * Revision 1.28 2002/03/04 17:59:59 oes
78 * Deleted deletePidFile(), cosmetics
80 * Revision 1.27 2002/03/04 02:08:01 david__schmidt
81 * Enable web editing of actions file on OS/2 (it had been broken all this time!)
83 * Revision 1.26 2002/01/09 19:05:45 steudten
84 * Fix big memory leak.
86 * Revision 1.25 2002/01/09 14:32:08 oes
87 * Added support for gmtime_r and localtime_r.
89 * Revision 1.24 2001/12/30 14:07:32 steudten
90 * - Add signal handling (unix)
91 * - Add SIGHUP handler (unix)
92 * - Add creation of pidfile (unix)
93 * - Add action 'top' in rc file (RH)
94 * - Add entry 'SIGNALS' to manpage
95 * - Add exit message to logfile (unix)
97 * Revision 1.23 2001/11/07 00:02:13 steudten
98 * Add line number in error output for lineparsing for
99 * actionsfile and configfile.
100 * Special handling for CLF added.
102 * Revision 1.22 2001/11/05 23:43:05 steudten
103 * Add time+date to log files.
105 * Revision 1.21 2001/10/25 03:40:47 david__schmidt
106 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
107 * threads to call select() simultaneously. So, it's time to do a real, live,
108 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
109 * (native). Both versions will work, but using __OS2__ offers multi-threading.
111 * Revision 1.20 2001/09/16 23:04:34 jongfoster
114 * Revision 1.19 2001/09/13 20:08:06 jongfoster
115 * Adding support for LOG_LEVEL_CGI
117 * Revision 1.18 2001/09/10 11:27:24 oes
118 * Declaration of w32_socket_strerr now conditional
120 * Revision 1.17 2001/09/10 10:17:13 oes
121 * Removed unused variable; Fixed sprintf format
123 * Revision 1.16 2001/07/30 22:08:36 jongfoster
124 * Tidying up #defines:
125 * - All feature #defines are now of the form FEATURE_xxx
126 * - Permanently turned off WIN_GUI_EDIT
127 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
129 * Revision 1.15 2001/07/29 17:41:10 jongfoster
130 * Now prints thread ID for each message (pthreads only)
132 * Revision 1.14 2001/07/19 19:03:48 haroon
133 * - Added case for LOG_LEVEL_POPUPS
135 * Revision 1.13 2001/07/13 13:58:58 oes
136 * - Added case for LOG_LEVEL_DEANIMATE
137 * - Removed all #ifdef PCRS
139 * Revision 1.12 2001/06/09 10:55:28 jongfoster
140 * Changing BUFSIZ ==> BUFFER_SIZE
142 * Revision 1.11 2001/06/01 18:14:49 jongfoster
143 * Changing the calls to strerr() to check HAVE_STRERR (which is defined
144 * in config.h if appropriate) rather than the NO_STRERR macro.
146 * Revision 1.10 2001/05/29 11:52:21 oes
147 * Conditional compilation of w32_socket_error
149 * Revision 1.9 2001/05/28 16:15:17 jongfoster
150 * Improved reporting of errors under Win32.
152 * Revision 1.8 2001/05/26 17:25:14 jongfoster
153 * Added support for CLF (Common Log Format) and fixed LOG_LEVEL_LOG
155 * Revision 1.7 2001/05/26 15:21:28 jongfoster
156 * Activity animation in Win32 GUI now works even if debug==0
158 * Revision 1.6 2001/05/25 21:55:08 jongfoster
159 * Now cleans up properly on FATAL (removes taskbar icon etc)
161 * Revision 1.5 2001/05/22 18:46:04 oes
163 * - Enabled filtering banners by size rather than URL
164 * by adding patterns that replace all standard banner
165 * sizes with the "Junkbuster" gif to the re_filterfile
167 * - Enabled filtering WebBugs by providing a pattern
168 * which kills all 1x1 images
170 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
171 * which is selected by the (nonstandard and therefore
172 * capital) letter 'U' in the option string.
173 * It causes the quantifiers to be ungreedy by default.
174 * Appending a ? turns back to greedy (!).
176 * - Added a new interceptor ijb-send-banner, which
177 * sends back the "Junkbuster" gif. Without imagelist or
178 * MSIE detection support, or if tinygif = 1, or the
179 * URL isn't recognized as an imageurl, a lame HTML
180 * explanation is sent instead.
182 * - Added new feature, which permits blocking remote
183 * script redirects and firing back a local redirect
185 * The feature is conditionally compiled, i.e. it
186 * can be disabled with --disable-fast-redirects,
187 * plus it must be activated by a "fast-redirects"
188 * line in the config file, has its own log level
189 * and of course wants to be displayed by show-proxy-args
190 * Note: Boy, all the #ifdefs in 1001 locations and
191 * all the fumbling with configure.in and acconfig.h
192 * were *way* more work than the feature itself :-(
194 * - Because a generic redirect template was needed for
195 * this, tinygif = 3 now uses the same.
197 * - Moved GIFs, and other static HTTP response templates
202 * - Removed some >400 CRs again (Jon, you really worked
205 * Revision 1.4 2001/05/21 19:32:54 jongfoster
206 * Added another #ifdef _WIN_CONSOLE
208 * Revision 1.3 2001/05/20 01:11:40 jongfoster
209 * Added support for LOG_LEVEL_FATAL
210 * Renamed LOG_LEVEL_FRC to LOG_LEVEL_FORCE,
211 * and LOG_LEVEL_REF to LOG_LEVEL_RE_FILTER
213 * Revision 1.2 2001/05/17 22:42:01 oes
214 * - Cleaned CRLF's from the sources and related files
215 * - Repaired logging for REF and FRC
217 * Revision 1.1.1.1 2001/05/15 13:58:51 oes
218 * Initial import of version 2.9.3 source tree
221 *********************************************************************/
225 #include "miscutil.h"
232 #if !defined(_WIN32) && !defined(__OS2__)
234 #endif /* !defined(_WIN32) && !defined(__OS2__) */
238 #ifdef FEATURE_PTHREAD
240 #endif /* def FEATURE_PTHREAD */
249 #endif /* ndef _WIN_CONSOLE */
250 #endif /* def _WIN32 */
253 #include <sys/socket.h> /* For sock_errno */
262 const char errlog_h_rcs[] = ERRLOG_H_VERSION;
266 * LOG_LEVEL_FATAL cannot be turned off. (There are
267 * some exceptional situations where we need to get a
268 * message to the user).
270 #define LOG_LEVEL_MINIMUM LOG_LEVEL_FATAL
272 /* where to log (default: stderr) */
273 static FILE *logfp = NULL;
275 /* logging detail level. */
276 static int debug = (LOG_LEVEL_FATAL | LOG_LEVEL_ERROR | LOG_LEVEL_INFO);
278 /* static functions */
279 static void fatal_error(const char * error_message);
281 static char *w32_socket_strerr(int errcode, char *tmp_buf);
284 static char *os2_socket_strerr(int errcode, char *tmp_buf);
287 /*********************************************************************
289 * Function : fatal_error
291 * Description : Displays a fatal error to standard error (or, on
292 * a WIN32 GUI, to a dialog box), and exits
293 * JunkBuster with status code 1.
296 * 1 : error_message = The error message to display.
298 * Returns : Does not return.
300 *********************************************************************/
301 static void fatal_error(const char * error_message)
303 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
304 MessageBox(g_hwndLogFrame, error_message, "Privoxy Error",
305 MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND | MB_TOPMOST);
307 /* Cleanup - remove taskbar icon etc. */
310 #else /* if !defined(_WIN32) || defined(_WIN_CONSOLE) */
311 fputs(error_message, stderr);
312 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
322 /*********************************************************************
324 * Function : init_error_log
326 * Description : Initializes the logging module. Must call before
330 * 1 : prog_name = The program name.
331 * 2 : logfname = The logfile name, or NULL for stderr.
332 * 3 : debuglevel = The debugging level.
336 *********************************************************************/
337 void init_error_log(const char *prog_name, const char *logfname, int debuglevel)
341 /* FIXME RACE HAZARD: should start critical section error_log_use here */
343 /* set the logging detail level */
344 debug = debuglevel | LOG_LEVEL_MINIMUM;
346 if ((logfp != NULL) && (logfp != stderr))
348 log_error(LOG_LEVEL_INFO, "(Re-)Open logfile %s", logfname ? logfname : "none");
353 /* set the designated log file */
356 if( NULL == (fp = fopen(logfname, "a")) )
358 log_error(LOG_LEVEL_FATAL, "init_error_log(): can't open logfile: %s", logfname);
361 /* set logging to be completely unbuffered */
367 log_error(LOG_LEVEL_INFO, "Privoxy version " VERSION);
368 if (prog_name != NULL)
370 log_error(LOG_LEVEL_INFO, "Program name: %s", prog_name);
373 /* FIXME RACE HAZARD: should end critical section error_log_use here */
375 } /* init_error_log */
378 /*********************************************************************
380 * Function : log_error
382 * Description : This is the error-reporting and logging function.
385 * 1 : loglevel = the type of message to be logged
386 * 2 : fmt = the main string we want logged, printf-like
387 * 3 : ... = arguments to be inserted in fmt (printf-like).
391 *********************************************************************/
392 void log_error(int loglevel, char *fmt, ...)
396 static char *outbuf_save = NULL;
399 long this_thread = 1; /* was: pthread_t this_thread;*/
405 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
407 * Irrespective of debug setting, a GET/POST/CONNECT makes
408 * the taskbar icon animate. (There is an option to disable
409 * this but checking that is handled inside LogShowActivity()).
411 if (loglevel == LOG_LEVEL_GPC)
415 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
417 /* verify if loglevel applies to current settings and bail out if negative */
418 if ((loglevel & debug) == 0)
423 /* FIXME get current thread id */
424 #ifdef FEATURE_PTHREAD
425 this_thread = (long)pthread_self();
426 #elif defined(_WIN32)
427 this_thread = GetCurrentThreadId();
428 #elif defined(__OS2__)
429 ulrc = DosGetInfoBlocks(&ptib, NULL);
431 this_thread = ptib -> tib_ptib2 -> tib2_ultid;
432 #endif /* def FEATURE_PTHREAD */
436 outbuf_save = outbuf = (char*)malloc(BUFFER_SIZE);
439 outbuf = outbuf_save;
443 * Write timestamp into tempbuf.
445 * Complex because not all OSs have tm_gmtoff or
446 * the %z field in strftime()
451 #ifdef HAVE_LOCALTIME_R
452 tm_now = *localtime_r(&now, &tm_now);
454 tm_now = *localtime (&now);
456 strftime(outbuf, BUFFER_SIZE-6, "%b %d %H:%M:%S ", &tm_now);
457 outbuf += strlen( outbuf );
461 case LOG_LEVEL_ERROR:
462 outc = sprintf(outbuf, "Privoxy(%05ld) Error: ", this_thread);
464 case LOG_LEVEL_FATAL:
465 outc = sprintf(outbuf, "Privoxy(%05ld) Fatal error: ", this_thread);
468 outc = sprintf(outbuf, "Privoxy(%05ld) Request: ", this_thread);
470 case LOG_LEVEL_CONNECT:
471 outc = sprintf(outbuf, "Privoxy(%05ld) Connect: ", this_thread);
474 outc = sprintf(outbuf, "Privoxy(%05ld) Writing: ", this_thread);
476 case LOG_LEVEL_HEADER:
477 outc = sprintf(outbuf, "Privoxy(%05ld) Header: ", this_thread);
480 outc = sprintf(outbuf, "Privoxy(%05ld) Info: ", this_thread);
482 case LOG_LEVEL_RE_FILTER:
483 outc = sprintf(outbuf, "Privoxy(%05ld) Re-Filter: ", this_thread);
485 #ifdef FEATURE_FORCE_LOAD
486 case LOG_LEVEL_FORCE:
487 outc = sprintf(outbuf, "Privoxy(%05ld) Force: ", this_thread);
489 #endif /* def FEATURE_FORCE_LOAD */
490 #ifdef FEATURE_FAST_REDIRECTS
491 case LOG_LEVEL_REDIRECTS:
492 outc = sprintf(outbuf, "Privoxy(%05ld) Redirect: ", this_thread);
494 #endif /* def FEATURE_FAST_REDIRECTS */
495 case LOG_LEVEL_DEANIMATE:
496 outc = sprintf(outbuf, "Privoxy(%05ld) Gif-Deanimate: ", this_thread);
499 outbuf = outbuf_save;
503 #ifdef FEATURE_KILL_POPUPS
504 case LOG_LEVEL_POPUPS:
505 outc = sprintf(outbuf, "Privoxy(%05ld) Kill-Popups: ", this_thread);
507 #endif /* def FEATURE_KILL_POPUPS */
509 outc = sprintf(outbuf, "Privoxy(%05ld) CGI: ", this_thread);
512 outc = sprintf(outbuf, "Privoxy(%05ld) UNKNOWN LOG TYPE(%d): ", this_thread, loglevel);
516 /* get ready to scan var. args. */
519 /* build formatted message from fmt and var-args */
520 while ((*src) && (outc < BUFFER_SIZE-2))
522 char tempbuf[BUFFER_SIZE];
541 outbuf[outc++] = '%';
544 ival = va_arg( ap, int );
546 outc += sprintf(tempbuf, "%d", ival);
547 if (outc < BUFFER_SIZE-1)
549 strcpy(outbuf + oldoutc, tempbuf);
553 outbuf[oldoutc] = '\0';
557 uval = va_arg( ap, unsigned );
559 outc += sprintf(tempbuf, "%u", uval);
560 if (outc < BUFFER_SIZE-1)
562 strcpy(outbuf + oldoutc, tempbuf);
566 outbuf[oldoutc] = '\0';
570 /* this is a modifier that must be followed by u or d */
574 lval = va_arg( ap, long );
576 outc += sprintf(tempbuf, "%ld", lval);
580 ulval = va_arg( ap, unsigned long );
582 outc += sprintf(tempbuf, "%lu", ulval);
587 sprintf(outbuf, "Privoxy(%ld) Error: log_error(): Bad format string:\n"
589 "Exiting.", this_thread, fmt);
590 /* FIXME RACE HAZARD: should start critical section error_log_use here */
595 fputs(outbuf, logfp);
596 /* FIXME RACE HAZARD: should end critical section error_log_use here */
601 if (outc < BUFFER_SIZE-1)
603 strcpy(outbuf + oldoutc, tempbuf);
607 outbuf[oldoutc] = '\0';
612 * Note that char paramaters are converted to int, so we need to
613 * pass "int" to va_arg. (See K&R, 2nd ed, section A7.3.2, page 202)
615 outbuf[outc++] = (char) va_arg( ap, int );
618 sval = va_arg( ap, char * );
624 outc += strlen(sval);
625 if (outc < BUFFER_SIZE-1)
627 strcpy(outbuf + oldoutc, sval);
631 outbuf[oldoutc] = '\0';
635 /* Non-standard: Print a counted string. Takes 2 parameters:
636 * int length, const char * string
638 ival = va_arg( ap, int );
639 sval = va_arg( ap, char * );
650 if (outc < BUFFER_SIZE-1)
652 memcpy(outbuf + oldoutc, sval, (size_t) ival);
656 outbuf[oldoutc] = '\0';
660 /* Non-standard: Print error code from errno */
662 ival = WSAGetLastError();
663 sval = w32_socket_strerr(ival, tempbuf);
667 sval = os2_socket_strerr(ival, tempbuf);
671 sval = strerror(ival);
673 #else /* ifndef _WIN32 */
676 sval = strerror(ival);
677 #else /* ifndef HAVE_STRERROR */
679 #endif /* ndef HAVE_STRERROR */
682 sprintf(tempbuf, "(errno = %d)", ival);
685 #endif /* ndef _WIN32 */
687 outc += strlen(sval);
688 if (outc < BUFFER_SIZE-1)
690 strcpy(outbuf + oldoutc, sval);
694 outbuf[oldoutc] = '\0';
698 /* Non-standard: Print a Common Log File timestamp */
701 * Write timestamp into tempbuf.
703 * Complex because not all OSs have tm_gmtoff or
704 * the %z field in strftime()
709 #ifdef HAVE_LOCALTIME_R
715 gmt = *gmtime_r(&now, &gmt);
719 #ifdef HAVE_LOCALTIME_R
720 tm_now = localtime_r(&now, &dummy);
722 tm_now = localtime (&now);
724 days = tm_now->tm_yday - gmt.tm_yday;
725 hrs = ((days < -1 ? 24 : 1 < days ? -24 : days * 24) + tm_now->tm_hour - gmt.tm_hour);
726 mins = hrs * 60 + tm_now->tm_min - gmt.tm_min;
727 strftime (tempbuf, BUFFER_SIZE-6, "%d/%b/%Y:%H:%M:%S ", tm_now);
728 sprintf (tempbuf + strlen(tempbuf), "%+03d%02d", mins / 60, abs(mins) % 60);
731 outc += strlen(tempbuf);
732 if (outc < BUFFER_SIZE-1)
734 strcpy(outbuf + oldoutc, tempbuf);
738 outbuf[oldoutc] = '\0';
742 sprintf(outbuf, "Privoxy(%ld) Error: log_error(): Bad format string:\n"
744 "Exiting.", this_thread, fmt);
745 /* FIXME RACE HAZARD: should start critical section error_log_use here */
750 fputs(outbuf_save, logfp);
751 /* FIXME RACE HAZARD: should end critical section error_log_use here */
752 fatal_error(outbuf_save);
760 /* done with var. args */
763 if (outc >= BUFFER_SIZE-2)
765 /* insufficient room for newline and trailing null. */
767 static const char warning[] = "... [too long, truncated]\n";
769 if (outc < BUFFER_SIZE)
771 /* Need to add terminating null in this case. */
775 /* Truncate output */
776 outbuf[BUFFER_SIZE - sizeof(warning)] = '\0';
779 strcat(outbuf, warning);
783 /* Add terminating newline and null */
784 outbuf[outc++] = '\n';
788 /* FIXME RACE HAZARD: should start critical section error_log_use here */
790 /* deal with glibc stupidity - it won't let you initialize logfp */
796 fputs(outbuf_save, logfp);
798 if (loglevel == LOG_LEVEL_FATAL)
800 fatal_error(outbuf_save);
804 /* FIXME RACE HAZARD: should end critical section error_log_use here */
806 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
807 /* Write to display */
808 LogPutString(outbuf_save);
809 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
815 /*********************************************************************
817 * Function : w32_socket_strerr
819 * Description : Translate the return value from WSAGetLastError()
823 * 1 : errcode = The return value from WSAGetLastError().
824 * 2 : tmp_buf = A temporary buffer that might be used to
827 * Returns : String representing the error code. This may be
828 * a global string constant or a string stored in
831 *********************************************************************/
832 static char *w32_socket_strerr(int errcode, char *tmp_buf)
834 #define TEXT_FOR_ERROR(code,text) \
835 if (errcode == code) \
837 return #code " - " text; \
840 TEXT_FOR_ERROR(WSAEACCES, "Permission denied")
841 TEXT_FOR_ERROR(WSAEADDRINUSE, "Address already in use.")
842 TEXT_FOR_ERROR(WSAEADDRNOTAVAIL, "Cannot assign requested address.");
843 TEXT_FOR_ERROR(WSAEAFNOSUPPORT, "Address family not supported by protocol family.");
844 TEXT_FOR_ERROR(WSAEALREADY, "Operation already in progress.");
845 TEXT_FOR_ERROR(WSAECONNABORTED, "Software caused connection abort.");
846 TEXT_FOR_ERROR(WSAECONNREFUSED, "Connection refused.");
847 TEXT_FOR_ERROR(WSAECONNRESET, "Connection reset by peer.");
848 TEXT_FOR_ERROR(WSAEDESTADDRREQ, "Destination address required.");
849 TEXT_FOR_ERROR(WSAEFAULT, "Bad address.");
850 TEXT_FOR_ERROR(WSAEHOSTDOWN, "Host is down.");
851 TEXT_FOR_ERROR(WSAEHOSTUNREACH, "No route to host.");
852 TEXT_FOR_ERROR(WSAEINPROGRESS, "Operation now in progress.");
853 TEXT_FOR_ERROR(WSAEINTR, "Interrupted function call.");
854 TEXT_FOR_ERROR(WSAEINVAL, "Invalid argument.");
855 TEXT_FOR_ERROR(WSAEISCONN, "Socket is already connected.");
856 TEXT_FOR_ERROR(WSAEMFILE, "Too many open sockets.");
857 TEXT_FOR_ERROR(WSAEMSGSIZE, "Message too long.");
858 TEXT_FOR_ERROR(WSAENETDOWN, "Network is down.");
859 TEXT_FOR_ERROR(WSAENETRESET, "Network dropped connection on reset.");
860 TEXT_FOR_ERROR(WSAENETUNREACH, "Network is unreachable.");
861 TEXT_FOR_ERROR(WSAENOBUFS, "No buffer space available.");
862 TEXT_FOR_ERROR(WSAENOPROTOOPT, "Bad protocol option.");
863 TEXT_FOR_ERROR(WSAENOTCONN, "Socket is not connected.");
864 TEXT_FOR_ERROR(WSAENOTSOCK, "Socket operation on non-socket.");
865 TEXT_FOR_ERROR(WSAEOPNOTSUPP, "Operation not supported.");
866 TEXT_FOR_ERROR(WSAEPFNOSUPPORT, "Protocol family not supported.");
867 TEXT_FOR_ERROR(WSAEPROCLIM, "Too many processes.");
868 TEXT_FOR_ERROR(WSAEPROTONOSUPPORT, "Protocol not supported.");
869 TEXT_FOR_ERROR(WSAEPROTOTYPE, "Protocol wrong type for socket.");
870 TEXT_FOR_ERROR(WSAESHUTDOWN, "Cannot send after socket shutdown.");
871 TEXT_FOR_ERROR(WSAESOCKTNOSUPPORT, "Socket type not supported.");
872 TEXT_FOR_ERROR(WSAETIMEDOUT, "Connection timed out.");
873 TEXT_FOR_ERROR(WSAEWOULDBLOCK, "Resource temporarily unavailable.");
874 TEXT_FOR_ERROR(WSAHOST_NOT_FOUND, "Host not found.");
875 TEXT_FOR_ERROR(WSANOTINITIALISED, "Successful WSAStartup not yet performed.");
876 TEXT_FOR_ERROR(WSANO_DATA, "Valid name, no data record of requested type.");
877 TEXT_FOR_ERROR(WSANO_RECOVERY, "This is a non-recoverable error.");
878 TEXT_FOR_ERROR(WSASYSNOTREADY, "Network subsystem is unavailable.");
879 TEXT_FOR_ERROR(WSATRY_AGAIN, "Non-authoritative host not found.");
880 TEXT_FOR_ERROR(WSAVERNOTSUPPORTED, "WINSOCK.DLL version out of range.");
881 TEXT_FOR_ERROR(WSAEDISCON, "Graceful shutdown in progress.");
883 * The following error codes are documented in the Microsoft WinSock
884 * reference guide, but don't actually exist.
886 * TEXT_FOR_ERROR(WSA_INVALID_HANDLE, "Specified event object handle is invalid.");
887 * TEXT_FOR_ERROR(WSA_INVALID_PARAMETER, "One or more parameters are invalid.");
888 * TEXT_FOR_ERROR(WSAINVALIDPROCTABLE, "Invalid procedure table from service provider.");
889 * TEXT_FOR_ERROR(WSAINVALIDPROVIDER, "Invalid service provider version number.");
890 * TEXT_FOR_ERROR(WSA_IO_PENDING, "Overlapped operations will complete later.");
891 * TEXT_FOR_ERROR(WSA_IO_INCOMPLETE, "Overlapped I/O event object not in signaled state.");
892 * TEXT_FOR_ERROR(WSA_NOT_ENOUGH_MEMORY, "Insufficient memory available.");
893 * TEXT_FOR_ERROR(WSAPROVIDERFAILEDINIT, "Unable to initialize a service provider.");
894 * TEXT_FOR_ERROR(WSASYSCALLFAILURE, "System call failure.");
895 * TEXT_FOR_ERROR(WSA_OPERATION_ABORTED, "Overlapped operation aborted.");
898 sprintf(tmp_buf, "(error number %d)", errcode);
901 #endif /* def _WIN32 */
905 /*********************************************************************
907 * Function : os2_socket_strerr
909 * Description : Translate the return value from sock_errno()
913 * 1 : errcode = The return value from sock_errno().
914 * 2 : tmp_buf = A temporary buffer that might be used to
917 * Returns : String representing the error code. This may be
918 * a global string constant or a string stored in
921 *********************************************************************/
922 static char *os2_socket_strerr(int errcode, char *tmp_buf)
924 #define TEXT_FOR_ERROR(code,text) \
925 if (errcode == code) \
927 return #code " - " text; \
930 TEXT_FOR_ERROR(SOCEPERM , "Not owner.")
931 TEXT_FOR_ERROR(SOCESRCH , "No such process.")
932 TEXT_FOR_ERROR(SOCEINTR , "Interrupted system call.")
933 TEXT_FOR_ERROR(SOCENXIO , "No such device or address.")
934 TEXT_FOR_ERROR(SOCEBADF , "Bad file number.")
935 TEXT_FOR_ERROR(SOCEACCES , "Permission denied.")
936 TEXT_FOR_ERROR(SOCEFAULT , "Bad address.")
937 TEXT_FOR_ERROR(SOCEINVAL , "Invalid argument.")
938 TEXT_FOR_ERROR(SOCEMFILE , "Too many open files.")
939 TEXT_FOR_ERROR(SOCEPIPE , "Broken pipe.")
940 TEXT_FOR_ERROR(SOCEWOULDBLOCK , "Operation would block.")
941 TEXT_FOR_ERROR(SOCEINPROGRESS , "Operation now in progress.")
942 TEXT_FOR_ERROR(SOCEALREADY , "Operation already in progress.")
943 TEXT_FOR_ERROR(SOCENOTSOCK , "Socket operation on non-socket.")
944 TEXT_FOR_ERROR(SOCEDESTADDRREQ , "Destination address required.")
945 TEXT_FOR_ERROR(SOCEMSGSIZE , "Message too long.")
946 TEXT_FOR_ERROR(SOCEPROTOTYPE , "Protocol wrong type for socket.")
947 TEXT_FOR_ERROR(SOCENOPROTOOPT , "Protocol not available.")
948 TEXT_FOR_ERROR(SOCEPROTONOSUPPORT, "Protocol not supported.")
949 TEXT_FOR_ERROR(SOCESOCKTNOSUPPORT, "Socket type not supported.")
950 TEXT_FOR_ERROR(SOCEOPNOTSUPP , "Operation not supported.")
951 TEXT_FOR_ERROR(SOCEPFNOSUPPORT , "Protocol family not supported.")
952 TEXT_FOR_ERROR(SOCEAFNOSUPPORT , "Address family not supported by protocol family.")
953 TEXT_FOR_ERROR(SOCEADDRINUSE , "Address already in use.")
954 TEXT_FOR_ERROR(SOCEADDRNOTAVAIL , "Can't assign requested address.")
955 TEXT_FOR_ERROR(SOCENETDOWN , "Network is down.")
956 TEXT_FOR_ERROR(SOCENETUNREACH , "Network is unreachable.")
957 TEXT_FOR_ERROR(SOCENETRESET , "Network dropped connection on reset.")
958 TEXT_FOR_ERROR(SOCECONNABORTED , "Software caused connection abort.")
959 TEXT_FOR_ERROR(SOCECONNRESET , "Connection reset by peer.")
960 TEXT_FOR_ERROR(SOCENOBUFS , "No buffer space available.")
961 TEXT_FOR_ERROR(SOCEISCONN , "Socket is already connected.")
962 TEXT_FOR_ERROR(SOCENOTCONN , "Socket is not connected.")
963 TEXT_FOR_ERROR(SOCESHUTDOWN , "Can't send after socket shutdown.")
964 TEXT_FOR_ERROR(SOCETOOMANYREFS , "Too many references: can't splice.")
965 TEXT_FOR_ERROR(SOCETIMEDOUT , "Operation timed out.")
966 TEXT_FOR_ERROR(SOCECONNREFUSED , "Connection refused.")
967 TEXT_FOR_ERROR(SOCELOOP , "Too many levels of symbolic links.")
968 TEXT_FOR_ERROR(SOCENAMETOOLONG , "File name too long.")
969 TEXT_FOR_ERROR(SOCEHOSTDOWN , "Host is down.")
970 TEXT_FOR_ERROR(SOCEHOSTUNREACH , "No route to host.")
971 TEXT_FOR_ERROR(SOCENOTEMPTY , "Directory not empty.")
972 TEXT_FOR_ERROR(SOCEOS2ERR , "OS/2 Error.")
974 sprintf(tmp_buf, "(error number %d)", errcode);
977 #endif /* def __OS2__ */