OSDN Git Service

Change behavior of automatic IPv4/IPv6 selection.
[ffftp/ffftp.git] / connect.c
index e530013..8742594 100644 (file)
--- a/connect.c
+++ b/connect.c
 \r
 /*===== プロトタイプ =====*/\r
 \r
-static BOOL CALLBACK QuickConDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
-static int SendInitCommand(char *Cmd);\r
+// 64ビット対応\r
+//static BOOL CALLBACK QuickConDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
+static INT_PTR CALLBACK QuickConDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
+// 同時接続対応\r
+//static int SendInitCommand(char *Cmd);\r
+static int SendInitCommand(SOCKET Socket, char *Cmd, int *CancelCheckWork);\r
 static void AskUseFireWall(char *Host, int *Fire, int *Pasv, int *List);\r
 static void SaveCurrentSetToHistory(void);\r
 static int ReConnectSkt(SOCKET *Skt);\r
@@ -121,6 +125,9 @@ static const struct in6_addr IN6ADDR_NONE = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff
 static int UseIPadrs;\r
 static char DomainName[HOST_ADRS_LEN+1];\r
 \r
+#if defined(HAVE_TANDEM)\r
+static int Oss = NO;  /* OSS ファイルシステムへアクセスしている場合は YES */\r
+#endif\r
 \r
 \r
 \r
@@ -160,6 +167,8 @@ void ConnectProc(int Type, int Num)
                CopyHostFromList(AskCurrentHost(), &CurHost);\r
                // UTF-8対応\r
                CurHost.CurNameKanjiCode = CurHost.NameKanjiCode;\r
