%% options copyright owner = Dirk Krause copyright year = 2015-xxxx license = bsd %% module #include "dk4sock.h" #include "dk4socka.h" #include "dk4mem.h" #include "dk4maodd.h" #include "dk4maodh.h" #if DK4_HAVE_ERRNO_H #ifndef ERRNO_H_INCLUDED #include #define ERRNO_H_INCLUDED 1 #endif #endif #if DK4_HAVE_STRING_H #ifndef STRING_H_INCLUDED #include #define STRING_H_INCLUDED 1 #endif #endif $!trace-include /** Constant text keywords, not localized. */ static const dkChar * const dk4socket_app_kwnl[] = { $!string-table macro=dkT # # 0 String table file name. # dk4sock.str # # 1 Separator for details line. # \n\t # # 2 Separator between function name and further text. # : # # 3 4 Function names # WSAStartup WSACleanup # # 5 6 7 Function names # socket close closesocket # # 8 Function name # bind # # 9 10 Function names # listen accept # # 11 Function name # connect # # 12 Function name # setsockopt # # 13 14 Function names # ioctlsocket fcntl # # 15 16 Function names # select getsockopt # # 17 18 Function names # getaddrinfo getnameinfo # # 19 20 Function names # gethostbyname getservbyname # # 21 Function name # GetAddrInfoW # # 22 Function name # inet_ntop # # 23 # shutdown # # 24 # send/sendto # # 25 # recv/recvfrom # # 26 # inet_pton $!end }; /** Constant text keywords, replaced by localized version if found. */ static const dkChar * const dk4socket_app_kw_def[] = { $!string-table macro=dkT # # 0 Error: Failed to initialize Winsock subsystem! # Failed to initialize Winsock subsystem! # # 1 Error: Failed to shut down Winsock subsystem! # Failed to shut down Winsock subsystem! # # 2 Error: Failed to create socket! # Failed to create socket! # # 3 Error: Failed to close socket! # Failed to close socket! # # 4 Error: Failed to bind local address! # Failed to bind local address! # # 5 Error: Failed to listen for incoming connection requests! # Failed to listen for incoming connection requests! # # 6 Error: Failed to accept incoming connection request! # Failed to accept incoming connection request! # # 7 Error: Failed to connect to remote address! # Failed to connect to remote address! # # 8 Error: Failed to set reusable flag for socket! # Failed to modify ``reusable'' option for socket! # # 9 Error: Failed to modify ``non-blocking'' option for socket! # Failed to modify ``non-blocking'' option for socket! # # 10 Error: Failed to retrieve remote address(es)! # Failed to retrieve remote address(es)! # # 11 Error: Failed to retrieve local address(es)! # Failed to retrieve local address(es)! # # 12 Error: Failed to retrieve remote host address! # Failed to retrieve remote host address! # # 13 Error: Failed to retrieve port number for remote service! # Failed to retrieve port number for remote service! # # 14 Error: Failed to retrieve port number for local service! # Failed to retrieve port number for local service! # # 15 16 17 Error: Failed to convert text to ASCII! # Failed to convert text to ASCII! " "! # # 18 19 Error: Failed to obtain local addresses ... # Failed to obtain local address(es)! Port/service: # # 20 21 22 Error: Failed to obtain remote address(es)! # Failed to obtain remote address(es)! Host: Port/service: # # 23 24 Error: Service/port not found # Service/port not found: " "! # # 25 26 Error: Failed to convert service/port to ASCII # Failed to convert service/port to ASCII: " "! # # 27 Error: No matching pair of local/remote addresses found! # No matching pair of local/remote addresses found! # # 28 Error: Illegal local port number! # Illegal local port number! # # 29 Error: Illegal remote port number! # Illegal remote port number! # # 30 Debug: Connection established. # Connection established. # # 31 Error: Illegal address length in getservbyname() result! # Illegal address length in gethostbyname() result! # # 32 Error: Illegal address family in gethostbyname() result! # Illegal address family in gethostbyname() result! # # 33 34 Error: Remote host not found: "..."! # Remote host not found: " "! # # 35 36 Error: Failed to convert host name to ASCII: ... # Non-ASCII characters in host name: \n\t" "! # # 37 38 39 40 Texts to show error code # errno= (0x ) WSAGetLastError()= # # 41 42 43 # Failed to create TCP connection! Local: Remote: # # 44 # Timeout while attempting to connect. # # 45 # Invalid arguments passed to function, probably a bug. # # 46 # No matching local/remote address pair available! # # 47 WSASYSNOTREADY # Network subsystem not yet ready. # # 48 WSAVERNOTSUPPORTED # Winsock version not supported! # # 49 WSAEINPROGRESS # Blocking Winsock operation in progress! # # 50 WSAEPROCLIM # Process limit for Winsock reached! # # 51 WSAEFAULT WSAEINVAL / EFAULT # Invalid parameters passed to function! # # 52 WSANOTINITIALIZED # Winsock not initialized! # # 53 WSAENETDOWN # Network subsystem has failed! # # 54 WSAEAFNOSUPPORT / EAFNOSUPPORT # Address family not supported! # # 55 WSAEMFILE # No more socket/file descriptors available # # 56 WSAENOBUFS # No buffer space available! # # 57 WSAEPROTONOSUPPORT # Protocol not supported! # # 58 WSAEPROTOTYPE # Wrong protocol type for socket! # # 59 WSAEPROVIDERFAILEDINIT # Service provider failed to initialize! # # 60 WSAESOCKTNOSUPPORT # Socket type not supported by address family! # # 61 WSAINVALIDPROVIDER # Unusable service provider version! # # 62 WSAINVALIDPROCTABLE # Invalid/incomplete procedure table from service provider! # # 63 WSAEACCES / EACCES # Insufficient permissions! # # 64 WSAEADDRINUSE / EADDRINUSE # Address already in use! # # 65 WSAEADDRNOTAVAIL / EADDRNOTAVAIL # Address not available! # # 66 WSAENOTSOCK # File descriptor is not a socket! # # 67 EAI_ADDRFAMILY # Host has no addresses in specified address family! # # 68 EAI_AGAIN / TRY_AGAIN # Temporary problem on name server, try again later! # # 69 EAI_BADFLAGS # Illegal flag combination! # # 70 EAI_FAIL # Name server failure! # # 71 EAI_FAMILY # Address family not supported! # # 72 EAI_MEMORY # Out of memory! # # 73 EAI_NODATA / NO_DATA # No network address found for host! # # 74 EAI_NONAME # No such name or number! # # 75 EAI_SERVICE # Service not available through specified socket type! # # 76 EAI_SOCKTYPE # Unsupported socket type or inconsistent arguments! # # 77 EAI_SYSTEM # System error, check errno! # # 78 EAI_OVERFLOW # Argument buffer overflow! # # 79 EAGAIN # Resource temporarily locked, try again later! # # 80 EALREADY # Attempt already in progress! # # 81 EBADF # Not a file descriptor! # # 82 ECONNREFUSED # No-one listening on remote address! # # 83 ECONNRESET # Connection reset by peer! # # 84 EDEADLK # Operation would result in deadlock! # # 85 EDESTADDRREQ / EISDIR # Destination address required! # # 86 EDOM # Timeout values too large! # # 87 EINPROGRESS # Operation is in progress. # # 88 EINTR # Operation interrupted by signal! # # 89 EISCONN # Socket is already connected! # # 90 EIO # I/O error occured! # # 91 ELOOP # Symbolic link loop detected! # # 92 EMFILE # No more file descriptors available for process! # # 93 ENAMETOOLONG # Address or path name too long! # # 94 ENETUNREACH # Network unreachable! # # 95 ENFILE # No more file descriptors available on system! # # 96 ENOENT # File or path component does not exist or is empty! # # 97 ENOLCK # Failed to set a lock! # # 98 ENOPROTOOPT # Attempt to retrieve or modify unsupported option! # # 99 ENOTDIR # Path component is not a directory! # # 100 ENOSPC # Provided buffer size is too small! # # 101 EOPNOTSUPP # Operation not supported by socket type or protocol! # # 102 EROFS # File system is mounted read-only! # # 103 ETIMEDOUT # Timed out! # # 104 EOVERFLOW # Numeric overflow in file size/position calculation! # # 105 WSAECONNABORTED # Connection closed due to timeout or other failure! # # 106 WSAEHOSTUNREACH # Host unreachable! # # 107 WSAEINTR # Blocking Winsock operation interrupted by WSACancelBlockingCall()! # # 108 109 110 111 WSAEINVAL # Socket is in listening state! No local address bound yet! Socket is not in listening state! Invalid shutdown parameter # # 112 WSAEMSGSIZE # Message size too large! # # 113 WSAENETRESET # Connection closed, failures in keep-alive tests! # # 114 WSAENOTCONN # Not connected! # # 115 WSAEPROVIDERFAILEDINIT # Failed to initialize socket provider! # # 116 WSAESHUTDOWN # Socket already shut down! # # 117 WSAEWOULDBLOCK # Operation would block! # # 118 WSAHOST_NOT_FOUND # Host not found (authorative answer)! # # 119 WSAINVALIDPROCTABLE # Service provider returned invalid/incomplete procedure table! # # 120 WSAINVALIDPROVIDER # Invalid service provider version! # # 121 EPROTO # Protocol error! # # 122 ENOSR # Insufficient stream resources! # # 123 EPFNOSUPPORT # Protocol family not supported! # # 124 ENOLINK # Connection to remote machine no longer active! # # 125 ENXIO # Server exited before completing connection! # # 126 ENODEV # Protocol family and type not found in network configuration! # # 127 ESTALE # Stale NFS file handle! # # 128 # Failed to shut down socket! # # 129 130 # Failed to bind local address\n\t" "! # # 131 132 # Failed to connect to remote address\n\t" "! # # 133 134 135 # Send operation completed partially, only of bytes! # # 136 # Send operation completed partially! # # 137 # Send operation failed! # # 138 # Failed to receive data! # # 139 # Failed to create listener sockets! # # 140 # Listening: # # 141 142 # Failed to obtain allowed peer from string:\n\t" "! $!end }; /** Number of elements in the dk4socket_app_kw_def array. */ static const size_t dk4socket_sz_kw_def = sizeof(dk4socket_app_kw_def)/sizeof(DK4_PCDKCHAR); size_t dk4socket_log_num_texts(void) { return (dk4socket_sz_kw_def); } const dkChar * const * dk4socket_log_texts(dk4_app_t *app) { const dkChar * const *back = dk4socket_app_kw_def; if (NULL != app) { back = dk4app_string_table(app,dk4socket_app_kwnl[0],dk4socket_app_kw_def); } return back; } void dk4socket_log_fctname_msg( const dkChar **fctname, const dkChar **msgtext, dk4_app_t *app, dk4_er_t *erp ) { const dkChar * const *msgtexts = dk4socket_app_kw_def; const dkChar *mytext = NULL; if ((NULL != app) && (NULL != erp)) { msgtexts = dk4app_string_table(app, dk4socket_app_kwnl[0], dk4socket_app_kw_def); if (NULL != fctname) { switch (erp->ec) { case DK4_E_SOCKET_GETADDRINFO : { #if DK4_CHAR_SIZE > 1 *fctname = dk4socket_app_kwnl[21]; #else *fctname = dk4socket_app_kwnl[17]; #endif } break; case DK4_E_SOCKET_GETADDRLOC : { #if DK4_CHAR_SIZE > 1 *fctname = dk4socket_app_kwnl[21]; #else *fctname = dk4socket_app_kwnl[17]; #endif } break; case DK4_E_SOCKET_UP : { *fctname = dk4socket_app_kwnl[3]; } break; case DK4_E_SOCKET_DOWN : { *fctname = dk4socket_app_kwnl[4]; } break; case DK4_E_SOCKET_SOCKET : { *fctname = dk4socket_app_kwnl[5]; } break; case DK4_E_SOCKET_CLOSE : { #if DK4_ON_WINDOWS *fctname = dk4socket_app_kwnl[7]; #else *fctname = dk4socket_app_kwnl[6]; #endif } break; case DK4_E_SOCKET_BIND : { *fctname = dk4socket_app_kwnl[8]; } break; case DK4_E_SOCKET_CONNECT : { *fctname = dk4socket_app_kwnl[11]; } break; case DK4_E_SOCKET_LISTEN : { *fctname = dk4socket_app_kwnl[9]; } break; case DK4_E_SOCKET_ACCEPT : { *fctname = dk4socket_app_kwnl[10]; } break; case DK4_E_SOCKET_SHUTDOWN : { *fctname = dk4socket_app_kwnl[23]; } break; case DK4_E_SOCKET_SEND : { *fctname = dk4socket_app_kwnl[24]; } break; case DK4_E_SOCKET_RECV : { *fctname = dk4socket_app_kwnl[25]; } break; case DK4_E_SOCKET_SELECT : { *fctname = dk4socket_app_kwnl[15]; } break; case DK4_E_SOCKET_SETSOCKOPT : { *fctname = dk4socket_app_kwnl[12]; } break; case DK4_E_SOCKET_GETSOCKOPT : { *fctname = dk4socket_app_kwnl[16]; } break; case DK4_E_SOCKET_IOCTLSOCKET : { *fctname = dk4socket_app_kwnl[13]; } break; case DK4_E_SOCKET_FCNTL : { *fctname = dk4socket_app_kwnl[14]; } break; case DK4_E_SOCKET_GETSERVBYNAME : { *fctname = dk4socket_app_kwnl[20]; } break; case DK4_E_SOCKET_GETHOSTBYNAME : { *fctname = dk4socket_app_kwnl[19]; } break; case DK4_E_SOCKET_INET_NTOP : { *fctname = dk4socket_app_kwnl[22]; } break; case DK4_E_SOCKET_INET_PTON : { *fctname = dk4socket_app_kwnl[26]; } break; default : { *fctname = NULL; } break; } } if (NULL != msgtext) { #if (DK4_CHAR_SIZE == 1) && (!DK4_ON_WINDOWS) switch (erp->ec) { case DK4_E_SOCKET_GETADDRINFO : case DK4_E_SOCKET_GETADDRLOC : { #if DK4_HAVE_GETADDRINFO mytext = gai_strerror((erp->dt).iDetails1); #endif } break; case DK4_E_SOCKET_UP : case DK4_E_SOCKET_DOWN : case DK4_E_SOCKET_SOCKET : case DK4_E_SOCKET_CLOSE : case DK4_E_SOCKET_BIND : case DK4_E_SOCKET_CONNECT : case DK4_E_SOCKET_LISTEN : case DK4_E_SOCKET_ACCEPT : case DK4_E_SOCKET_SHUTDOWN : case DK4_E_SOCKET_SEND : case DK4_E_SOCKET_RECV : case DK4_E_SOCKET_SELECT : case DK4_E_SOCKET_SETSOCKOPT : case DK4_E_SOCKET_GETSOCKOPT : case DK4_E_SOCKET_IOCTLSOCKET : case DK4_E_SOCKET_FCNTL : case DK4_E_SOCKET_INET_NTOP : case DK4_E_SOCKET_INET_PTON : { mytext = strerror((erp->dt).iDetails1); } break; } #endif if (NULL == mytext) { $? ". no mytext yet" switch (erp->ec) { #if DK4_ON_WINDOWS /* +++++ Windows +++++ */ case DK4_E_SOCKET_GETADDRINFO : case DK4_E_SOCKET_GETADDRLOC : { switch (erp->dt.iDetails1) { case EAI_AGAIN : { /* Temporary problem in name resolution */ mytext = msgtexts[68]; } break; case EAI_BADFLAGS : { /* Incorrect flag combination */ mytext = msgtexts[69]; } break; case EAI_FAIL : { /* Nonrecoverable failure in name resolution */ mytext = msgtexts[70]; } break; case EAI_FAMILY : { /* Unsupported address family */ mytext = msgtexts[71]; } break; case EAI_MEMORY: { /* Not enough memory available */ mytext = msgtexts[72]; } break; case EAI_NONAME : { /* No address found for host */ mytext = msgtexts[74]; } break; case EAI_SERVICE : { /* Service type not supported for specified socket type */ mytext = msgtexts[75]; } break; case EAI_SOCKTYPE : { /* Socket type not supported */ mytext = msgtexts[76]; } break; } } break; case DK4_E_SOCKET_UP : case DK4_E_SOCKET_DOWN : case DK4_E_SOCKET_SOCKET : case DK4_E_SOCKET_CLOSE : case DK4_E_SOCKET_BIND : case DK4_E_SOCKET_CONNECT : case DK4_E_SOCKET_LISTEN : case DK4_E_SOCKET_ACCEPT : case DK4_E_SOCKET_SHUTDOWN : case DK4_E_SOCKET_SEND : case DK4_E_SOCKET_RECV : case DK4_E_SOCKET_SELECT : case DK4_E_SOCKET_SETSOCKOPT : case DK4_E_SOCKET_GETSOCKOPT : case DK4_E_SOCKET_IOCTLSOCKET : case DK4_E_SOCKET_FCNTL : case DK4_E_SOCKET_GETSERVBYNAME : case DK4_E_SOCKET_GETHOSTBYNAME : case DK4_E_SOCKET_INET_NTOP : case DK4_E_SOCKET_INET_PTON : { switch (erp->dt.iDetails1) { case ERROR_INVALID_PARAMETER : { /* inet_ntop: Buffer not present or too small */ mytext = msgtexts[100]; } break; case WSAEACCES : { /* bind: Insufficient permissions */ /* connect, send, sendto */ mytext = msgtexts[63]; } break; case WSAEADDRINUSE : { /* bind: Address is already in use */ /* connect, listen */ mytext = msgtexts[64]; } break; case WSAEADDRNOTAVAIL : { /* bind: Address is not valid in context, not a local address*/ /* connect: Invalid remote address */ /* sendto */ mytext = msgtexts[65]; } break; case WSAEAFNOSUPPORT : { /* socket: Addres family is not supported */ /* connect, sendto, inet_ntop, inet_pton */ mytext = msgtexts[54]; } break; case WSAEALREADY : { /* connect: Non-blocking connect already running for socket */ mytext = msgtexts[80]; } break; case WSAECONNABORTED : { /* send: Timeout or other failure, close the socket */ /* sendto, recv, shutdown */ mytext = msgtexts[105]; } break; case WSAECONNREFUSED : { /* connect: Connect attempt forcefully rejected */ mytext = msgtexts[82]; } break; case WSAECONNRESET : { /* accept: Connection request followed by termination request */ /* send, sendto, recv, recvfrom, shutdown */ mytext = msgtexts[83]; } break; case WSAEDESTADDRREQ : { /* sendto: Destination address required */ mytext = msgtexts[85]; } break; case WSAEFAULT : { /* WSAStartup: Invalid data pointer */ /* bind, connect, accept, select, ioctlsocket, gethostbyname */ /* send, sendto, recv, recvfrom, inet_pton */ mytext = msgtexts[51]; } break; case WSAEHOSTUNREACH : { /* connect: Host unreachable */ /* send, sendto */ mytext = msgtexts[106]; } break; case WSAEINPROGRESS : { /* WSAStartup: Blocking Winsock 1.1 operation in progress */ /* WSACleanup, socket, bind, connect, listen, select */ /* ioctlsocket, closesocket, gethostbyname, getservbyname */ /* send, sendto, recv, recvfrom, shutdown */ mytext = msgtexts[49]; } break; case WSAEINTR : { /* connect: Blocking call cancelled by WSACancelBlockingCall */ /* accept, select, closesocket, gethostbyname, getservbyname */ /* send, sendto, recv, recvfrom */ mytext = msgtexts[107]; } break; case WSAEINVAL : { /* socket: Invalid argument supplied */ /* bind, select, send, sendto, recv, recvfrom */ /* connect: The socket is in listening state */ /* listen: Socket not yet bound */ /* accept: Not listening */ /* shutdown: Invalid shutdown parameter */ switch (erp->ec) { case DK4_E_SOCKET_CONNECT : { mytext = msgtexts[108]; } break; case DK4_E_SOCKET_LISTEN : { mytext = msgtexts[109]; } break; case DK4_E_SOCKET_ACCEPT : { mytext = msgtexts[110]; } break; case DK4_E_SOCKET_SHUTDOWN : { mytext = msgtexts[111]; } break; default : { mytext = msgtexts[51]; } break; } } break; case WSAEINVALIDPROCTABLE : { /* socket: Service provider returned invalid procedure table */ mytext = msgtexts[119]; } break; case WSAEINVALIDPROVIDER : { /* socket: Invalid provider version */ mytext = msgtexts[120]; } break; case WSAEISCONN : { /* connect: Socket already connected */ /* listen */ /* recvfrom */ mytext = msgtexts[89]; } break; case WSAEMFILE : { /* socket: No more file descriptors available */ /* listen, accept */ mytext = msgtexts[92]; } break; case WSAEMSGSIZE : { /* send: Message size too large */ /* sendto, recv, recvfrom */ mytext = msgtexts[112]; } break; case WSAENETDOWN : { /* WSACleanup: Network subsystem has failed */ /* socket, bind, connect, listen, accept, select, ioctlsocket */ /* closesocket, gethostbyname, getservbyname, send, sendto */ /* recv, recvfrom, shutdown */ mytext = msgtexts[53]; } break; case WSAENETRESET : { /* send: Connection closed while keep-alive tests */ /* sendto, recv, recvfrom */ mytext = msgtexts[113]; } break; case WSAENETUNREACH : { /* connect: Network unreachable */ /* sendto */ mytext = msgtexts[94]; } break; case WSAENOBUFS : { /* socket: No buffer space available */ /* bind, connect, listen, accept, send, sendto */ mytext = msgtexts[56]; } break; case WSAENOTCONN : { /* send: Not connected */ /* recv, shutdown */ mytext = msgtexts[114]; } break; case WSAENOTSOCK : { /* bind: file descriptor is not a socket */ /* connect, listen, connect, select, ioctlsocket */ /* closesocket, send, sendto, recv, recvfrom, shutdown */ mytext = msgtexts[66]; } break; case WSAEOPNOTSUPP : { /* listen: Not supported by socket type */ /* accept, send, sendto, recv, recvfrom */ mytext = msgtexts[101]; } break; case WSAEPROCLIM : { /* WSAStartup: Limit of processes using Winsock is reached */ mytext = msgtexts[50]; } break; case WSAEPROTONOSUPPORT : { /* socket: Unsupported protocol */ mytext = msgtexts[57]; } break; case WSAEPROTOTYPE : { /* socket: Specified protocol invalid for socket */ mytext = msgtexts[58]; } break; case WSAEPROVIDERFAILEDINIT : { /* socket: Failed to initialize socket provider */ mytext = msgtexts[115]; } break; case WSAESHUTDOWN : { /* send: Socket was shut down */ /* sendto, recv, recvfrom */ mytext = msgtexts[116]; } break; case WSAESOCKTNOSUPPORT : { /* socket: Socket type not supported by address family */ mytext = msgtexts[60]; } break; case WSAETIMEDOUT : { /* connect: Timeout */ /* send, sendto, recv, recvfrom */ mytext = msgtexts[103]; } break; case WSAEWOULDBLOCK : { /* connect: Connection not finished on non-blocking socket */ /* accept: Non-blocking, not connection attempts are present */ /* closesocket, send, sendto, recv, recvfrom */ mytext = msgtexts[117]; } break; case WSAHOST_NOT_FOUND : { /* gethostbyname: Host not found (authorative answer) */ /* getservbyname */ mytext = msgtexts[118]; } break; case WSANO_DATA : { /* gethostbyname: Host name is valid, but no data found */ /* getservbyname */ mytext = msgtexts[73]; } break; case WSANO_RECOVERY : { /* gethostbyname: Unrecoverable error */ /* getservbyname */ mytext = msgtexts[70]; } break; case WSANOTINITIALISED : { /* WSACleanup: Winsock not initialized */ /* socket, bind, connect, listen, accept, select, ioctlsocket */ /* closesocket, gethostbyname, getservbyname, send, sendto */ /* recv, recvfrom, shutdown */ mytext = msgtexts[52]; } break; case WSASYSNOTREADY : { /* WSAStartup: Underlying subsystem not yet read */ mytext = msgtexts[47]; } break; case WSATRY_AGAIN : { /* gethostbyname: Host not found (non-authorative, or server failure */ /* getservbyname */ mytext = msgtexts[68]; } break; case WSAVERNOTSUPPORTED : { /* WSAStartup: The requested version is not supported */ mytext = msgtexts[48]; } break; } } break; /* ----- Windows ----- */ #else /* +++++ non-Windows +++++ */ case DK4_E_SOCKET_GETADDRINFO : case DK4_E_SOCKET_GETADDRLOC : { switch (erp->dt.iDetails1) { #ifdef EAI_ADDRFAMILY case EAI_ADDRFAMILY : { mytext = msgtexts[67]; } break; #endif #ifdef EAI_AGAIN case EAI_AGAIN : { mytext = msgtexts[68]; } break; #endif #ifdef EAI_BADFLAGS case EAI_BADFLAGS : { mytext = msgtexts[69]; } break; #endif #ifdef EAI_FAIL case EAI_FAIL : { mytext = msgtexts[70]; } break; #endif #ifdef EAI_FAMILY case EAI_FAMILY : { mytext = msgtexts[71]; } break; #endif #ifdef EAI_MEMORY case EAI_MEMORY : { mytext = msgtexts[72]; } break; #endif #ifdef EAI_NODATA case EAI_NODATA : { mytext = msgtexts[73]; } break; #endif #ifdef EAI_NONAME case EAI_NONAME : { mytext = msgtexts[74]; } break; #endif #ifdef EAI_OVERFLOW case EAI_OVERFLOW : { mytext = msgtexts[78]; } break; #endif #ifdef EAI_SERVICE case EAI_SERVICE : { mytext = msgtexts[75]; } break; #endif #ifdef EAI_SOCKTYPE case EAI_SOCKTYPE : { mytext = msgtexts[76]; } break; #endif #ifdef EAI_SYSTEM case EAI_SYSTEM : { mytext = msgtexts[77]; } break; #endif } } break; case DK4_E_SOCKET_GETHOSTBYNAME : { switch (erp->dt.iDetails1) { #ifdef HOST_NOT_FOUND case HOST_NOT_FOUND : { mytext = msgtexts[73]; } break; #endif #ifdef NO_ADDRESS case NO_ADDRESS : { mytext = msgtexts[73]; } break; #endif #if defined(NO_DATA) && ((!defined(NO_ADDRESS)) || (NO_DATA != NO_ADDRESS)) case NO_DATA : { mytext = msgtexts[73]; } break; #endif #ifdef NO_RECOVERY case NO_RECOVERY : { mytext = msgtexts[70]; } break; #endif #ifdef TRY_AGAIN case TRY_AGAIN : { mytext = msgtexts[68]; } break; #endif } } break; case DK4_E_SOCKET_UP : case DK4_E_SOCKET_DOWN : case DK4_E_SOCKET_SOCKET : case DK4_E_SOCKET_CLOSE : case DK4_E_SOCKET_BIND : case DK4_E_SOCKET_CONNECT : case DK4_E_SOCKET_LISTEN : case DK4_E_SOCKET_ACCEPT : case DK4_E_SOCKET_SELECT : case DK4_E_SOCKET_SETSOCKOPT : case DK4_E_SOCKET_GETSOCKOPT : case DK4_E_SOCKET_IOCTLSOCKET : case DK4_E_SOCKET_FCNTL : case DK4_E_SOCKET_INET_NTOP : case DK4_E_SOCKET_INET_PTON : { switch (erp->dt.iDetails1) { #ifdef EACCES case EACCES : { /* socket: Insufficient permissions */ /* bind, connect, listen, send */ mytext = msgtexts[63]; } break; #endif #ifdef EADDRINUSE case EADDRINUSE : { /* bind: Address already in used */ /* connect */ /* listen */ mytext = msgtexts[64]; } break; #endif #ifdef EADDRNOTAVAIL case EADDRNOTAVAIL : { /* bind: nonexistent interface or address is not local */ /* connect */ mytext = msgtexts[65]; } break; #endif #ifdef EAFNOSUPPORT case EAFNOSUPPORT : { /* socket: Address family not supported */ /* bind: Mismatch address and address family */ /* connect, sendto, inet_pton */ mytext = msgtexts[54]; } break; #endif #ifdef EAGAIN case EAGAIN : { /* accept: Socket non-blocking, no incoming requests */ /* send, recv */ mytext = msgtexts[79]; } break; #endif #ifdef EALREADY case EALREADY : { /* connect: Already connected */ mytext = msgtexts[80]; } break; #endif #ifdef EBADF case EBADF : { /* close: Not a file descriptr */ /* shutdown, bind, connect */ /* listen, accept, send, recv */ mytext = msgtexts[81]; } break; #endif #ifdef ECONNABORTED case ECONNABORTED : { /* accept: Connection attempt aborted */ mytext = msgtexts[105]; } break; #endif #ifdef ECONNREFUSED case ECONNREFUSED : { /* connect: No-one listening on remote address */ /* recv */ mytext = msgtexts[82]; } break; #endif #ifdef ECONNRESET case ECONNRESET : { /* connect: Remote host denied connection */ /* send, recv */ mytext = msgtexts[83]; } break; #endif #ifdef EDEADLK case EDEADLK : { mytext = msgtexts[84]; } break; #endif #ifdef EDESTADDRREQ case EDESTADDRREQ : { /* bind: Address is a NULL pointer */ /* listen: Socket not yet bound */ /* send */ mytext = msgtexts[85]; } break; #endif #ifdef EDOM case EDOM : { mytext = msgtexts[86]; } break; #endif #ifdef EFAULT case EFAULT : { /* bind: Pointer to outside usable address space */ /* connect, accept, send, recv */ mytext = msgtexts[51]; } break; #endif #ifdef EHOSTUNREACH case EHOSTUNREACH : { /* connect: Remote host unreachable */ /* send */ mytext = msgtexts[106]; } break; #endif #ifdef EINPROGRESS case EINPROGRESS : { /* connect: Socket is non-blocking, operation would block */ mytext = msgtexts[87]; } break; #endif #ifdef EINTR case EINTR : { /* close: Interrupted by signal */ /* connect, accept, send, recv */ mytext = msgtexts[88]; } break; #endif #ifdef EINVAL case EINVAL : { /* socket: unknown protocol, illegal protocol family or flags */ /* shutdown: Invalid argument */ /* bind: Socket already bound */ /* bind: wrong address length */ /* bind: Socket already shut down */ /* connect: Wrong address length or address family */ /* listen: Socket already connected */ /* listen: Socket already shut down */ /* accept: Socket not listening, or illegal socket value */ /* accept: Invalid flags */ /* send: Invalid arguments , recv */ mytext = msgtexts[51]; } break; #endif #ifdef EISCONN case EISCONN : { /* bind: Socket already connected */ /* connect, send */ mytext = msgtexts[89]; } break; #endif #ifdef EISDIR case EISDIR : { /* bind: Address is a NULL pointer */ mytext = msgtexts[85]; } break; #endif #ifdef EIO case EIO : { /* close: I/O error */ /* connect, send */ mytext = msgtexts[90]; } break; #endif #ifdef ELOOP case ELOOP : { /* bind: Too many symbolic links or symlink loop */ /* connect, send */ mytext = msgtexts[91]; } break; #endif #ifdef EMFILE case EMFILE : { /* socket: Process file table overflow */ /* accept */ mytext = msgtexts[92]; } break; #endif #ifdef EMSGSIZE case EMSGSIZE : { /* send: Message size too large */ mytext = msgtexts[112]; } break; #endif #ifdef ENAMETOOLONG case ENAMETOOLONG : { /* bind: Address is too long */ /* connect, send */ mytext = msgtexts[93]; } break; #endif #ifdef ENETDOWN case ENETDOWN : { /* connect: Local network interface is down */ /* send */ mytext = msgtexts[53]; } break; #endif #ifdef ENETUNREACH case ENETUNREACH : { /* connect: Network is unreachable */ /* send */ mytext = msgtexts[94]; } break; #endif #ifdef ENFILE case ENFILE : { /* socket: System file table overflow */ /* accept */ mytext = msgtexts[95]; } break; #endif #ifdef ENOBUFS case ENOBUFS : { /* socket: No memory for buffers */ /* shutdown: Insufficient resources */ /* connect, listen, accept, send */ mytext = msgtexts[56]; } break; #endif #ifdef ENODEV case ENODEV : { /* accept: Protocol family and type not in network config */ mytext = msgtexts[126]; } break; #endif #ifdef ENOENT case ENOENT : { /* bind: File does not exist */ /* connect, send */ mytext = msgtexts[96]; } break; #endif #ifdef ENOLCK case ENOLCK : { mytext = msgtexts[97]; } break; #endif #ifdef ENOLINK case ENOLINK : { /* close: Connection to remote machine no longer active */ mytext = msgtexts[124]; } break; #endif #ifdef ENOMEM case ENOMEM : { /* socket: Not enough memory available */ /* bind, accept, send, recv */ mytext = msgtexts[72]; } break; #endif #ifdef ENOPROTOOPT case ENOPROTOOPT : { mytext = msgtexts[98]; } break; #endif #ifdef ENOSR case ENOSR : { /* socket: Insufficient stream resources */ /* bind, connect, accept, send, recv, shutdown */ mytext = msgtexts[122]; } break; #endif #ifdef ENOTCONN case ENOTCONN : { /* shutdown: Not connected */ /* send, recv */ mytext = msgtexts[114]; } break; #endif #ifdef ENOTDIR case ENOTDIR : { /* bind: Component or path prefix is not a directory */ /* connect, send */ mytext = msgtexts[99]; } break; #endif #ifdef ENOTSOCK case ENOTSOCK : { /* shutdown: Not a socket */ /* bind, connect, listen, accept, send, recv */ mytext = msgtexts[66]; } break; #endif #ifdef ENOSPC case ENOSPC : { /* inet_pton: Insufficient buffer size */ /* close: Not enough space on device */ mytext = msgtexts[100]; } break; #endif #ifdef ENXIO case ENXIO : { /* connect: Server exited before completing connection */ mytext = msgtexts[125]; } break; #endif #ifdef EOPNOTSUPP case EOPNOTSUPP : { /* bind: Operation not supported by socket type */ /* connect: Socket is listening */ /* listen: Socket can not listen */ /* accept: Not a stream socket */ /* send: Illegal flags, recv */ mytext = msgtexts[101]; } break; #endif #ifdef EPERM case EPERM : { /* connect: Insufficient permissions */ /* accept: Firewall rules forbid connection */ mytext = msgtexts[63]; } break; #endif #ifdef EPFNOSUPPORT case EPFNOSUPPORT : { /* socket: Protocol family not supported */ mytext = msgtexts[123]; } break; #endif #ifdef EPIPE case EPIPE : { mytext = msgtexts[116]; } break; #endif #ifdef EPROTONOSUPPORT case EPROTONOSUPPORT : { /* socket: Protocol type not supported in this domain */ mytext = msgtexts[57]; } break; #endif #ifdef EPROTO case EPROTO : { /* accept: Protocol error */ mytext = msgtexts[121]; } break; #endif #ifdef EPROTOTYPE case EPROTOTYPE : { /* socket: Socket type not supported by protocol */ /* connect: Remote type is different address family as local */ mytext = msgtexts[58]; } break; #endif #ifdef EROFS case EROFS : { /* bind: File system is mounted read-only */ mytext = msgtexts[102]; } break; #endif #ifdef ESTALE case ESTALE : { /* recv: Stale NFS file handle */ mytext = msgtexts[127]; } break; #endif #ifdef ETIMEDOUT case ETIMEDOUT : { /* connect: Timed out */ /* recv */ mytext = msgtexts[103]; } break; #endif #ifdef EOVERFLOW case EOVERFLOW : { mytext = msgtexts[104]; } break; #endif #if defined(EWOULDBLOCK) && ((!defined(EAGAIN)) || (EWOULDBLOCK != EAGAIN)) case EWOULDBLOCK : { /* accept: Socket non-blocking, no incoming requests */ /* send, recv */ mytext = msgtexts[79]; } break; #endif } } break; /* ----- non-Windows ----- */ #endif } } *msgtext = mytext; } } } void dk4socket_log_simple_1( dk4_app_t *app, int ll, size_t imain, dk4_er_t *erp ) { dkChar b1[16*sizeof(dk4_um_t)]; /* decimal */ dkChar b2[16*sizeof(dk4_um_t)]; /* hexadecimal */ const dkChar *fctn = NULL; /* Function name */ const dkChar *errt = NULL; /* Error text */ const dkChar *msgt[16]; /* Message components */ const dkChar * const *msga; /* Localized texts array */ size_t used = 0; /* Number of used components */ int res = 0; /* Conversion result */ if (0 != dk4app_log_do(app, ll)) { msga = dk4app_string_table(app,dk4socket_app_kwnl[0],dk4socket_app_kw_def); if (dk4socket_sz_kw_def > imain) { msgt[used++] = msga[imain]; dk4socket_log_fctname_msg(&fctn, &errt, app, erp); if (NULL != fctn) { if (NULL != errt) { msgt[used++] = dk4socket_app_kwnl[1]; msgt[used++] = fctn; msgt[used++] = dk4socket_app_kwnl[2]; msgt[used++] = errt; } else { res = dk4ma_write_decimal_signed( b1, DK4_SIZEOF(b1,dkChar), (dk4_um_t)(erp->dt.iDetails1), 0, NULL ); if (0 != res) { res = dk4ma_write_hex_signed( b2, DK4_SIZEOF(b2,dkChar), (dk4_im_t)(erp->dt.iDetails1), 8, NULL ); if (0 != res) { msgt[used++] = dk4socket_app_kwnl[1]; msgt[used++] = fctn; msgt[used++] = dk4socket_app_kwnl[2]; #if DK4_ON_WINDOWS msgt[used++] = msga[40]; #else msgt[used++] = msga[37]; #endif msgt[used++] = b1; msgt[used++] = msga[38]; msgt[used++] = b2; msgt[used++] = msga[39]; } } } } else { if (NULL != errt) { msgt[used++] = dk4socket_app_kwnl[1]; msgt[used++] = errt; } else { } } dk4app_log_msg(app, ll, msgt, used); } } } void dk4socket_log_simple_3( dk4_app_t *app, int ll, size_t i1, size_t i2, const dkChar *ctext, dk4_er_t *erp ) { dkChar b1[16*sizeof(dk4_um_t)]; /* decimal */ dkChar b2[16*sizeof(dk4_um_t)]; /* hexadecimal */ const dkChar *fctn = NULL; /* Function name */ const dkChar *errt = NULL; /* Error text */ const dkChar *msgt[16]; /* Message components */ const dkChar * const *msga; /* Localized texts array */ size_t used = 0; /* Number of used components */ int res = 0; /* Conversion result */ if (0 != dk4app_log_do(app, ll)) { msga = dk4app_string_table(app,dk4socket_app_kwnl[0],dk4socket_app_kw_def); if ((dk4socket_sz_kw_def > i1) && (dk4socket_sz_kw_def > i2)) { msgt[used++] = msga[i1]; if (NULL != ctext) { msgt[used++] = ctext; } msgt[used++] = msga[i2]; dk4socket_log_fctname_msg(&fctn, &errt, app, erp); if (NULL != fctn) { if (NULL != errt) { msgt[used++] = dk4socket_app_kwnl[1]; msgt[used++] = fctn; msgt[used++] = dk4socket_app_kwnl[2]; msgt[used++] = errt; } else { res = dk4ma_write_decimal_signed( b1, DK4_SIZEOF(b1,dkChar), (dk4_um_t)(erp->dt.iDetails1), 0, NULL ); if (0 != res) { res = dk4ma_write_hex_signed( b2, DK4_SIZEOF(b2,dkChar), (dk4_im_t)(erp->dt.iDetails1), 8, NULL ); if (0 != res) { msgt[used++] = dk4socket_app_kwnl[1]; msgt[used++] = fctn; msgt[used++] = dk4socket_app_kwnl[2]; #if DK4_ON_WINDOWS msgt[used++] = msga[40]; #else msgt[used++] = msga[37]; #endif msgt[used++] = b1; msgt[used++] = msga[38]; msgt[used++] = b2; msgt[used++] = msga[39]; } } } } else { if (NULL != errt) { msgt[used++] = dk4socket_app_kwnl[1]; msgt[used++] = errt; } else { } } dk4app_log_msg(app, ll, msgt, used); } } } void dk4socket_log_simple_5( dk4_app_t *app, int ll, size_t i1, size_t i2, size_t i3, const dkChar *ct1, const dkChar *ct2, dk4_er_t *erp ) { dkChar b1[16*sizeof(dk4_um_t)]; /* decimal */ dkChar b2[16*sizeof(dk4_um_t)]; /* hexadecimal */ const dkChar *fctn = NULL; /* Function name */ const dkChar *errt = NULL; /* Error text */ const dkChar *msgt[16]; /* Message components */ const dkChar * const *msga; /* Localized texts array */ size_t used = 0; /* Number of used components */ int res = 0; /* Conversion result */ if (0 != dk4app_log_do(app, ll)) { msga = dk4app_string_table(app,dk4socket_app_kwnl[0],dk4socket_app_kw_def); if ((dk4socket_sz_kw_def > i1) && (dk4socket_sz_kw_def > i2)) { msgt[used++] = msga[i1]; if (NULL != ct1) { msgt[used++] = ct1; } msgt[used++] = msga[i2]; if (NULL != ct2) { msgt[used++] = ct2; } msgt[used++] = msga[i3]; dk4socket_log_fctname_msg(&fctn, &errt, app, erp); if (NULL != fctn) { if (NULL != errt) { msgt[used++] = dk4socket_app_kwnl[1]; msgt[used++] = fctn; msgt[used++] = dk4socket_app_kwnl[2]; msgt[used++] = errt; } else { res = dk4ma_write_decimal_signed( b1, DK4_SIZEOF(b1,dkChar), (dk4_um_t)(erp->dt.iDetails1), 0, NULL ); if (0 != res) { res = dk4ma_write_hex_signed( b2, DK4_SIZEOF(b2,dkChar), (dk4_im_t)(erp->dt.iDetails1), 8, NULL ); if (0 != res) { msgt[used++] = dk4socket_app_kwnl[1]; msgt[used++] = fctn; msgt[used++] = dk4socket_app_kwnl[2]; #if DK4_ON_WINDOWS msgt[used++] = msga[40]; #else msgt[used++] = msga[37]; #endif msgt[used++] = b1; msgt[used++] = msga[38]; msgt[used++] = b2; msgt[used++] = msga[39]; } } } } else { if (NULL != errt) { msgt[used++] = dk4socket_app_kwnl[1]; msgt[used++] = errt; } else { } } dk4app_log_msg(app, ll, msgt, used); } } }