1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
/* sockerror.c --- convert WinSock error number to string
Vince Del Vecchio <vdelvecc@spd.analog.com>
This file is part of GNU CVS.
GNU CVS is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. */
#include <stdio.h>
#include <winsock.h>
struct err_strs {
char **strs;
int first;
int last;
};
static char *errs1[] = {
/* EINTR */ "Interrupted system call"
};
static char *errs2[] = {
/* EBADF */ "Bad file descriptor"
};
static char *errs3[] = {
/* EACCES */ "Permission denied",
/* EFAULT */ "Bad address"
};
static char *errs4[] = {
/* EINVAL */ "Invalid argument"
};
static char *errs5[] = {
/* EMFILE */ "Too many open files",
};
static char *errs6[] = {
/* EWOULDBLOCK */ "Resource temporarily unavailable",
/* EINPROGRESS */ "Operation now in progress",
/* EALREADY */ "Operation already in progress",
/* ENOTSOCK */ "Socket operation on non-socket",
/* EDESTADDRREQ */ "Destination address required",
/* EMSGSIZE */ "Message too long",
/* EPROTOTYPE */ "Protocol wrong type for socket",
/* ENOPROTOOPT */ "Protocol not available",
/* EPROTONOSUPPORT */ "Protocol not supported",
/* ESOCKTNOSUPPORT */ "Socket type not supported",
/* EOPNOTSUPP */ "Operation not supported on socket",
/* EPFNOSUPPORT */ "Protocol family not supported",
/* EAFNOSUPPORT */ "Address family not supported by protocol",
/* EADDRINUSE */ "Address already in use",
/* EADDRNOTAVAIL */ "Can't assign requested address",
/* ENETDOWN */ "Network is down",
/* ENETUNREACH */ "Network is unreachable",
/* ENETRESET */ "Network connection dropped on reset",
/* ECONNABORTED */ "Software caused connection abort",
/* ECONNRESET */ "Connection reset by peer",
/* ENOBUFS */ "No buffer space available",
/* EISCONN */ "Socket is already connected",
/* ENOTCONN */ "Socket is not connected",
/* ESHUTDOWN */ "Can't send after socket shutdown",
/* ETOOMANYREFS */ "Too many references: can't splice",
/* ETIMEDOUT */ "Connection timed out",
/* ECONNREFUSED */ "Connection refused",
/* ELOOP */ "Too many levels of symbolic links",
/* ENAMETOOLONG */ "File name too long",
/* EHOSTDOWN */ "Host is down",
/* EHOSTUNREACH */ "No route to host",
/* ENOTEMPTY */ "Directory not empty",
/* EPROCLIM */ "Too many processes",
/* EUSERS */ "Too many users",
/* EDQUOT */ "Disc quota exceeded",
/* ESTALE */ "Stale NFS file handle",
/* EREMOTE */ "Object is remote"
};
static char *errs7[] = {
/* SYSNOTREADY */ "Network subsystem unavailable",
/* VERNOTSUPPORTED */ "Requested WinSock version not supported",
/* NOTINITIALISED */ "WinSock was not initialized"
};
#ifdef WSAEDISCON
static char *errs8[] = {
/* EDISCON */ "Graceful shutdown in progress"
};
#endif
static char *errs9[] = {
/* HOST_NOT_FOUND */ "Unknown host",
/* TRY_AGAIN */ "Host name lookup failure",
/* NO_RECOVERY */ "Unknown server error",
/* NO_DATA */ "No address associated with name",
};
/* Some of these errors are defined in the winsock.h header file I have,
but not in the Winsock 1.1 spec. I include them some of them anyway,
where it is not too hard to avoid referencing the symbolic constant. */
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;
}
|