+               // IPv6対応\r
+               CurHost.CurNetType = CurHost.NetType;\r
 \r
                if(ConnectRas(CurHost.Dialup, CurHost.DialupAlways, CurHost.DialupNotify, CurHost.DialEntry) == FFFTP_SUCCESS)\r
                {\r
@@ -231,7 +240,7 @@ void ConnectProc(int Type, int Num)
                                DispWindowTitle();\r
                                SoundPlay(SND_CONNECT);\r
 \r
-                               SendInitCommand(CurHost.InitCmd);\r
+                               SendInitCommand(CmdCtrlSocket, CurHost.InitCmd, &CancelFlg);\r
 \r
                                if(strlen(CurHost.LocalInitDir) > 0)\r
                                {\r
@@ -285,6 +294,8 @@ void QuickConnectProc(void)
                CopyDefaultHost(&CurHost);\r
                // UTF-8対応\r
                CurHost.CurNameKanjiCode = CurHost.NameKanjiCode;\r
+               // IPv6対応\r
+               CurHost.CurNetType = CurHost.NetType;\r
                if(SplitUNCpath(Tmp, CurHost.HostAdrs, CurHost.RemoteInitDir, File, CurHost.UserName, CurHost.PassWord, &CurHost.Port) == FFFTP_SUCCESS)\r
                {\r
                        if(strlen(CurHost.UserName) == 0)\r
@@ -329,7 +340,7 @@ void QuickConnectProc(void)
                                EnableUserOpe();\r
 \r
                                if(strlen(File) > 0)\r
-                                       DirectDownLoadProc(File);\r
+                                       DirectDownloadProc(File);\r
                        }\r
                        else\r
                        {\r
@@ -354,7 +365,9 @@ void QuickConnectProc(void)
 *              BOOL TRUE/FALSE\r
 *----------------------------------------------------------------------------*/\r
 \r
-static BOOL CALLBACK QuickConDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)\r
+// 64ビット対応\r
+//static BOOL CALLBACK QuickConDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)\r
+static INT_PTR CALLBACK QuickConDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)\r
 {\r
        static char *Buf;\r
        int i;\r
@@ -475,6 +488,8 @@ void DirectConnectProc(char *unc, int Kanji, int Kana, int Fkanji, int TrMode)
                CurHost.KanaCnv = YES;                  /* とりあえず */\r
                // UTF-8対応\r
                CurHost.CurNameKanjiCode = CurHost.NameKanjiCode;\r
+               // IPv6対応\r
+               CurHost.CurNetType = CurHost.NetType;\r
 \r
                SetHostKanaCnvImm(CurHost.KanaCnv);\r
                SetHostKanjiCodeImm(CurHost.KanjiCode);\r
@@ -513,7 +528,7 @@ void DirectConnectProc(char *unc, int Kanji, int Kana, int Fkanji, int TrMode)
                        EnableUserOpe();\r
 \r
                        if(strlen(File) > 0)\r
-                               DirectDownLoadProc(File);\r
+                               DirectDownloadProc(File);\r
                        else\r
                                ResetAutoExitFlg();\r
                }\r
@@ -559,6 +574,8 @@ void HistoryConnectProc(int MenuCmd)
                CopyHistoryToHost(&Hist, &CurHost);\r
                // UTF-8対応\r
                CurHost.CurNameKanjiCode = CurHost.NameKanjiCode;\r
+               // IPv6対応\r
+               CurHost.CurNetType = CurHost.NetType;\r
 \r
                if(ConnectRas(CurHost.Dialup, CurHost.DialupAlways, CurHost.DialupNotify, CurHost.DialEntry) == FFFTP_SUCCESS)\r
                {\r
@@ -594,7 +611,7 @@ void HistoryConnectProc(int MenuCmd)
                                DispWindowTitle();\r
                                SoundPlay(SND_CONNECT);\r
 \r
-                               SendInitCommand(CurHost.InitCmd);\r
+                               SendInitCommand(CmdCtrlSocket, CurHost.InitCmd, &CancelFlg);\r
 \r
                                DoLocalCWD(CurHost.LocalInitDir);\r
                                GetLocalDirForWnd();\r
@@ -633,7 +650,9 @@ void HistoryConnectProc(int MenuCmd)
 *                      cmd1\r\ncmd2\r\n\0\r
 *----------------------------------------------------------------------------*/\r
 \r
-static int SendInitCommand(char *Cmd)\r
+// 同時接続対応\r
+//static int SendInitCommand(char *Cmd)\r
+static int SendInitCommand(SOCKET Socket, char *Cmd, int *CancelCheckWork)\r
 {\r
        char Tmp[INITCMD_LEN+1];\r
        char *Pos;\r
@@ -644,7 +663,8 @@ static int SendInitCommand(char *Cmd)
                if((Pos = strchr(Tmp, '\r')) != NULL)\r
                        *Pos = NUL;\r
                if(strlen(Tmp) > 0)\r
-                       DoQUOTE(Tmp);\r
+//                     DoQUOTE(Tmp);\r
+                       DoQUOTE(Socket, Tmp, CancelCheckWork);\r
 \r
                if((Cmd = strchr(Cmd, '\n')) != NULL)\r
                        Cmd++;\r
@@ -883,6 +903,14 @@ int AskHostType(void)
        if(AskCurrentHost() != HOSTNUM_NOENTRY)\r
                CopyHostFromListInConnect(AskCurrentHost(), &CurHost);\r
 \r
+#if defined(HAVE_TANDEM)\r
+       /* OSS ファイルシステムは UNIX ファイルシステムと同じでいいので AUTO を返す\r
+          ただし、Guardian ファイルシステムに戻ったときにおかしくならないように\r
+          CurHost.HostType 変数は更新しない */\r
+       if(CurHost.HostType == HTYPE_TANDEM && Oss == YES)\r
+               return(HTYPE_AUTO);\r
+#endif\r
+\r
        return(CurHost.HostType);\r
 }\r
 \r
@@ -1074,11 +1102,16 @@ int ReConnectTrnSkt(SOCKET *Skt, int *CancelCheckWork)
                HostData.UseSFTP = NO;\r
        // UTF-8対応\r
        HostData.CurNameKanjiCode = HostData.NameKanjiCode;\r
+       // IPv6対応\r
+       HostData.CurNetType = HostData.NetType;\r
+       // 同時接続対応\r
+       HostData.NoDisplayUI = YES;\r
        // 暗号化通信対応\r
        // 同時接続対応\r
 //     if((*Skt = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security)) != INVALID_SOCKET)\r
        if((*Skt = DoConnect(&HostData, CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security, CancelCheckWork)) != INVALID_SOCKET)\r
        {\r
+               SendInitCommand(*Skt, CurHost.InitCmd, CancelCheckWork);\r
 //             AskRemoteCurDir(Path, FMAX_PATH);\r
 //             DoCWD(Path, YES, YES, YES);\r
                Sts = FFFTP_SUCCESS;\r
@@ -1120,6 +1153,7 @@ static int ReConnectSkt(SOCKET *Skt)
 //     if((*Skt = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security)) != INVALID_SOCKET)\r
        if((*Skt = DoConnect(&CurHost, CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security, &CancelFlg)) != INVALID_SOCKET)\r
        {\r
+               SendInitCommand(*Skt, CurHost.InitCmd, &CancelFlg);\r
                AskRemoteCurDir(Path, FMAX_PATH);\r
                DoCWD(Path, YES, YES, YES);\r
                Sts = FFFTP_SUCCESS;\r
@@ -1231,13 +1265,17 @@ void DisconnectProc(void)
 \r
        if((CmdCtrlSocket != INVALID_SOCKET) && (CmdCtrlSocket != TrnCtrlSocket))\r
        {\r
-               DoQUIT(CmdCtrlSocket);\r
+               // 同時接続対応\r
+//             DoQUIT(CmdCtrlSocket);\r
+               DoQUIT(CmdCtrlSocket, &CancelFlg);\r
                DoClose(CmdCtrlSocket);\r
        }\r
 \r
        if(TrnCtrlSocket != INVALID_SOCKET)\r
        {\r
-               DoQUIT(TrnCtrlSocket);\r
+               // 同時接続対応\r
+//             DoQUIT(TrnCtrlSocket);\r
+               DoQUIT(TrnCtrlSocket, &CancelFlg);\r
                DoClose(TrnCtrlSocket);\r
 \r
                SaveCurrentSetToHistory();\r
@@ -1300,6 +1338,62 @@ int AskConnecting(void)
 }\r
 \r
 \r
+#if defined(HAVE_TANDEM)\r
+/*----- 接続している本当のホストのホストタイプを返す --------------------------\r
+*\r
+*      Parameter\r
+*              なし\r
+*\r
+*      Return Value\r
+*              char *ファイル名/オプション\r
+*----------------------------------------------------------------------------*/\r
+\r
+int AskRealHostType(void)\r
+{\r
+       if(AskCurrentHost() != HOSTNUM_NOENTRY)\r
+               CopyHostFromListInConnect(AskCurrentHost(), &CurHost);\r
+\r
+       return(CurHost.HostType);\r
+}\r
+\r
+/*----- OSS ファイルシステムにアクセスしているかどうかのフラグを変更する ------\r
+*\r
+*      Parameter\r
+*              int ステータス (YES/NO)\r
+*\r
+*      Return Value\r
+*              int ステータス (YES/NO)\r
+*----------------------------------------------------------------------------*/\r
+\r
+int SetOSS(int wkOss)\r
+{\r
+       if(Oss != wkOss) {\r
+               if (wkOss == YES) {\r
+                       strcpy(CurHost.InitCmd, "OSS");\r
+               } else {\r
+                       strcpy(CurHost.InitCmd, "GUARDIAN");\r
+               }\r
+       }\r
+       Oss = wkOss;\r
+       return(Oss);\r
+}\r
+\r
+/*----- OSS ファイルシステムにアクセスしているかどうかを返す ------------------\r
+*\r
+*      Parameter\r
+*              なし\r
+*\r
+*      Return Value\r
+*              int ステータス (YES/NO)\r
+*----------------------------------------------------------------------------*/\r
+\r
+int AskOSS(void)\r
+{\r
+       return(Oss);\r
+}\r
+#endif /* HAVE_TANDEM */\r
+\r
+\r
 /*----- ホストへ接続する ------------------------------------------------------\r
 *\r
 *      Parameter\r
@@ -1486,8 +1580,11 @@ static SOCKET DoConnectCrypt(int CryptMode, HOSTDATA* HostData, char *Host, char
                                                else\r
                                                {\r
                                                        Anony = NO;\r
+                                                       // 同時接続対応\r
+//                                                     if((strlen(User) != 0) || \r
+//                                                        (InputDialogBox(username_dlg, GetMainHwnd(), NULL, User, USER_NAME_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
                                                        if((strlen(User) != 0) || \r
-                                                          (InputDialogBox(username_dlg, GetMainHwnd(), NULL, User, USER_NAME_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
+                                                          ((HostData->NoDisplayUI == NO) && (InputDialogBox(username_dlg, GetMainHwnd(), NULL, User, USER_NAME_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)))\r
                                                        {\r
                                                                if(Anony == YES)\r
                                                                {\r
@@ -1530,6 +1627,18 @@ static SOCKET DoConnectCrypt(int CryptMode, HOSTDATA* HostData, char *Host, char
                                                                                Sts = FTP_ERROR;\r
                                                                }\r
 \r
+                                                               // FTPIS対応\r
+                                                               // "PBSZ 0"と"PROT P"は黙示的に設定されているはずだが念のため\r
+                                                               if(CryptMode == CRYPT_FTPIS)\r
+                                                               {\r
+                                                                       if((Sts = command(ContSock, Reply, CancelCheckWork, "PBSZ 0")) == 200)\r
+                                                                       {\r
+                                                                               if((Sts = command(ContSock, Reply, CancelCheckWork, "PROT P")) == 200)\r
+                                                                               {\r
+                                                                               }\r
+                                                                       }\r
+                                                               }\r
+\r
                                                                ReInPass = NO;\r
                                                                do\r
                                                                {\r
@@ -1541,8 +1650,11 @@ static SOCKET DoConnectCrypt(int CryptMode, HOSTDATA* HostData, char *Host, char
 //                                                                     if((Sts = command(ContSock, Reply, &CancelFlg, "USER %s", Buf) / 100) == FTP_CONTINUE)\r
                                                                        if((Sts = command(ContSock, Reply, CancelCheckWork, "USER %s", Buf) / 100) == FTP_CONTINUE)\r
                                                                        {\r
+                                                                               // 同時接続対応\r
+//                                                                             if((strlen(Pass) != 0) || \r
+//                                                                                (InputDialogBox(passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
                                                                                if((strlen(Pass) != 0) || \r
-                                                                                  (InputDialogBox(passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
+                                                                                  ((HostData->NoDisplayUI == NO) && (InputDialogBox(passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)))\r
                                                                                {\r
                                                                                        CheckOneTimePassword(Pass, Reply, Security);\r
 \r
@@ -1556,7 +1668,9 @@ static SOCKET DoConnectCrypt(int CryptMode, HOSTDATA* HostData, char *Host, char
                                                                                        if(Sts == FTP_ERROR)\r
                                                                                        {\r
                                                                                                strcpy(Pass, "");\r
-                                                                                               if(InputDialogBox(re_passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)\r
+                                                                                               // 同時接続対応\r
+//                                                                                             if(InputDialogBox(re_passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)\r
+                                                                                               if(HostData->NoDisplayUI == NO && InputDialogBox(re_passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)\r
                                                                                                        Continue = YES;\r
                                                                                                else\r
                                                                                                        DoPrintf("No password specified.");\r
@@ -1564,8 +1678,11 @@ static SOCKET DoConnectCrypt(int CryptMode, HOSTDATA* HostData, char *Host, char
                                                                                        }\r
                                                                                        else if(Sts == FTP_CONTINUE)\r
                                                                                        {\r
+                                                                                               // 同時接続対応\r
+//                                                                                             if((strlen(Acct) != 0) || \r
+//                                                                                                (InputDialogBox(account_dlg, GetMainHwnd(), NULL, Acct, ACCOUNT_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
                                                                                                if((strlen(Acct) != 0) || \r
-                                                                                                  (InputDialogBox(account_dlg, GetMainHwnd(), NULL, Acct, ACCOUNT_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
+                                                                                                  ((HostData->NoDisplayUI == NO) && (InputDialogBox(account_dlg, GetMainHwnd(), NULL, Acct, ACCOUNT_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)))\r
                                                                                                {\r
                                                                                                        // 同時接続対応\r
 //                                                                                                     Sts = command(ContSock, NULL, &CancelFlg, "ACCT %s", Acct) / 100;\r
@@ -1581,6 +1698,9 @@ static SOCKET DoConnectCrypt(int CryptMode, HOSTDATA* HostData, char *Host, char
                                                                                        DoPrintf("No password specified.");\r
                                                                                }\r
                                                                        }\r
+                                                                       // FTPES対応\r
+                                                                       if(Continue == YES)\r
+                                                                               Sts = FTP_COMPLETE;\r
                                                                }\r
                                                                while(Continue == YES);\r
                                                        }\r
@@ -1598,7 +1718,9 @@ static SOCKET DoConnectCrypt(int CryptMode, HOSTDATA* HostData, char *Host, char
                                                        }\r
                                                        else if((SavePass == YES) && (ReInPass == YES))\r
                                                        {\r
-                                                               if(DialogBox(GetFtpInst(), MAKEINTRESOURCE(savepass_dlg), GetMainHwnd(), ExeEscDialogProc) == YES)\r
+                                                               // 同時接続対応\r
+//                                                             if(DialogBox(GetFtpInst(), MAKEINTRESOURCE(savepass_dlg), GetMainHwnd(), ExeEscDialogProc) == YES)\r
+                                                               if(HostData->NoDisplayUI == NO && DialogBox(GetFtpInst(), MAKEINTRESOURCE(savepass_dlg), GetMainHwnd(), ExeEscDialogProc) == YES)\r
                                                                        SetHostPassword(AskCurrentHost(), Pass);\r
                                                        }\r
                                                }\r
@@ -1655,6 +1777,61 @@ static SOCKET DoConnectCrypt(int CryptMode, HOSTDATA* HostData, char *Host, char
        }\r
        else if(CryptMode == CRYPT_SFTP)\r
        {\r
+               // TODO:\r
+               // テストコード\r
+               // ログイン成功を確認\r
+#define strrcmp(_Str1, _Str2) (strcmp(strstr(_Str1, _Str2) ? strstr(_Str1, _Str2) : "", _Str2))\r
+               size_t r;\r
+               ContSock = SFTP_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);\r
+               SFTP_SetTimeoutCallback(ContSock, SSLTimeoutCallback);\r
+               while(1)\r
+               {\r
+                       r = SFTP_recv(ContSock, Reply, 1024, 0);\r
+                       if(r == SOCKET_ERROR)\r
+                               break;\r
+                       if(r <= 0)\r
+                               continue;\r
+                       Reply[r] = '\0';\r
+                       SetTaskMsg("%s", Reply);\r
+                       if(strrcmp(Reply, "psftp> ") == 0)\r
+                               break;\r
+               }\r
+               r = SFTP_send(ContSock, "open \"", strlen("open \""), 0);\r
+               r = SFTP_send(ContSock, Host, strlen(Host), 0);\r
+               r = SFTP_send(ContSock, "\"\r\n", strlen("\"\r\n"), 0);\r
+               while(1)\r
+               {\r
+                       r = SFTP_recv(ContSock, Reply, 1024, 0);\r
+                       if(r == SOCKET_ERROR)\r
+                               break;\r
+                       if(r <= 0)\r
+                               continue;\r
+                       Reply[r] = '\0';\r
+                       SetTaskMsg("%s", Reply);\r
+                       if(strrcmp(Reply, "Store key in cache? (y/n) ") == 0)\r
+                       {\r
+                               r = SFTP_send(ContSock, "n\r\n", strlen("n\r\n"), 0);\r
+                       }\r
+                       if(strrcmp(Reply, "Update cached key? (y/n, Return cancels connection) ") == 0)\r
+                       {\r
+                               r = SFTP_send(ContSock, "\r\n", strlen("\r\n"), 0);\r
+                       }\r
+                       if(strrcmp(Reply, "login as: ") == 0)\r
+                       {\r
+                               r = SFTP_send(ContSock, User, strlen(User), 0);\r
+                               r = SFTP_send(ContSock, "\r\n", strlen("\r\n"), 0);\r
+                       }\r
+                       if(strrcmp(Reply, "password: ") == 0)\r
+                       {\r
+                               r = SFTP_send(ContSock, Pass, strlen(Pass), 0);\r
+                               r = SFTP_send(ContSock, "\r\n", strlen("\r\n"), 0);\r
+                       }\r
+                       if(strrcmp(Reply, "psftp> ") == 0)\r
+                               break;\r
+                       Sleep(1);\r
+               }\r
+               SFTP_closesocket(ContSock);\r
+               ContSock = INVALID_SOCKET;\r
        }\r
 \r
        return(ContSock);\r
@@ -1821,23 +1998,117 @@ static int CheckOneTimePassword(char *Pass, char *Reply, int Type)
 *----------------------------------------------------------------------------*/\r
 \r
 // IPv6対応\r
+typedef SOCKET (__cdecl* LPCONNECTSOCK)(char*, int, char*, int*);\r
+\r
+typedef struct\r
+{\r
+       HANDLE h;\r
+       DWORD ExitCode;\r
+       char *host;\r
+       int port;\r
+       char *PreMsg;\r
+       int CancelCheckWork;\r
+       LPCONNECTSOCK f;\r
+       SOCKET s;\r
+} CONNECTSOCKDATA;\r
+\r
+DWORD WINAPI connectsockThreadProc(LPVOID lpParameter)\r
+{\r
+       CONNECTSOCKDATA* pData;\r
+       pData = (CONNECTSOCKDATA*)lpParameter;\r
+       pData->s = pData->f(pData->host, pData->port, pData->PreMsg, &pData->CancelCheckWork);\r
+       return 0;\r
+}\r
+\r
+// IPv6対応\r
 SOCKET connectsock(char *host, int port, char *PreMsg, int *CancelCheckWork)\r
 {\r
        SOCKET Result;\r
+       CONNECTSOCKDATA DataIPv4;\r
+       CONNECTSOCKDATA DataIPv6;\r
        Result = INVALID_SOCKET;\r
-       switch(CurHost.InetFamily)\r
+       switch(CurHost.CurNetType)\r
        {\r
-       case AF_UNSPEC:\r
-               if((Result = connectsockIPv4(host, port, PreMsg, CancelCheckWork)) != INVALID_SOCKET)\r
-                       CurHost.InetFamily = AF_INET;\r
-               else if(CurHost.UseIPv6 == YES && (Result = connectsockIPv6(host, port, PreMsg, CancelCheckWork)) != INVALID_SOCKET)\r
-                       CurHost.InetFamily = AF_INET6;\r
+       case NTYPE_AUTO:\r
+//             if((Result = connectsockIPv4(host, port, PreMsg, CancelCheckWork)) != INVALID_SOCKET)\r
+//                     CurHost.CurNetType = NTYPE_IPV4;\r
+//             else if((Result = connectsockIPv6(host, port, PreMsg, CancelCheckWork)) != INVALID_SOCKET)\r
+//                     CurHost.CurNetType = NTYPE_IPV6;\r
+               DataIPv4.host = host;\r
+               DataIPv4.port = port;\r
+               DataIPv4.PreMsg = PreMsg;\r
+               DataIPv4.CancelCheckWork = *CancelCheckWork;\r
+               DataIPv4.f = connectsockIPv4;\r
+               DataIPv4.h = CreateThread(NULL, 0, connectsockThreadProc, &DataIPv4, 0, NULL);\r
+               DataIPv6.host = host;\r
+               DataIPv6.port = port;\r
+               DataIPv6.PreMsg = PreMsg;\r
+               DataIPv6.CancelCheckWork = *CancelCheckWork;\r
+               DataIPv6.f = connectsockIPv6;\r
+               DataIPv6.h = CreateThread(NULL, 0, connectsockThreadProc, &DataIPv6, 0, NULL);\r
+               while(1)\r
+               {\r
+                       if(GetExitCodeThread(DataIPv4.h, &DataIPv4.ExitCode))\r
+                       {\r
+                               if(DataIPv4.ExitCode != STILL_ACTIVE)\r
+                               {\r
+                                       if(DataIPv4.s != INVALID_SOCKET)\r
+                                       {\r
+                                               Result = DataIPv4.s;\r
+                                               CurHost.CurNetType = NTYPE_IPV4;\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       }\r
+                       if(GetExitCodeThread(DataIPv6.h, &DataIPv6.ExitCode))\r
+                       {\r
+                               if(DataIPv6.ExitCode != STILL_ACTIVE)\r
+                               {\r
+                                       if(DataIPv6.s != INVALID_SOCKET)\r
+                                       {\r
+                                               Result = DataIPv6.s;\r
+                                               CurHost.CurNetType = NTYPE_IPV6;\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       }\r
+                       if(GetExitCodeThread(DataIPv4.h, &DataIPv4.ExitCode) && GetExitCodeThread(DataIPv6.h, &DataIPv6.ExitCode))\r
+                       {\r
+                               if(DataIPv4.ExitCode != STILL_ACTIVE && DataIPv6.ExitCode != STILL_ACTIVE)\r
+                               {\r
+                                       if(DataIPv4.s == INVALID_SOCKET && DataIPv6.s == INVALID_SOCKET)\r
+                                               break;\r
+                               }\r
+                       }\r
+                       DataIPv4.CancelCheckWork = *CancelCheckWork;\r
+                       DataIPv6.CancelCheckWork = *CancelCheckWork;\r
+                       BackgrndMessageProc();\r
+                       Sleep(1);\r
+               }\r
+               while(1)\r
+               {\r
+                       if(GetExitCodeThread(DataIPv4.h, &DataIPv4.ExitCode) && GetExitCodeThread(DataIPv6.h, &DataIPv6.ExitCode))\r
+                       {\r
+                               if(DataIPv4.ExitCode != STILL_ACTIVE && DataIPv6.ExitCode != STILL_ACTIVE)\r
+                               {\r
+                                       CloseHandle(DataIPv4.h);\r
+                                       CloseHandle(DataIPv6.h);\r
+                                       break;\r
+                               }\r
+                       }\r
+                       DataIPv4.CancelCheckWork = YES;\r
+                       DataIPv6.CancelCheckWork = YES;\r
+                       BackgrndMessageProc();\r
+                       Sleep(1);\r
+               }\r
                break;\r
-       case AF_INET:\r
+       case NTYPE_IPV4:\r
                Result = connectsockIPv4(host, port, PreMsg, CancelCheckWork);\r
+               CurHost.CurNetType = NTYPE_IPV4;\r
                break;\r
-       case AF_INET6:\r
+       case NTYPE_IPV6:\r
                Result = connectsockIPv6(host, port, PreMsg, CancelCheckWork);\r
+               CurHost.CurNetType = NTYPE_IPV6;\r
                break;\r
        }\r
        return Result;\r
@@ -1892,7 +2163,9 @@ SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork)
                else\r
                {\r
                        // アドレスを取得\r
-                       SetTaskMsg(MSGJPN016, DomainName);\r
+                       // IPv6対応\r
+//                     SetTaskMsg(MSGJPN016, DomainName);\r
+                       SetTaskMsg(MSGJPN016, DomainName, MSGJPN333);\r
                        // IPv6対応\r
 //                     pHostEntry = do_gethostbyname(host, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork);\r
                        pHostEntry = do_gethostbynameIPv4(host, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork);\r
@@ -1904,7 +2177,9 @@ SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork)
 //                     memcpy((char *)&CurSockAddr.sin_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
 //                     SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet_ntoa(CurSockAddr.sin_addr), ntohs(CurSockAddr.sin_port));\r
                        memcpy((char *)&CurSockAddrIPv4.sin_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
-                       SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet_ntoa(CurSockAddrIPv4.sin_addr), ntohs(CurSockAddrIPv4.sin_port));\r
+                       // IPv6対応\r
+//                     SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet_ntoa(CurSockAddrIPv4.sin_addr), ntohs(CurSockAddrIPv4.sin_port));\r
+                       SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet_ntoa(CurSockAddrIPv4.sin_addr), ntohs(CurSockAddrIPv4.sin_port), MSGJPN333);\r
                }\r
                else\r
                {\r
@@ -1913,11 +2188,13 @@ SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork)
                                UseIPadrs = NO;\r
                                // IPv6対応\r
 //                             SetTaskMsg(MSGJPN018, PreMsg, DomainName, ntohs(CurSockAddr.sin_port));\r
-                               SetTaskMsg(MSGJPN018, PreMsg, DomainName, ntohs(CurSockAddrIPv4.sin_port));\r
+                               SetTaskMsg(MSGJPN018, PreMsg, DomainName, ntohs(CurSockAddrIPv4.sin_port), MSGJPN333);\r
                        }\r
                        else\r
                        {\r
-                               SetTaskMsg(MSGJPN019, host);\r
+                               // IPv6対応\r
+//                             SetTaskMsg(MSGJPN019, host);\r
+                               SetTaskMsg(MSGJPN019, host, MSGJPN333);\r
                                return(INVALID_SOCKET);\r
                        }\r
                }\r
@@ -1925,7 +2202,7 @@ SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork)
        else\r
                // IPv6対応\r
 //             SetTaskMsg(MSGJPN020, PreMsg, inet_ntoa(CurSockAddr.sin_addr), ntohs(CurSockAddr.sin_port));\r
-               SetTaskMsg(MSGJPN020, PreMsg, inet_ntoa(CurSockAddrIPv4.sin_addr), ntohs(CurSockAddrIPv4.sin_port));\r
+               SetTaskMsg(MSGJPN020, PreMsg, inet_ntoa(CurSockAddrIPv4.sin_addr), ntohs(CurSockAddrIPv4.sin_port), MSGJPN333);\r
 \r
        if((Fwall == FWALL_SOCKS4) || (Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
        {\r
@@ -1963,7 +2240,9 @@ SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork)
                                memcpy((char *)&SocksSockAddrIPv4.sin_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
                        else\r
                        {\r
-                               SetTaskMsg(MSGJPN021, FwallHost);\r
+                               // IPv6対応\r
+//                             SetTaskMsg(MSGJPN021, FwallHost);\r
+                               SetTaskMsg(MSGJPN021, FwallHost, MSGJPN333);\r
                                return INVALID_SOCKET;\r
                        }\r
                }\r
@@ -1973,7 +2252,9 @@ SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork)
 //             SetTaskMsg(MSGJPN022, inet_ntoa(SocksSockAddr.sin_addr), ntohs(SocksSockAddr.sin_port));\r
                SocksSockAddrIPv4.sin_port = htons((u_short)FwallPort);\r
                SocksSockAddrIPv4.sin_family = AF_INET;\r
-               SetTaskMsg(MSGJPN022, inet_ntoa(SocksSockAddrIPv4.sin_addr), ntohs(SocksSockAddrIPv4.sin_port));\r
+               // IPv6対応\r
+//             SetTaskMsg(MSGJPN022, inet_ntoa(SocksSockAddrIPv4.sin_addr), ntohs(SocksSockAddrIPv4.sin_port));\r
+               SetTaskMsg(MSGJPN022, inet_ntoa(SocksSockAddrIPv4.sin_addr), ntohs(SocksSockAddrIPv4.sin_port), MSGJPN333);\r
                // connectで接続する先はSOCKSサーバ\r
                // IPv6対応\r
 //             memcpy(&saSockAddr, &SocksSockAddr, sizeof(SocksSockAddr));\r
@@ -2006,7 +2287,9 @@ SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork)
                                   (Socks4GetCmdReply(sSocket, &Socks4Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
                                   (Socks4Reply.Result != SOCKS4_RES_OK))\r
                                {\r
-                                       SetTaskMsg(MSGJPN023, Socks4Reply.Result);\r
+                                       // IPv6対応\r
+//                                     SetTaskMsg(MSGJPN023, Socks4Reply.Result);\r
+                                       SetTaskMsg(MSGJPN023, Socks4Reply.Result, MSGJPN333);\r
                                        DoClose(sSocket);\r
                                        sSocket = INVALID_SOCKET;\r
                                }\r
@@ -2028,7 +2311,9 @@ SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork)
                                   (Socks5GetCmdReply(sSocket, &Socks5Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
                                   (Socks5Reply.Result != SOCKS5_RES_OK))\r
                                {\r
-                                       SetTaskMsg(MSGJPN024, Socks5Reply.Result);\r
+                                       // IPv6対応\r
+//                                     SetTaskMsg(MSGJPN024, Socks5Reply.Result);\r
+                                       SetTaskMsg(MSGJPN024, Socks5Reply.Result, MSGJPN333);\r
                                        DoClose(sSocket);\r
                                        sSocket = INVALID_SOCKET;\r
                                }\r
@@ -2036,18 +2321,24 @@ SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork)
                        }\r
 \r
                        if(sSocket != INVALID_SOCKET)\r
-                               SetTaskMsg(MSGJPN025);\r
+                               // IPv6対応\r
+//                             SetTaskMsg(MSGJPN025);\r
+                               SetTaskMsg(MSGJPN025, MSGJPN333);\r
                }\r
                else\r
                {\r
 //#pragma aaa\r
-                       SetTaskMsg(MSGJPN026/*"接続できません(2) %x", sSocket*/);\r
+                       // IPv6対応\r
+//                     SetTaskMsg(MSGJPN026/*"接続できません(2) %x", sSocket*/);\r
+                       SetTaskMsg(MSGJPN026/*"接続できません(2) %x", sSocket*/, MSGJPN333);\r
                        DoClose(sSocket);\r
                        sSocket = INVALID_SOCKET;\r
                }\r
        }\r
        else\r
