hints.ai_next = NULL;
if ((result = getaddrinfo(host, NULL, &hints, &ai)) != 0) {
- throw Exception("unable to resolve host by name: %s",
- gai_strerror(result));
+ throw GAIException("unable to resolve host by name", result);
}
sock = -1;
snprintf (service, sizeof (service) - 1, "%d", port);
service[sizeof (service) - 1] = '\0';
if ((result = getaddrinfo(addr, service, &hints, &ai)) != 0)
- throw rdr::Exception("unable to resolve listening address: %s",
- gai_strerror(result));
+ throw GAIException("unable to resolve listening address", result);
try {
createTcpListeners(listeners, ai);
}
if ((result = getaddrinfo (p, NULL, &hints, &ai)) != 0) {
- throw Exception("unable to resolve host by name: %s",
- gai_strerror(result));
+ throw GAIException("unable to resolve host by name", result);
}
memcpy (&pattern.address.u.sa, ai->ai_addr, ai->ai_addrlen);
#include <tchar.h>
#include <winsock2.h>
#include <windows.h>
+#include <ws2tcpip.h>
+#else
+#include <netdb.h>
#endif
#include <string.h>
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_)
{
struct SystemException : public Exception {
int err;
SystemException(const char* s, int err_);
- };
+ };
+
+ struct GAIException : public Exception {
+ int err;
+ GAIException(const char* s, int err_);
+ };
struct TimedOut : public Exception {
TimedOut() : Exception("Timed out") {}
};
-
+
struct EndOfStream : public Exception {
EndOfStream() : Exception("End of stream") {}
};