+#ifdef _WIN32
+/*********************************************************************
+ *
+ * Function : w32_socket_strerr
+ *
+ * Description : Translate the return value from WSAGetLastError()
+ * into a string.
+ *
+ * Parameters :
+ * 1 : errcode = The return value from WSAGetLastError().
+ * 2 : tmp_buf = A temporary buffer that might be used to
+ * store the string.
+ *
+ * Returns : String representing the error code. This may be
+ * a global string constant or a string stored in
+ * tmp_buf.
+ *
+ *********************************************************************/
+static char *w32_socket_strerr(int errcode, char *tmp_buf)
+{
+#define TEXT_FOR_ERROR(code,text) \
+ if (errcode == code) \
+ { \
+ return #code " - " text; \
+ }
+
+ TEXT_FOR_ERROR(WSAEACCES, "Permission denied")
+ TEXT_FOR_ERROR(WSAEADDRINUSE, "Address already in use.")
+ TEXT_FOR_ERROR(WSAEADDRNOTAVAIL, "Cannot assign requested address.");
+ TEXT_FOR_ERROR(WSAEAFNOSUPPORT, "Address family not supported by protocol family.");
+ TEXT_FOR_ERROR(WSAEALREADY, "Operation already in progress.");
+ TEXT_FOR_ERROR(WSAECONNABORTED, "Software caused connection abort.");
+ TEXT_FOR_ERROR(WSAECONNREFUSED, "Connection refused.");
+ TEXT_FOR_ERROR(WSAECONNRESET, "Connection reset by peer.");
+ TEXT_FOR_ERROR(WSAEDESTADDRREQ, "Destination address required.");
+ TEXT_FOR_ERROR(WSAEFAULT, "Bad address.");
+ TEXT_FOR_ERROR(WSAEHOSTDOWN, "Host is down.");
+ TEXT_FOR_ERROR(WSAEHOSTUNREACH, "No route to host.");
+ TEXT_FOR_ERROR(WSAEINPROGRESS, "Operation now in progress.");
+ TEXT_FOR_ERROR(WSAEINTR, "Interrupted function call.");
+ TEXT_FOR_ERROR(WSAEINVAL, "Invalid argument.");
+ TEXT_FOR_ERROR(WSAEISCONN, "Socket is already connected.");
+ TEXT_FOR_ERROR(WSAEMFILE, "Too many open sockets.");
+ TEXT_FOR_ERROR(WSAEMSGSIZE, "Message too long.");
+ TEXT_FOR_ERROR(WSAENETDOWN, "Network is down.");
+ TEXT_FOR_ERROR(WSAENETRESET, "Network dropped connection on reset.");
+ TEXT_FOR_ERROR(WSAENETUNREACH, "Network is unreachable.");
+ TEXT_FOR_ERROR(WSAENOBUFS, "No buffer space available.");
+ TEXT_FOR_ERROR(WSAENOPROTOOPT, "Bad protocol option.");
+ TEXT_FOR_ERROR(WSAENOTCONN, "Socket is not connected.");
+ TEXT_FOR_ERROR(WSAENOTSOCK, "Socket operation on non-socket.");
+ TEXT_FOR_ERROR(WSAEOPNOTSUPP, "Operation not supported.");
+ TEXT_FOR_ERROR(WSAEPFNOSUPPORT, "Protocol family not supported.");
+ TEXT_FOR_ERROR(WSAEPROCLIM, "Too many processes.");
+ TEXT_FOR_ERROR(WSAEPROTONOSUPPORT, "Protocol not supported.");
+ TEXT_FOR_ERROR(WSAEPROTOTYPE, "Protocol wrong type for socket.");
+ TEXT_FOR_ERROR(WSAESHUTDOWN, "Cannot send after socket shutdown.");
+ TEXT_FOR_ERROR(WSAESOCKTNOSUPPORT, "Socket type not supported.");
+ TEXT_FOR_ERROR(WSAETIMEDOUT, "Connection timed out.");
+ TEXT_FOR_ERROR(WSAEWOULDBLOCK, "Resource temporarily unavailable.");
+ TEXT_FOR_ERROR(WSAHOST_NOT_FOUND, "Host not found.");
+ TEXT_FOR_ERROR(WSANOTINITIALISED, "Successful WSAStartup not yet performed.");
+ TEXT_FOR_ERROR(WSANO_DATA, "Valid name, no data record of requested type.");
+ TEXT_FOR_ERROR(WSANO_RECOVERY, "This is a non-recoverable error.");
+ TEXT_FOR_ERROR(WSASYSNOTREADY, "Network subsystem is unavailable.");
+ TEXT_FOR_ERROR(WSATRY_AGAIN, "Non-authoritative host not found.");
+ TEXT_FOR_ERROR(WSAVERNOTSUPPORTED, "WINSOCK.DLL version out of range.");
+ TEXT_FOR_ERROR(WSAEDISCON, "Graceful shutdown in progress.");
+ /*
+ * The following error codes are documented in the Microsoft WinSock
+ * reference guide, but don't actually exist.
+ *
+ * TEXT_FOR_ERROR(WSA_INVALID_HANDLE, "Specified event object handle is invalid.");
+ * TEXT_FOR_ERROR(WSA_INVALID_PARAMETER, "One or more parameters are invalid.");
+ * TEXT_FOR_ERROR(WSAINVALIDPROCTABLE, "Invalid procedure table from service provider.");
+ * TEXT_FOR_ERROR(WSAINVALIDPROVIDER, "Invalid service provider version number.");
+ * TEXT_FOR_ERROR(WSA_IO_PENDING, "Overlapped operations will complete later.");
+ * TEXT_FOR_ERROR(WSA_IO_INCOMPLETE, "Overlapped I/O event object not in signaled state.");
+ * TEXT_FOR_ERROR(WSA_NOT_ENOUGH_MEMORY, "Insufficient memory available.");
+ * TEXT_FOR_ERROR(WSAPROVIDERFAILEDINIT, "Unable to initialize a service provider.");
+ * TEXT_FOR_ERROR(WSASYSCALLFAILURE, "System call failure.");
+ * TEXT_FOR_ERROR(WSA_OPERATION_ABORTED, "Overlapped operation aborted.");
+ */
+
+ sprintf(tmp_buf, "(error number %d)", errcode);
+ return tmp_buf;
+}
+#endif /* def _WIN32 */
+
+
+#ifdef __OS2__
+/*********************************************************************
+ *
+ * Function : os2_socket_strerr
+ *
+ * Description : Translate the return value from sock_errno()
+ * into a string.
+ *
+ * Parameters :
+ * 1 : errcode = The return value from sock_errno().
+ * 2 : tmp_buf = A temporary buffer that might be used to
+ * store the string.
+ *
+ * Returns : String representing the error code. This may be
+ * a global string constant or a string stored in
+ * tmp_buf.
+ *
+ *********************************************************************/
+static char *os2_socket_strerr(int errcode, char *tmp_buf)
+{
+#define TEXT_FOR_ERROR(code,text) \
+ if (errcode == code) \
+ { \
+ return #code " - " text; \
+ }
+
+ TEXT_FOR_ERROR(SOCEPERM , "Not owner.")
+ TEXT_FOR_ERROR(SOCESRCH , "No such process.")
+ TEXT_FOR_ERROR(SOCEINTR , "Interrupted system call.")
+ TEXT_FOR_ERROR(SOCENXIO , "No such device or address.")
+ TEXT_FOR_ERROR(SOCEBADF , "Bad file number.")
+ TEXT_FOR_ERROR(SOCEACCES , "Permission denied.")
+ TEXT_FOR_ERROR(SOCEFAULT , "Bad address.")
+ TEXT_FOR_ERROR(SOCEINVAL , "Invalid argument.")
+ TEXT_FOR_ERROR(SOCEMFILE , "Too many open files.")
+ TEXT_FOR_ERROR(SOCEPIPE , "Broken pipe.")
+ TEXT_FOR_ERROR(SOCEWOULDBLOCK , "Operation would block.")
+ TEXT_FOR_ERROR(SOCEINPROGRESS , "Operation now in progress.")
+ TEXT_FOR_ERROR(SOCEALREADY , "Operation already in progress.")
+ TEXT_FOR_ERROR(SOCENOTSOCK , "Socket operation on non-socket.")
+ TEXT_FOR_ERROR(SOCEDESTADDRREQ , "Destination address required.")
+ TEXT_FOR_ERROR(SOCEMSGSIZE , "Message too long.")
+ TEXT_FOR_ERROR(SOCEPROTOTYPE , "Protocol wrong type for socket.")
+ TEXT_FOR_ERROR(SOCENOPROTOOPT , "Protocol not available.")
+ TEXT_FOR_ERROR(SOCEPROTONOSUPPORT, "Protocol not supported.")
+ TEXT_FOR_ERROR(SOCESOCKTNOSUPPORT, "Socket type not supported.")
+ TEXT_FOR_ERROR(SOCEOPNOTSUPP , "Operation not supported.")
+ TEXT_FOR_ERROR(SOCEPFNOSUPPORT , "Protocol family not supported.")
+ TEXT_FOR_ERROR(SOCEAFNOSUPPORT , "Address family not supported by protocol family.")
+ TEXT_FOR_ERROR(SOCEADDRINUSE , "Address already in use.")
+ TEXT_FOR_ERROR(SOCEADDRNOTAVAIL , "Can't assign requested address.")
+ TEXT_FOR_ERROR(SOCENETDOWN , "Network is down.")
+ TEXT_FOR_ERROR(SOCENETUNREACH , "Network is unreachable.")
+ TEXT_FOR_ERROR(SOCENETRESET , "Network dropped connection on reset.")
+ TEXT_FOR_ERROR(SOCECONNABORTED , "Software caused connection abort.")
+ TEXT_FOR_ERROR(SOCECONNRESET , "Connection reset by peer.")
+ TEXT_FOR_ERROR(SOCENOBUFS , "No buffer space available.")
+ TEXT_FOR_ERROR(SOCEISCONN , "Socket is already connected.")
+ TEXT_FOR_ERROR(SOCENOTCONN , "Socket is not connected.")
+ TEXT_FOR_ERROR(SOCESHUTDOWN , "Can't send after socket shutdown.")
+ TEXT_FOR_ERROR(SOCETOOMANYREFS , "Too many references: can't splice.")
+ TEXT_FOR_ERROR(SOCETIMEDOUT , "Operation timed out.")
+ TEXT_FOR_ERROR(SOCECONNREFUSED , "Connection refused.")
+ TEXT_FOR_ERROR(SOCELOOP , "Too many levels of symbolic links.")
+ TEXT_FOR_ERROR(SOCENAMETOOLONG , "File name too long.")
+ TEXT_FOR_ERROR(SOCEHOSTDOWN , "Host is down.")
+ TEXT_FOR_ERROR(SOCEHOSTUNREACH , "No route to host.")
+ TEXT_FOR_ERROR(SOCENOTEMPTY , "Directory not empty.")
+ TEXT_FOR_ERROR(SOCEOS2ERR , "OS/2 Error.")
+
+ sprintf(tmp_buf, "(error number %d)", errcode);
+ return tmp_buf;
+}
+#endif /* def __OS2__ */
+
+