-               SetTaskMsg(MSGJPN027);\r
+               // IPv6対応\r
+//             SetTaskMsg(MSGJPN027);\r
+               SetTaskMsg(MSGJPN027, MSGJPN333);\r
 \r
        return(sSocket);\r
 }\r
@@ -2093,31 +2384,31 @@ SOCKET connectsockIPv6(char *host, int port, char *PreMsg, int *CancelCheckWork)
                else\r
                {\r
                        // アドレスを取得\r
-                       SetTaskMsg(MSGJPN016, DomainName);\r
+                       SetTaskMsg(MSGJPN016, DomainName, MSGJPN334);\r
                        pHostEntry = do_gethostbynameIPv6(host, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork);\r
                }\r
 \r
                if(pHostEntry != NULL)\r
                {\r
                        memcpy((char *)&CurSockAddrIPv6.sin6_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
-                       SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet6_ntoa(CurSockAddrIPv6.sin6_addr), ntohs(CurSockAddrIPv6.sin6_port));\r
+                       SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet6_ntoa(CurSockAddrIPv6.sin6_addr), ntohs(CurSockAddrIPv6.sin6_port), MSGJPN334);\r
                }\r
                else\r
                {\r
                        if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
                        {\r
                                UseIPadrs = NO;\r
-                               SetTaskMsg(MSGJPN018, PreMsg, DomainName, ntohs(CurSockAddrIPv6.sin6_port));\r
+                               SetTaskMsg(MSGJPN018, PreMsg, DomainName, ntohs(CurSockAddrIPv6.sin6_port), MSGJPN334);\r
                        }\r
                        else\r
                        {\r
-                               SetTaskMsg(MSGJPN019, host);\r
+                               SetTaskMsg(MSGJPN019, host, MSGJPN334);\r
                                return(INVALID_SOCKET);\r
                        }\r
                }\r
        }\r
        else\r
