00001
00002 #include <socket_exception.h>
00003
00004 #if defined(_WINNT) || defined(_Windows)
00005
00006 #include <winsock2.h>
00007
00008 #elif defined(_SOLARIS)
00009
00010 #include <sys/types.h>
00011 #include <sys/socket.h>
00012
00013
00014
00015
00016 #else //-----------------------------------
00017
00018 #error socket_exception.h not completed for this O/S
00019
00020 #endif
00021
00022
00023 #pragma package(smart_init)
00024
00025
00026 const char * worm_socket_exception::DecodeError() const
00027 {
00028 return DecodeError(FunctionId, ErrorCode);
00029 }
00030
00031 const char * worm_socket_exception::DecodeError( WS_FUNCTION_ID p_functionid, int p_errcode )
00032 {
00033 char * r_message = "Unidentified socket error.";
00034
00035 switch( p_errcode )
00036 {
00037 #if defined(_WINNT) || defined(_Windows)
00038
00039 case WSANOTINITIALISED:
00040 r_message = "A successful WSAStartup must occur before using this function.";
00041 break;
00042 case WSAEINPROGRESS:
00043 r_message = "A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.";
00044 break;
00045 case WSAENOTSOCK:
00046 r_message = "The descriptor is not a socket.";
00047 break;
00048 case WSAEACCES:
00049 switch( p_functionid )
00050 {
00051 case WSF_SEND:
00052 r_message = "The requested address is a broadcast address, but the appropriate flag was not set.";
00053 break;
00054 case WSF_CONNECT:
00055 r_message = "Attempt to connect datagram socket to broadcast address failed because setsockopt SO_BROADCAST is not enabled.";
00056 break;
00057 }
00058 break;
00059 case WSAEADDRINUSE:
00060 r_message = "The specified address is already in use. (See the SO_REUSEADDR socket option under setsockopt.)";
00061 break;
00062 case WSAEADDRNOTAVAIL:
00063 r_message = "The specified address is not available from the local machine.";
00064 break;
00065 case WSAEAFNOSUPPORT:
00066 switch( p_functionid )
00067 {
00068 case WSF_SOCKET:
00069 r_message = "The specified address family is not supported.";
00070 break;
00071 case WSF_CONNECT:
00072 r_message = "Addresses in the specified family cannot be used with this socket.";
00073 break;
00074 }
00075 break;
00076 case WSAEALREADY:
00077 r_message = "A nonblocking connect call is in progress on the specified socket.";
00078 break;
00079 case WSAECONNABORTED:
00080 r_message = "The virtual circuit was terminated due to a time-out or other failure. The application should close the socket as it is no longer usable.";
00081 break;
00082 case WSAECONNRESET:
00083 switch( p_functionid )
00084 {
00085 case WSF_CONNECT:
00086 r_message = "The attempt to connect was forcefully rejected.";
00087 break;
00088 case WSF_SEND:
00089 r_message = "The virtual circuit was reset by the remote side executing a 'hard' or 'abortive' close. For UPD sockets, the remote host was unable to deliver a previously sent UDP datagram and responded with a 'Port Unreachable' ICMP packet. The application should close the socket as it is no longer usable";
00090 break;
00091 case WSF_RECV:
00092 case WSF_RECVFROM:
00093 r_message = "The virtual circuit was reset by the remote side executing a 'hard' or 'abortive' close. The application should close the socket as it is no longer usable. On a UDP datagram socket this error would indicate that a previous send operation resulted in an ICMP 'Port Unreachable' message.";
00094 break;
00095 }
00096 break;
00097 case WSAEFAULT:
00098 switch( p_functionid )
00099 {
00100 case WSF_ACCEPT:
00101 r_message = "The addrlen argument is too small or addr is not a valid part of the user address space.";
00102 break;
00103 case WSF_BIND:
00104 r_message = "The name or the namelen argument is not a valid part of the user address space, the namelen argument is too small, the name argument contains incorrect address format for the associated address family, or the first two bytes of the memory block specified by name does not match the address family associated with the socket descriptor s.";
00105 break;
00106 case WSF_CONNECT:
00107 r_message = "The name or the namelen argument is not a valid part of the user address space, the namelen argument is too small, or the name argument contains incorrect address format for the associated address family.";
00108 break;
00109 case WSF_IOCTLSOCK:
00110 r_message = "The argp argument is not a valid part of the user address space";
00111 break;
00112 case WSF_SETSOCKOPT:
00113 r_message = "optval is not in a valid part of the process address space or optlen argument is too small";
00114 break;
00115 case WSF_GETSOCKOPT:
00116 r_message = "One of the optval or the optlen arguments is not a valid part of the user address space, or the optlen argument is too small.";
00117 break;
00118 case WSF_SELECT:
00119 r_message = "The Windows Sockets implementation was unable to allocated needed resources for its internal operations, or the readfds, writefds, exceptfds, or timeval parameters are not part of the user address space.";
00120 break;
00121 case WSF_SEND:
00122 r_message = "The buf argument is not totally contained in a valid part of the user address space.";
00123 break;
00124 case WSF_RECV:
00125 r_message = "The buf argument is not totally contained in a valid part of the user address space.";
00126 break;
00127 case WSF_RECVFROM:
00128 r_message = "The buf or from parameters are not part of the user address space, or the fromlen argument is too small to accommodate the peer address.";
00129 break;
00130 }
00131 break;
00132 case WSAEHOSTUNREACH:
00133 r_message = "The remote host cannot be reached from this host at this time";
00134 break;
00135 case WSAEINTR:
00136 r_message = "The (blocking) call was canceled through WSACancelBlockingCall.";
00137 break;
00138 case WSAEINVAL:
00139 switch( p_functionid )
00140 {
00141 case WSF_ACCEPT:
00142 r_message = "listen was not invoked prior to accept.";
00143 break;
00144 case WSF_BIND:
00145 r_message = "The socket is already bound to an address.";
00146 break;
00147 case WSF_CONNECT:
00148 r_message = "The parameter s is a listening socket, or the destination address specified is not consistent with that of the constrained group the socket belongs to.";
00149 break;
00150 case WSF_SETSOCKOPT:
00151 r_message = "level is not valid, or the information in optval is not valid";
00152 break;
00153 case WSF_GETSOCKOPT:
00154 r_message = "level is unknown or invalid";
00155 break;
00156 case WSF_SELECT:
00157 r_message = "The timeout value is not valid, or all three descriptor parameters were NULL.";
00158 break;
00159 case WSF_SEND:
00160 r_message = "The socket has not been bound with bind, or an unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled.";
00161 break;
00162 case WSF_RECV:
00163 case WSF_RECVFROM:
00164 r_message = "The socket has not been bound with bind, or an unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled or (for byte stream sockets only) len was zero or negative.";
00165 break;
00166 }
00167 break;
00168 case WSAEISCONN:
00169 r_message = "The socket is already connected (connection-oriented sockets only).";
00170 break;
00171 case WSAEMFILE:
00172 r_message = "No more socket descriptors are available";
00173 break;
00174 case WSAEMSGSIZE:
00175 switch( p_functionid )
00176 {
00177 case WSF_SEND:
00178 r_message = "The socket is message oriented, and the message is larger than the maximum supported by the underlying transport.";
00179 break;
00180 case WSF_RECV:
00181 case WSF_RECVFROM:
00182 r_message = "The message was too large to fit into the specified buffer and was truncated.";
00183 break;
00184 }
00185 break;
00186 case WSAENETDOWN:
00187 r_message = "The network subsystem or the associated service provider has failed.";
00188 break;
00189 case WSAENETRESET:
00190 switch( p_functionid )
00191 {
00192 case WSF_SETSOCKOPT:
00193 r_message = "Connection has timed out when SO_KEEPALIVE is set";
00194 break;
00195 case WSF_SEND:
00196 case WSF_RECV:
00197 case WSF_RECVFROM:
00198 r_message = "The connection has been broken due to the remote host resetting.";
00199 break;
00200 }
00201 break;
00202 case WSAENETUNREACH:
00203 r_message = "The network cannot be reached from this host at this time.";
00204 break;
00205 case WSAENOBUFS:
00206 switch( p_functionid )
00207 {
00208 case WSF_ACCEPT:
00209 r_message = "No buffer space available.";
00210 break;
00211 case WSF_BIND:
00212 r_message = "Not enough buffers available, too many connections.";
00213 break;
00214 case WSF_SOCKET:
00215 r_message = "No buffer space is available. The socket cannot be created.";
00216 break;
00217 case WSF_CONNECT:
00218 r_message = "No buffer space is available. The socket cannot be connected.";
00219 break;
00220 case WSF_IOCTLSOCK:
00221 case WSF_SEND:
00222 r_message = "No buffer space is available.";
00223 break;
00224 }
00225 break;
00226 case WSAENOPROTOOPT:
00227 switch( p_functionid )
00228 {
00229 case WSF_SETSOCKOPT:
00230 r_message = "The option is unknown or unsupported for the specified provider.";
00231 break;
00232 case WSF_GETSOCKOPT:
00233 r_message = "The option is unknown or unsupported by the indicated protocol family.";
00234 break;
00235 case WSF_SOCKET:
00236 r_message = "The specified protocol is the wrong type for this socket.";
00237 break;
00238 }
00239 break;
00240 case WSAENOTCONN:
00241 switch( p_functionid )
00242 {
00243 case WSF_SETSOCKOPT:
00244 r_message = "Connection has been reset when SO_KEEPALIVE is set";
00245 break;
00246 case WSF_SEND:
00247 case WSF_RECV:
00248 r_message = "The socket is not connected.";
00249 break;
00250 case WSF_RECVFROM:
00251 r_message = "The socket is not connected (connection-oriented sockets only).";
00252 break;
00253 }
00254 break;
00255 case WSAEOPNOTSUPP:
00256 switch( p_functionid )
00257 {
00258 case WSF_ACCEPT:
00259 r_message = "The referenced socket is not a type that supports connection-oriented service.";
00260 break;
00261 case WSF_SEND:
00262 r_message = "MSG_OOB was specified, but the socket is not stream style such as type SOCK_STREAM, out-of-band data is not supported in the communication domain associated with this socket, or the socket is unidirectional and supports only receive operations.";
00263 break;
00264 case WSF_RECV:
00265 case WSF_RECVFROM:
00266 r_message = "MSG_OOB was specified, but the socket is not stream style such as type SOCK_STREAM, out-of-band data is not supported in the communication domain associated with this socket, or the socket is unidirectional and supports only send operations.";
00267 break;
00268 }
00269 break;
00270 case WSAEPROTONOSUPPORT:
00271 r_message = "The specified protocol is not supported";
00272 break;
00273 case WSAEPROTOTYPE:
00274 r_message = "The specified protocol is the wrong type for this socket";
00275 break;
00276 case WSAESHUTDOWN:
00277 switch( p_functionid )
00278 {
00279 case WSF_SEND:
00280 r_message = "The socket has been shut down; it is not possible to send on a socket after shutdown has been invoked with how set to SD_SEND or SD_BOTH";
00281 break;
00282 case WSF_RECV:
00283 r_message = "The socket has been shut down; it is not possible to recv on a socket after shutdown has been invoked with how set to SD_RECEIVE or SD_BOTH.";
00284 break;
00285 case WSF_RECVFROM:
00286 r_message = "The socket has been shut down; it is not possible to recvfrom on a socket after shutdown has been invoked with how set to SD_RECEIVE or SD_BOTH.";
00287 break;
00288 }
00289 break;
00290 case WSAESOCKTNOSUPPORT:
00291 r_message = "The specified socket type is not supported in this address family";
00292 break;
00293 case WSAETIMEDOUT:
00294 switch( p_functionid )
00295 {
00296 case WSF_CONNECT:
00297 r_message = "Attempt to connect timed out without establishing a connection.";
00298 break;
00299 case WSF_SEND:
00300 r_message = "The connection has been dropped because of a network failure or because the system on the other end went down without notice";
00301 break;
00302 case WSF_RECV:
00303 r_message = "The connection has been dropped because of a network failure or because the peer system failed to respond.";
00304 break;
00305 case WSF_RECVFROM:
00306 r_message = "The connection has been dropped, because of a network failure or because the system on the other end went down without notice.";
00307 break;
00308 }
00309 break;
00310 case WSAEWOULDBLOCK:
00311 switch( p_functionid )
00312 {
00313 case WSF_ACCEPT:
00314 r_message = "The socket is marked as nonblocking and no connections are present to be accepted.";
00315 break;
00316 case WSF_CONNECT:
00317 r_message = "The socket is marked as nonblocking and the connection cannot be completed immediately. It is possible to select the socket while it is connecting by selecting it for writing.";
00318 break;
00319 case WSF_SEND:
00320 r_message = "The socket is marked as nonblocking and the requested operation would block.";
00321 break;
00322 case WSF_RECV:
00323 r_message = "The socket is marked as nonblocking and the receive operation would block.";
00324 break;
00325 case WSF_RECVFROM:
00326 r_message = "The socket is marked as nonblocking and the recvfrom operation would block.";
00327 break;
00328 }
00329 break;
00330
00331 #elif defined(_SOLARIS)
00332
00333 case EACCES:
00334 switch( p_functionid )
00335 {
00336 case WSF_SOCKET:
00337 r_message = "Permission to create a socket of the specified type and/or protocol is denied.";
00338 break;
00339
00340 case WSF_BIND:
00341 r_message = "The requested address is protected and the current user has inadequate permission to access it.";
00342 break;
00343
00344 case WSF_CONNECT:
00345 r_message = "Search permission is denied for a component of the path prefix of the pathname in name.";
00346 break;
00347 }
00348 break;
00349
00350
00351 case EADDRINUSE:
00352 switch( p_functionid )
00353 {
00354 case WSF_CONNECT:
00355 r_message = "The address is already in use.";
00356 break;
00357
00358 case WSF_BIND:
00359 r_message = "The specified address is already in use.";
00360 break;
00361 }
00362 break;
00363
00364 case EADDRNOTAVAIL:
00365 switch( p_functionid )
00366 {
00367 case WSF_CONNECT:
00368 r_message = "The specified address is not available on the remote machine.";
00369 break;
00370
00371 case WSF_BIND:
00372 r_message = "The specified address is not available on the local machine.";
00373 break;
00374 }
00375 break;
00376
00377 case EAFNOSUPPORT:
00378 r_message = "Addresses in the specified address family cannot be used with this socket.";
00379 break;
00380
00381 case EALREADY:
00382 r_message = "The socket is non-blocking and a previous connection attempt has not yet been completed.";
00383 break;
00384
00385 case EBADF:
00386 switch( p_functionid )
00387 {
00388 case WSF_SEND:
00389 case WSF_RECV:
00390 r_message = "s is an invalid file descriptor.";
00391 break;
00392
00393 case WSF_ACCEPT:
00394 r_message = "The descriptor is invalid.";
00395 break;
00396
00397 case WSF_CONNECT:
00398 case WSF_BIND:
00399 r_message = "s is not a valid descriptor.";
00400 break;
00401
00402 case WSF_LISTEN:
00403 r_message = "The argument s is not a valid file descriptor.";
00404 break;
00405 }
00406 break;
00407
00408 case ECONNREFUSED:
00409 r_message = "The attempt to connect was forcefully rejected. The calling program should close(2) the socket descriptor, and issue another socket(3N) call to obtain a new descriptor before attempting another connect() call.";
00410 break;
00411
00412 case EINPROGRESS:
00413 r_message = "The socket is non-blocking and the connection cannot be completed immediately. It is possible to select(3C) for completion by selecting the socket for writing. However, this is only possible if the socket STREAMS module is the topmost module on the protocol stack with a write service procedure. This will be the normal case.";
00414 break;
00415
00416 case EINTR:
00417 switch( p_functionid )
00418 {
00419 case WSF_SEND:
00420 r_message = "The operation was interrupted by delivery of a signal before any data could be buffered to be sent.";
00421 break;
00422
00423 case WSF_RECV:
00424 r_message = "The operation was interrupted by delivery of a signal before any data was available to be received.";
00425 break;
00426
00427 case WSF_ACCEPT:
00428 r_message = "The accept attempt was interrupted by the delivery of a signal.";
00429 break;
00430
00431 case WSF_CONNECT:
00432 r_message = "The connection attempt was interrupted before any data arrived by the delivery of a signal.";
00433 break;
00434 }
00435 break;
00436
00437 case EINVAL:
00438 switch( p_functionid )
00439 {
00440 case WSF_SEND:
00441 r_message = "tolen is not the size of a valid address for the specified address family.";
00442 break;
00443
00444 case WSF_BIND:
00445 r_message = "The socket is already bound to an address. or namelen is not the size of a valid address for the specified address family.";
00446 break;
00447
00448 case WSF_CONNECT:
00449 r_message = "namelen is not the size of a valid address for the specified address family.";
00450 break;
00451 }
00452 break;
00453
00454 case EIO:
00455 switch( p_functionid )
00456 {
00457 case WSF_CONNECT:
00458 case WSF_RECV:
00459 r_message = "An I/O error occurred while reading from or writing to the file system.";
00460 break;
00461 }
00462
00463 case EISCONN:
00464 r_message = "The socket is already connected.";
00465 break;
00466
00467 case ELOOP:
00468 r_message = "Too many symbolic links were encountered in translating the pathname in name.";
00469 break;
00470
00471 case EMFILE:
00472 switch( p_functionid )
00473 {
00474 case WSF_SOCKET:
00475 case WSF_ACCEPT:
00476 r_message = "The per-process descriptor table is full."
00477 break;
00478 }
00479 break;
00480
00481 case EMSGSIZE:
00482 r_message = "The socket requires that message be sent atomically, and the message was too long.";
00483 break;
00484
00485 case ENETUNREACH:
00486 r_message = "The network is not reachable from this host.";
00487 break;
00488
00489 case ENODEV:
00490 r_message = "The protocol family and type corresponding to s could not be found in the netconfig file.";
00491 break;
00492
00493 case ENOENT:
00494 r_message = "The socket referred to by the pathname in name does not exist.";
00495 break;
00496
00497 case ENOMEM:
00498 switch( p_functionid )
00499 {
00500 case WSF_SEND:
00501 r_message = "There was insufficient memory available to complete the operation.";
00502 break;
00503
00504 case WSF_RECV:
00505 r_message = "There was insufficient user memory available for the operation to complete.";
00506 break;
00507
00508 case WSF_SOCKET:
00509 r_message = "Insufficient user memory is available.";
00510 break;
00511
00512 case WSF_ACCEPT:
00513 r_message = "There was insufficient user memory available to complete the operation.";
00514 break;
00515 }
00516 break;
00517
00518 case ENOSR:
00519 switch( p_functionid )
00520 {
00521 case WSF_SEND:
00522 case WSF_RECV:
00523 r_message = "There were insufficient STREAMS resources available for the operation to complete.";
00524 break;
00525
00526 case WSF_ACCEPT:
00527 case WSF_CONNECT:
00528 case WSF_SOCKET:
00529 r_message = "There were insufficient STREAMS resources available to complete the operation.";
00530 break;
00531
00532 case WSF_BIND:
00533 r_message = "There were insufficient STREAMS resources for the operation to complete.";
00534 break;
00535 }
00536 break;
00537
00538 case ENOTSOCK:
00539 switch( p_functionid )
00540 {
00541 case WSF_SEND:
00542 case WSF_RECV:
00543 r_message = "s is not a socket.";
00544 break;
00545
00546 case WSF_ACCEPT:
00547 r_message = "The descriptor does not reference a socket.";
00548 break;
00549
00550 case WSF_BIND:
00551 r_message = "s is a descriptor for a file, not a socket.";
00552 break;
00553
00554 case WSF_LISTEN:
00555 r_message = "The argument s is not a socket.";
00556 break;
00557 }
00558 break;
00559
00560 case ENXIO:
00561 r_message = "The server exited before the connection was complete.";
00562 break;
00563
00564 case EOPNOTSUPP:
00565 switch( p_functionid )
00566 {
00567 case WSF_ACCEPT:
00568 r_message = "The referenced socket is not of type SOCK_STREAM.";
00569 break;
00570
00571 case WSF_LISTEN:
00572 r_message = "The socket is not of a type that supports the operation listen().";
00573 break;
00574 }
00575 break;
00576
00577 case EPROTO:
00578 r_message = "A protocol error has occurred; for example, the STREAMS protocol stack has not been initialized or the connection has already been released.";
00579 break;
00580
00581 case EPROTONOSUPPORT:
00582 r_message = "The protocol type or the specified protocol is not supported within this domain.";
00583 break;
00584
00585 case ESTALE:
00586 r_message = "A stale NFS file handle exists.";
00587 break;
00588
00589 case ETIMEDOUT:
00590 r_message = "Connection establishment timed out without establishing a connection.";
00591 break;
00592
00593 case EWOULDBLOCK:
00594 switch( p_functionid )
00595 {
00596 case WSF_SEND:
00597 case WSF_RECV:
00598 case WSF_CONNECT:
00599 r_message = "The socket is marked as non-blocking, and the requested operation would block.";
00600 break;
00601
00602 case WSF_ACCEPT:
00603 r_message = "The socket is marked as non-blocking and no connections are present to be accepted.";
00604 break;
00605 }
00606 break;
00607 #else
00608 #error socket_exception.cpp not complete for this O/S
00609 #endif
00610
00611 }
00612 return r_message;
00613 }
00614