RE: [ProgSoc] Converting windows socket error codes to strings [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] RE: [ProgSoc] Converting windows socket error codes to strings To: Nicholas FitzRoy-Dale
Subject: RE: [ProgSoc] Converting windows socket error codes to strings From: Shaun Clowes Date: Wed, 1 Dec 2004 15:45:09 +1100 (EST) Cc: progsoc@xxxxxxxxxxxxxxxxxx In-reply-to: List-archive: List-id: References: <001901c4d757$fdf672d0$5829198a@nigelnote> Sender: owner-progsoc@xxxxxxxxxxxxxxxxxx On Wed, 1 Dec 2004, Nicholas FitzRoy-Dale wrote: On Wed, 1 Dec 2004, Nigel Sheridan-Smith wrote: In winsock2, is there a way to convert windows socket error codes as
returned from WSAGetLastError() into strings, eg: WSAENOTCONN - "Socket is not connected" I'm working in C++. Can't remember any function specific to Winsock but you could try
FormatMessage() with dwFlags==FORMAT_MESSAGE_FROM_SYSTEM.
After reading Bryn's "do it yourself" comment I did a quick search, and
sure enough the only thing that's out there is a GPLed function that does
it for you.
Well, it's not exactly difficult, feed the HTML source of the "Windows Socket Error Codes" document in MSDN to this perl inline: perl -ne 'BEGIN{print "switch (errno)\n{\n"} /A id=\"([^"]*)/ && ($id = $1); /([^<]*)/ && print "\tcase $id:\n\t\tprintf(\"$1\\n\"); break;\n"; END { print "}\n"; }' I get: switch (errno) { case WSAEINTR: printf("Interrupted function call.\n"); break; case WSAEACCES: printf("Permission denied\n"); break; case WSAEFAULT: printf("Bad address\n"); break; case WSAEINVAL: printf("Invalid argument.\n"); break; case WSAEMFILE: printf("Too many open files.\n"); break; case WSAEWOULDBLOCK: printf("Resource temporarily unavailable\n"); break; case WSAEINPROGRESS: printf("Operation now in progress\n"); break; case WSAEALREADY: printf("Operation already in progress\n"); break; case WSAENOTSOCK: printf("Socket operation on nonsocket.\n"); break; case WSAEDESTADDRREQ: printf("Destination address required\n"); break; case WSAEMSGSIZE: printf("Message too long\n"); break; case WSAEPROTOTYPE: printf("Protocol wrong type for socket\n"); break; case WSAENOPROTOOPT: printf("Bad protocol option.\n"); break; case WSAEPROTONOSUPPORT: printf("Protocol not supported\n"); break; case WSAESOCKTNOSUPPORT: printf("Socket type not supported.\n"); break; case WSAEOPNOTSUPP: printf("Operation not supported\n"); break; case WSAEPFNOSUPPORT: printf("Protocol family not supported\n"); break; case WSAEAFNOSUPPORT: printf("Address family not supported by protocol family\n"); break; case WSAEADDRINUSE: printf("Address already in use\n"); break; case WSAEADDRNOTAVAIL: printf("Cannot assign requested address\n"); break; case WSAENETDOWN: printf("Network is down\n"); break; case WSAENETUNREACH: printf("Network is unreachable\n"); break; case WSAENETRESET: printf("Network dropped connection on reset\n"); break; case WSAECONNABORTED: printf("Software caused connection abort\n"); break; case WSAECONNRESET: printf("Connection reset by peer\n"); break; case WSAENOBUFS: printf("No buffer space available.\n"); break; case WSAEISCONN: printf("Socket is already connected.\n"); break; case WSAENOTCONN: printf("Socket is not connected\n"); break; case WSAESHUTDOWN: printf("Cannot send after socket shutdown\n"); break; case WSAETIMEDOUT: printf("Connection timed out.\n"); break; case WSAECONNREFUSED: printf("Connection refused\n"); break; case WSAEHOSTDOWN: printf("Host is down\n"); break; case WSAEHOSTUNREACH: printf("No route to host\n"); break; case WSAEPROCLIM: printf("Too many processes.\n"); break; case WSASYSNOTREADY: printf("Network subsystem is unavailable.\n"); break; case WSAVERNOTSUPPORTED: printf("Winsock.dll version out of range.\n"); break; case WSANOTINITIALISED: printf("Successful WSAStartup not yet performed.\n"); break; case WSAEDISCON: printf("Graceful shutdown in progress.\n"); break; case WSATYPE_NOT_FOUND: printf("Class type not found.\n"); break; case WSAHOST_NOT_FOUND: printf("Host not found.\n"); break; case WSATRY_AGAIN: printf("Nonauthoritative host not found.\n"); break; case WSANO_RECOVERY: printf("This is a nonrecoverable error.\n"); break; case WSANO_DATA: printf("Valid name, no data record of requested type.\n"); break; case WSA_INVALID_HANDLE: printf("Specified event object handle is invalid.\n"); break; case WSA_INVALID_PARAMETER: printf("One or more parameters are invalid.\n"); break; case WSA_IO_INCOMPLETE: printf("Overlapped I/O event object not in signaled state.\n"); break; case WSA_IO_PENDING: printf("Overlapped operations will complete later.\n"); break; case WSA_NOT_ENOUGH_MEMORY: printf("Insufficient memory available.\n"); break; case WSA_OPERATION_ABORTED: printf("Overlapped operation aborted.\n"); break; case WSAINVALIDPROCTABLE: printf("Invalid procedure table from service provider.\n"); break; case WSAINVALIDPROVIDER: printf("Invalid service provider version number.\n"); break; case WSAPROVIDERFAILEDINIT: printf("Unable to initialize a service provider.\n"); break; case WSASYSCALLFAILURE: printf("System call failure.\n"); break; } I hereby contribute this code to the public domain ;) Cheers,
Shaun -
You are subscribed to the progsoc mailing list. To unsubscribe, send a
message containing "unsubscribe" to progsoc-request@xxxxxxxxxxxxxxxxxxx
If you are having trouble, ask owner-progsoc@xxxxxxxxxxxxxxxxxx for help. Follow-Ups: RE: [ProgSoc] Converting windows socket error codes to strings From: Nicholas FitzRoy-Dale References: RE: [ProgSoc] Converting windows socket error codes to strings From: Nigel Sheridan-Smith RE: [ProgSoc] Converting windows socket error codes to strings From: Nicholas FitzRoy-Dale Prev by Date: RE: [ProgSoc] Converting windows socket error codes to strings Next by Date: [ProgSoc] Mail Whitelist Previous by thread: RE: [ProgSoc] Converting windows socket error codes to strings Next by thread: RE: [ProgSoc] Converting windows socket error codes to strings Index(es): Date Thread