-               SetTaskMsg(MSGJPN020, PreMsg, inet6_ntoa(CurSockAddrIPv6.sin6_addr), ntohs(CurSockAddrIPv6.sin6_port));\r
+               SetTaskMsg(MSGJPN020, PreMsg, inet6_ntoa(CurSockAddrIPv6.sin6_addr), ntohs(CurSockAddrIPv6.sin6_port), MSGJPN334);\r
 \r
        if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
        {\r
@@ -2135,13 +2426,13 @@ SOCKET connectsockIPv6(char *host, int port, char *PreMsg, int *CancelCheckWork)
                                memcpy((char *)&SocksSockAddrIPv6.sin6_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
                        else\r
                        {\r
-                               SetTaskMsg(MSGJPN021, FwallHost);\r
+                               SetTaskMsg(MSGJPN021, FwallHost, MSGJPN334);\r
                                return INVALID_SOCKET;\r
                        }\r
                }\r
                SocksSockAddrIPv6.sin6_port = htons((u_short)FwallPort);\r
                SocksSockAddrIPv6.sin6_family = AF_INET6;\r
-               SetTaskMsg(MSGJPN022, inet6_ntoa(SocksSockAddrIPv6.sin6_addr), ntohs(SocksSockAddrIPv6.sin6_port));\r
+               SetTaskMsg(MSGJPN022, inet6_ntoa(SocksSockAddrIPv6.sin6_addr), ntohs(SocksSockAddrIPv6.sin6_port), MSGJPN334);\r
                // connectで接続する先はSOCKSサーバ\r
                memcpy(&saSockAddr, &SocksSockAddrIPv6, sizeof(SocksSockAddrIPv6));\r
        }\r
