OSDN Git Service

Modify documents.
[ffftp/ffftp.git] / socket.c
index 419d9c4..1da9215 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -29,7 +29,7 @@
 \r
 #define        STRICT\r
 // IPv6対応\r
-#include <ws2tcpip.h>\r
+#include <winsock2.h>\r
 #include <windows.h>\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
@@ -40,8 +40,6 @@
 \r
 #include "common.h"\r
 #include "resource.h"\r
-// UTF-8対応\r
-#include "punycode.h"\r
 \r
 #define USE_THIS       1\r
 #define DBG_MSG                0\r
@@ -68,6 +66,11 @@ typedef struct {
        int FdRead;\r
        int FdWrite;\r
        int Error;\r
+       // ソケットにデータを付与\r
+       struct sockaddr_in HostAddrIPv4;\r
+       struct sockaddr_in SocksAddrIPv4;\r
+       struct sockaddr_in6 HostAddrIPv6;\r
+       struct sockaddr_in6 SocksAddrIPv6;\r
 } ASYNCSIGNAL;\r
 \r
 \r
@@ -93,14 +96,10 @@ typedef struct {
 static LRESULT CALLBACK SocketWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);\r
 static int AskAsyncDone(SOCKET s, int *Error, int Mask);\r
 static int AskAsyncDoneDbase(HANDLE Async, int *Error);\r
-static int RegistAsyncTable(SOCKET s);\r
-static int RegistAsyncTableDbase(HANDLE Async);\r
-static int UnRegistAsyncTable(SOCKET s);\r
-static int UnRegistAsyncTableDbase(HANDLE Async);\r
-// UTF-8対応\r
-static HANDLE WSAAsyncGetHostByNameM(HWND hWnd, u_int wMsg, const char * name, char * buf, int buflen);\r
-// IPv6対応\r
-static HANDLE WSAAsyncGetHostByNameIPv6M(HWND hWnd, u_int wMsg, const char * name, char * buf, int buflen, short Family);\r
+static int RegisterAsyncTable(SOCKET s);\r
+static int RegisterAsyncTableDbase(HANDLE Async);\r
+static int UnregisterAsyncTable(SOCKET s);\r
+static int UnregisterAsyncTableDbase(HANDLE Async);\r
 \r
 \r
 /*===== 外部参照 =====*/\r
