Loweynet
Revisão | 29207baed700471a3d39f1b97713a2a110937a0b (tree) |
---|---|
Hora | 2012-02-20 00:59:37 |
Autor | s_kawamoto <s_kawamoto@user...> |
Commiter | s_kawamoto |
Fix bugs of socket connection.
Fix bugs of processing replies of EPRT command.
@@ -1827,6 +1827,11 @@ char *AskLocalFreeSpace(char *Path); | ||
1827 | 1827 | |
1828 | 1828 | int MakeSocketWin(HWND hWnd, HINSTANCE hInst); |
1829 | 1829 | void DeleteSocketWin(void); |
1830 | +// ソケットにデータを付与 | |
1831 | +int SetAsyncTableDataIPv4(SOCKET s, struct sockaddr_in* Host, struct sockaddr_in* Socks); | |
1832 | +int SetAsyncTableDataIPv6(SOCKET s, struct sockaddr_in6* Host, struct sockaddr_in6* Socks); | |
1833 | +int GetAsyncTableDataIPv4(SOCKET s, struct sockaddr_in* Host, struct sockaddr_in* Socks); | |
1834 | +int GetAsyncTableDataIPv6(SOCKET s, struct sockaddr_in6* Host, struct sockaddr_in6* Socks); | |
1830 | 1835 | // IPv6対応 |
1831 | 1836 | //struct hostent *do_gethostbyname(const char *Name, char *Buf, int Len, int *CancelCheckWork); |
1832 | 1837 | struct hostent *do_gethostbynameIPv4(const char *Name, char *Buf, int Len, int *CancelCheckWork); |
@@ -116,11 +116,6 @@ static HOSTDATA CurHost; | ||
116 | 116 | // IPv6対応 |
117 | 117 | //static struct sockaddr_in SocksSockAddr; /* SOCKSサーバのアドレス情報 */ |
118 | 118 | //static struct sockaddr_in CurSockAddr; /* 接続先ホストのアドレス情報 */ |
119 | -static struct sockaddr_in SocksSockAddrIPv4; /* SOCKSサーバのアドレス情報 */ | |
120 | -static struct sockaddr_in CurSockAddrIPv4; /* 接続先ホストのアドレス情報 */ | |
121 | -static struct sockaddr_in6 SocksSockAddrIPv6; /* SOCKSサーバのアドレス情報 */ | |
122 | -static struct sockaddr_in6 CurSockAddrIPv6; /* 接続先ホストのアドレス情報 */ | |
123 | -static const struct in6_addr IN6ADDR_NONE = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; | |
124 | 119 | |
125 | 120 | static int UseIPadrs; |
126 | 121 | static char DomainName[HOST_ADRS_LEN+1]; |
@@ -2119,6 +2114,9 @@ SOCKET connectsock(char *host, int port, char *PreMsg, int *CancelCheckWork) | ||
2119 | 2114 | //SOCKET connectsock(char *host, int port, char *PreMsg, int *CancelCheckWork) |
2120 | 2115 | SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork) |
2121 | 2116 | { |
2117 | + // IPv6対応 | |
2118 | + struct sockaddr_in SocksSockAddr; /* SOCKSサーバのアドレス情報 */ | |
2119 | + struct sockaddr_in CurSockAddr; /* 接続先ホストのアドレス情報 */ | |
2122 | 2120 | struct sockaddr_in saSockAddr; |
2123 | 2121 | char HostEntry[MAXGETHOSTSTRUCT]; |
2124 | 2122 | struct hostent *pHostEntry; |
@@ -2142,15 +2140,10 @@ SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork) | ||
2142 | 2140 | |
2143 | 2141 | UseIPadrs = YES; |
2144 | 2142 | strcpy(DomainName, host); |
2145 | - // IPv6対応 | |
2146 | -// memset(&CurSockAddr, 0, sizeof(CurSockAddr)); | |
2147 | -// CurSockAddr.sin_port = htons((u_short)port); | |
2148 | -// CurSockAddr.sin_family = AF_INET; | |
2149 | -// if((CurSockAddr.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) | |
2150 | - memset(&CurSockAddrIPv4, 0, sizeof(CurSockAddrIPv4)); | |
2151 | - CurSockAddrIPv4.sin_port = htons((u_short)port); | |
2152 | - CurSockAddrIPv4.sin_family = AF_INET; | |
2153 | - if((CurSockAddrIPv4.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) | |
2143 | + memset(&CurSockAddr, 0, sizeof(CurSockAddr)); | |
2144 | + CurSockAddr.sin_port = htons((u_short)port); | |
2145 | + CurSockAddr.sin_family = AF_INET; | |
2146 | + if((CurSockAddr.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) | |
2154 | 2147 | { |
2155 | 2148 | // ホスト名が指定された |
2156 | 2149 | // ホスト名からアドレスを求める |
@@ -2173,13 +2166,10 @@ SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork) | ||
2173 | 2166 | |
2174 | 2167 | if(pHostEntry != NULL) |
2175 | 2168 | { |
2169 | + memcpy((char *)&CurSockAddr.sin_addr, pHostEntry->h_addr, pHostEntry->h_length); | |
2176 | 2170 | // IPv6対応 |
2177 | -// memcpy((char *)&CurSockAddr.sin_addr, pHostEntry->h_addr, pHostEntry->h_length); | |
2178 | 2171 | // SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet_ntoa(CurSockAddr.sin_addr), ntohs(CurSockAddr.sin_port)); |
2179 | - memcpy((char *)&CurSockAddrIPv4.sin_addr, pHostEntry->h_addr, pHostEntry->h_length); | |
2180 | - // IPv6対応 | |
2181 | -// SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet_ntoa(CurSockAddrIPv4.sin_addr), ntohs(CurSockAddrIPv4.sin_port)); | |
2182 | - SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet_ntoa(CurSockAddrIPv4.sin_addr), ntohs(CurSockAddrIPv4.sin_port), MSGJPN333); | |
2172 | + SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet_ntoa(CurSockAddr.sin_addr), ntohs(CurSockAddr.sin_port), MSGJPN333); | |
2183 | 2173 | } |
2184 | 2174 | else |
2185 | 2175 | { |
@@ -2188,7 +2178,7 @@ SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork) | ||
2188 | 2178 | UseIPadrs = NO; |
2189 | 2179 | // IPv6対応 |
2190 | 2180 | // SetTaskMsg(MSGJPN018, PreMsg, DomainName, ntohs(CurSockAddr.sin_port)); |
2191 | - SetTaskMsg(MSGJPN018, PreMsg, DomainName, ntohs(CurSockAddrIPv4.sin_port), MSGJPN333); | |
2181 | + SetTaskMsg(MSGJPN018, PreMsg, DomainName, ntohs(CurSockAddr.sin_port), MSGJPN333); | |
2192 | 2182 | } |
2193 | 2183 | else |
2194 | 2184 | { |
@@ -2202,7 +2192,7 @@ SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork) | ||
2202 | 2192 | else |
2203 | 2193 | // IPv6対応 |
2204 | 2194 | // SetTaskMsg(MSGJPN020, PreMsg, inet_ntoa(CurSockAddr.sin_addr), ntohs(CurSockAddr.sin_port)); |
2205 | - SetTaskMsg(MSGJPN020, PreMsg, inet_ntoa(CurSockAddrIPv4.sin_addr), ntohs(CurSockAddrIPv4.sin_port), MSGJPN333); | |
2195 | + SetTaskMsg(MSGJPN020, PreMsg, inet_ntoa(CurSockAddr.sin_addr), ntohs(CurSockAddr.sin_port), MSGJPN333); | |
2206 | 2196 | |
2207 | 2197 | if((Fwall == FWALL_SOCKS4) || (Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER)) |
2208 | 2198 | { |
@@ -2212,32 +2202,23 @@ SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork) | ||
2212 | 2202 | { |
2213 | 2203 | Socks4Cmd.Ver = SOCKS4_VER; |
2214 | 2204 | Socks4Cmd.Cmd = SOCKS4_CMD_CONNECT; |
2215 | - // IPv6対応 | |
2216 | -// Socks4Cmd.Port = CurSockAddr.sin_port; | |
2217 | -// Socks4Cmd.AdrsInt = CurSockAddr.sin_addr.s_addr; | |
2218 | - Socks4Cmd.Port = CurSockAddrIPv4.sin_port; | |
2219 | - Socks4Cmd.AdrsInt = CurSockAddrIPv4.sin_addr.s_addr; | |
2205 | + Socks4Cmd.Port = CurSockAddr.sin_port; | |
2206 | + Socks4Cmd.AdrsInt = CurSockAddr.sin_addr.s_addr; | |
2220 | 2207 | strcpy(Socks4Cmd.UserID, FwallUser); |
2221 | 2208 | Len = offsetof(SOCKS4CMD, UserID) + strlen(FwallUser) + 1; |
2222 | 2209 | } |
2223 | 2210 | else |
2224 | 2211 | { |
2225 | - // IPv6対応 | |
2226 | -// Len = Socks5MakeCmdPacket(&Socks5Cmd, SOCKS5_CMD_CONNECT, UseIPadrs, CurSockAddr.sin_addr.s_addr, DomainName, CurSockAddr.sin_port); | |
2227 | - Len = Socks5MakeCmdPacket(&Socks5Cmd, SOCKS5_CMD_CONNECT, UseIPadrs, CurSockAddrIPv4.sin_addr.s_addr, DomainName, CurSockAddrIPv4.sin_port); | |
2212 | + Len = Socks5MakeCmdPacket(&Socks5Cmd, SOCKS5_CMD_CONNECT, UseIPadrs, CurSockAddr.sin_addr.s_addr, DomainName, CurSockAddr.sin_port); | |
2228 | 2213 | } |
2229 | 2214 | |
2230 | - // IPv6対応 | |
2231 | -// memset(&SocksSockAddr, 0, sizeof(SocksSockAddr)); | |
2232 | -// if((SocksSockAddr.sin_addr.s_addr = inet_addr(FwallHost)) == INADDR_NONE) | |
2233 | - memset(&SocksSockAddrIPv4, 0, sizeof(SocksSockAddrIPv4)); | |
2234 | - if((SocksSockAddrIPv4.sin_addr.s_addr = inet_addr(FwallHost)) == INADDR_NONE) | |
2215 | + memset(&SocksSockAddr, 0, sizeof(SocksSockAddr)); | |
2216 | + if((SocksSockAddr.sin_addr.s_addr = inet_addr(FwallHost)) == INADDR_NONE) | |
2235 | 2217 | { |
2236 | 2218 | // IPv6対応 |
2237 | 2219 | // if((pHostEntry = do_gethostbyname(FwallHost, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork)) != NULL) |
2238 | -// memcpy((char *)&SocksSockAddr.sin_addr, pHostEntry->h_addr, pHostEntry->h_length); | |
2239 | 2220 | if((pHostEntry = do_gethostbynameIPv4(FwallHost, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork)) != NULL) |
2240 | - memcpy((char *)&SocksSockAddrIPv4.sin_addr, pHostEntry->h_addr, pHostEntry->h_length); | |
2221 | + memcpy((char *)&SocksSockAddr.sin_addr, pHostEntry->h_addr, pHostEntry->h_length); | |
2241 | 2222 | else |
2242 | 2223 | { |
2243 | 2224 | // IPv6対応 |
@@ -2246,26 +2227,18 @@ SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork) | ||
2246 | 2227 | return INVALID_SOCKET; |
2247 | 2228 | } |
2248 | 2229 | } |
2230 | + SocksSockAddr.sin_port = htons((u_short)FwallPort); | |
2231 | + SocksSockAddr.sin_family = AF_INET; | |
2249 | 2232 | // IPv6対応 |
2250 | -// SocksSockAddr.sin_port = htons((u_short)FwallPort); | |
2251 | -// SocksSockAddr.sin_family = AF_INET; | |
2252 | 2233 | // SetTaskMsg(MSGJPN022, inet_ntoa(SocksSockAddr.sin_addr), ntohs(SocksSockAddr.sin_port)); |
2253 | - SocksSockAddrIPv4.sin_port = htons((u_short)FwallPort); | |
2254 | - SocksSockAddrIPv4.sin_family = AF_INET; | |
2255 | - // IPv6対応 | |
2256 | -// SetTaskMsg(MSGJPN022, inet_ntoa(SocksSockAddrIPv4.sin_addr), ntohs(SocksSockAddrIPv4.sin_port)); | |
2257 | - SetTaskMsg(MSGJPN022, inet_ntoa(SocksSockAddrIPv4.sin_addr), ntohs(SocksSockAddrIPv4.sin_port), MSGJPN333); | |
2234 | + SetTaskMsg(MSGJPN022, inet_ntoa(SocksSockAddr.sin_addr), ntohs(SocksSockAddr.sin_port), MSGJPN333); | |
2258 | 2235 | // connectで接続する先はSOCKSサーバ |
2259 | - // IPv6対応 | |
2260 | -// memcpy(&saSockAddr, &SocksSockAddr, sizeof(SocksSockAddr)); | |
2261 | - memcpy(&saSockAddr, &SocksSockAddrIPv4, sizeof(SocksSockAddrIPv4)); | |
2236 | + memcpy(&saSockAddr, &SocksSockAddr, sizeof(SocksSockAddr)); | |
2262 | 2237 | } |
2263 | 2238 | else |
2264 | 2239 | { |
2265 | 2240 | // connectで接続するのは接続先のホスト |
2266 | - // IPv6対応 | |
2267 | -// memcpy(&saSockAddr, &CurSockAddr, sizeof(CurSockAddr)); | |
2268 | - memcpy(&saSockAddr, &CurSockAddrIPv4, sizeof(CurSockAddrIPv4)); | |
2241 | + memcpy(&saSockAddr, &CurSockAddr, sizeof(CurSockAddr)); | |
2269 | 2242 | } |
2270 | 2243 | |
2271 | 2244 | ///////////// |
@@ -2274,6 +2247,8 @@ SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork) | ||
2274 | 2247 | |
2275 | 2248 | if((sSocket = do_socket(AF_INET, SOCK_STREAM, TCP_PORT)) != INVALID_SOCKET) |
2276 | 2249 | { |
2250 | + // ソケットにデータを付与 | |
2251 | + SetAsyncTableDataIPv4(sSocket, &CurSockAddr, &SocksSockAddr); | |
2277 | 2252 | if(do_connect(sSocket, (struct sockaddr *)&saSockAddr, sizeof(saSockAddr), CancelCheckWork) != SOCKET_ERROR) |
2278 | 2253 | { |
2279 | 2254 | if(Fwall == FWALL_SOCKS4) |
@@ -2346,6 +2321,8 @@ SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork) | ||
2346 | 2321 | |
2347 | 2322 | SOCKET connectsockIPv6(char *host, int port, char *PreMsg, int *CancelCheckWork) |
2348 | 2323 | { |
2324 | + struct sockaddr_in6 SocksSockAddr; /* SOCKSサーバのアドレス情報 */ | |
2325 | + struct sockaddr_in6 CurSockAddr; /* 接続先ホストのアドレス情報 */ | |
2349 | 2326 | struct sockaddr_in6 saSockAddr; |
2350 | 2327 | char HostEntry[MAXGETHOSTSTRUCT]; |
2351 | 2328 | struct hostent *pHostEntry; |
@@ -2367,11 +2344,11 @@ SOCKET connectsockIPv6(char *host, int port, char *PreMsg, int *CancelCheckWork) | ||
2367 | 2344 | |
2368 | 2345 | UseIPadrs = YES; |
2369 | 2346 | strcpy(DomainName, host); |
2370 | - memset(&CurSockAddrIPv6, 0, sizeof(CurSockAddrIPv6)); | |
2371 | - CurSockAddrIPv6.sin6_port = htons((u_short)port); | |
2372 | - CurSockAddrIPv6.sin6_family = AF_INET6; | |
2373 | - CurSockAddrIPv6.sin6_addr = inet6_addr(host); | |
2374 | - if(memcmp(&CurSockAddrIPv6.sin6_addr, &IN6ADDR_NONE, sizeof(struct in6_addr)) == 0) | |
2347 | + memset(&CurSockAddr, 0, sizeof(CurSockAddr)); | |
2348 | + CurSockAddr.sin6_port = htons((u_short)port); | |
2349 | + CurSockAddr.sin6_family = AF_INET6; | |
2350 | + CurSockAddr.sin6_addr = inet6_addr(host); | |
2351 | + if(memcmp(&CurSockAddr.sin6_addr, &IN6ADDR_NONE, sizeof(struct in6_addr)) == 0) | |
2375 | 2352 | { |
2376 | 2353 | // ホスト名が指定された |
2377 | 2354 | // ホスト名からアドレスを求める |
@@ -2390,15 +2367,15 @@ SOCKET connectsockIPv6(char *host, int port, char *PreMsg, int *CancelCheckWork) | ||
2390 | 2367 | |
2391 | 2368 | if(pHostEntry != NULL) |
2392 | 2369 | { |
2393 | - memcpy((char *)&CurSockAddrIPv6.sin6_addr, pHostEntry->h_addr, pHostEntry->h_length); | |
2394 | - SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet6_ntoa(CurSockAddrIPv6.sin6_addr), ntohs(CurSockAddrIPv6.sin6_port), MSGJPN334); | |
2370 | + memcpy((char *)&CurSockAddr.sin6_addr, pHostEntry->h_addr, pHostEntry->h_length); | |
2371 | + SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet6_ntoa(CurSockAddr.sin6_addr), ntohs(CurSockAddr.sin6_port), MSGJPN334); | |
2395 | 2372 | } |
2396 | 2373 | else |
2397 | 2374 | { |
2398 | 2375 | if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER)) |
2399 | 2376 | { |
2400 | 2377 | UseIPadrs = NO; |
2401 | - SetTaskMsg(MSGJPN018, PreMsg, DomainName, ntohs(CurSockAddrIPv6.sin6_port), MSGJPN334); | |
2378 | + SetTaskMsg(MSGJPN018, PreMsg, DomainName, ntohs(CurSockAddr.sin6_port), MSGJPN334); | |
2402 | 2379 | } |
2403 | 2380 | else |
2404 | 2381 | { |
@@ -2408,47 +2385,48 @@ SOCKET connectsockIPv6(char *host, int port, char *PreMsg, int *CancelCheckWork) | ||
2408 | 2385 | } |
2409 | 2386 | } |
2410 | 2387 | else |
2411 | - SetTaskMsg(MSGJPN020, PreMsg, inet6_ntoa(CurSockAddrIPv6.sin6_addr), ntohs(CurSockAddrIPv6.sin6_port), MSGJPN334); | |
2388 | + SetTaskMsg(MSGJPN020, PreMsg, inet6_ntoa(CurSockAddr.sin6_addr), ntohs(CurSockAddr.sin6_port), MSGJPN334); | |
2412 | 2389 | |
2413 | 2390 | if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER)) |
2414 | 2391 | { |
2415 | 2392 | // SOCKSを使う |
2416 | 2393 | // SOCKSに接続する準備 |
2417 | 2394 | { |
2418 | - Len = Socks5MakeCmdPacketIPv6(&Socks5Cmd, SOCKS5_CMD_CONNECT, UseIPadrs, (char*)&CurSockAddrIPv6.sin6_addr, DomainName, CurSockAddrIPv6.sin6_port); | |
2395 | + Len = Socks5MakeCmdPacketIPv6(&Socks5Cmd, SOCKS5_CMD_CONNECT, UseIPadrs, (char*)&CurSockAddr.sin6_addr, DomainName, CurSockAddr.sin6_port); | |
2419 | 2396 | } |
2420 | 2397 | |
2421 | - memset(&SocksSockAddrIPv6, 0, sizeof(SocksSockAddrIPv6)); | |
2422 | - SocksSockAddrIPv6.sin6_addr = inet6_addr(FwallHost); | |
2423 | - if(memcmp(&SocksSockAddrIPv6.sin6_addr, &IN6ADDR_NONE, sizeof(struct in6_addr)) == 0) | |
2398 | + memset(&SocksSockAddr, 0, sizeof(SocksSockAddr)); | |
2399 | + SocksSockAddr.sin6_addr = inet6_addr(FwallHost); | |
2400 | + if(memcmp(&SocksSockAddr.sin6_addr, &IN6ADDR_NONE, sizeof(struct in6_addr)) == 0) | |
2424 | 2401 | { |
2425 | 2402 | if((pHostEntry = do_gethostbynameIPv6(FwallHost, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork)) != NULL) |
2426 | - memcpy((char *)&SocksSockAddrIPv6.sin6_addr, pHostEntry->h_addr, pHostEntry->h_length); | |
2403 | + memcpy((char *)&SocksSockAddr.sin6_addr, pHostEntry->h_addr, pHostEntry->h_length); | |
2427 | 2404 | else |
2428 | 2405 | { |
2429 | 2406 | SetTaskMsg(MSGJPN021, FwallHost, MSGJPN334); |
2430 | 2407 | return INVALID_SOCKET; |
2431 | 2408 | } |
2432 | 2409 | } |
2433 | - SocksSockAddrIPv6.sin6_port = htons((u_short)FwallPort); | |
2434 | - SocksSockAddrIPv6.sin6_family = AF_INET6; | |
2435 | - SetTaskMsg(MSGJPN022, inet6_ntoa(SocksSockAddrIPv6.sin6_addr), ntohs(SocksSockAddrIPv6.sin6_port), MSGJPN334); | |
2410 | + SocksSockAddr.sin6_port = htons((u_short)FwallPort); | |
2411 | + SocksSockAddr.sin6_family = AF_INET6; | |
2412 | + SetTaskMsg(MSGJPN022, inet6_ntoa(SocksSockAddr.sin6_addr), ntohs(SocksSockAddr.sin6_port), MSGJPN334); | |
2436 | 2413 | // connectで接続する先はSOCKSサーバ |
2437 | - memcpy(&saSockAddr, &SocksSockAddrIPv6, sizeof(SocksSockAddrIPv6)); | |
2414 | + memcpy(&saSockAddr, &SocksSockAddr, sizeof(SocksSockAddr)); | |
2438 | 2415 | } |
2439 | 2416 | else |
2440 | 2417 | { |
2441 | 2418 | // connectで接続するのは接続先のホスト |
2442 | - memcpy(&saSockAddr, &CurSockAddrIPv6, sizeof(CurSockAddrIPv6)); | |
2419 | + memcpy(&saSockAddr, &CurSockAddr, sizeof(CurSockAddr)); | |
2443 | 2420 | } |
2444 | 2421 | |
2445 | 2422 | ///////////// |
2446 | 2423 | // 接続実行 |
2447 | 2424 | ///////////// |
2448 | 2425 | |
2449 | - inet6_ntoa(saSockAddr.sin6_addr); | |
2450 | 2426 | if((sSocket = do_socket(AF_INET6, SOCK_STREAM, TCP_PORT)) != INVALID_SOCKET) |
2451 | 2427 | { |
2428 | + // ソケットにデータを付与 | |
2429 | + SetAsyncTableDataIPv6(sSocket, &CurSockAddr, &SocksSockAddr); | |
2452 | 2430 | if(do_connect(sSocket, (struct sockaddr *)&saSockAddr, sizeof(saSockAddr), CancelCheckWork) != SOCKET_ERROR) |
2453 | 2431 | { |
2454 | 2432 | if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER)) |
@@ -2524,6 +2502,9 @@ SOCKET GetFTPListenSocket(SOCKET ctrl_skt, int *CancelCheckWork) | ||
2524 | 2502 | //SOCKET GetFTPListenSocket(SOCKET ctrl_skt, int *CancelCheckWork) |
2525 | 2503 | SOCKET GetFTPListenSocketIPv4(SOCKET ctrl_skt, int *CancelCheckWork) |
2526 | 2504 | { |
2505 | + // IPv6対応 | |
2506 | + struct sockaddr_in SocksSockAddr; /* SOCKSサーバのアドレス情報 */ | |
2507 | + struct sockaddr_in CurSockAddr; /* 接続先ホストのアドレス情報 */ | |
2527 | 2508 | SOCKET listen_skt; |
2528 | 2509 | int iLength; |
2529 | 2510 | char *a,*p; |
@@ -2537,6 +2518,9 @@ SOCKET GetFTPListenSocketIPv4(SOCKET ctrl_skt, int *CancelCheckWork) | ||
2537 | 2518 | int Len; |
2538 | 2519 | int Fwall; |
2539 | 2520 | |
2521 | + // ソケットにデータを付与 | |
2522 | + GetAsyncTableDataIPv4(ctrl_skt, &CurSockAddr, &SocksSockAddr); | |
2523 | + | |
2540 | 2524 | Fwall = FWALL_NONE; |
2541 | 2525 | if(AskHostFireWall() == YES) |
2542 | 2526 | Fwall = FwallType; |
@@ -2547,17 +2531,12 @@ SOCKET GetFTPListenSocketIPv4(SOCKET ctrl_skt, int *CancelCheckWork) | ||
2547 | 2531 | { |
2548 | 2532 | /*===== SOCKS4を使う =====*/ |
2549 | 2533 | DoPrintf("Use SOCKS4 BIND"); |
2550 | - // IPv6対応 | |
2551 | -// if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddr, sizeof(SocksSockAddr), CancelCheckWork) != SOCKET_ERROR) | |
2552 | - if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddrIPv4, sizeof(SocksSockAddrIPv4), CancelCheckWork) != SOCKET_ERROR) | |
2534 | + if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddr, sizeof(SocksSockAddr), CancelCheckWork) != SOCKET_ERROR) | |
2553 | 2535 | { |
2554 | 2536 | Socks4Cmd.Ver = SOCKS4_VER; |
2555 | 2537 | Socks4Cmd.Cmd = SOCKS4_CMD_BIND; |
2556 | - // IPv6対応 | |
2557 | -// Socks4Cmd.Port = CurSockAddr.sin_port; | |
2558 | -// Socks4Cmd.AdrsInt = CurSockAddr.sin_addr.s_addr; | |
2559 | - Socks4Cmd.Port = CurSockAddrIPv4.sin_port; | |
2560 | - Socks4Cmd.AdrsInt = CurSockAddrIPv4.sin_addr.s_addr; | |
2538 | + Socks4Cmd.Port = CurSockAddr.sin_port; | |
2539 | + Socks4Cmd.AdrsInt = CurSockAddr.sin_addr.s_addr; | |
2561 | 2540 | strcpy(Socks4Cmd.UserID, FwallUser); |
2562 | 2541 | Len = offsetof(SOCKS4CMD, UserID) + strlen(FwallUser) + 1; |
2563 | 2542 |
@@ -2578,9 +2557,7 @@ SOCKET GetFTPListenSocketIPv4(SOCKET ctrl_skt, int *CancelCheckWork) | ||
2578 | 2557 | } |
2579 | 2558 | |
2580 | 2559 | if(Socks4Reply.AdrsInt == 0) |
2581 | - // IPv6対応 | |
2582 | -// Socks4Reply.AdrsInt = SocksSockAddr.sin_addr.s_addr; | |
2583 | - Socks4Reply.AdrsInt = SocksSockAddrIPv4.sin_addr.s_addr; | |
2560 | + Socks4Reply.AdrsInt = SocksSockAddr.sin_addr.s_addr; | |
2584 | 2561 | |
2585 | 2562 | a = (char *)&Socks4Reply.AdrsInt; |
2586 | 2563 | p = (char *)&Socks4Reply.Port; |
@@ -2590,9 +2567,7 @@ SOCKET GetFTPListenSocketIPv4(SOCKET ctrl_skt, int *CancelCheckWork) | ||
2590 | 2567 | { |
2591 | 2568 | /*===== SOCKS5を使う =====*/ |
2592 | 2569 | DoPrintf("Use SOCKS5 BIND"); |
2593 | - // IPv6対応 | |
2594 | -// if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddr, sizeof(SocksSockAddr), CancelCheckWork) != SOCKET_ERROR) | |
2595 | - if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddrIPv4, sizeof(SocksSockAddrIPv4), CancelCheckWork) != SOCKET_ERROR) | |
2570 | + if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddr, sizeof(SocksSockAddr), CancelCheckWork) != SOCKET_ERROR) | |
2596 | 2571 | { |
2597 | 2572 | if(Socks5SelMethod(listen_skt, CancelCheckWork) == FFFTP_FAIL) |
2598 | 2573 | { |
@@ -2601,9 +2576,7 @@ SOCKET GetFTPListenSocketIPv4(SOCKET ctrl_skt, int *CancelCheckWork) | ||
2601 | 2576 | return(listen_skt); |
2602 | 2577 | } |
2603 | 2578 | |
2604 | - // IPv6対応 | |
2605 | -// Len = Socks5MakeCmdPacket(&Socks5Cmd, SOCKS5_CMD_BIND, UseIPadrs, CurSockAddr.sin_addr.s_addr, DomainName, CurSockAddr.sin_port); | |
2606 | - Len = Socks5MakeCmdPacket(&Socks5Cmd, SOCKS5_CMD_BIND, UseIPadrs, CurSockAddrIPv4.sin_addr.s_addr, DomainName, CurSockAddrIPv4.sin_port); | |
2579 | + Len = Socks5MakeCmdPacket(&Socks5Cmd, SOCKS5_CMD_BIND, UseIPadrs, CurSockAddr.sin_addr.s_addr, DomainName, CurSockAddr.sin_port); | |
2607 | 2580 | |
2608 | 2581 | Socks5Reply.Result = -1; |
2609 | 2582 | // 同時接続対応 |
@@ -2711,6 +2684,8 @@ SOCKET GetFTPListenSocketIPv4(SOCKET ctrl_skt, int *CancelCheckWork) | ||
2711 | 2684 | |
2712 | 2685 | SOCKET GetFTPListenSocketIPv6(SOCKET ctrl_skt, int *CancelCheckWork) |
2713 | 2686 | { |
2687 | + struct sockaddr_in6 SocksSockAddr; /* SOCKSサーバのアドレス情報 */ | |
2688 | + struct sockaddr_in6 CurSockAddr; /* 接続先ホストのアドレス情報 */ | |
2714 | 2689 | SOCKET listen_skt; |
2715 | 2690 | int iLength; |
2716 | 2691 | char *a,*p; |
@@ -2724,6 +2699,9 @@ SOCKET GetFTPListenSocketIPv6(SOCKET ctrl_skt, int *CancelCheckWork) | ||
2724 | 2699 | |
2725 | 2700 | char Adrs[40]; |
2726 | 2701 | |
2702 | + // ソケットにデータを付与 | |
2703 | + GetAsyncTableDataIPv6(ctrl_skt, &CurSockAddr, &SocksSockAddr); | |
2704 | + | |
2727 | 2705 | Fwall = FWALL_NONE; |
2728 | 2706 | if(AskHostFireWall() == YES) |
2729 | 2707 | Fwall = FwallType; |
@@ -2734,7 +2712,7 @@ SOCKET GetFTPListenSocketIPv6(SOCKET ctrl_skt, int *CancelCheckWork) | ||
2734 | 2712 | { |
2735 | 2713 | /*===== SOCKS5を使う =====*/ |
2736 | 2714 | DoPrintf("Use SOCKS5 BIND"); |
2737 | - if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddrIPv6, sizeof(SocksSockAddrIPv6), CancelCheckWork) != SOCKET_ERROR) | |
2715 | + if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddr, sizeof(SocksSockAddr), CancelCheckWork) != SOCKET_ERROR) | |
2738 | 2716 | { |
2739 | 2717 | if(Socks5SelMethod(listen_skt, CancelCheckWork) == FFFTP_FAIL) |
2740 | 2718 | { |
@@ -2743,7 +2721,7 @@ SOCKET GetFTPListenSocketIPv6(SOCKET ctrl_skt, int *CancelCheckWork) | ||
2743 | 2721 | return(listen_skt); |
2744 | 2722 | } |
2745 | 2723 | |
2746 | - Len = Socks5MakeCmdPacketIPv6(&Socks5Cmd, SOCKS5_CMD_BIND, UseIPadrs, (char*)&CurSockAddrIPv6.sin6_addr, DomainName, CurSockAddrIPv6.sin6_port); | |
2724 | + Len = Socks5MakeCmdPacketIPv6(&Socks5Cmd, SOCKS5_CMD_BIND, UseIPadrs, (char*)&CurSockAddr.sin6_addr, DomainName, CurSockAddr.sin6_port); | |
2747 | 2725 | |
2748 | 2726 | Socks5Reply.Result = -1; |
2749 | 2727 | // 同時接続対応 |
@@ -4051,7 +4051,7 @@ static int GetAdrsAndPortIPv6(SOCKET Skt, char *Str, char *Adrs, int *Port, int | ||
4051 | 4051 | char *Pos; |
4052 | 4052 | char *Btm; |
4053 | 4053 | int Sts; |
4054 | - int i; | |
4054 | +// int i; | |
4055 | 4055 | struct sockaddr_in6 SockAddr; |
4056 | 4056 | |
4057 | 4057 | Sts = FFFTP_FAIL; |
@@ -4080,8 +4080,9 @@ static int GetAdrsAndPortIPv6(SOCKET Skt, char *Str, char *Adrs, int *Port, int | ||
4080 | 4080 | } |
4081 | 4081 | else |
4082 | 4082 | { |
4083 | - i = sizeof(SockAddr); | |
4084 | - if(getpeername(Skt, (struct sockaddr*)&SockAddr, &i) != SOCKET_ERROR) | |
4083 | +// i = sizeof(SockAddr); | |
4084 | +// if(getpeername(Skt, (struct sockaddr*)&SockAddr, &i) != SOCKET_ERROR) | |
4085 | + if(GetAsyncTableDataIPv6(Skt, &SockAddr, NULL) == YES) | |
4085 | 4086 | AddressToStringIPv6(Adrs, &SockAddr.sin6_addr); |
4086 | 4087 | } |
4087 | 4088 |
@@ -234,7 +234,7 @@ BYTE SSLRootCAFileHash[20]; | ||
234 | 234 | // ファイルアイコン表示対応 |
235 | 235 | int DispFileIcon = NO; |
236 | 236 | // ディレクトリ自動作成 |
237 | -int MakeAllDir = NO; | |
237 | +int MakeAllDir = YES; | |
238 | 238 | |
239 | 239 | |
240 | 240 |
@@ -66,6 +66,11 @@ typedef struct { | ||
66 | 66 | int FdRead; |
67 | 67 | int FdWrite; |
68 | 68 | int Error; |
69 | + // ソケットにデータを付与 | |
70 | + struct sockaddr_in HostAddrIPv4; | |
71 | + struct sockaddr_in SocksAddrIPv4; | |
72 | + struct sockaddr_in6 HostAddrIPv6; | |
73 | + struct sockaddr_in6 SocksAddrIPv6; | |
69 | 74 | } ASYNCSIGNAL; |
70 | 75 | |
71 | 76 |
@@ -489,6 +494,11 @@ static int RegisterAsyncTable(SOCKET s) | ||
489 | 494 | Signal[Pos].FdAccept = 0; |
490 | 495 | Signal[Pos].FdRead = 0; |
491 | 496 | Signal[Pos].FdWrite = 0; |
497 | + // ソケットにデータを付与 | |
498 | + memset(&Signal[Pos].HostAddrIPv4, 0, sizeof(struct sockaddr_in)); | |
499 | + memset(&Signal[Pos].SocksAddrIPv4, 0, sizeof(struct sockaddr_in)); | |
500 | + memset(&Signal[Pos].HostAddrIPv6, 0, sizeof(struct sockaddr_in6)); | |
501 | + memset(&Signal[Pos].SocksAddrIPv6, 0, sizeof(struct sockaddr_in6)); | |
492 | 502 | Sts = YES; |
493 | 503 | break; |
494 | 504 | } |
@@ -639,6 +649,104 @@ static int UnregisterAsyncTableDbase(HANDLE Async) | ||
639 | 649 | } |
640 | 650 | |
641 | 651 | |
652 | +// ソケットにデータを付与 | |
653 | + | |
654 | +int SetAsyncTableDataIPv4(SOCKET s, struct sockaddr_in* Host, struct sockaddr_in* Socks) | |
655 | +{ | |
656 | + int Sts; | |
657 | + int Pos; | |
658 | + | |
659 | + WaitForSingleObject(hAsyncTblAccMutex, INFINITE); | |
660 | + Sts = NO; | |
661 | + for(Pos = 0; Pos < MAX_SIGNAL_ENTRY; Pos++) | |
662 | + { | |
663 | + if(Signal[Pos].Socket == s) | |
664 | + { | |
665 | + if(Host != NULL) | |
666 | + memcpy(&Signal[Pos].HostAddrIPv4, Host, sizeof(struct sockaddr_in)); | |
667 | + if(Socks != NULL) | |
668 | + memcpy(&Signal[Pos].SocksAddrIPv4, Socks, sizeof(struct sockaddr_in)); | |
669 | + Sts = YES; | |
670 | + break; | |
671 | + } | |
672 | + } | |
673 | + ReleaseMutex(hAsyncTblAccMutex); | |
674 | + | |
675 | + return(Sts); | |
676 | +} | |
677 | + | |
678 | +int SetAsyncTableDataIPv6(SOCKET s, struct sockaddr_in6* Host, struct sockaddr_in6* Socks) | |
679 | +{ | |
680 | + int Sts; | |
681 | + int Pos; | |
682 | + | |
683 | + WaitForSingleObject(hAsyncTblAccMutex, INFINITE); | |
684 | + Sts = NO; | |
685 | + for(Pos = 0; Pos < MAX_SIGNAL_ENTRY; Pos++) | |
686 | + { | |
687 | + if(Signal[Pos].Socket == s) | |
688 | + { | |
689 | + if(Host != NULL) | |
690 | + memcpy(&Signal[Pos].HostAddrIPv6, Host, sizeof(struct sockaddr_in6)); | |
691 | + if(Socks != NULL) | |
692 | + memcpy(&Signal[Pos].SocksAddrIPv6, Socks, sizeof(struct sockaddr_in6)); | |
693 | + Sts = YES; | |
694 | + break; | |
695 | + } | |
696 | + } | |
697 | + ReleaseMutex(hAsyncTblAccMutex); | |
698 | + | |
699 | + return(Sts); | |
700 | +} | |
701 | + | |
702 | +int GetAsyncTableDataIPv4(SOCKET s, struct sockaddr_in* Host, struct sockaddr_in* Socks) | |
703 | +{ | |
704 | + int Sts; | |
705 | + int Pos; | |
706 | + | |
707 | + WaitForSingleObject(hAsyncTblAccMutex, INFINITE); | |
708 | + Sts = NO; | |
709 | + for(Pos = 0; Pos < MAX_SIGNAL_ENTRY; Pos++) | |
710 | + { | |
711 | + if(Signal[Pos].Socket == s) | |
712 | + { | |
713 | + if(Host != NULL) | |
714 | + memcpy(Host, &Signal[Pos].HostAddrIPv4, sizeof(struct sockaddr_in)); | |
715 | + if(Socks != NULL) | |
716 | + memcpy(Socks, &Signal[Pos].SocksAddrIPv4, sizeof(struct sockaddr_in)); | |
717 | + Sts = YES; | |
718 | + break; | |
719 | + } | |
720 | + } | |
721 | + ReleaseMutex(hAsyncTblAccMutex); | |
722 | + | |
723 | + return(Sts); | |
724 | +} | |
725 | + | |
726 | +int GetAsyncTableDataIPv6(SOCKET s, struct sockaddr_in6* Host, struct sockaddr_in6* Socks) | |
727 | +{ | |
728 | + int Sts; | |
729 | + int Pos; | |
730 | + | |
731 | + WaitForSingleObject(hAsyncTblAccMutex, INFINITE); | |
732 | + Sts = NO; | |
733 | + for(Pos = 0; Pos < MAX_SIGNAL_ENTRY; Pos++) | |
734 | + { | |
735 | + if(Signal[Pos].Socket == s) | |
736 | + { | |
737 | + if(Host != NULL) | |
738 | + memcpy(Host, &Signal[Pos].HostAddrIPv6, sizeof(struct sockaddr_in6)); | |
739 | + if(Socks != NULL) | |
740 | + memcpy(Socks, &Signal[Pos].SocksAddrIPv6, sizeof(struct sockaddr_in6)); | |
741 | + Sts = YES; | |
742 | + break; | |
743 | + } | |
744 | + } | |
745 | + ReleaseMutex(hAsyncTblAccMutex); | |
746 | + | |
747 | + return(Sts); | |
748 | +} | |
749 | + | |
642 | 750 | |
643 | 751 | |
644 | 752 |
@@ -720,7 +828,7 @@ struct hostent *do_gethostbynameIPv6(const char *Name, char *Buf, int Len, int * | ||
720 | 828 | |
721 | 829 | if(*CancelCheckWork == YES) |
722 | 830 | { |
723 | - WSACancelAsyncRequest(hAsync); | |
831 | + WSACancelAsyncRequestIPv6(hAsync); | |
724 | 832 | } |
725 | 833 | else if(Error == 0) |
726 | 834 | { |
@@ -641,6 +641,8 @@ int FTPS_recv(SOCKET s, char * buf, int len, int flags) | ||
641 | 641 | |
642 | 642 | // IPv6対応 |
643 | 643 | |
644 | +const struct in6_addr IN6ADDR_NONE = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; | |
645 | + | |
644 | 646 | typedef struct |
645 | 647 | { |
646 | 648 | HANDLE h; |
@@ -682,7 +684,7 @@ DWORD WINAPI WSAAsyncGetHostByNameIPv6ThreadProc(LPVOID lpParameter) | ||
682 | 684 | pHost->h_addr_list[0] = (char*)(&pHost->h_addr_list[2]); |
683 | 685 | pHost->h_addr_list[1] = NULL; |
684 | 686 | memcpy(pHost->h_addr_list[0], &((struct sockaddr_in*)p->ai_addr)->sin_addr, sizeof(struct in_addr)); |
685 | - PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(sizeof(struct hostent) + sizeof(char*) * 2 + p->ai_addrlen)); | |
687 | + PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(sizeof(struct hostent) + sizeof(char*) * 2 + sizeof(struct in_addr))); | |
686 | 688 | } |
687 | 689 | else |
688 | 690 | PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(WSAENOBUFS << 16)); |
@@ -700,7 +702,7 @@ DWORD WINAPI WSAAsyncGetHostByNameIPv6ThreadProc(LPVOID lpParameter) | ||
700 | 702 | pHost->h_addr_list[0] = (char*)(&pHost->h_addr_list[2]); |
701 | 703 | pHost->h_addr_list[1] = NULL; |
702 | 704 | memcpy(pHost->h_addr_list[0], &((struct sockaddr_in6*)p->ai_addr)->sin6_addr, sizeof(struct in6_addr)); |
703 | - PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(sizeof(struct hostent) + sizeof(char*) * 2 + p->ai_addrlen)); | |
705 | + PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(sizeof(struct hostent) + sizeof(char*) * 2 + sizeof(struct in6_addr))); | |
704 | 706 | } |
705 | 707 | else |
706 | 708 | PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(WSAENOBUFS << 16)); |
@@ -768,7 +770,10 @@ int WSACancelAsyncRequestIPv6(HANDLE hAsyncTaskHandle) | ||
768 | 770 | int Result; |
769 | 771 | Result = SOCKET_ERROR; |
770 | 772 | if(TerminateThread(hAsyncTaskHandle, 0)) |
773 | + { | |
774 | + CloseHandle(hAsyncTaskHandle); | |
771 | 775 | Result = 0; |
776 | + } | |
772 | 777 | return Result; |
773 | 778 | } |
774 | 779 |
@@ -844,7 +849,7 @@ struct in6_addr inet6_addr(const char* cp) | ||
844 | 849 | { |
845 | 850 | if(!cp) |
846 | 851 | { |
847 | - memset(&Result, 0xff, sizeof(Result)); | |
852 | + memcpy(&Result, &IN6ADDR_NONE, sizeof(struct in6_addr)); | |
848 | 853 | break; |
849 | 854 | } |
850 | 855 | if(i >= AfterZero) |
@@ -868,7 +873,7 @@ struct in6_addr inet6_addr(const char* cp) | ||
868 | 873 | Result.u.Word[i] = ((Result.u.Word[i] & 0xff00) >> 8) | ((Result.u.Word[i] & 0x00ff) << 8); |
869 | 874 | if(strncmp(p, ":", 1) != 0 && strlen(p) > 0) |
870 | 875 | { |
871 | - memset(&Result, 0xff, sizeof(Result)); | |
876 | + memcpy(&Result, &IN6ADDR_NONE, sizeof(struct in6_addr)); | |
872 | 877 | break; |
873 | 878 | } |
874 | 879 | if(cp = strstr(cp, ":")) |
@@ -40,6 +40,8 @@ struct in6_addr inet6_addr(const char* cp); | ||
40 | 40 | HANDLE WSAAsyncGetHostByNameM(HWND hWnd, u_int wMsg, const char * name, char * buf, int buflen); |
41 | 41 | HANDLE WSAAsyncGetHostByNameIPv6M(HWND hWnd, u_int wMsg, const char * name, char * buf, int buflen, short Family); |
42 | 42 | |
43 | +extern const struct in6_addr IN6ADDR_NONE; | |
44 | + | |
43 | 45 | BOOL LoadPuTTY(); |
44 | 46 | void FreePuTTY(); |
45 | 47 | BOOL IsPuTTYLoaded(); |