1 | /*
|
---|
2 | * synergy -- mouse and keyboard sharing utility
|
---|
3 | * Copyright (C) 2002 Chris Schoeneman
|
---|
4 | *
|
---|
5 | * This package is free software; you can redistribute it and/or
|
---|
6 | * modify it under the terms of the GNU General Public License
|
---|
7 | * found in the file COPYING that should have accompanied this file.
|
---|
8 | *
|
---|
9 | * This package is distributed in the hope that it will be useful,
|
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | * GNU General Public License for more details.
|
---|
13 | */
|
---|
14 |
|
---|
15 | #include "XArchWindows.h"
|
---|
16 | #include "CArchNetworkWinsock.h"
|
---|
17 |
|
---|
18 | //
|
---|
19 | // XArchEvalWindows
|
---|
20 | //
|
---|
21 |
|
---|
22 | XArchEval*
|
---|
23 | XArchEvalWindows::clone() const throw()
|
---|
24 | {
|
---|
25 | return new XArchEvalWindows(m_errno);
|
---|
26 | }
|
---|
27 |
|
---|
28 | std::string
|
---|
29 | XArchEvalWindows::eval() const throw()
|
---|
30 | {
|
---|
31 | char* cmsg;
|
---|
32 | if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
---|
33 | FORMAT_MESSAGE_IGNORE_INSERTS |
|
---|
34 | FORMAT_MESSAGE_FROM_SYSTEM,
|
---|
35 | 0,
|
---|
36 | m_errno,
|
---|
37 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
---|
38 | (LPTSTR)&cmsg,
|
---|
39 | 0,
|
---|
40 | NULL) == 0) {
|
---|
41 | cmsg = NULL;
|
---|
42 | return "Unknown error";
|
---|
43 | }
|
---|
44 | std::string smsg(cmsg);
|
---|
45 | LocalFree(cmsg);
|
---|
46 | return smsg;
|
---|
47 | }
|
---|
48 |
|
---|
49 |
|
---|
50 | //
|
---|
51 | // XArchEvalWinsock
|
---|
52 | //
|
---|
53 |
|
---|
54 | XArchEval*
|
---|
55 | XArchEvalWinsock::clone() const throw()
|
---|
56 | {
|
---|
57 | return new XArchEvalWinsock(m_errno);
|
---|
58 | }
|
---|
59 |
|
---|
60 | std::string
|
---|
61 | XArchEvalWinsock::eval() const throw()
|
---|
62 | {
|
---|
63 | // built-in windows function for looking up error message strings
|
---|
64 | // may not look up network error messages correctly. we'll have
|
---|
65 | // to do it ourself.
|
---|
66 | static const struct { int m_code; const char* m_msg; } s_netErrorCodes[] = {
|
---|
67 | /* 10004 */{WSAEINTR, "The (blocking) call was canceled via WSACancelBlockingCall"},
|
---|
68 | /* 10009 */{WSAEBADF, "Bad file handle"},
|
---|
69 | /* 10013 */{WSAEACCES, "The requested address is a broadcast address, but the appropriate flag was not set"},
|
---|
70 | /* 10014 */{WSAEFAULT, "WSAEFAULT"},
|
---|
71 | /* 10022 */{WSAEINVAL, "WSAEINVAL"},
|
---|
72 | /* 10024 */{WSAEMFILE, "No more file descriptors available"},
|
---|
73 | /* 10035 */{WSAEWOULDBLOCK, "Socket is marked as non-blocking and no connections are present or the receive operation would block"},
|
---|
74 | /* 10036 */{WSAEINPROGRESS, "A blocking Windows Sockets operation is in progress"},
|
---|
75 | /* 10037 */{WSAEALREADY, "The asynchronous routine being canceled has already completed"},
|
---|
76 | /* 10038 */{WSAENOTSOCK, "At least on descriptor is not a socket"},
|
---|
77 | /* 10039 */{WSAEDESTADDRREQ, "A destination address is required"},
|
---|
78 | /* 10040 */{WSAEMSGSIZE, "The datagram was too large to fit into the specified buffer and was truncated"},
|
---|
79 | /* 10041 */{WSAEPROTOTYPE, "The specified protocol is the wrong type for this socket"},
|
---|
80 | /* 10042 */{WSAENOPROTOOPT, "The option is unknown or unsupported"},
|
---|
81 | /* 10043 */{WSAEPROTONOSUPPORT,"The specified protocol is not supported"},
|
---|
82 | /* 10044 */{WSAESOCKTNOSUPPORT,"The specified socket type is not supported by this address family"},
|
---|
83 | /* 10045 */{WSAEOPNOTSUPP, "The referenced socket is not a type that supports that operation"},
|
---|
84 | /* 10046 */{WSAEPFNOSUPPORT, "BSD: Protocol family not supported"},
|
---|
85 | /* 10047 */{WSAEAFNOSUPPORT, "The specified address family is not supported"},
|
---|
86 | /* 10048 */{WSAEADDRINUSE, "The specified address is already in use"},
|
---|
87 | /* 10049 */{WSAEADDRNOTAVAIL, "The specified address is not available from the local machine"},
|
---|
88 | /* 10050 */{WSAENETDOWN, "The Windows Sockets implementation has detected that the network subsystem has failed"},
|
---|
89 | /* 10051 */{WSAENETUNREACH, "The network can't be reached from this hos at this time"},
|
---|
90 | /* 10052 */{WSAENETRESET, "The connection must be reset because the Windows Sockets implementation dropped it"},
|
---|
91 | /* 10053 */{WSAECONNABORTED, "The virtual circuit was aborted due to timeout or other failure"},
|
---|
92 | /* 10054 */{WSAECONNRESET, "The virtual circuit was reset by the remote side"},
|
---|
93 | /* 10055 */{WSAENOBUFS, "No buffer space is available or a buffer deadlock has occured. The socket cannot be created"},
|
---|
94 | /* 10056 */{WSAEISCONN, "The socket is already connected"},
|
---|
95 | /* 10057 */{WSAENOTCONN, "The socket is not connected"},
|
---|
96 | /* 10058 */{WSAESHUTDOWN, "The socket has been shutdown"},
|
---|
97 | /* 10059 */{WSAETOOMANYREFS, "BSD: Too many references"},
|
---|
98 | /* 10060 */{WSAETIMEDOUT, "Attempt to connect timed out without establishing a connection"},
|
---|
99 | /* 10061 */{WSAECONNREFUSED, "The attempt to connect was forcefully rejected"},
|
---|
100 | /* 10062 */{WSAELOOP, "Undocumented WinSock error code used in BSD"},
|
---|
101 | /* 10063 */{WSAENAMETOOLONG, "Undocumented WinSock error code used in BSD"},
|
---|
102 | /* 10064 */{WSAEHOSTDOWN, "Undocumented WinSock error code used in BSD"},
|
---|
103 | /* 10065 */{WSAEHOSTUNREACH, "No route to host"},
|
---|
104 | /* 10066 */{WSAENOTEMPTY, "Undocumented WinSock error code"},
|
---|
105 | /* 10067 */{WSAEPROCLIM, "Undocumented WinSock error code"},
|
---|
106 | /* 10068 */{WSAEUSERS, "Undocumented WinSock error code"},
|
---|
107 | /* 10069 */{WSAEDQUOT, "Undocumented WinSock error code"},
|
---|
108 | /* 10070 */{WSAESTALE, "Undocumented WinSock error code"},
|
---|
109 | /* 10071 */{WSAEREMOTE, "Undocumented WinSock error code"},
|
---|
110 | /* 10091 */{WSASYSNOTREADY, "Underlying network subsytem is not ready for network communication"},
|
---|
111 | /* 10092 */{WSAVERNOTSUPPORTED, "The version of WinSock API support requested is not provided in this implementation"},
|
---|
112 | /* 10093 */{WSANOTINITIALISED, "WinSock subsystem not properly initialized"},
|
---|
113 | /* 10101 */{WSAEDISCON, "Virtual circuit has gracefully terminated connection"},
|
---|
114 | /* 11001 */{WSAHOST_NOT_FOUND, "The specified host is unknown"},
|
---|
115 | /* 11002 */{WSATRY_AGAIN, "A temporary error occurred on an authoritative name server"},
|
---|
116 | /* 11003 */{WSANO_RECOVERY, "A non-recoverable name server error occurred"},
|
---|
117 | /* 11004 */{WSANO_DATA, "The requested name is valid but does not have an IP address"},
|
---|
118 | /* end */{0, NULL}
|
---|
119 | };
|
---|
120 |
|
---|
121 | for (unsigned int i = 0; s_netErrorCodes[i].m_code != 0; ++i) {
|
---|
122 | if (s_netErrorCodes[i].m_code == m_errno) {
|
---|
123 | return s_netErrorCodes[i].m_msg;
|
---|
124 | }
|
---|
125 | }
|
---|
126 | return "Unknown error";
|
---|
127 | }
|
---|