@@ -281,7 +280,7 @@ static LRESULT CALLBACK SocketWndProc(HWND hWnd, UINT message, WPARAM wParam, LP
 \r
                case WM_ASYNC_DBASE :\r
                        // APIの仕様上ハンドルが登録される前にウィンドウメッセージが呼び出される可能性あり\r
-                       RegistAsyncTableDbase((HANDLE)wParam);\r
+                       RegisterAsyncTableDbase((HANDLE)wParam);\r
                        // スレッド衝突のバグ修正\r
                        WaitForSingleObject(hAsyncTblAccMutex, INFINITE);\r
                        for(Pos = 0; Pos < MAX_SIGNAL_ENTRY_DBASE; Pos++)\r
@@ -456,7 +455,7 @@ static int AskAsyncDoneDbase(HANDLE Async, int *Error)
 *              \r
 *----------------------------------------------------------------------------*/\r
 \r
-static int RegistAsyncTable(SOCKET s)\r
+static int RegisterAsyncTable(SOCKET s)\r
 {\r
        int Sts;\r
        int Pos;\r
@@ -495,6 +494,11 @@ static int RegistAsyncTable(SOCKET s)
                                Signal[Pos].FdAccept = 0;\r
                                Signal[Pos].FdRead = 0;\r
                                Signal[Pos].FdWrite = 0;\r
+                               // ソケットにデータを付与\r
+                               memset(&Signal[Pos].HostAddrIPv4, 0, sizeof(struct sockaddr_in));\r
+                               memset(&Signal[Pos].SocksAddrIPv4, 0, sizeof(struct sockaddr_in));\r
+                               memset(&Signal[Pos].HostAddrIPv6, 0, sizeof(struct sockaddr_in6));\r
+                               memset(&Signal[Pos].SocksAddrIPv6, 0, sizeof(struct sockaddr_in6));\r
                                Sts = YES;\r
                                break;\r
                        }\r
@@ -522,7 +526,7 @@ static int RegistAsyncTable(SOCKET s)
 *              \r
 *----------------------------------------------------------------------------*/\r
 \r
-static int RegistAsyncTableDbase(HANDLE Async)\r
+static int RegisterAsyncTableDbase(HANDLE Async)\r
 {\r
        int Sts;\r
        int Pos;\r
@@ -584,7 +588,7 @@ static int RegistAsyncTableDbase(HANDLE Async)
 *              \r
 *----------------------------------------------------------------------------*/\r
 \r
-static int UnRegistAsyncTable(SOCKET s)\r
+static int UnregisterAsyncTable(SOCKET s)\r
 {\r
        int Sts;\r
        int Pos;\r
@@ -619,7 +623,7 @@ static int UnRegistAsyncTable(SOCKET s)
 *              \r
 *----------------------------------------------------------------------------*/\r
 \r
-static int UnRegistAsyncTableDbase(HANDLE Async)\r
+static int UnregisterAsyncTableDbase(HANDLE Async)\r
 {\r
        int Sts;\r
        int Pos;\r
@@ -645,6 +649,104 @@ static int UnRegistAsyncTableDbase(HANDLE Async)
 }\r
 \r
 \r
+// ソケットにデータを付与\r
+\r
+int SetAsyncTableDataIPv4(SOCKET s, struct sockaddr_in* Host, struct sockaddr_in* Socks)\r
+{\r
+       int Sts;\r
+       int Pos;\r
+\r
+       WaitForSingleObject(hAsyncTblAccMutex, INFINITE);\r
+       Sts = NO;\r
+       for(Pos = 0; Pos < MAX_SIGNAL_ENTRY; Pos++)\r
+       {\r
+               if(Signal[Pos].Socket == s)\r
+               {\r
+                       if(Host != NULL)\r
+                               memcpy(&Signal[Pos].HostAddrIPv4, Host, sizeof(struct sockaddr_in));\r
+                       if(Socks != NULL)\r
+                               memcpy(&Signal[Pos].SocksAddrIPv4, Socks, sizeof(struct sockaddr_in));\r
+                       Sts = YES;\r
+                       break;\r
+               }\r
+       }\r
+       ReleaseMutex(hAsyncTblAccMutex);\r
+\r
+       return(Sts);\r
+}\r
+\r
+int SetAsyncTableDataIPv6(SOCKET s, struct sockaddr_in6* Host, struct sockaddr_in6* Socks)\r
+{\r
+       int Sts;\r
+       int Pos;\r
+\r
+       WaitForSingleObject(hAsyncTblAccMutex, INFINITE);\r
+       Sts = NO;\r
+       for(Pos = 0; Pos < MAX_SIGNAL_ENTRY; Pos++)\r
+       {\r
+               if(Signal[Pos].Socket == s)\r
+               {\r
+                       if(Host != NULL)\r
+                               memcpy(&Signal[Pos].HostAddrIPv6, Host, sizeof(struct sockaddr_in6));\r
+                       if(Socks != NULL)\r
+                               memcpy(&Signal[Pos].SocksAddrIPv6, Socks, sizeof(struct sockaddr_in6));\r
+                       Sts = YES;\r
+                       break;\r
+               }\r
+       }\r
+       ReleaseMutex(hAsyncTblAccMutex);\r
+\r
+       return(Sts);\r
+}\r
+\r
+int GetAsyncTableDataIPv4(SOCKET s, struct sockaddr_in* Host, struct sockaddr_in* Socks)\r
+{\r
+       int Sts;\r
+       int Pos;\r
+\r
+       WaitForSingleObject(hAsyncTblAccMutex, INFINITE);\r
+       Sts = NO;\r
+       for(Pos = 0; Pos < MAX_SIGNAL_ENTRY; Pos++)\r
+       {\r
+               if(Signal[Pos].Socket == s)\r
+               {\r
+                       if(Host != NULL)\r
+                               memcpy(Host, &Signal[Pos].HostAddrIPv4, sizeof(struct sockaddr_in));\r
+                       if(Socks != NULL)\r
+                               memcpy(Socks, &Signal[Pos].SocksAddrIPv4, sizeof(struct sockaddr_in));\r
+                       Sts = YES;\r
+                       break;\r
+               }\r
+       }\r
+       ReleaseMutex(hAsyncTblAccMutex);\r
+\r
+       return(Sts);\r
+}\r
+\r
+int GetAsyncTableDataIPv6(SOCKET s, struct sockaddr_in6* Host, struct sockaddr_in6* Socks)\r
+{\r
+       int Sts;\r
+       int Pos;\r
+\r
+       WaitForSingleObject(hAsyncTblAccMutex, INFINITE);\r
+       Sts = NO;\r
+       for(Pos = 0; Pos < MAX_SIGNAL_ENTRY; Pos++)\r
+       {\r
+               if(Signal[Pos].Socket == s)\r
+               {\r
+                       if(Host != NULL)\r
+                               memcpy(Host, &Signal[Pos].HostAddrIPv6, sizeof(struct sockaddr_in6));\r
+                       if(Socks != NULL)\r
+                               memcpy(Socks, &Signal[Pos].SocksAddrIPv6, sizeof(struct sockaddr_in6));\r
+                       Sts = YES;\r
+                       break;\r
+               }\r
+       }\r
+       ReleaseMutex(hAsyncTblAccMutex);\r
+\r
+       return(Sts);\r
+}\r
+\r
 \r
 \r
 \r
@@ -672,7 +774,7 @@ struct hostent *do_gethostbynameIPv4(const char *Name, char *Buf, int Len, int *
        hAsync = WSAAsyncGetHostByNameM(hWndSocket, WM_ASYNC_DBASE, Name, Buf, Len);\r
        if(hAsync != NULL)\r
        {\r
-               RegistAsyncTableDbase(hAsync);\r
+               RegisterAsyncTableDbase(hAsync);\r
                while((*CancelCheckWork == NO) && (AskAsyncDoneDbase(hAsync, &Error) != YES))\r
                {\r
                        Sleep(1);\r
@@ -688,7 +790,7 @@ struct hostent *do_gethostbynameIPv4(const char *Name, char *Buf, int Len, int *
                {\r
                        Ret = (struct hostent *)Buf;\r
                }\r
-               UnRegistAsyncTableDbase(hAsync);\r
+               UnregisterAsyncTableDbase(hAsync);\r
        }\r
        return(Ret);\r
 #else\r
@@ -716,7 +818,7 @@ struct hostent *do_gethostbynameIPv6(const char *Name, char *Buf, int Len, int *
        hAsync = WSAAsyncGetHostByNameIPv6M(hWndSocket, WM_ASYNC_DBASE, Name, Buf, Len, AF_INET6);\r
        if(hAsync != NULL)\r
        {\r
-               RegistAsyncTableDbase(hAsync);\r
+               RegisterAsyncTableDbase(hAsync);\r
                while((*CancelCheckWork == NO) && (AskAsyncDoneDbase(hAsync, &Error) != YES))\r
                {\r
                        Sleep(1);\r
@@ -726,13 +828,13 @@ struct hostent *do_gethostbynameIPv6(const char *Name, char *Buf, int Len, int *
 \r
                if(*CancelCheckWork == YES)\r
                {\r
-                       WSACancelAsyncRequest(hAsync);\r
+                       WSACancelAsyncRequestIPv6(hAsync);\r
                }\r
                else if(Error == 0)\r
                {\r
                        Ret = (struct hostent *)Buf;\r
                }\r
-               UnRegistAsyncTableDbase(hAsync);\r
+               UnregisterAsyncTableDbase(hAsync);\r
        }\r
        return(Ret);\r
 #else\r
@@ -751,7 +853,7 @@ SOCKET do_socket(int af, int type, int protocol)
        Ret = socket(af, type, protocol);\r
        if(Ret != INVALID_SOCKET)\r
        {\r
-               RegistAsyncTable(Ret);\r
+               RegisterAsyncTable(Ret);\r
        }\r
 #if DBG_MSG\r
        DoPrintf("# do_socket (S=%x)", Ret);\r
@@ -775,10 +877,10 @@ int do_closesocket(SOCKET s)
 \r
        // スレッド衝突のバグ修正\r
        WSAAsyncSelect(s, hWndSocket, WM_ASYNC_SOCKET, 0);\r
-       UnRegistAsyncTable(s);\r
+       UnregisterAsyncTable(s);\r
        // FTPS対応\r
 //     Ret = closesocket(s);\r
-       Ret = closesocketS(s);\r
+       Ret = FTPS_closesocket(s);\r
        if(Ret == SOCKET_ERROR)\r
        {\r
                Error = 0;\r
@@ -798,7 +900,7 @@ int do_closesocket(SOCKET s)
        if(BackgrndMessageProc() == YES)\r
                CancelCheckWork = YES;\r
        // スレッド衝突のバグ修正\r
-//     UnRegistAsyncTable(s);\r
+//     UnregisterAsyncTable(s);\r
 \r
 #if DBG_MSG\r
        DoPrintf("# Exit close");\r
@@ -935,8 +1037,10 @@ SOCKET do_accept(SOCKET s, struct sockaddr *addr, int *addrlen)
                                DoPrintf("## do_sccept (S=%x)", Ret2);\r
                                DoPrintf("## Async set: FD_CONNECT|FD_CLOSE|FD_ACCEPT|FD_READ|FD_WRITE");\r
 #endif\r
-                               RegistAsyncTable(Ret2);\r
-                               if(WSAAsyncSelect(Ret2, hWndSocket, WM_ASYNC_SOCKET, FD_CONNECT | FD_CLOSE | FD_ACCEPT | FD_READ | FD_WRITE) == SOCKET_ERROR)\r
+                               RegisterAsyncTable(Ret2);\r
+                               // 高速化のためFD_READとFD_WRITEを使用しない\r
+//                             if(WSAAsyncSelect(Ret2, hWndSocket, WM_ASYNC_SOCKET, FD_CONNECT | FD_CLOSE | FD_ACCEPT | FD_READ | FD_WRITE) == SOCKET_ERROR)\r
+                               if(WSAAsyncSelect(Ret2, hWndSocket, WM_ASYNC_SOCKET, FD_CONNECT | FD_CLOSE | FD_ACCEPT) == SOCKET_ERROR)\r
                                {\r
                                        do_closesocket(Ret2);\r
                                        Ret2 = INVALID_SOCKET;\r
@@ -1035,7 +1139,7 @@ int do_recv(SOCKET s, char *buf, int len, int flags, int *TimeOutErr, int *Cance
 \r
                        // FTPS対応\r
 //                     Ret = recv(s, buf, len, flags);\r
-                       Ret = recvS(s, buf, len, flags);\r
+                       Ret = FTPS_recv(s, buf, len, flags);\r
                        if(Ret != SOCKET_ERROR)\r
                                break;\r
                        Error = WSAGetLastError();\r
@@ -1145,7 +1249,7 @@ int do_send(SOCKET s, const char *buf, int len, int flags, int *TimeOutErr, int
 \r
                        // FTPS対応\r
 //                     Ret = send(s, buf, len, flags);\r
-                       Ret = sendS(s, buf, len, flags);\r
+                       Ret = FTPS_send(s, buf, len, flags);\r
                        if(Ret != SOCKET_ERROR)\r
                        {\r
 #if DBG_MSG\r
@@ -1196,11 +1300,11 @@ void RemoveReceivedData(SOCKET s)
 {\r
        char buf[1024];\r
        int len;\r
-       int Error;\r
-       while((len = recvS(s, buf, sizeof(buf), MSG_PEEK)) >= 0)\r
+//     int Error;\r
+       while((len = FTPS_recv(s, buf, sizeof(buf), MSG_PEEK)) > 0)\r
        {\r
-               AskAsyncDone(s, &Error, FD_READ);\r
-               recvS(s, buf, len, 0);\r
+//             AskAsyncDone(s, &Error, FD_READ);\r
+               FTPS_recv(s, buf, len, 0);\r
        }\r
 }\r
 \r
@@ -1231,357 +1335,19 @@ int CheckClosedAndReconnect(void)
 \r
 \r
 \r
-// IPv6対応\r
-\r
-typedef struct\r
-{\r
-       HANDLE h;\r
-       HWND hWnd;\r
-       u_int wMsg;\r
-       char * name;\r
-       char * buf;\r
-       int buflen;\r
-       short Family;\r
-} GETHOSTBYNAMEDATA;\r
-\r
-static DWORD WINAPI WSAAsyncGetHostByNameIPv6ThreadProc(LPVOID lpParameter)\r
-{\r
-       GETHOSTBYNAMEDATA* pData;\r
-       struct hostent* pHost;\r
-       struct addrinfo* pAddr;\r
-       struct addrinfo* p;\r
-       pHost = NULL;\r
-       pData = (GETHOSTBYNAMEDATA*)lpParameter;\r
-       if(getaddrinfo(pData->name, NULL, NULL, &pAddr) == 0)\r
-       {\r
-               p = pAddr;\r
-               while(p)\r
-               {\r
-                       if(p->ai_family == pData->Family)\r
-                       {\r
-                               switch(p->ai_family)\r
-                               {\r
-                               case AF_INET:\r
-                                       pHost = (struct hostent*)pData->buf;\r
-                                       if((size_t)pData->buflen >= sizeof(struct hostent) + sizeof(char*) * 2 + sizeof(struct in_addr)\r
-                                               && p->ai_addrlen >= sizeof(struct sockaddr_in))\r
-                                       {\r
-                                               pHost->h_name = NULL;\r
-                                               pHost->h_aliases = NULL;\r
-                                               pHost->h_addrtype = p->ai_family;\r
-                                               pHost->h_length = sizeof(struct in_addr);\r
-                                               pHost->h_addr_list = (char**)(&pHost[1]);\r
-                                               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
-                                       }\r
-                                       else\r
-                                               PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(WSAENOBUFS << 16));\r
-                                       break;\r
-                               case AF_INET6:\r
-                                       pHost = (struct hostent*)pData->buf;\r
-                                       if((size_t)pData->buflen >= sizeof(struct hostent) + sizeof(char*) * 2 + sizeof(struct in6_addr)\r
-                                               && p->ai_addrlen >= sizeof(struct sockaddr_in6))\r
-                                       {\r
-                                               pHost->h_name = NULL;\r
-                                               pHost->h_aliases = NULL;\r
-                                               pHost->h_addrtype = p->ai_family;\r
-                                               pHost->h_length = sizeof(struct in6_addr);\r
-                                               pHost->h_addr_list = (char**)(&pHost[1]);\r
-                                               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
-                                       }\r
-                                       else\r
-                                               PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(WSAENOBUFS << 16));\r
-                                       break;\r
-                               }\r
-                       }\r
-                       if(pHost)\r
-                               break;\r
-                       p = p->ai_next;\r
-               }\r
-               if(!p)\r
-                       PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(ERROR_INVALID_FUNCTION << 16));\r
-               freeaddrinfo(pAddr);\r
-       }\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
-       return 0;\r
-}\r
-\r
-// IPv6対応のWSAAsyncGetHostByName相当の関数\r
-// FamilyにはAF_INETまたはAF_INET6を指定可能\r
-// ただしANSI用\r
-static HANDLE WSAAsyncGetHostByNameIPv6(HWND hWnd, u_int wMsg, const char * name, char * buf, int buflen, short Family)\r
-{\r
-       HANDLE hResult;\r
-       GETHOSTBYNAMEDATA* pData;\r
-       hResult = NULL;\r
-       if(pData = malloc(sizeof(GETHOSTBYNAMEDATA)))\r
-       {\r
-               pData->hWnd = hWnd;\r
-               pData->wMsg = wMsg;\r
-               if(pData->name = malloc(sizeof(char) * (strlen(name) + 1)))\r
-               {\r
-                       strcpy(pData->name, name);\r
-                       pData->buf = buf;\r
-                       pData->buflen = buflen;\r
-                       pData->Family = Family;\r
-                       if(pData->h = CreateThread(NULL, 0, WSAAsyncGetHostByNameIPv6ThreadProc, pData, CREATE_SUSPENDED, NULL))\r
-                       {\r
-                               ResumeThread(pData->h);\r
-                               hResult = pData->h;\r
-                       }\r
-               }\r
-       }\r
-       if(!hResult)\r
-       {\r
-               if(pData)\r
-               {\r
-                       if(pData->name)\r
-                               free(pData->name);\r
-                       free(pData);\r
-               }\r
-       }\r
-       return hResult;\r
-}\r
-\r
-// WSAAsyncGetHostByNameIPv6用のWSACancelAsyncRequest相当の関数\r
-int WSACancelAsyncRequestIPv6(HANDLE hAsyncTaskHandle)\r
-{\r
-       int Result;\r
-       Result = SOCKET_ERROR;\r
-       if(TerminateThread(hAsyncTaskHandle, 0))\r
-               Result = 0;\r
-       return Result;\r
-}\r
-\r
-char* AddressToStringIPv6(char* str, void* in6)\r
-{\r
-       char* pResult;\r
-       unsigned char* p;\r
-       int MaxZero;\r
-       int MaxZeroLen;\r
-       int i;\r
-       int j;\r
-       char Tmp[5];\r
-       pResult = str;\r
-       p = (unsigned char*)in6;\r
-       MaxZero = 8;\r
-       MaxZeroLen = 1;\r
-       for(i = 0; i < 8; i++)\r
-       {\r
-               for(j = i; j < 8; j++)\r
-               {\r
-                       if(p[j * 2] != 0 || p[j * 2 + 1] != 0)\r
-                               break;\r
-               }\r
-               if(j - i > MaxZeroLen)\r
-               {\r
-                       MaxZero = i;\r
-                       MaxZeroLen = j - i;\r
-               }\r
-       }\r
-       strcpy(str, "");\r
-       for(i = 0; i < 8; i++)\r
-       {\r
-               if(i == MaxZero)\r
-               {\r
-                       if(i == 0)\r
-                               strcat(str, ":");\r
-                       strcat(str, ":");\r
-               }\r
-               else if(i < MaxZero || i >= MaxZero + MaxZeroLen)\r
-               {\r
-                       sprintf(Tmp, "%x", (((int)p[i * 2] & 0xff) << 8) | ((int)p[i * 2 + 1] & 0xff));\r
-                       strcat(str, Tmp);\r
-                       if(i < 7)\r
-                               strcat(str, ":");\r
-               }\r
-       }\r
-       return pResult;\r
-}\r
-\r
-// IPv6対応のinet_ntoa相当の関数\r
-// ただしANSI用\r
-char* inet6_ntoa(struct in6_addr in6)\r
-{\r
-       char* pResult;\r
-       static char Adrs[40];\r
-       pResult = NULL;\r
-       memset(Adrs, 0, sizeof(Adrs));\r
-       pResult = AddressToStringIPv6(Adrs, &in6);\r
-       return pResult;\r
-}\r
-\r
-// IPv6対応のinet_addr相当の関数\r
-// ただしANSI用\r
-struct in6_addr inet6_addr(const char* cp)\r
-{\r
-       struct in6_addr Result;\r
-       int AfterZero;\r
-       int i;\r
-       char* p;\r
-       memset(&Result, 0, sizeof(Result));\r
-       AfterZero = 0;\r
-       for(i = 0; i < 8; i++)\r
-       {\r
-               if(!cp)\r
-               {\r
-                       memset(&Result, 0xff, sizeof(Result));\r
-                       break;\r
-               }\r
-               if(i >= AfterZero)\r
-               {\r
-                       if(strncmp(cp, ":", 1) == 0)\r
-                       {\r
-                               cp = cp + 1;\r
-                               if(i == 0 && strncmp(cp, ":", 1) == 0)\r
-                                       cp = cp + 1;\r
-                               p = (char*)cp;\r
-                               AfterZero = 7;\r
-                               while(p = strstr(p, ":"))\r
-                               {\r
-                                       p = p + 1;\r
-                                       AfterZero--;\r
-                               }\r
-                       }\r
-                       else\r
-                       {\r
-                               Result.u.Word[i] = (USHORT)strtol(cp, &p, 16);\r
-                               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
-                                       break;\r
-                               }\r
-                               if(cp = strstr(cp, ":"))\r
-                                       cp = cp + 1;\r
-                       }\r
-               }\r
-       }\r
-       return Result;\r
-}\r
-\r
-// UTF-8対応\r
-\r
-static BOOL ConvertStringToPunycode(LPSTR Output, DWORD Count, LPCSTR Input)\r
-{\r
-       BOOL bResult;\r
-       punycode_uint* pUnicode;\r
-       punycode_uint* p;\r
-       BOOL bNeeded;\r
-       LPCSTR InputString;\r
-       punycode_uint Length;\r
-       punycode_uint OutputLength;\r
-       bResult = FALSE;\r
-       if(pUnicode = malloc(sizeof(punycode_uint) * strlen(Input)))\r
-       {\r
-               p = pUnicode;\r
-               bNeeded = FALSE;\r
-               InputString = Input;\r
-               Length = 0;\r
-               while(*InputString != '\0')\r
-               {\r
-                       *p = (punycode_uint)GetNextCharM(InputString, &InputString);\r
-                       if(*p >= 0x80)\r
-                               bNeeded = TRUE;\r
-                       p++;\r
-                       Length++;\r
-               }\r
-               if(bNeeded)\r
-               {\r
-                       if(Count >= strlen("xn--") + 1)\r
-                       {\r
-                               strcpy(Output, "xn--");\r
-                               OutputLength = Count - strlen("xn--");\r
-                               if(punycode_encode(Length, pUnicode, NULL, (punycode_uint*)&OutputLength, Output + strlen("xn--")) == punycode_success)\r
-                               {\r
-                                       Output[strlen("xn--") + OutputLength] = '\0';\r
-                                       bResult = TRUE;\r
-                               }\r
-                       }\r
-               }\r
-               free(pUnicode);\r
-       }\r
-       if(!bResult)\r
-       {\r
-               if(Count >= strlen(Input) + 1)\r
-               {\r
-                       strcpy(Output, Input);\r
-                       bResult = TRUE;\r
-               }\r
-       }\r
-       return bResult;\r
-}\r
-\r
-static BOOL ConvertNameToPunycode(LPSTR Output, LPCSTR Input)\r
+// 同時接続対応\r
+int CheckClosedAndReconnectTrnSkt(SOCKET *Skt, int *CancelCheckWork)\r
 {\r
-       BOOL bResult;\r
-       DWORD Length;\r
-       char* pm0;\r
-       char* pm1;\r
-       char* p;\r
-       char* pNext;\r
-       bResult = FALSE;\r
-       Length = strlen(Input);\r
-       if(pm0 = AllocateStringM(Length + 1))\r
-       {\r
-               if(pm1 = AllocateStringM(Length * 4 + 1))\r
-               {\r
-                       strcpy(pm0, Input);\r
-                       p = pm0;\r
-                       while(p)\r
-                       {\r
-                               if(pNext = strchr(p, '.'))\r
-                               {\r
-                                       *pNext = '\0';\r
-                                       pNext++;\r
-                               }\r
-                               if(ConvertStringToPunycode(pm1, Length * 4, p))\r
-                                       strcat(Output, pm1);\r
-                               if(pNext)\r
-                                       strcat(Output, ".");\r
-                               p = pNext;\r
-                       }\r
-                       bResult = TRUE;\r
-                       FreeDuplicatedString(pm1);\r
-               }\r
-               FreeDuplicatedString(pm0);\r
-       }\r
-       return bResult;\r
-}\r
+       int Error;\r
+       int Sts;\r
 \r
-static HANDLE WSAAsyncGetHostByNameM(HWND hWnd, u_int wMsg, const char * name, char * buf, int buflen)\r
-{\r
-       HANDLE r = NULL;\r
-       char* pa0 = NULL;\r
-       if(pa0 = AllocateStringA(strlen(name) * 4))\r
-       {\r
-               if(ConvertNameToPunycode(pa0, name))\r
-                       r = WSAAsyncGetHostByName(hWnd, wMsg, pa0, buf, buflen);\r
-       }\r
-       FreeDuplicatedString(pa0);\r
-       return r;\r
-}\r
+//SetTaskMsg("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");\r
 \r
-static HANDLE WSAAsyncGetHostByNameIPv6M(HWND hWnd, u_int wMsg, const char * name, char * buf, int buflen, short Family)\r
-{\r
-       HANDLE r = NULL;\r
-       char* pa0 = NULL;\r
-       if(pa0 = AllocateStringA(strlen(name) * 4))\r
+       Sts = FFFTP_SUCCESS;\r
+       if(AskAsyncDone(*Skt, &Error, FD_CLOSE) == YES)\r
        {\r
-               if(ConvertNameToPunycode(pa0, name))\r
-                       r = WSAAsyncGetHostByNameIPv6(hWnd, wMsg, pa0, buf, buflen, Family);\r
+               Sts = ReConnectTrnSkt(Skt, CancelCheckWork);\r
        }\r
-       FreeDuplicatedString(pa0);\r
-       return r;\r
+       return(Sts);\r
 }\r
 \r