@@ -2177,7 +2468,7 @@ SOCKET connectsockIPv6(char *host, int port, char *PreMsg, int *CancelCheckWork)
                                   (Socks5GetCmdReply(sSocket, &Socks5Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
                                   (Socks5Reply.Result != SOCKS5_RES_OK))\r
                                {\r
-                                       SetTaskMsg(MSGJPN024, Socks5Reply.Result);\r
+                                       SetTaskMsg(MSGJPN024, Socks5Reply.Result, MSGJPN334);\r
                                        DoClose(sSocket);\r
                                        sSocket = INVALID_SOCKET;\r
                                }\r
@@ -2185,18 +2476,18 @@ SOCKET connectsockIPv6(char *host, int port, char *PreMsg, int *CancelCheckWork)
                        }\r
 \r
                        if(sSocket != INVALID_SOCKET)\r
-                               SetTaskMsg(MSGJPN025);\r
+                               SetTaskMsg(MSGJPN025, MSGJPN334);\r
                }\r
                else\r
                {\r
 //#pragma aaa\r
-                       SetTaskMsg(MSGJPN026/*"接続できません(2) %x", sSocket*/);\r
+                       SetTaskMsg(MSGJPN026/*"接続できません(2) %x", sSocket*/, MSGJPN334);\r
                        DoClose(sSocket);\r
                        sSocket = INVALID_SOCKET;\r
                }\r
        }\r
        else\r
