OSDN Git Service

Change to specify explicitly code pages.
[ffftp/ffftp.git] / socketwrapper.c
index 6ebe36d..caae589 100644 (file)
@@ -641,6 +641,8 @@ int FTPS_recv(SOCKET s, char * buf, int len, int flags)
 \r
 // IPv6対応\r
 \r
+const struct in6_addr IN6ADDR_NONE = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};\r
+\r
 typedef struct\r
 {\r
        HANDLE h;\r
@@ -682,7 +684,7 @@ DWORD WINAPI WSAAsyncGetHostByNameIPv6ThreadProc(LPVOID lpParameter)
                                                pHost->h_addr_list[0] = (char*)(&pHost->h_addr_list[2]);\r
                                                pHost->h_addr_list[1] = NULL;\r
                                                memcpy(pHost->h_addr_list[0], &((struct sockaddr_in*)p->ai_addr)->sin_addr, sizeof(struct in_addr));\r
-                                               PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(sizeof(struct hostent) + sizeof(char*) * 2 + p->ai_addrlen));\r
+                                               PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(sizeof(struct hostent) + sizeof(char*) * 2 + sizeof(struct in_addr)));\r
                                        }\r
                                        else\r
                                                PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(WSAENOBUFS << 16));\r
@@ -700,7 +702,7 @@ DWORD WINAPI WSAAsyncGetHostByNameIPv6ThreadProc(LPVOID lpParameter)
                                                pHost->h_addr_list[0] = (char*)(&pHost->h_addr_list[2]);\r
                                                pHost->h_addr_list[1] = NULL;\r
                                                memcpy(pHost->h_addr_list[0], &((struct sockaddr_in6*)p->ai_addr)->sin6_addr, sizeof(struct in6_addr));\r
-                                               PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(sizeof(struct hostent) + sizeof(char*) * 2 + p->ai_addrlen));\r
+                                               PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(sizeof(struct hostent) + sizeof(char*) * 2 + sizeof(struct in6_addr)));\r
                                        }\r
                                        else\r
                                                PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(WSAENOBUFS << 16));\r
@@ -717,10 +719,11 @@ DWORD WINAPI WSAAsyncGetHostByNameIPv6ThreadProc(LPVOID lpParameter)
        }\r
        else\r
                PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(ERROR_INVALID_FUNCTION << 16));\r
-       free(pData->name);\r
-       free(pData);\r
        // CreateThreadが返すハンドルが重複するのを回避\r
        Sleep(10000);\r
+       CloseHandle(pData->h);\r
+       free(pData->name);\r
+       free(pData);\r
        return 0;\r
 }\r
 \r
@@ -767,7 +770,10 @@ int WSACancelAsyncRequestIPv6(HANDLE hAsyncTaskHandle)
        int Result;\r
        Result = SOCKET_ERROR;\r
        if(TerminateThread(hAsyncTaskHandle, 0))\r
+       {\r
+               CloseHandle(hAsyncTaskHandle);\r
                Result = 0;\r
+       }\r
        return Result;\r
 }\r
 \r
@@ -843,7 +849,7 @@ struct in6_addr inet6_addr(const char* cp)
        {\r
                if(!cp)\r
                {\r
-                       memset(&Result, 0xff, sizeof(Result));\r
+                       memcpy(&Result, &IN6ADDR_NONE, sizeof(struct in6_addr));\r
                        break;\r
                }\r
                if(i >= AfterZero)\r
@@ -867,7 +873,7 @@ struct in6_addr inet6_addr(const char* cp)
                                Result.u.Word[i] = ((Result.u.Word[i] & 0xff00) >> 8) | ((Result.u.Word[i] & 0x00ff) << 8);\r
                                if(strncmp(p, ":", 1) != 0 && strlen(p) > 0)\r
                                {\r
-                                       memset(&Result, 0xff, sizeof(Result));\r
+                                       memcpy(&Result, &IN6ADDR_NONE, sizeof(struct in6_addr));\r
                                        break;\r
                                }\r
                                if(cp = strstr(cp, ":"))\r
@@ -1046,8 +1052,16 @@ BOOL LoadPuTTY()
        RegisterTrustedModuleSHA1Hash("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00");\r
 #endif\r
        // デバッグ用\r
-//     g_hPuTTY = LoadLibrary("putty.dll");\r
-       g_hPuTTY = LoadLibrary("C:\\SourceForge\\ffftp\\putty\\Debug\\PuTTY.dll");\r
+#ifdef _DEBUG\r
+       {\r
+               char Path[MAX_PATH];\r
+               GetModuleFileName(NULL, Path, MAX_PATH);\r
+               strcpy(strrchr(Path, '\\'), "\\..\\putty\\Debug\\PuTTY.dll");\r
+               g_hPuTTY = LoadLibrary(Path);\r
+       }\r
+#else\r
+       g_hPuTTY = LoadLibrary("putty.dll");\r
+#endif\r
        if(!g_hPuTTY\r
                || !(p_SFTP_Create = (_SFTP_Create)GetProcAddress(g_hPuTTY, "SFTP_Create"))\r
                || !(p_SFTP_Destroy = (_SFTP_Destroy)GetProcAddress(g_hPuTTY, "SFTP_Destroy"))\r