aboutsummaryrefslogtreecommitdiffstats
path: root/common/rdr/Exception.cxx
diff options
context:
space:
mode:
authorAlex Tanskanen <aleta@cendio.com>2020-03-10 13:33:01 +0100
committerAlex Tanskanen <aleta@cendio.com>2020-03-17 14:46:20 +0100
commite52923415e55add9aa448ffcbb018a84fa39b742 (patch)
tree5ac63ed06a13c6a6a28e389ec051c4e82bfca2e4 /common/rdr/Exception.cxx
parent01ca961b0cf009a6f1e4603ad84b09d475b9f515 (diff)
downloadtigervnc-e52923415e55add9aa448ffcbb018a84fa39b742.tar.gz
tigervnc-e52923415e55add9aa448ffcbb018a84fa39b742.zip
Throw GAIException() for getaddrinfo errors
Created a new subclass of Exception called GAIException() that will handle error messages from getaddrinfo() instead of letting Exception() handle it. GAIException() will make use of gai_strerror() to map the error code to text. On Windows, gai_strerrorW() must be used if the text is encoded with UTF-8.
Diffstat (limited to 'common/rdr/Exception.cxx')
-rw-r--r--common/rdr/Exception.cxx18
1 files changed, 18 insertions, 0 deletions
diff --git a/common/rdr/Exception.cxx b/common/rdr/Exception.cxx
index e0592b29..9b6096b6 100644
--- a/common/rdr/Exception.cxx
+++ b/common/rdr/Exception.cxx
@@ -31,6 +31,9 @@
#include <tchar.h>
#include <winsock2.h>
#include <windows.h>
+#include <ws2tcpip.h>
+#else
+#include <netdb.h>
#endif
#include <string.h>
@@ -49,6 +52,21 @@ Exception::Exception(const char *format, ...) {
va_end(ap);
}
+GAIException::GAIException(const char* s, int err)
+ : Exception("%s", s)
+{
+ strncat(str_, ": ", len-1-strlen(str_));
+#ifdef _WIN32
+ wchar_t currStr[len-strlen(str_)];
+ wcsncpy(currStr, gai_strerrorW(err), len-1-strlen(str_));
+ WideCharToMultiByte(CP_UTF8, 0, currStr, -1, str_+strlen(str_),
+ len-1-strlen(str_), 0, 0);
+#else
+ //FIXME: perhaps print the error number (NNNN)
+ strncat(str_, gai_strerror(err), len-1-strlen(str_));
+#endif
+}
+
SystemException::SystemException(const char* s, int err_)
: Exception("%s", s), err(err_)
{