+SOCKET connectsockIPv6(char *host, int port, char *PreMsg, int *CancelCheckWork)\r
+{\r
+ struct sockaddr_in6 saSockAddr;\r
+ char HostEntry[MAXGETHOSTSTRUCT];\r
+ struct hostent *pHostEntry;\r
+ SOCKET sSocket;\r
+ int Len;\r
+ int Fwall;\r
+ SOCKS5REQUEST Socks5Cmd;\r
+ SOCKS5REPLY Socks5Reply;\r
+\r
+ //////////////////////////////\r
+ // ホスト名解決と接続の準備\r
+ //////////////////////////////\r
+\r
+ Fwall = FWALL_NONE;\r
+ if(AskHostFireWall() == YES)\r
+ Fwall = FwallType;\r
+\r
+ sSocket = INVALID_SOCKET;\r
+\r
+ UseIPadrs = YES;\r
+ strcpy(DomainName, host);\r
+ memset(&CurSockAddrIPv6, 0, sizeof(CurSockAddrIPv6));\r
+ CurSockAddrIPv6.sin6_port = htons((u_short)port);\r
+ CurSockAddrIPv6.sin6_family = AF_INET6;\r
+ CurSockAddrIPv6.sin6_addr = inet6_addr(host);\r
+ if(memcmp(&CurSockAddrIPv6.sin6_addr, &IN6ADDR_NONE, sizeof(struct in6_addr)) == 0)\r
+ {\r
+ // ホスト名が指定された\r
+ // ホスト名からアドレスを求める\r
+ if(((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER)) &&\r
+ (FwallResolv == YES))\r
+ {\r
+ // ホスト名解決はSOCKSサーバに任せる\r
+ pHostEntry = NULL;\r
+ }\r
+ else\r
+ {\r
+ // アドレスを取得\r
+ SetTaskMsg(MSGJPN016, DomainName);\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
+ }\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
+ }\r
+ else\r
+ {\r
+ SetTaskMsg(MSGJPN019, host);\r
+ return(INVALID_SOCKET);\r
+ }\r
+ }\r
+ }\r
+ else\r
+ SetTaskMsg(MSGJPN020, PreMsg, inet6_ntoa(CurSockAddrIPv6.sin6_addr), ntohs(CurSockAddrIPv6.sin6_port));\r
+\r
+ if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
+ {\r
+ // SOCKSを使う\r
+ // SOCKSに接続する準備\r
+ {\r
+ Len = Socks5MakeCmdPacketIPv6(&Socks5Cmd, SOCKS5_CMD_CONNECT, UseIPadrs, (char*)&CurSockAddrIPv6.sin6_addr, DomainName, CurSockAddrIPv6.sin6_port);\r
+ }\r
+\r
+ memset(&SocksSockAddrIPv6, 0, sizeof(SocksSockAddrIPv6));\r
+ SocksSockAddrIPv6.sin6_addr = inet6_addr(FwallHost);\r
+ if(memcmp(&SocksSockAddrIPv6.sin6_addr, &IN6ADDR_NONE, sizeof(struct in6_addr)) == 0)\r
+ {\r
+ if((pHostEntry = do_gethostbynameIPv6(FwallHost, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork)) != NULL)\r
+ memcpy((char *)&SocksSockAddrIPv6.sin6_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
+ else\r
+ {\r
+ SetTaskMsg(MSGJPN021, FwallHost);\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
+ // connectで接続する先はSOCKSサーバ\r
+ memcpy(&saSockAddr, &SocksSockAddrIPv6, sizeof(SocksSockAddrIPv6));\r
+ }\r
+ else\r
+ {\r
+ // connectで接続するのは接続先のホスト\r
+ memcpy(&saSockAddr, &CurSockAddrIPv6, sizeof(CurSockAddrIPv6));\r
+ }\r
+\r
+ /////////////\r
+ // 接続実行\r
+ /////////////\r
+\r
+ inet6_ntoa(saSockAddr.sin6_addr);\r
+ if((sSocket = do_socket(AF_INET6, SOCK_STREAM, TCP_PORT)) != INVALID_SOCKET)\r
+ {\r
+ if(do_connect(sSocket, (struct sockaddr *)&saSockAddr, sizeof(saSockAddr), CancelCheckWork) != SOCKET_ERROR)\r
+ {\r
+ if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
+ {\r
+ if(Socks5SelMethod(sSocket, CancelCheckWork) == FFFTP_FAIL)\r
+ {\r
+ DoClose(sSocket);\r
+ sSocket = INVALID_SOCKET;\r
+ }\r
+\r
+ Socks5Reply.Result = -1;\r
+ // 同時接続対応\r
+// if((SocksSendCmd(sSocket, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
+// (Socks5GetCmdReply(sSocket, &Socks5Reply) != FFFTP_SUCCESS) || \r
+// (Socks5Reply.Result != SOCKS5_RES_OK))\r
+ if((SocksSendCmd(sSocket, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
+ (Socks5GetCmdReply(sSocket, &Socks5Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
+ (Socks5Reply.Result != SOCKS5_RES_OK))\r
+ {\r
+ SetTaskMsg(MSGJPN024, Socks5Reply.Result);\r
+ DoClose(sSocket);\r
+ sSocket = INVALID_SOCKET;\r
+ }\r
+\r
+ }\r
+\r
+ if(sSocket != INVALID_SOCKET)\r
+ SetTaskMsg(MSGJPN025);\r
+ }\r
+ else\r
+ {\r
+//#pragma aaa\r
+ SetTaskMsg(MSGJPN026/*"接続できません(2) %x", sSocket*/);\r
+ DoClose(sSocket);\r
+ sSocket = INVALID_SOCKET;\r
+ }\r
+ }\r
+ else\r
+ SetTaskMsg(MSGJPN027);\r
+\r
+ return(sSocket);\r
+}\r
+\r
+\r
+/*----- リッスンソケットを取得 ------------------------------------------------\r