-               SetTaskMsg(MSGJPN027);\r
+               SetTaskMsg(MSGJPN027, MSGJPN334);\r
 \r
        return(sSocket);\r
 }\r
@@ -2216,14 +2507,12 @@ SOCKET GetFTPListenSocket(SOCKET ctrl_skt, int *CancelCheckWork)
 {\r
        SOCKET Result;\r
        Result = INVALID_SOCKET;\r
-       switch(CurHost.InetFamily)\r
+       switch(CurHost.CurNetType)\r
        {\r
-       case AF_UNSPEC:\r
-               break;\r
-       case AF_INET:\r
+       case NTYPE_IPV4:\r
                Result = GetFTPListenSocketIPv4(ctrl_skt, CancelCheckWork);\r
                break;\r
-       case AF_INET6:\r
+       case NTYPE_IPV6:\r
                Result = GetFTPListenSocketIPv6(ctrl_skt, CancelCheckWork);\r
                break;\r
        }\r
@@ -2281,7 +2570,9 @@ SOCKET GetFTPListenSocketIPv4(SOCKET ctrl_skt, int *CancelCheckWork)
                                   (Socks4GetCmdReply(listen_skt, &Socks4Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
                                   (Socks4Reply.Result != SOCKS4_RES_OK))\r
                                {\r
-                                       SetTaskMsg(MSGJPN028, Socks4Reply.Result);\r
+                                       // IPv6対応\r
+//                                     SetTaskMsg(MSGJPN028, Socks4Reply.Result);\r
+                                       SetTaskMsg(MSGJPN028, Socks4Reply.Result, MSGJPN333);\r
                                        DoClose(listen_skt);\r
                                        listen_skt = INVALID_SOCKET;\r
                                }\r
@@ -2323,7 +2614,9 @@ SOCKET GetFTPListenSocketIPv4(SOCKET ctrl_skt, int *CancelCheckWork)
                                   (Socks5GetCmdReply(listen_skt, &Socks5Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
                                   (Socks5Reply.Result != SOCKS5_RES_OK))\r
                                {\r
-                                       SetTaskMsg(MSGJPN029, Socks5Reply.Result);\r
+                                       // IPv6対応\r
+//                                     SetTaskMsg(MSGJPN029, Socks5Reply.Result);\r
+                                       SetTaskMsg(MSGJPN029, Socks5Reply.Result, MSGJPN333);\r
                                        DoClose(listen_skt);\r
                                        listen_skt = INVALID_SOCKET;\r
                                }\r
@@ -2383,7 +2676,9 @@ SOCKET GetFTPListenSocketIPv4(SOCKET ctrl_skt, int *CancelCheckWork)
                        }\r
 \r
                        if(listen_skt == INVALID_SOCKET)\r
-                               SetTaskMsg(MSGJPN030);\r
+                               // IPv6対応\r
+//                             SetTaskMsg(MSGJPN030);\r
+                               SetTaskMsg(MSGJPN030, MSGJPN333);\r
                }\r
        }\r
        else\r
