diff --git a/contrib/win32/win32compat/socketio.c b/contrib/win32/win32compat/socketio.c index e78532d..1f16f65 100644 --- a/contrib/win32/win32compat/socketio.c +++ b/contrib/win32/win32compat/socketio.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "w32fd.h" #include #include "inc\utf.h" @@ -985,20 +986,26 @@ int w32_gethostname(char *name_utf8, size_t len) { wchar_t name_utf16[256]; char* tmp_name_utf8 = NULL; - if (GetHostNameW(name_utf16, 256) == SOCKET_ERROR) { - errno = errno_from_WSALastError(); - return -1; - } - if ((tmp_name_utf8 = utf16_to_utf8(name_utf16)) == NULL || - strlen(tmp_name_utf8) >= len) { - errno = EFAULT; //?? - return -1; - } + if (IsWindows8OrGreater()) { + /* TODO - GetHostNameW not present in Win7, do GetProcAddr on Win8+*/ + // if (GetHostNameW(name_utf16, 256) == SOCKET_ERROR) { + // errno = errno_from_WSALastError(); + // return -1; + // } - memcpy(name_utf8, tmp_name_utf8, strlen(tmp_name_utf8) + 1); - free(tmp_name_utf8); - return 0; + // if ((tmp_name_utf8 = utf16_to_utf8(name_utf16)) == NULL || + // strlen(tmp_name_utf8) >= len) { + // errno = EFAULT; //?? + // return -1; + // } + + // memcpy(name_utf8, tmp_name_utf8, strlen(tmp_name_utf8) + 1); + // free(tmp_name_utf8); + // return 0; + } + else + return gethostname(name_utf8, len); } void diff --git a/sshd.c b/sshd.c index b3ab6dd..2c988cd 100644 --- a/sshd.c +++ b/sshd.c @@ -1895,9 +1895,10 @@ main(int ac, char **av) { do { - SERVICE_TABLE_ENTRY DispatchTable[] = + int wmain(int , wchar_t **); + SERVICE_TABLE_ENTRYW DispatchTable[] = { - {SVCNAME, (LPSERVICE_MAIN_FUNCTION) main}, + {L"SSHD", (LPSERVICE_MAIN_FUNCTIONW) wmain}, {NULL, NULL} }; @@ -1920,7 +1921,7 @@ main(int ac, char **av) * for any other reason, bail out. */ - if (!StartServiceCtrlDispatcher(DispatchTable)) + if (!StartServiceCtrlDispatcherW(DispatchTable)) { if (GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) {