1 #include "HsNet.h"
2 #include "HsFFI.h"
3 
4 #if defined(_WIN32)
5 #include <stdio.h>
6 
7 /* to the end */
8 
9 const char*
getWSErrorDescr(int err)10 getWSErrorDescr(int err)
11 {
12   static char  otherErrMsg[256];
13 
14   switch (err) {
15   case WSAEINTR:  return "Interrupted function call (WSAEINTR)";
16   case WSAEBADF:  return "bad socket descriptor (WSAEBADF)";
17   case WSAEACCES: return "Permission denied (WSAEACCESS)";
18   case WSAEFAULT: return "Bad address (WSAEFAULT)";
19   case WSAEINVAL: return "Invalid argument (WSAEINVAL)";
20   case WSAEMFILE: return "Too many open files (WSAEMFILE)";
21   case WSAEWOULDBLOCK:  return "Resource temporarily unavailable (WSAEWOULDBLOCK)";
22   case WSAEINPROGRESS:  return "Operation now in progress (WSAEINPROGRESS)";
23   case WSAEALREADY:     return "Operation already in progress (WSAEALREADY)";
24   case WSAENOTSOCK:     return "Socket operation on non-socket (WSAENOTSOCK)";
25   case WSAEDESTADDRREQ: return "Destination address required (WSAEDESTADDRREQ)";
26   case WSAEMSGSIZE:    	return "Message too long (WSAEMSGSIZE)";
27   case WSAEPROTOTYPE:   return "Protocol wrong type for socket (WSAEPROTOTYPE)";
28   case WSAENOPROTOOPT:  return "Bad protocol option (WSAENOPROTOOPT)";
29   case WSAEPROTONOSUPPORT: return "Protocol not supported (WSAEPROTONOSUPPORT)";
30   case WSAESOCKTNOSUPPORT: return "Socket type not supported (WSAESOCKTNOSUPPORT)";
31   case WSAEOPNOTSUPP:      return "Operation not supported (WSAEOPNOTSUPP)";
32   case WSAEPFNOSUPPORT:    return "Protocol family not supported (WSAEPFNOSUPPORT)";
33   case WSAEAFNOSUPPORT:    return "Address family not supported by protocol family (WSAEAFNOSUPPORT)";
34   case WSAEADDRINUSE:      return "Address already in use (WSAEADDRINUSE)";
35   case WSAEADDRNOTAVAIL:   return "Cannot assign requested address (WSAEADDRNOTAVAIL)";
36   case WSAENETDOWN:        return "Network is down (WSAENETDOWN)";
37   case WSAENETUNREACH:     return "Network is unreachable (WSAENETUNREACH)";
38   case WSAENETRESET:       return "Network dropped connection on reset (WSAENETRESET)";
39   case WSAECONNABORTED:    return "Software caused connection abort (WSAECONNABORTED)";
40   case WSAECONNRESET:      return "Connection reset by peer (WSAECONNRESET)";
41   case WSAENOBUFS:         return "No buffer space available (WSAENOBUFS)";
42   case WSAEISCONN:         return "Socket is already connected (WSAEISCONN)";
43   case WSAENOTCONN:        return "Socket is not connected (WSAENOTCONN)";
44   case WSAESHUTDOWN:       return "Cannot send after socket shutdown (WSAESHUTDOWN)";
45   case WSAETOOMANYREFS:    return "Too many references (WSAETOOMANYREFS)";
46   case WSAETIMEDOUT:       return "Connection timed out (WSAETIMEDOUT)";
47   case WSAECONNREFUSED:    return "Connection refused (WSAECONNREFUSED)";
48   case WSAELOOP:           return "Too many levels of symbolic links (WSAELOOP)";
49   case WSAENAMETOOLONG:    return "Filename too long (WSAENAMETOOLONG)";
50   case WSAEHOSTDOWN:       return "Host is down (WSAEHOSTDOWN)";
51   case WSAEHOSTUNREACH:    return "Host is unreachable (WSAEHOSTUNREACH)";
52   case WSAENOTEMPTY:       return "Resource not empty (WSAENOTEMPTY)";
53   case WSAEPROCLIM:        return "Too many processes (WSAEPROCLIM)";
54   case WSAEUSERS:          return "Too many users (WSAEUSERS)";
55   case WSAEDQUOT:          return "Disk quota exceeded (WSAEDQUOT)";
56   case WSAESTALE:          return "Stale NFS file handle (WSAESTALE)";
57   case WSAEREMOTE:         return "Too many levels of remote in path (WSAEREMOTE)";
58   case WSAEDISCON:         return "Graceful shutdown in progress (WSAEDISCON)";
59   case WSASYSNOTREADY:     return "Network subsystem is unavailable (WSASYSNOTREADY)";
60   case WSAVERNOTSUPPORTED: return "Winsock.dll version out of range (WSAVERNOTSUPPORTED)";
61   case WSANOTINITIALISED:  return "Successful WSAStartup not yet performed (WSANOTINITIALISED)";
62 #ifdef WSATYPE_NOT_FOUND
63   case WSATYPE_NOT_FOUND:  return "Class type not found (WSATYPE_NOT_FOUND)";
64 #endif
65   case WSAHOST_NOT_FOUND:  return "Host not found (WSAHOST_NOT_FOUND)";
66   case WSATRY_AGAIN:       return "Nonauthoritative host not found (WSATRY_AGAIN)";
67   case WSANO_RECOVERY:     return "This is a nonrecoverable error (WSANO_RECOVERY)";
68   case WSANO_DATA:         return "Valid name, no data record of requested type (WSANO_DATA)";
69   default:
70     sprintf(otherErrMsg, "Unknown WinSock error: %u", err);
71     return otherErrMsg;
72   }
73 }
74 
75 #endif
76 
77