@@ -2400,7 +2695,9 @@ SOCKET GetFTPListenSocketIPv4(SOCKET ctrl_skt, int *CancelCheckWork)
                                UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]),\r
                                UC(p[0]), UC(p[1])) / 100) != FTP_COMPLETE)\r
                {\r
-                       SetTaskMsg(MSGJPN031);\r
+                       // IPv6対応\r
+//                     SetTaskMsg(MSGJPN031);\r
+                       SetTaskMsg(MSGJPN031, MSGJPN333);\r
                        do_closesocket(listen_skt);\r
                        listen_skt = INVALID_SOCKET;\r
                }\r
@@ -2457,7 +2754,7 @@ SOCKET GetFTPListenSocketIPv6(SOCKET ctrl_skt, int *CancelCheckWork)
                                   (Socks5GetCmdReply(listen_skt, &Socks5Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
                                   (Socks5Reply.Result != SOCKS5_RES_OK))\r
                                {\r
-                                       SetTaskMsg(MSGJPN029, Socks5Reply.Result);\r
+                                       SetTaskMsg(MSGJPN029, Socks5Reply.Result, MSGJPN334);\r
                                        DoClose(listen_skt);\r
                                        listen_skt = INVALID_SOCKET;\r
                                }\r
@@ -2517,7 +2814,7 @@ SOCKET GetFTPListenSocketIPv6(SOCKET ctrl_skt, int *CancelCheckWork)
                        }\r
 \r
                        if(listen_skt == INVALID_SOCKET)\r
