1 /*********************************************************************
3 * File : $Source: /cvsroot/ijbswa/current/errlog.c,v $
5 * Purpose : Log errors to a designated destination in an elegant,
8 * Copyright : Written by and Copyright (C) 2001-2014 the
9 * Privoxy team. https://www.privoxy.org/
11 * Based on the Internet Junkbuster originally written
12 * by and Copyright (C) 1997 Anonymous Coders and
13 * Junkbusters Corporation. http://www.junkbusters.com
15 * This program is free software; you can redistribute it
16 * and/or modify it under the terms of the GNU General
17 * Public License as published by the Free Software
18 * Foundation; either version 2 of the License, or (at
19 * your option) any later version.
21 * This program is distributed in the hope that it will
22 * be useful, but WITHOUT ANY WARRANTY; without even the
23 * implied warranty of MERCHANTABILITY or FITNESS FOR A
24 * PARTICULAR PURPOSE. See the GNU General Public
25 * License for more details.
27 * The GNU General Public License should be included with
28 * this file. If not, you can view it at
29 * http://www.gnu.org/copyleft/gpl.html
30 * or write to the Free Software Foundation, Inc., 59
31 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 *********************************************************************/
45 /* For gettimeofday() */
50 #endif /* !defined(_WIN32) */
62 #endif /* ndef _WIN_CONSOLE */
63 #endif /* def _WIN32 */
65 #define inline __inline
66 #endif /* def _MSC_VER */
71 #ifdef FEATURE_EXTERNAL_FILTERS
72 #include "jbsockets.h"
76 * LOG_LEVEL_FATAL cannot be turned off. (There are
77 * some exceptional situations where we need to get a
78 * message to the user).
80 #define LOG_LEVEL_MINIMUM LOG_LEVEL_FATAL
82 /* where to log (default: stderr) */
83 static FILE *logfp = NULL;
85 /* logging detail level. XXX: stupid name. */
86 static int debug = (LOG_LEVEL_FATAL | LOG_LEVEL_ERROR);
88 /* static functions */
89 static void fatal_error(const char * error_message);
91 static char *w32_socket_strerr(int errcode, char *tmp_buf);
94 #ifdef MUTEX_LOCKS_AVAILABLE
95 static void lock_logfile(void)
97 privoxy_mutex_lock(&log_mutex);
99 static void unlock_logfile(void)
101 privoxy_mutex_unlock(&log_mutex);
103 static void lock_loginit(void)
105 privoxy_mutex_lock(&log_init_mutex);
107 static void unlock_loginit(void)
109 privoxy_mutex_unlock(&log_init_mutex);
111 #else /* ! MUTEX_LOCKS_AVAILABLE */
113 * FIXME we need a cross-platform locking mechanism.
114 * The locking/unlocking functions below should be
115 * fleshed out for non-pthread implementations.
117 static void lock_logfile() {}
118 static void unlock_logfile() {}
119 static void lock_loginit() {}
120 static void unlock_loginit() {}
123 /*********************************************************************
125 * Function : fatal_error
127 * Description : Displays a fatal error to standard error (or, on
128 * a WIN32 GUI, to a dialog box), and exits Privoxy
129 * with status code 1.
132 * 1 : error_message = The error message to display.
134 * Returns : Does not return.
136 *********************************************************************/
137 static void fatal_error(const char *error_message)
141 fputs(error_message, logfp);
144 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
146 /* Skip timestamp and thread id for the message box. */
147 const char *box_message = strstr(error_message, "Fatal error");
148 if (NULL == box_message)
150 /* Shouldn't happen but ... */
151 box_message = error_message;
153 MessageBox(g_hwndLogFrame, box_message, "Privoxy Error",
154 MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND | MB_TOPMOST);
156 /* Cleanup - remove taskbar icon etc. */
159 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
172 /*********************************************************************
174 * Function : show_version
176 * Description : Logs the Privoxy version and the program name.
179 * 1 : prog_name = The program name.
183 *********************************************************************/
184 void show_version(const char *prog_name)
186 log_error(LOG_LEVEL_INFO, "Privoxy version " VERSION);
187 if (prog_name != NULL)
189 log_error(LOG_LEVEL_INFO, "Program name: %s", prog_name);
194 /*********************************************************************
196 * Function : init_log_module
198 * Description : Initializes the logging module to log to stderr.
199 * Can only be called while stderr hasn't been closed
200 * yet and is only supposed to be called once.
203 * 1 : prog_name = The program name.
207 *********************************************************************/
208 void init_log_module(void)
213 set_debug_level(debug);
217 /*********************************************************************
219 * Function : set_debug_level
221 * Description : Sets the debug level to the provided value
222 * plus LOG_LEVEL_MINIMUM.
224 * XXX: we should only use the LOG_LEVEL_MINIMUM
225 * until the first time the configuration file has
228 * Parameters : 1: debug_level = The debug level to set.
232 *********************************************************************/
233 void set_debug_level(int debug_level)
236 if (LOG_LEVEL_STFU == debug_level)
238 debug = LOG_LEVEL_STFU;
240 if (LOG_LEVEL_STFU == debug)
246 debug = debug_level | LOG_LEVEL_MINIMUM;
250 /*********************************************************************
252 * Function : debug_level_is_enabled
254 * Description : Checks if a certain debug level is enabled.
256 * Parameters : 1: debug_level = The debug level to check.
260 *********************************************************************/
261 int debug_level_is_enabled(int debug_level)
263 return (0 != (debug & debug_level));
267 /*********************************************************************
269 * Function : disable_logging
271 * Description : Disables logging.
277 *********************************************************************/
278 void disable_logging(void)
282 log_error(LOG_LEVEL_INFO,
283 "No logfile configured. Please enable it before reporting any problems.");
292 /*********************************************************************
294 * Function : init_error_log
296 * Description : Initializes the logging module to log to a file.
298 * XXX: should be renamed.
301 * 1 : prog_name = The program name.
302 * 2 : logfname = The logfile to (re)open.
306 *********************************************************************/
307 void init_error_log(const char *prog_name, const char *logfname)
311 assert(NULL != logfname);
315 if ((logfp != NULL) && (logfp != stderr))
317 log_error(LOG_LEVEL_INFO, "(Re-)Opening logfile \'%s\'", logfname);
320 /* set the designated log file */
321 fp = fopen(logfname, "a");
322 if ((NULL == fp) && (logfp != NULL))
325 * Some platforms (like OS/2 (XXX: no longer supported)) don't
326 * allow us to open the same file twice, therefore we give it
327 * another shot after closing the old file descriptor first.
329 * We don't do it right away because it prevents us
330 * from logging the "can't open logfile" message to
333 * XXX: this is a lame workaround and once the next
334 * release is out we should stop bothering reopening
335 * the logfile unless we have to.
337 * Currently we reopen it every time the config file
338 * has been reloaded, but actually we only have to
339 * reopen it if the file name changed or if the
340 * configuration reload was caused by a SIGHUP.
342 log_error(LOG_LEVEL_INFO, "Failed to reopen logfile: \'%s\'. "
343 "Retrying after closing the old file descriptor first. If that "
344 "doesn't work, Privoxy will exit without being able to log a message.",
350 fp = fopen(logfname, "a");
355 log_error(LOG_LEVEL_FATAL, "init_error_log(): can't open logfile: \'%s\'", logfname);
358 #ifdef FEATURE_EXTERNAL_FILTERS
359 mark_socket_for_close_on_execute(3);
362 /* set logging to be completely unbuffered */
371 if (daemon_mode && (logfp == stderr))
373 if (dup2(1, 2) == -1)
376 * We only use fatal_error() to clear the pid
377 * file and to exit. Given that stderr has just
378 * been closed, the user will not see the error
381 fatal_error("Failed to reserve fd 2.");
388 show_version(prog_name);
392 } /* init_error_log */
395 /*********************************************************************
397 * Function : get_thread_id
399 * Description : Returns a number that is different for each thread.
401 * XXX: Should be moved elsewhere (miscutil.c?)
405 * Returns : thread_id
407 *********************************************************************/
408 static long get_thread_id(void)
412 /* FIXME get current thread id */
413 #ifdef FEATURE_PTHREAD
414 this_thread = (long)pthread_self();
417 * Mac OSX (and perhaps other Mach instances) doesn't have a unique
418 * value at the lowest order 4 bytes of pthread_self()'s return value, a pthread_t,
419 * so trim the three lowest-order bytes from the value (16^3).
421 this_thread = this_thread / 4096;
422 #endif /* def __MACH__ */
423 #elif defined(_WIN32)
424 this_thread = GetCurrentThreadId();
426 /* Forking instead of threading. */
428 #endif /* def FEATURE_PTHREAD */
434 /*********************************************************************
436 * Function : get_log_timestamp
438 * Description : Generates the time stamp for the log message prefix.
441 * 1 : buffer = Storage buffer
442 * 2 : buffer_size = Size of storage buffer
444 * Returns : Number of written characters or 0 for error.
446 *********************************************************************/
447 static size_t get_log_timestamp(char *buffer, size_t buffer_size)
452 struct timeval tv_now; /* XXX: stupid name */
454 int msecs_length = 0;
456 gettimeofday(&tv_now, NULL);
457 msecs = tv_now.tv_usec / 1000;
460 #ifdef HAVE_LOCALTIME_R
461 tm_now = *localtime_r(&now, &tm_now);
462 #elif defined(MUTEX_LOCKS_AVAILABLE)
463 privoxy_mutex_lock(&localtime_mutex);
464 tm_now = *localtime(&now);
465 privoxy_mutex_unlock(&localtime_mutex);
467 tm_now = *localtime(&now);
470 length = strftime(buffer, buffer_size, "%Y-%m-%d %H:%M:%S", &tm_now);
471 if (length > (size_t)0)
473 msecs_length = snprintf(buffer+length, buffer_size - length, ".%.3ld", msecs);
475 if (msecs_length > 0)
477 length += (size_t)msecs_length;
488 /*********************************************************************
490 * Function : get_clf_timestamp
492 * Description : Generates a Common Log Format time string.
495 * 1 : buffer = Storage buffer
496 * 2 : buffer_size = Size of storage buffer
498 * Returns : Number of written characters or 0 for error.
500 *********************************************************************/
501 static size_t get_clf_timestamp(char *buffer, size_t buffer_size)
504 * Complex because not all OSs have tm_gmtoff or
505 * the %z field in strftime()
510 #ifdef HAVE_LOCALTIME_R
518 gmt = *privoxy_gmtime_r(&now, &gmt);
519 #ifdef HAVE_LOCALTIME_R
520 tm_now = localtime_r(&now, &dummy);
521 #elif defined(MUTEX_LOCKS_AVAILABLE)
522 privoxy_mutex_lock(&localtime_mutex);
523 tm_now = localtime(&now);
525 tm_now = localtime(&now);
527 days = tm_now->tm_yday - gmt.tm_yday;
528 hrs = ((days < -1 ? 24 : 1 < days ? -24 : days * 24) + tm_now->tm_hour - gmt.tm_hour);
529 mins = hrs * 60 + tm_now->tm_min - gmt.tm_min;
531 length = strftime(buffer, buffer_size, "%d/%b/%Y:%H:%M:%S ", tm_now);
532 #if !defined(HAVE_LOCALTIME_R) && defined(MUTEX_LOCKS_AVAILABLE)
533 privoxy_mutex_unlock(&localtime_mutex);
536 if (length > (size_t)0)
538 tz_length = snprintf(buffer+length, buffer_size-length,
539 "%+03d%02d", mins / 60, abs(mins) % 60);
543 length += (size_t)tz_length;
554 /*********************************************************************
556 * Function : get_log_level_string
558 * Description : Translates a numerical loglevel into a string.
561 * 1 : loglevel = LOG_LEVEL_FOO
563 * Returns : Log level string.
565 *********************************************************************/
566 static const char *get_log_level_string(int loglevel)
568 char *log_level_string = NULL;
570 assert(0 < loglevel);
574 case LOG_LEVEL_ERROR:
575 log_level_string = "Error";
577 case LOG_LEVEL_FATAL:
578 log_level_string = "Fatal error";
580 case LOG_LEVEL_REQUEST:
581 log_level_string = "Request";
583 case LOG_LEVEL_CONNECT:
584 log_level_string = "Connect";
586 case LOG_LEVEL_TAGGING:
587 log_level_string = "Tagging";
589 case LOG_LEVEL_WRITING:
590 log_level_string = "Writing";
592 case LOG_LEVEL_RECEIVED:
593 log_level_string = "Received";
595 case LOG_LEVEL_HEADER:
596 log_level_string = "Header";
599 log_level_string = "Info";
601 case LOG_LEVEL_RE_FILTER:
602 log_level_string = "Re-Filter";
604 #ifdef FEATURE_FORCE_LOAD
605 case LOG_LEVEL_FORCE:
606 log_level_string = "Force";
608 #endif /* def FEATURE_FORCE_LOAD */
609 case LOG_LEVEL_REDIRECTS:
610 log_level_string = "Redirect";
612 case LOG_LEVEL_DEANIMATE:
613 log_level_string = "Gif-Deanimate";
615 case LOG_LEVEL_CRUNCH:
616 log_level_string = "Crunch";
619 log_level_string = "CGI";
621 case LOG_LEVEL_ACTIONS:
622 log_level_string = "Actions";
625 log_level_string = "Unknown log level";
628 assert(NULL != log_level_string);
630 return log_level_string;
634 #define LOG_BUFFER_SIZE BUFFER_SIZE
635 /*********************************************************************
637 * Function : log_error
639 * Description : This is the error-reporting and logging function.
642 * 1 : loglevel = the type of message to be logged
643 * 2 : fmt = the main string we want logged, printf-like
644 * 3 : ... = arguments to be inserted in fmt (printf-like).
648 *********************************************************************/
649 void log_error(int loglevel, const char *fmt, ...)
652 char outbuf[LOG_BUFFER_SIZE+1];
653 char tempbuf[LOG_BUFFER_SIZE];
655 const char * src = fmt;
658 const size_t log_buffer_size = LOG_BUFFER_SIZE;
660 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
662 * Irrespective of debug setting, a GET/POST/CONNECT makes
663 * the taskbar icon animate. (There is an option to disable
664 * this but checking that is handled inside LogShowActivity()).
666 if ((loglevel == LOG_LEVEL_REQUEST) || (loglevel == LOG_LEVEL_CRUNCH))
670 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
673 * verify that the loglevel applies to current
674 * settings and that logging is enabled.
675 * Bail out otherwise.
677 if ((0 == (loglevel & debug))
684 if (debug == LOG_LEVEL_STFU)
686 if (loglevel == LOG_LEVEL_FATAL)
693 if (loglevel == LOG_LEVEL_FATAL)
695 fatal_error("Fatal error. You're not supposed to"
696 "see this message. Please file a bug report.");
701 thread_id = get_thread_id();
702 get_log_timestamp(timestamp, sizeof(timestamp));
705 * Memsetting the whole buffer to zero (in theory)
706 * makes things easier later on.
708 memset(outbuf, 0, sizeof(outbuf));
710 /* Add prefix for everything but Common Log Format messages */
711 if (loglevel != LOG_LEVEL_CLF)
713 length = (size_t)snprintf(outbuf, log_buffer_size, "%s %08lx %s: ",
714 timestamp, thread_id, get_log_level_string(loglevel));
717 /* get ready to scan var. args. */
720 /* build formatted message from fmt and var-args */
721 while ((*src) && (length < log_buffer_size-2))
723 const char *sval = NULL; /* %N string */
724 int ival; /* %N string length or an error code */
725 unsigned uval; /* %u value */
726 long lval; /* %l value */
727 unsigned long ulval; /* %ul value */
729 const char *format_string = tempbuf;
734 outbuf[length++] = ch;
736 * XXX: Only necessary on platforms where multiple threads
737 * can write to the buffer at the same time because we
738 * don't support mutexes.
739 * XXX: Are there any such platforms left now that OS/2 is gone?
741 outbuf[length] = '\0';
744 outbuf[length] = '\0';
752 ival = va_arg(ap, int);
753 snprintf(tempbuf, sizeof(tempbuf), "%d", ival);
756 uval = va_arg(ap, unsigned);
757 snprintf(tempbuf, sizeof(tempbuf), "%u", uval);
760 /* this is a modifier that must be followed by u, lu, or d */
764 lval = va_arg(ap, long);
765 snprintf(tempbuf, sizeof(tempbuf), "%ld", lval);
769 ulval = va_arg(ap, unsigned long);
770 snprintf(tempbuf, sizeof(tempbuf), "%lu", ulval);
772 else if ((ch == 'l') && (*src == 'u'))
774 unsigned long long lluval = va_arg(ap, unsigned long long);
775 snprintf(tempbuf, sizeof(tempbuf), "%llu", lluval);
780 snprintf(tempbuf, sizeof(tempbuf), "Bad format string: \"%s\"", fmt);
781 loglevel = LOG_LEVEL_FATAL;
786 * Note that char parameters are converted to int, so we need to
787 * pass "int" to va_arg. (See K&R, 2nd ed, section A7.3.2, page 202)
789 tempbuf[0] = (char) va_arg(ap, int);
793 format_string = va_arg(ap, char *);
794 if (format_string == NULL)
796 format_string = "[null]";
801 * Non-standard: Print a counted unterminated string,
802 * replacing unprintable bytes with their hex value.
803 * Takes 2 parameters: int length, const char * string.
805 ival = va_arg(ap, int);
807 sval = va_arg(ap, char *);
808 assert(sval != NULL);
810 while ((ival-- > 0) && (length < log_buffer_size - 6))
812 if (isprint((int)*sval) && (*sval != '\\'))
814 outbuf[length++] = *sval;
815 outbuf[length] = '\0';
819 int ret = snprintf(outbuf + length,
820 log_buffer_size - length - 2, "\\x%.2x", (unsigned char)*sval);
830 * XXX: In case of printable characters at the end of
831 * the %N string, we're not using the whole buffer.
833 format_string = (length < log_buffer_size - 6) ? "" : "[too long]";
836 /* Non-standard: Print error code from errno */
838 ival = WSAGetLastError();
839 format_string = w32_socket_strerr(ival, tempbuf);
840 #else /* ifndef _WIN32 */
843 format_string = strerror(ival);
844 #else /* ifndef HAVE_STRERROR */
845 format_string = NULL;
846 #endif /* ndef HAVE_STRERROR */
849 snprintf(tempbuf, sizeof(tempbuf), "(errno = %d)", ival);
851 #endif /* ndef _WIN32 */
854 /* Non-standard: Print a Common Log File timestamp */
855 get_clf_timestamp(tempbuf, sizeof(tempbuf));
858 snprintf(tempbuf, sizeof(tempbuf), "Bad format string: \"%s\"", fmt);
859 loglevel = LOG_LEVEL_FATAL;
863 assert(length < log_buffer_size);
864 length += strlcpy(outbuf + length, format_string, log_buffer_size - length);
866 if (length >= log_buffer_size-2)
868 static const char warning[] = "... [too long, truncated]";
870 length = log_buffer_size - sizeof(warning) - 1;
871 length += strlcpy(outbuf + length, warning, log_buffer_size - length);
872 assert(length < log_buffer_size);
878 /* done with var. args */
881 assert(length < log_buffer_size);
882 length += strlcpy(outbuf + length, "\n", log_buffer_size - length);
884 /* Some sanity checks */
885 if ((length >= log_buffer_size)
886 || (outbuf[log_buffer_size-1] != '\0')
887 || (outbuf[log_buffer_size] != '\0')
890 /* Repeat as assertions */
891 assert(length < log_buffer_size);
892 assert(outbuf[log_buffer_size-1] == '\0');
894 * outbuf's real size is log_buffer_size+1,
895 * so while this looks like an off-by-one,
896 * we're only checking our paranoia byte.
898 assert(outbuf[log_buffer_size] == '\0');
900 snprintf(outbuf, log_buffer_size,
901 "%s %08lx Fatal error: log_error()'s sanity checks failed."
902 "length: %d. Exiting.",
903 timestamp, thread_id, (int)length);
904 loglevel = LOG_LEVEL_FATAL;
909 * On Windows this is acceptable in case
910 * we are logging to the GUI window only.
912 assert(NULL != logfp);
917 if (loglevel == LOG_LEVEL_FATAL)
924 fputs(outbuf, logfp);
927 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
928 /* Write to display */
929 LogPutString(outbuf);
930 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
937 /*********************************************************************
939 * Function : jb_err_to_string
941 * Description : Translates JB_ERR_FOO codes into strings.
944 * 1 : jb_error = a valid jb_err code
946 * Returns : A string with the jb_err translation
948 *********************************************************************/
949 const char *jb_err_to_string(jb_err jb_error)
954 return "Success, no error";
956 return "Out of memory";
957 case JB_ERR_CGI_PARAMS:
958 return "Missing or corrupt CGI parameters";
960 return "Error opening, reading or writing a file";
962 return "Parse error";
963 case JB_ERR_MODIFIED:
964 return "File has been modified outside of the CGI actions editor.";
965 case JB_ERR_COMPRESS:
966 return "(De)compression failure";
969 return "Internal error";
973 /*********************************************************************
975 * Function : w32_socket_strerr
977 * Description : Translate the return value from WSAGetLastError()
981 * 1 : errcode = The return value from WSAGetLastError().
982 * 2 : tmp_buf = A temporary buffer that might be used to
985 * Returns : String representing the error code. This may be
986 * a global string constant or a string stored in
989 *********************************************************************/
990 static char *w32_socket_strerr(int errcode, char *tmp_buf)
992 #define TEXT_FOR_ERROR(code,text) \
993 if (errcode == code) \
995 return #code " - " text; \
998 TEXT_FOR_ERROR(WSAEACCES, "Permission denied")
999 TEXT_FOR_ERROR(WSAEADDRINUSE, "Address already in use.")
1000 TEXT_FOR_ERROR(WSAEADDRNOTAVAIL, "Cannot assign requested address.");
1001 TEXT_FOR_ERROR(WSAEAFNOSUPPORT, "Address family not supported by protocol family.");
1002 TEXT_FOR_ERROR(WSAEALREADY, "Operation already in progress.");
1003 TEXT_FOR_ERROR(WSAECONNABORTED, "Software caused connection abort.");
1004 TEXT_FOR_ERROR(WSAECONNREFUSED, "Connection refused.");
1005 TEXT_FOR_ERROR(WSAECONNRESET, "Connection reset by peer.");
1006 TEXT_FOR_ERROR(WSAEDESTADDRREQ, "Destination address required.");
1007 TEXT_FOR_ERROR(WSAEFAULT, "Bad address.");
1008 TEXT_FOR_ERROR(WSAEHOSTDOWN, "Host is down.");
1009 TEXT_FOR_ERROR(WSAEHOSTUNREACH, "No route to host.");
1010 TEXT_FOR_ERROR(WSAEINPROGRESS, "Operation now in progress.");
1011 TEXT_FOR_ERROR(WSAEINTR, "Interrupted function call.");
1012 TEXT_FOR_ERROR(WSAEINVAL, "Invalid argument.");
1013 TEXT_FOR_ERROR(WSAEISCONN, "Socket is already connected.");
1014 TEXT_FOR_ERROR(WSAEMFILE, "Too many open sockets.");
1015 TEXT_FOR_ERROR(WSAEMSGSIZE, "Message too long.");
1016 TEXT_FOR_ERROR(WSAENETDOWN, "Network is down.");
1017 TEXT_FOR_ERROR(WSAENETRESET, "Network dropped connection on reset.");
1018 TEXT_FOR_ERROR(WSAENETUNREACH, "Network is unreachable.");
1019 TEXT_FOR_ERROR(WSAENOBUFS, "No buffer space available.");
1020 TEXT_FOR_ERROR(WSAENOPROTOOPT, "Bad protocol option.");
1021 TEXT_FOR_ERROR(WSAENOTCONN, "Socket is not connected.");
1022 TEXT_FOR_ERROR(WSAENOTSOCK, "Socket operation on non-socket.");
1023 TEXT_FOR_ERROR(WSAEOPNOTSUPP, "Operation not supported.");
1024 TEXT_FOR_ERROR(WSAEPFNOSUPPORT, "Protocol family not supported.");
1025 TEXT_FOR_ERROR(WSAEPROCLIM, "Too many processes.");
1026 TEXT_FOR_ERROR(WSAEPROTONOSUPPORT, "Protocol not supported.");
1027 TEXT_FOR_ERROR(WSAEPROTOTYPE, "Protocol wrong type for socket.");
1028 TEXT_FOR_ERROR(WSAESHUTDOWN, "Cannot send after socket shutdown.");
1029 TEXT_FOR_ERROR(WSAESOCKTNOSUPPORT, "Socket type not supported.");
1030 TEXT_FOR_ERROR(WSAETIMEDOUT, "Connection timed out.");
1031 TEXT_FOR_ERROR(WSAEWOULDBLOCK, "Resource temporarily unavailable.");
1032 TEXT_FOR_ERROR(WSAHOST_NOT_FOUND, "Host not found.");
1033 TEXT_FOR_ERROR(WSANOTINITIALISED, "Successful WSAStartup not yet performed.");
1034 TEXT_FOR_ERROR(WSANO_DATA, "Valid name, no data record of requested type.");
1035 TEXT_FOR_ERROR(WSANO_RECOVERY, "This is a non-recoverable error.");
1036 TEXT_FOR_ERROR(WSASYSNOTREADY, "Network subsystem is unavailable.");
1037 TEXT_FOR_ERROR(WSATRY_AGAIN, "Non-authoritative host not found.");
1038 TEXT_FOR_ERROR(WSAVERNOTSUPPORTED, "WINSOCK.DLL version out of range.");
1039 TEXT_FOR_ERROR(WSAEDISCON, "Graceful shutdown in progress.");
1041 * The following error codes are documented in the Microsoft WinSock
1042 * reference guide, but don't actually exist.
1044 * TEXT_FOR_ERROR(WSA_INVALID_HANDLE, "Specified event object handle is invalid.");
1045 * TEXT_FOR_ERROR(WSA_INVALID_PARAMETER, "One or more parameters are invalid.");
1046 * TEXT_FOR_ERROR(WSAINVALIDPROCTABLE, "Invalid procedure table from service provider.");
1047 * TEXT_FOR_ERROR(WSAINVALIDPROVIDER, "Invalid service provider version number.");
1048 * TEXT_FOR_ERROR(WSA_IO_PENDING, "Overlapped operations will complete later.");
1049 * TEXT_FOR_ERROR(WSA_IO_INCOMPLETE, "Overlapped I/O event object not in signaled state.");
1050 * TEXT_FOR_ERROR(WSA_NOT_ENOUGH_MEMORY, "Insufficient memory available.");
1051 * TEXT_FOR_ERROR(WSAPROVIDERFAILEDINIT, "Unable to initialize a service provider.");
1052 * TEXT_FOR_ERROR(WSASYSCALLFAILURE, "System call failure.");
1053 * TEXT_FOR_ERROR(WSA_OPERATION_ABORTED, "Overlapped operation aborted.");
1056 sprintf(tmp_buf, "(error number %d)", errcode);
1059 #endif /* def _WIN32 */