#include <stdio.h>
#include <winsock.h>
struct err_strs {
char **strs;
int first;
int last;
};
static char *errs1[] = {
"Interrupted system call"
};
static char *errs2[] = {
"Bad file descriptor"
};
static char *errs3[] = {
"Permission denied",
"Bad address"
};
static char *errs4[] = {
"Invalid argument"
};
static char *errs5[] = {
"Too many open files",
};
static char *errs6[] = {
"Resource temporarily unavailable",
"Operation now in progress",
"Operation already in progress",
"Socket operation on non-socket",
"Destination address required",
"Message too long",
"Protocol wrong type for socket",
"Protocol not available",
"Protocol not supported",
"Socket type not supported",
"Operation not supported on socket",
"Protocol family not supported",
"Address family not supported by protocol",
"Address already in use",
"Can't assign requested address",
"Network is down",
"Network is unreachable",
"Network connection dropped on reset",
"Software caused connection abort",
"Connection reset by peer",
"No buffer space available",
"Socket is already connected",
"Socket is not connected",
"Can't send after socket shutdown",
"Too many references: can't splice",
"Connection timed out",
"Connection refused",
"Too many levels of symbolic links",
"File name too long",
"Host is down",
"No route to host",
"Directory not empty",
"Too many processes",
"Too many users",
"Disc quota exceeded",
"Stale NFS file handle",
"Object is remote"
};
static char *errs7[] = {
"Network subsystem unavailable",
"Requested WinSock version not supported",
"WinSock was not initialized"
};
#ifdef WSAEDISCON
static char *errs8[] = {
"Graceful shutdown in progress"
};
#endif
static char *errs9[] = {
"Unknown host",
"Host name lookup failure",
"Unknown server error",
"No address associated with name",
};
static struct err_strs sock_errlist[] = {
{ errs1, WSAEINTR, WSAEINTR },
{ errs2, WSAEBADF, WSAEBADF },
{ errs3, WSAEACCES, WSAEFAULT },
{ errs4, WSAEINVAL, WSAEINVAL },
{ errs5, WSAEMFILE, WSAEMFILE },
{ errs6, WSAEWOULDBLOCK, WSAEHOSTUNREACH + 6 },
{ errs7, WSASYSNOTREADY, WSANOTINITIALISED },
#ifdef WSAEDISCON
{ errs8, WSAEDISCON, WSAEDISCON },
#endif
{ errs9, WSAHOST_NOT_FOUND, WSANO_DATA }
};
char *
sock_strerror (int errnum)
{
static char buf[40];
int i;
for (i = 0; i < (sizeof sock_errlist / sizeof *sock_errlist); i++)
{
if (errnum >= sock_errlist[i].first && errnum <= sock_errlist[i].last)
return sock_errlist[i].strs[errnum - sock_errlist[i].first];
}
sprintf(buf, "Unknown socket error: %d", errnum);
return buf;
}