#include "winsock2.h"
static struct {
	int ern;
	char *msg;
} asockerr[]= {	
    {WSAEINTR ,               "WSAEINTR: Interrupted function call"},
    {WSAEBADF ,               "WSAEBADF: Bad file number"},
    {WSAEACCES ,              "WSAEACCES: Permission denied"},
    {WSAEFAULT ,              "WSAEFAULT: Address fault"},
    {WSAEINVAL ,              "WSAEINVAL: Invalid argument"},
    {WSAEMFILE ,              "WSAEMFILE: Too many open files"},
    {WSAEWOULDBLOCK ,         "WSAEWOULDBLOCK: Resource temporarily unavailable (Would block)"},
    {WSAEINPROGRESS ,         "WSAEINPROGRESS: Operation now in progress"},
    {WSAEALREADY ,            "WSAEALREADY: Operation already in progress"},
    {WSAENOTSOCK ,            "WSAENOTSOCK: Socket operation on non-socket"},
    {WSAEDESTADDRREQ ,        "WSAEDESTADDRREQ: Destination address required"},
    {WSAEMSGSIZE ,            "WSAEMSGSIZE: Message too long"},
    {WSAEPROTOTYPE ,          "WSAEPROTOTYPE: Protocol wrong type for socket"},
    {WSAENOPROTOOPT ,         "WSAENOPROTOOPT: Bad protocol option"},
    {WSAEPROTONOSUPPORT ,     "WSAEPROTONOSUPPORT: Protocol not supported"},
    {WSAESOCKTNOSUPPORT ,     "WSAESOCKTNOSUPPORT: Socket type not supported"},
    {WSAEOPNOTSUPP ,          "WSAEOPNOTSUPP: Operation not supported"},
    {WSAEPFNOSUPPORT ,        "WSAEPFNOSUPPORT: Protocol family not supported"},
    {WSAEAFNOSUPPORT ,        "WSAEAFNOSUPPORT: Address family not supported by protocol family"},
    {WSAEADDRINUSE ,          "WSAEADDRINUSE: Address already in use"},
    {WSAEADDRNOTAVAIL ,       "WSAEADDRNOTAVAIL: Cannot assign requested address"},
    {WSAENETDOWN ,            "WSAENETDOWN: Network is down"},
    {WSAENETUNREACH ,         "WSAENETUNREACH: Network is unreachable"},
    {WSAENETRESET ,           "WSAENETRESET: Network dropped connection on reset"},
    {WSAECONNABORTED ,        "WSAECONNABORTED: Software caused connection abort"},
    {WSAECONNRESET ,          "WSAECONNRESET: Connection reset by peer"},
    {WSAENOBUFS ,             "WSAENOBUFS: No buffer space available"},
    {WSAEISCONN ,             "WSAEISCONN: Socket is already connected"},
    {WSAENOTCONN ,            "WSAENOTCONN: Socket is not connected"},
    {WSAESHUTDOWN ,           "WSAESHUTDOWN: Cannot send after socket shutdown"},
    {WSAETOOMANYREFS ,        "WSAETOOMANYREFS: Too many references"},
    {WSAETIMEDOUT ,           "WSAETIMEDOUT: Connection timed out"},
    {WSAECONNREFUSED ,        "WSAECONNREFUSED: Connection refused"},
    {WSAELOOP ,               "WSAELOOP: Loop"},
    {WSAENAMETOOLONG ,        "WSAENAMETOOLONG: Name too long"},
    {WSAEHOSTDOWN ,           "WSAEHOSTDOWN: Host is down"},
    {WSAEHOSTUNREACH ,        "WSAEHOSTUNREACH: No route to host"},
    {WSAENOTEMPTY ,           "WSAENOTEMPTY: Directory not empty"},
    {WSAEPROCLIM ,            "WSAEPROCLIM: Too many processes"},
    {WSAEUSERS ,              "WSAEUSERS: Too many users"},
    {WSAEDQUOT ,              "WSAEDQUOT: Disk quota"},
    {WSAESTALE ,              "WSAESTALE: Stale"},
    {WSAEREMOTE ,             "WSAEREMOTE: Remote"},
    {WSASYSNOTREADY ,         "WSASYSNOTREADY: Network subsystem is unavailable"},
    {WSAVERNOTSUPPORTED ,     "WSAVERNOTSUPPORTED: WINSOCK.DLL version out of range"},
    {WSANOTINITIALISED ,      "WSANOTINITIALISED: Successful WSAStartup() not yet performed"},
    {WSAEDISCON ,             "WSAEDISCON: Graceful shutdown in progress"},
    {WSAHOST_NOT_FOUND ,      "WSAHOST_NOT_FOUND: Host not found"},
    {WSATRY_AGAIN ,           "WSATRY_AGAIN: Non-authoritative host not found"},
    {WSANO_RECOVERY ,         "WSANO_RECOVERY: Non-recoverable error"},
    {WSANO_DATA ,             "WSANO_DATA: Valid name no data record of requested type"},
	{0,0}
};

char *sockerr(int errn){
	int i;
	for(i= 0; asockerr[i].ern; i++)
		if(asockerr[i].ern==errn)
			return asockerr[i].msg;
	return "?";
}