-                               SetTaskMsg(MSGJPN030);\r
+                               SetTaskMsg(MSGJPN030, MSGJPN334);\r
                }\r
        }\r
        else\r
@@ -2534,7 +2831,7 @@ SOCKET GetFTPListenSocketIPv6(SOCKET ctrl_skt, int *CancelCheckWork)
                                AddressToStringIPv6(Adrs, a),\r
                                (UC(p[0]) << 8) | UC(p[1])) / 100) != FTP_COMPLETE)\r
                {\r
-                       SetTaskMsg(MSGJPN031);\r
+                       SetTaskMsg(MSGJPN031, MSGJPN334);\r
                        do_closesocket(listen_skt);\r
                        listen_skt = INVALID_SOCKET;\r
                }\r
@@ -2944,13 +3241,25 @@ int AskUseMLSD(void)
 }\r
 \r
 // IPv6対応\r
-int AskInetFamily(void)\r
+int AskCurNetType(void)\r
+{\r
+       return(CurHost.CurNetType);\r
+}\r
+\r
+// 自動切断対策\r
+int AskNoopInterval(void)\r
+{\r
+       return(CurHost.NoopInterval);\r
+}\r
+\r
+// 再転送対応\r
+int AskTransferErrorMode(void)\r
 {\r
-       return(CurHost.InetFamily);\r
+       return(CurHost.TransferErrorMode);\r
 }\r
 \r
-int AskUseIPv6(void)\r
+int AskTransferErrorNotify(void)\r
 {\r
-       return(CurHost.UseIPv6);\r
+       return(CurHost.TransferErrorNotify);\r
 }\r
 \r