FFFTPのソースコードです。
Revision | 700b7eb9066c105aaf9b42ad67ba43ee8c030f0b (tree) |
---|---|
Time | 2011-11-14 21:12:33 |
Author | s_kawamoto <s_kawamoto@user...> |
Commiter | s_kawamoto |
Fix bugs of routines for IPv6.
Fix bugs of opening wrong files when they contain no extensions.
Fix bugs of UTF-8 to UTF-16 API bridge.
Fix bugs of treating local filenames.
Modify documents.
@@ -31,6 +31,8 @@ | ||
31 | 31 | //#define WINVER 0x400 |
32 | 32 | |
33 | 33 | #define STRICT |
34 | +// IPv6対応 | |
35 | +#include <winsock2.h> | |
34 | 36 | #include <windows.h> |
35 | 37 | #include <stdio.h> |
36 | 38 | #include <stdlib.h> |
@@ -28,6 +28,8 @@ | ||
28 | 28 | /============================================================================*/ |
29 | 29 | |
30 | 30 | #define STRICT |
31 | +// IPv6対応 | |
32 | +#include <winsock2.h> | |
31 | 33 | #include <windows.h> |
32 | 34 | #include <stdio.h> |
33 | 35 | #include <stdlib.h> |
@@ -28,6 +28,8 @@ | ||
28 | 28 | /============================================================================*/ |
29 | 29 | |
30 | 30 | #define STRICT |
31 | +// IPv6対応 | |
32 | +#include <winsock2.h> | |
31 | 33 | #include <windows.h> |
32 | 34 | #include <stdio.h> |
33 | 35 | #include <stdlib.h> |
@@ -31,7 +31,9 @@ | ||
31 | 31 | #include <stdio.h> |
32 | 32 | #include <stdlib.h> |
33 | 33 | #include <string.h> |
34 | -#include <winsock.h> | |
34 | +// IPv6対応 | |
35 | +//#include <winsock.h> | |
36 | +#include <winsock2.h> | |
35 | 37 | #include <mbstring.h> |
36 | 38 | #include <windowsx.h> |
37 | 39 |
@@ -1695,6 +1695,8 @@ int ConvertNum(int x, int Dir, const INTCONVTBL *Tbl, int Num); | ||
1695 | 1695 | int MoveFileToTrashCan(char *Path); |
1696 | 1696 | LONGLONG MakeLongLong(DWORD High, DWORD Low); |
1697 | 1697 | char *MakeNumString(LONGLONG Num, char *Buf, BOOL Comma); |
1698 | +// 異なるファイルが表示されるバグ修正 | |
1699 | +char* MakeDistinguishableFileName(char* Out, char* In); | |
1698 | 1700 | |
1699 | 1701 | /*===== dlgsize.c =====*/ |
1700 | 1702 |
@@ -1751,10 +1753,6 @@ int do_send(SOCKET s, const char *buf, int len, int flags, int *TimeOutErr, int | ||
1751 | 1753 | void RemoveReceivedData(SOCKET s); |
1752 | 1754 | int CheckClosedAndReconnect(void); |
1753 | 1755 | void CheckAllEventClosed(void); |
1754 | -// IPv6対応 | |
1755 | -char* AddressToStringIPv6(char* str, void* in6); | |
1756 | -char* inet6_ntoa(struct in6_addr in6); | |
1757 | -struct in6_addr inet6_addr(const char* cp); | |
1758 | 1756 | |
1759 | 1757 | /*===== updatebell.c =====*/ |
1760 | 1758 |
@@ -37,7 +37,7 @@ | ||
37 | 37 | #include <time.h> |
38 | 38 | // IPv6対応 |
39 | 39 | //#include <winsock.h> |
40 | -#include <ws2tcpip.h> | |
40 | +#include <winsock2.h> | |
41 | 41 | #include <windowsx.h> |
42 | 42 | #include <commctrl.h> |
43 | 43 |
@@ -28,6 +28,8 @@ | ||
28 | 28 | /============================================================================*/ |
29 | 29 | |
30 | 30 | #define STRICT |
31 | +// IPv6対応 | |
32 | +#include <winsock2.h> | |
31 | 33 | #include <windows.h> |
32 | 34 | #include <stdio.h> |
33 | 35 | #include <stdlib.h> |
@@ -35,7 +37,8 @@ | ||
35 | 37 | #include <mbstring.h> |
36 | 38 | #include <malloc.h> |
37 | 39 | #include <windowsx.h> |
38 | -#include <winsock.h> | |
40 | +// IPv6対応 | |
41 | +//#include <winsock.h> | |
39 | 42 | |
40 | 43 | #include "common.h" |
41 | 44 | #include "resource.h" |
@@ -28,6 +28,8 @@ | ||
28 | 28 | /============================================================================*/ |
29 | 29 | |
30 | 30 | #define STRICT |
31 | +// IPv6対応 | |
32 | +#include <winsock2.h> | |
31 | 33 | #include <windows.h> |
32 | 34 | #include <stdio.h> |
33 | 35 | #include <stdlib.h> |
@@ -49,6 +49,10 @@ Changes in Ver.1.99 | ||
49 | 49 | |
50 | 50 | -- Changed to detect encoding of strings in INI file automatically. |
51 | 51 | |
52 | +-- Added settings to reuse connection of the main window for transfer threads. | |
53 | + This may allow to transfer files successfully as with 1.97b or earlier, | |
54 | + but sometimes may cause some errors. | |
55 | + | |
52 | 56 | |
53 | 57 | Outline |
54 | 58 | ------- |
@@ -47,6 +47,10 @@ Changes in Ver.1.98c | ||
47 | 47 | |
48 | 48 | -- Changed size and layout of the window at the first run. |
49 | 49 | |
50 | +-- Added settings to reuse connection of the main window for transfer threads. | |
51 | + This may allow to transfer files successfully as with 1.97b or earlier, | |
52 | + but sometimes may cause some errors. | |
53 | + | |
50 | 54 | Changes in Ver.1.98b |
51 | 55 | -------------------- |
52 | 56 |
@@ -51,6 +51,10 @@ Ver 1.99 | ||
51 | 51 | |
52 | 52 | ・INIファイルの文字列の文字コードを自動判別するように変更しました。 |
53 | 53 | |
54 | +・メインウィンドウが使用している接続を転送用に再使用するための設定を | |
55 | + 追加しました。これにより1.97b以前で転送可能だったが1.98で転送不能に | |
56 | + なるという症状が改善されますが、不具合が発生する可能性があります。 | |
57 | + | |
54 | 58 | |
55 | 59 | Ver 1.96d以前へ戻す場合 |
56 | 60 | ----------------------- |
@@ -23,6 +23,10 @@ FFFTP | ||
23 | 23 | |
24 | 24 | ・INIファイルの文字列の文字コードを自動判別するように変更しました。 |
25 | 25 | |
26 | +・メインウィンドウが使用している接続を転送用に再使用するための設定を | |
27 | + 追加しました。これにより1.97b以前で転送可能だったが1.98で転送不能に | |
28 | + なるという症状が改善されますが、不具合が発生する可能性があります。 | |
29 | + | |
26 | 30 | ■Ver 1.98c |
27 | 31 | |
28 | 32 | ・日本語ドメイン名のホストへの接続時にアドレスをPunycodeへ変換してから |
@@ -31,6 +31,8 @@ | ||
31 | 31 | //#define _WIN32_WINNT 0x400 |
32 | 32 | |
33 | 33 | #define STRICT |
34 | +// IPv6対応 | |
35 | +#include <winsock2.h> | |
34 | 36 | #include <windows.h> |
35 | 37 | #include <stdio.h> |
36 | 38 | #include <stdlib.h> |
@@ -28,6 +28,8 @@ | ||
28 | 28 | /============================================================================*/ |
29 | 29 | |
30 | 30 | #define STRICT |
31 | +// IPv6対応 | |
32 | +#include <winsock2.h> | |
31 | 33 | #include <windows.h> |
32 | 34 | #include <stdio.h> |
33 | 35 | #include <stdlib.h> |
@@ -2098,7 +2100,9 @@ static void DelNotifyAndDo(FILELIST *Dt, int Win, int *Sw, int *Flg, char *CurDi | ||
2098 | 2100 | { |
2099 | 2101 | sprintf(TmpString, "%s", Path); |
2100 | 2102 | |
2101 | - if(AskHostType() == HTYPE_VMS) | |
2103 | + // ローカルのファイルのパスの最後の'\\'が消えるバグ修正 | |
2104 | +// if(AskHostType() == HTYPE_VMS) | |
2105 | + if(Win == WIN_REMOTE && AskHostType() == HTYPE_VMS) | |
2102 | 2106 | ReformToVMSstylePathName(TmpString); |
2103 | 2107 | |
2104 | 2108 | CurWin = Win; |
@@ -43,7 +43,7 @@ | ||
43 | 43 | #include <time.h> |
44 | 44 | // IPv6対応 |
45 | 45 | //#include <winsock.h> |
46 | -#include <ws2tcpip.h> | |
46 | +#include <winsock2.h> | |
47 | 47 | #include <windowsx.h> |
48 | 48 | #include <commctrl.h> |
49 | 49 | #include <process.h> |
@@ -28,6 +28,8 @@ | ||
28 | 28 | /============================================================================*/ |
29 | 29 | |
30 | 30 | #define STRICT |
31 | +// IPv6対応 | |
32 | +#include <winsock2.h> | |
31 | 33 | #include <windows.h> |
32 | 34 | #include <stdio.h> |
33 | 35 | #include <stdlib.h> |
@@ -37,7 +39,8 @@ | ||
37 | 39 | #include <windowsx.h> |
38 | 40 | #include <commctrl.h> |
39 | 41 | #include <stdarg.h> |
40 | -#include <winsock.h> | |
42 | +// IPv6対応 | |
43 | +//#include <winsock.h> | |
41 | 44 | |
42 | 45 | #include "common.h" |
43 | 46 | #include "resource.h" |
@@ -28,6 +28,8 @@ | ||
28 | 28 | /============================================================================*/ |
29 | 29 | |
30 | 30 | #define STRICT |
31 | +// IPv6対応 | |
32 | +#include <winsock2.h> | |
31 | 33 | #include <windows.h> |
32 | 34 | #include <stdio.h> |
33 | 35 | #include <stdlib.h> |
@@ -28,6 +28,8 @@ | ||
28 | 28 | /============================================================================*/ |
29 | 29 | |
30 | 30 | #define STRICT |
31 | +// IPv6対応 | |
32 | +#include <winsock2.h> | |
31 | 33 | #include <windows.h> |
32 | 34 | #include <stdio.h> |
33 | 35 | #include <stdlib.h> |
@@ -182,8 +184,6 @@ void DispFileProperty(char *Fname) | ||
182 | 184 | { |
183 | 185 | SHELLEXECUTEINFO sInfo; |
184 | 186 | // 異なるファイルが表示されるバグ修正 |
185 | - // UNCでない場合に末尾に半角スペースを置くと拡張子の補完がされなくなる | |
186 | - // 現在UNC対応の予定は無い | |
187 | 187 | char Fname2[FMAX_PATH+1]; |
188 | 188 | |
189 | 189 | memset(&sInfo, NUL, sizeof(SHELLEXECUTEINFO)); |
@@ -193,9 +193,7 @@ void DispFileProperty(char *Fname) | ||
193 | 193 | sInfo.lpVerb = "Properties"; |
194 | 194 | // 異なるファイルが表示されるバグ修正 |
195 | 195 | // sInfo.lpFile = Fname; |
196 | - strcpy(Fname2, Fname); | |
197 | - strcat(Fname2, " "); | |
198 | - sInfo.lpFile = Fname2; | |
196 | + sInfo.lpFile = MakeDistinguishableFileName(Fname2, Fname); | |
199 | 197 | sInfo.lpParameters = NULL; |
200 | 198 | sInfo.lpDirectory = NULL; |
201 | 199 | sInfo.nShow = SW_NORMAL; |
@@ -30,6 +30,8 @@ | ||
30 | 30 | /* このソースは MFC Programmer's SourceBook (http://www.codeguru.com/)を参考にしました */ |
31 | 31 | |
32 | 32 | #define STRICT |
33 | +// IPv6対応 | |
34 | +#include <winsock2.h> | |
33 | 35 | #include <windows.h> |
34 | 36 | #include <stdio.h> |
35 | 37 | #include <stdlib.h> |
@@ -28,6 +28,8 @@ | ||
28 | 28 | /============================================================================*/ |
29 | 29 | |
30 | 30 | #define STRICT |
31 | +// IPv6対応 | |
32 | +#include <winsock2.h> | |
31 | 33 | #include <windows.h> |
32 | 34 | #include <stdio.h> |
33 | 35 | #include <stdlib.h> |
@@ -37,7 +39,8 @@ | ||
37 | 39 | #include <windowsx.h> |
38 | 40 | #include <commctrl.h> |
39 | 41 | #include <stdarg.h> |
40 | -#include <winsock.h> | |
42 | +// IPv6対応 | |
43 | +//#include <winsock.h> | |
41 | 44 | |
42 | 45 | #include "common.h" |
43 | 46 | #include "resource.h" |
@@ -2476,7 +2479,7 @@ void ExecViewer(char *Fname, int App) | ||
2476 | 2479 | // 任意のコードが実行されるバグ修正 |
2477 | 2480 | // 拡張子が無いと補完されるため |
2478 | 2481 | // if((App == -1) && (FindExecutable(Fname, NULL, AssocProg) > (HINSTANCE)32)) |
2479 | - if((App == -1) && strrchr(Fname, '.') > strrchr(Fname, '\\') && (FindExecutable(Fname, NULL, AssocProg) > (HINSTANCE)32)) | |
2482 | + if((App == -1) && (strlen(GetFileExt(GetFileName(Fname))) > 0) && (FindExecutable(Fname, NULL, AssocProg) > (HINSTANCE)32)) | |
2480 | 2483 | { |
2481 | 2484 | DoPrintf("ShellExecute - %s", Fname); |
2482 | 2485 | ShellExecute(NULL, "open", Fname, NULL, CurDir, SW_SHOW); |
@@ -7,6 +7,7 @@ | ||
7 | 7 | #define UNICODE |
8 | 8 | #define _UNICODE |
9 | 9 | |
10 | +#include <stdio.h> | |
10 | 11 | #include <tchar.h> |
11 | 12 | #include <direct.h> |
12 | 13 | #include <windows.h> |
@@ -2149,12 +2150,11 @@ START_ROUTINE | ||
2149 | 2150 | while((c = GetNextCharM(_Str, &p)) > 0) |
2150 | 2151 | { |
2151 | 2152 | if(c == _Ch) |
2152 | - { | |
2153 | - r = (unsigned char*)_Str; | |
2154 | 2153 | break; |
2155 | - } | |
2156 | 2154 | _Str = p; |
2157 | 2155 | } |
2156 | + if(c == _Ch) | |
2157 | + r = (unsigned char*)_Str; | |
2158 | 2158 | END_ROUTINE |
2159 | 2159 | return r; |
2160 | 2160 | } |
@@ -2171,6 +2171,8 @@ START_ROUTINE | ||
2171 | 2171 | r = (unsigned char*)_Str; |
2172 | 2172 | _Str = p; |
2173 | 2173 | } |
2174 | + if(c == _Ch) | |
2175 | + r = (unsigned char*)_Str; | |
2174 | 2176 | END_ROUTINE |
2175 | 2177 | return r; |
2176 | 2178 | } |
@@ -33,7 +33,9 @@ | ||
33 | 33 | #include <stdarg.h> |
34 | 34 | #include <string.h> |
35 | 35 | #include <mbstring.h> |
36 | -#include <winsock.h> | |
36 | +// IPv6対応 | |
37 | +//#include <winsock.h> | |
38 | +#include <winsock2.h> | |
37 | 39 | #include <windowsx.h> |
38 | 40 | #include <commctrl.h> |
39 | 41 | #include <shlobj.h> |
@@ -1724,3 +1726,44 @@ char *MakeNumString(LONGLONG Num, char *Buf, BOOL Comma) | ||
1724 | 1726 | } |
1725 | 1727 | |
1726 | 1728 | |
1729 | +// 異なるファイルが表示されるバグ修正 | |
1730 | + | |
1731 | +// ShellExecute等で使用されるファイル名を修正 | |
1732 | +// UNCでない場合に末尾の半角スペースは無視されるため拡張子が補完されなくなるまで半角スペースを追加 | |
1733 | +// 現在UNC対応の予定は無い | |
1734 | +char* MakeDistinguishableFileName(char* Out, char* In) | |
1735 | +{ | |
1736 | + char Tmp[FMAX_PATH+1]; | |
1737 | + char Tmp2[FMAX_PATH+3]; | |
1738 | + HANDLE hFind; | |
1739 | + WIN32_FIND_DATA Find; | |
1740 | + if(strlen(GetFileExt(GetFileName(In))) > 0) | |
1741 | + strcpy(Out, In); | |
1742 | + else | |
1743 | + { | |
1744 | + strcpy(Tmp, In); | |
1745 | + strcpy(Tmp2, Tmp); | |
1746 | + strcat(Tmp2, ".*"); | |
1747 | + while(strlen(Tmp) < FMAX_PATH && (hFind = FindFirstFile(Tmp2, &Find)) != INVALID_HANDLE_VALUE) | |
1748 | + { | |
1749 | + do | |
1750 | + { | |
1751 | + if(strchr(Find.cFileName, '.')) | |
1752 | + break; | |
1753 | + } | |
1754 | + while(FindNextFile(hFind, &Find)); | |
1755 | + FindClose(hFind); | |
1756 | + if(strchr(Find.cFileName, '.')) | |
1757 | + { | |
1758 | + strcat(Tmp, " "); | |
1759 | + strcpy(Tmp2, Tmp); | |
1760 | + strcat(Tmp2, ".*"); | |
1761 | + } | |
1762 | + else | |
1763 | + break; | |
1764 | + } | |
1765 | + strcpy(Out, Tmp); | |
1766 | + } | |
1767 | + return Out; | |
1768 | +} | |
1769 | + |
@@ -28,6 +28,8 @@ | ||
28 | 28 | /============================================================================*/ |
29 | 29 | |
30 | 30 | #define STRICT |
31 | +// IPv6対応 | |
32 | +#include <winsock2.h> | |
31 | 33 | #include <windows.h> |
32 | 34 | #include <stdio.h> |
33 | 35 | #include <stdlib.h> |
@@ -32,6 +32,8 @@ | ||
32 | 32 | // UTF-8対応 |
33 | 33 | //#define WINVER 0x400 |
34 | 34 | |
35 | +// IPv6対応 | |
36 | +#include <winsock2.h> | |
35 | 37 | #include <windows.h> |
36 | 38 | #include <stdio.h> |
37 | 39 | #include <stdlib.h> |
@@ -39,7 +41,8 @@ | ||
39 | 41 | #include <mbstring.h> |
40 | 42 | #include <malloc.h> |
41 | 43 | #include <windowsx.h> |
42 | -#include <winsock.h> | |
44 | +// IPv6対応 | |
45 | +//#include <winsock.h> | |
43 | 46 | #include <ras.h> |
44 | 47 | #include <rasdlg.h> |
45 | 48 | #include <raserror.h> |
@@ -30,7 +30,9 @@ | ||
30 | 30 | #define STRICT |
31 | 31 | #include <stdio.h> |
32 | 32 | #include <stdlib.h> |
33 | -#include <winsock.h> | |
33 | +// IPv6対応 | |
34 | +//#include <winsock.h> | |
35 | +#include <winsock2.h> | |
34 | 36 | #include <windowsx.h> |
35 | 37 | |
36 | 38 | #include "common.h" |
@@ -33,6 +33,8 @@ | ||
33 | 33 | #endif |
34 | 34 | |
35 | 35 | #define STRICT |
36 | +// IPv6対応 | |
37 | +#include <winsock2.h> | |
36 | 38 | #include <windows.h> |
37 | 39 | #include <stdio.h> |
38 | 40 | #include <stdlib.h> |
@@ -36,7 +36,9 @@ | ||
36 | 36 | #include <string.h> |
37 | 37 | #include <mbstring.h> |
38 | 38 | #include <time.h> |
39 | -#include <winsock.h> | |
39 | +// IPv6対応 | |
40 | +//#include <winsock.h> | |
41 | +#include <winsock2.h> | |
40 | 42 | #include <windowsx.h> |
41 | 43 | #include <commctrl.h> |
42 | 44 |
@@ -32,7 +32,9 @@ | ||
32 | 32 | #define STRICT |
33 | 33 | #include <stdlib.h> |
34 | 34 | #include <string.h> |
35 | -#include <winsock.h> | |
35 | +// IPv6対応 | |
36 | +//#include <winsock.h> | |
37 | +#include <winsock2.h> | |
36 | 38 | #include <windowsx.h> |
37 | 39 | |
38 | 40 | #include "common.h" |
@@ -29,7 +29,7 @@ | ||
29 | 29 | |
30 | 30 | #define STRICT |
31 | 31 | // IPv6対応 |
32 | -#include <ws2tcpip.h> | |
32 | +#include <winsock2.h> | |
33 | 33 | #include <windows.h> |
34 | 34 | #include <stdio.h> |
35 | 35 | #include <stdlib.h> |
@@ -40,8 +40,6 @@ | ||
40 | 40 | |
41 | 41 | #include "common.h" |
42 | 42 | #include "resource.h" |
43 | -// UTF-8対応 | |
44 | -#include "punycode.h" | |
45 | 43 | |
46 | 44 | #define USE_THIS 1 |
47 | 45 | #define DBG_MSG 0 |
@@ -97,10 +95,6 @@ static int RegistAsyncTable(SOCKET s); | ||
97 | 95 | static int RegistAsyncTableDbase(HANDLE Async); |
98 | 96 | static int UnRegistAsyncTable(SOCKET s); |
99 | 97 | static int UnRegistAsyncTableDbase(HANDLE Async); |
100 | -// UTF-8対応 | |
101 | -static HANDLE WSAAsyncGetHostByNameM(HWND hWnd, u_int wMsg, const char * name, char * buf, int buflen); | |
102 | -// IPv6対応 | |
103 | -static HANDLE WSAAsyncGetHostByNameIPv6M(HWND hWnd, u_int wMsg, const char * name, char * buf, int buflen, short Family); | |
104 | 98 | |
105 | 99 | |
106 | 100 | /*===== 外部参照 =====*/ |
@@ -1231,357 +1225,3 @@ int CheckClosedAndReconnect(void) | ||
1231 | 1225 | |
1232 | 1226 | |
1233 | 1227 | |
1234 | -// IPv6対応 | |
1235 | - | |
1236 | -typedef struct | |
1237 | -{ | |
1238 | - HANDLE h; | |
1239 | - HWND hWnd; | |
1240 | - u_int wMsg; | |
1241 | - char * name; | |
1242 | - char * buf; | |
1243 | - int buflen; | |
1244 | - short Family; | |
1245 | -} GETHOSTBYNAMEDATA; | |
1246 | - | |
1247 | -static DWORD WINAPI WSAAsyncGetHostByNameIPv6ThreadProc(LPVOID lpParameter) | |
1248 | -{ | |
1249 | - GETHOSTBYNAMEDATA* pData; | |
1250 | - struct hostent* pHost; | |
1251 | - struct addrinfo* pAddr; | |
1252 | - struct addrinfo* p; | |
1253 | - pHost = NULL; | |
1254 | - pData = (GETHOSTBYNAMEDATA*)lpParameter; | |
1255 | - if(getaddrinfo(pData->name, NULL, NULL, &pAddr) == 0) | |
1256 | - { | |
1257 | - p = pAddr; | |
1258 | - while(p) | |
1259 | - { | |
1260 | - if(p->ai_family == pData->Family) | |
1261 | - { | |
1262 | - switch(p->ai_family) | |
1263 | - { | |
1264 | - case AF_INET: | |
1265 | - pHost = (struct hostent*)pData->buf; | |
1266 | - if((size_t)pData->buflen >= sizeof(struct hostent) + sizeof(char*) * 2 + sizeof(struct in_addr) | |
1267 | - && p->ai_addrlen >= sizeof(struct sockaddr_in)) | |
1268 | - { | |
1269 | - pHost->h_name = NULL; | |
1270 | - pHost->h_aliases = NULL; | |
1271 | - pHost->h_addrtype = p->ai_family; | |
1272 | - pHost->h_length = sizeof(struct in_addr); | |
1273 | - pHost->h_addr_list = (char**)(&pHost[1]); | |
1274 | - pHost->h_addr_list[0] = (char*)(&pHost->h_addr_list[2]); | |
1275 | - pHost->h_addr_list[1] = NULL; | |
1276 | - memcpy(pHost->h_addr_list[0], &((struct sockaddr_in*)p->ai_addr)->sin_addr, sizeof(struct in_addr)); | |
1277 | - PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(sizeof(struct hostent) + sizeof(char*) * 2 + p->ai_addrlen)); | |
1278 | - } | |
1279 | - else | |
1280 | - PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(WSAENOBUFS << 16)); | |
1281 | - break; | |
1282 | - case AF_INET6: | |
1283 | - pHost = (struct hostent*)pData->buf; | |
1284 | - if((size_t)pData->buflen >= sizeof(struct hostent) + sizeof(char*) * 2 + sizeof(struct in6_addr) | |
1285 | - && p->ai_addrlen >= sizeof(struct sockaddr_in6)) | |
1286 | - { | |
1287 | - pHost->h_name = NULL; | |
1288 | - pHost->h_aliases = NULL; | |
1289 | - pHost->h_addrtype = p->ai_family; | |
1290 | - pHost->h_length = sizeof(struct in6_addr); | |
1291 | - pHost->h_addr_list = (char**)(&pHost[1]); | |
1292 | - pHost->h_addr_list[0] = (char*)(&pHost->h_addr_list[2]); | |
1293 | - pHost->h_addr_list[1] = NULL; | |
1294 | - memcpy(pHost->h_addr_list[0], &((struct sockaddr_in6*)p->ai_addr)->sin6_addr, sizeof(struct in6_addr)); | |
1295 | - PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(sizeof(struct hostent) + sizeof(char*) * 2 + p->ai_addrlen)); | |
1296 | - } | |
1297 | - else | |
1298 | - PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(WSAENOBUFS << 16)); | |
1299 | - break; | |
1300 | - } | |
1301 | - } | |
1302 | - if(pHost) | |
1303 | - break; | |
1304 | - p = p->ai_next; | |
1305 | - } | |
1306 | - if(!p) | |
1307 | - PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(ERROR_INVALID_FUNCTION << 16)); | |
1308 | - freeaddrinfo(pAddr); | |
1309 | - } | |
1310 | - else | |
1311 | - PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(ERROR_INVALID_FUNCTION << 16)); | |
1312 | - free(pData->name); | |
1313 | - free(pData); | |
1314 | - // CreateThreadが返すハンドルが重複するのを回避 | |
1315 | - Sleep(10000); | |
1316 | - return 0; | |
1317 | -} | |
1318 | - | |
1319 | -// IPv6対応のWSAAsyncGetHostByName相当の関数 | |
1320 | -// FamilyにはAF_INETまたはAF_INET6を指定可能 | |
1321 | -// ただしANSI用 | |
1322 | -static HANDLE WSAAsyncGetHostByNameIPv6(HWND hWnd, u_int wMsg, const char * name, char * buf, int buflen, short Family) | |
1323 | -{ | |
1324 | - HANDLE hResult; | |
1325 | - GETHOSTBYNAMEDATA* pData; | |
1326 | - hResult = NULL; | |
1327 | - if(pData = malloc(sizeof(GETHOSTBYNAMEDATA))) | |
1328 | - { | |
1329 | - pData->hWnd = hWnd; | |
1330 | - pData->wMsg = wMsg; | |
1331 | - if(pData->name = malloc(sizeof(char) * (strlen(name) + 1))) | |
1332 | - { | |
1333 | - strcpy(pData->name, name); | |
1334 | - pData->buf = buf; | |
1335 | - pData->buflen = buflen; | |
1336 | - pData->Family = Family; | |
1337 | - if(pData->h = CreateThread(NULL, 0, WSAAsyncGetHostByNameIPv6ThreadProc, pData, CREATE_SUSPENDED, NULL)) | |
1338 | - { | |
1339 | - ResumeThread(pData->h); | |
1340 | - hResult = pData->h; | |
1341 | - } | |
1342 | - } | |
1343 | - } | |
1344 | - if(!hResult) | |
1345 | - { | |
1346 | - if(pData) | |
1347 | - { | |
1348 | - if(pData->name) | |
1349 | - free(pData->name); | |
1350 | - free(pData); | |
1351 | - } | |
1352 | - } | |
1353 | - return hResult; | |
1354 | -} | |
1355 | - | |
1356 | -// WSAAsyncGetHostByNameIPv6用のWSACancelAsyncRequest相当の関数 | |
1357 | -int WSACancelAsyncRequestIPv6(HANDLE hAsyncTaskHandle) | |
1358 | -{ | |
1359 | - int Result; | |
1360 | - Result = SOCKET_ERROR; | |
1361 | - if(TerminateThread(hAsyncTaskHandle, 0)) | |
1362 | - Result = 0; | |
1363 | - return Result; | |
1364 | -} | |
1365 | - | |
1366 | -char* AddressToStringIPv6(char* str, void* in6) | |
1367 | -{ | |
1368 | - char* pResult; | |
1369 | - unsigned char* p; | |
1370 | - int MaxZero; | |
1371 | - int MaxZeroLen; | |
1372 | - int i; | |
1373 | - int j; | |
1374 | - char Tmp[5]; | |
1375 | - pResult = str; | |
1376 | - p = (unsigned char*)in6; | |
1377 | - MaxZero = 8; | |
1378 | - MaxZeroLen = 1; | |
1379 | - for(i = 0; i < 8; i++) | |
1380 | - { | |
1381 | - for(j = i; j < 8; j++) | |
1382 | - { | |
1383 | - if(p[j * 2] != 0 || p[j * 2 + 1] != 0) | |
1384 | - break; | |
1385 | - } | |
1386 | - if(j - i > MaxZeroLen) | |
1387 | - { | |
1388 | - MaxZero = i; | |
1389 | - MaxZeroLen = j - i; | |
1390 | - } | |
1391 | - } | |
1392 | - strcpy(str, ""); | |
1393 | - for(i = 0; i < 8; i++) | |
1394 | - { | |
1395 | - if(i == MaxZero) | |
1396 | - { | |
1397 | - if(i == 0) | |
1398 | - strcat(str, ":"); | |
1399 | - strcat(str, ":"); | |
1400 | - } | |
1401 | - else if(i < MaxZero || i >= MaxZero + MaxZeroLen) | |
1402 | - { | |
1403 | - sprintf(Tmp, "%x", (((int)p[i * 2] & 0xff) << 8) | ((int)p[i * 2 + 1] & 0xff)); | |
1404 | - strcat(str, Tmp); | |
1405 | - if(i < 7) | |
1406 | - strcat(str, ":"); | |
1407 | - } | |
1408 | - } | |
1409 | - return pResult; | |
1410 | -} | |
1411 | - | |
1412 | -// IPv6対応のinet_ntoa相当の関数 | |
1413 | -// ただしANSI用 | |
1414 | -char* inet6_ntoa(struct in6_addr in6) | |
1415 | -{ | |
1416 | - char* pResult; | |
1417 | - static char Adrs[40]; | |
1418 | - pResult = NULL; | |
1419 | - memset(Adrs, 0, sizeof(Adrs)); | |
1420 | - pResult = AddressToStringIPv6(Adrs, &in6); | |
1421 | - return pResult; | |
1422 | -} | |
1423 | - | |
1424 | -// IPv6対応のinet_addr相当の関数 | |
1425 | -// ただしANSI用 | |
1426 | -struct in6_addr inet6_addr(const char* cp) | |
1427 | -{ | |
1428 | - struct in6_addr Result; | |
1429 | - int AfterZero; | |
1430 | - int i; | |
1431 | - char* p; | |
1432 | - memset(&Result, 0, sizeof(Result)); | |
1433 | - AfterZero = 0; | |
1434 | - for(i = 0; i < 8; i++) | |
1435 | - { | |
1436 | - if(!cp) | |
1437 | - { | |
1438 | - memset(&Result, 0xff, sizeof(Result)); | |
1439 | - break; | |
1440 | - } | |
1441 | - if(i >= AfterZero) | |
1442 | - { | |
1443 | - if(strncmp(cp, ":", 1) == 0) | |
1444 | - { | |
1445 | - cp = cp + 1; | |
1446 | - if(i == 0 && strncmp(cp, ":", 1) == 0) | |
1447 | - cp = cp + 1; | |
1448 | - p = (char*)cp; | |
1449 | - AfterZero = 7; | |
1450 | - while(p = strstr(p, ":")) | |
1451 | - { | |
1452 | - p = p + 1; | |
1453 | - AfterZero--; | |
1454 | - } | |
1455 | - } | |
1456 | - else | |
1457 | - { | |
1458 | - Result.u.Word[i] = (USHORT)strtol(cp, &p, 16); | |
1459 | - Result.u.Word[i] = ((Result.u.Word[i] & 0xff00) >> 8) | ((Result.u.Word[i] & 0x00ff) << 8); | |
1460 | - if(strncmp(p, ":", 1) != 0 && strlen(p) > 0) | |
1461 | - { | |
1462 | - memset(&Result, 0xff, sizeof(Result)); | |
1463 | - break; | |
1464 | - } | |
1465 | - if(cp = strstr(cp, ":")) | |
1466 | - cp = cp + 1; | |
1467 | - } | |
1468 | - } | |
1469 | - } | |
1470 | - return Result; | |
1471 | -} | |
1472 | - | |
1473 | -// UTF-8対応 | |
1474 | - | |
1475 | -static BOOL ConvertStringToPunycode(LPSTR Output, DWORD Count, LPCSTR Input) | |
1476 | -{ | |
1477 | - BOOL bResult; | |
1478 | - punycode_uint* pUnicode; | |
1479 | - punycode_uint* p; | |
1480 | - BOOL bNeeded; | |
1481 | - LPCSTR InputString; | |
1482 | - punycode_uint Length; | |
1483 | - punycode_uint OutputLength; | |
1484 | - bResult = FALSE; | |
1485 | - if(pUnicode = malloc(sizeof(punycode_uint) * strlen(Input))) | |
1486 | - { | |
1487 | - p = pUnicode; | |
1488 | - bNeeded = FALSE; | |
1489 | - InputString = Input; | |
1490 | - Length = 0; | |
1491 | - while(*InputString != '\0') | |
1492 | - { | |
1493 | - *p = (punycode_uint)GetNextCharM(InputString, &InputString); | |
1494 | - if(*p >= 0x80) | |
1495 | - bNeeded = TRUE; | |
1496 | - p++; | |
1497 | - Length++; | |
1498 | - } | |
1499 | - if(bNeeded) | |
1500 | - { | |
1501 | - if(Count >= strlen("xn--") + 1) | |
1502 | - { | |
1503 | - strcpy(Output, "xn--"); | |
1504 | - OutputLength = Count - strlen("xn--"); | |
1505 | - if(punycode_encode(Length, pUnicode, NULL, (punycode_uint*)&OutputLength, Output + strlen("xn--")) == punycode_success) | |
1506 | - { | |
1507 | - Output[strlen("xn--") + OutputLength] = '\0'; | |
1508 | - bResult = TRUE; | |
1509 | - } | |
1510 | - } | |
1511 | - } | |
1512 | - free(pUnicode); | |
1513 | - } | |
1514 | - if(!bResult) | |
1515 | - { | |
1516 | - if(Count >= strlen(Input) + 1) | |
1517 | - { | |
1518 | - strcpy(Output, Input); | |
1519 | - bResult = TRUE; | |
1520 | - } | |
1521 | - } | |
1522 | - return bResult; | |
1523 | -} | |
1524 | - | |
1525 | -static BOOL ConvertNameToPunycode(LPSTR Output, LPCSTR Input) | |
1526 | -{ | |
1527 | - BOOL bResult; | |
1528 | - DWORD Length; | |
1529 | - char* pm0; | |
1530 | - char* pm1; | |
1531 | - char* p; | |
1532 | - char* pNext; | |
1533 | - bResult = FALSE; | |
1534 | - Length = strlen(Input); | |
1535 | - if(pm0 = AllocateStringM(Length + 1)) | |
1536 | - { | |
1537 | - if(pm1 = AllocateStringM(Length * 4 + 1)) | |
1538 | - { | |
1539 | - strcpy(pm0, Input); | |
1540 | - p = pm0; | |
1541 | - while(p) | |
1542 | - { | |
1543 | - if(pNext = strchr(p, '.')) | |
1544 | - { | |
1545 | - *pNext = '\0'; | |
1546 | - pNext++; | |
1547 | - } | |
1548 | - if(ConvertStringToPunycode(pm1, Length * 4, p)) | |
1549 | - strcat(Output, pm1); | |
1550 | - if(pNext) | |
1551 | - strcat(Output, "."); | |
1552 | - p = pNext; | |
1553 | - } | |
1554 | - bResult = TRUE; | |
1555 | - FreeDuplicatedString(pm1); | |
1556 | - } | |
1557 | - FreeDuplicatedString(pm0); | |
1558 | - } | |
1559 | - return bResult; | |
1560 | -} | |
1561 | - | |
1562 | -static HANDLE WSAAsyncGetHostByNameM(HWND hWnd, u_int wMsg, const char * name, char * buf, int buflen) | |
1563 | -{ | |
1564 | - HANDLE r = NULL; | |
1565 | - char* pa0 = NULL; | |
1566 | - if(pa0 = AllocateStringA(strlen(name) * 4)) | |
1567 | - { | |
1568 | - if(ConvertNameToPunycode(pa0, name)) | |
1569 | - r = WSAAsyncGetHostByName(hWnd, wMsg, pa0, buf, buflen); | |
1570 | - } | |
1571 | - FreeDuplicatedString(pa0); | |
1572 | - return r; | |
1573 | -} | |
1574 | - | |
1575 | -static HANDLE WSAAsyncGetHostByNameIPv6M(HWND hWnd, u_int wMsg, const char * name, char * buf, int buflen, short Family) | |
1576 | -{ | |
1577 | - HANDLE r = NULL; | |
1578 | - char* pa0 = NULL; | |
1579 | - if(pa0 = AllocateStringA(strlen(name) * 4)) | |
1580 | - { | |
1581 | - if(ConvertNameToPunycode(pa0, name)) | |
1582 | - r = WSAAsyncGetHostByNameIPv6(hWnd, wMsg, pa0, buf, buflen, Family); | |
1583 | - } | |
1584 | - FreeDuplicatedString(pa0); | |
1585 | - return r; | |
1586 | -} | |
1587 | - |
@@ -2,15 +2,19 @@ | ||
2 | 2 | // Copyright (C) 2011 Suguru Kawamoto |
3 | 3 | // ソケットラッパー |
4 | 4 | // socket関連関数をOpenSSL用に置換 |
5 | +// socket関連関数のIPv6対応 | |
5 | 6 | // コンパイルにはOpenSSLのヘッダーファイルが必要 |
6 | 7 | // 実行にはOpenSSLのDLLが必要 |
7 | 8 | |
9 | +#include <ws2tcpip.h> | |
8 | 10 | #include <windows.h> |
9 | 11 | #include <mmsystem.h> |
10 | 12 | #include <openssl/ssl.h> |
11 | 13 | |
12 | 14 | #include "socketwrapper.h" |
13 | 15 | #include "protectprocess.h" |
16 | +#include "mbswrapper.h" | |
17 | +#include "punycode.h" | |
14 | 18 | |
15 | 19 | typedef void (__cdecl* _SSL_load_error_strings)(); |
16 | 20 | typedef int (__cdecl* _SSL_library_init)(); |
@@ -581,3 +585,355 @@ int recvS(SOCKET s, char * buf, int len, int flags) | ||
581 | 585 | return p_SSL_read(*ppSSL, buf, len); |
582 | 586 | } |
583 | 587 | |
588 | +// IPv6対応 | |
589 | + | |
590 | +typedef struct | |
591 | +{ | |
592 | + HANDLE h; | |
593 | + HWND hWnd; | |
594 | + u_int wMsg; | |
595 | + char * name; | |
596 | + char * buf; | |
597 | + int buflen; | |
598 | + short Family; | |
599 | +} GETHOSTBYNAMEDATA; | |
600 | + | |
601 | +DWORD WINAPI WSAAsyncGetHostByNameIPv6ThreadProc(LPVOID lpParameter) | |
602 | +{ | |
603 | + GETHOSTBYNAMEDATA* pData; | |
604 | + struct hostent* pHost; | |
605 | + struct addrinfo* pAddr; | |
606 | + struct addrinfo* p; | |
607 | + pHost = NULL; | |
608 | + pData = (GETHOSTBYNAMEDATA*)lpParameter; | |
609 | + if(getaddrinfo(pData->name, NULL, NULL, &pAddr) == 0) | |
610 | + { | |
611 | + p = pAddr; | |
612 | + while(p) | |
613 | + { | |
614 | + if(p->ai_family == pData->Family) | |
615 | + { | |
616 | + switch(p->ai_family) | |
617 | + { | |
618 | + case AF_INET: | |
619 | + pHost = (struct hostent*)pData->buf; | |
620 | + if((size_t)pData->buflen >= sizeof(struct hostent) + sizeof(char*) * 2 + sizeof(struct in_addr) | |
621 | + && p->ai_addrlen >= sizeof(struct sockaddr_in)) | |
622 | + { | |
623 | + pHost->h_name = NULL; | |
624 | + pHost->h_aliases = NULL; | |
625 | + pHost->h_addrtype = p->ai_family; | |
626 | + pHost->h_length = sizeof(struct in_addr); | |
627 | + pHost->h_addr_list = (char**)(&pHost[1]); | |
628 | + pHost->h_addr_list[0] = (char*)(&pHost->h_addr_list[2]); | |
629 | + pHost->h_addr_list[1] = NULL; | |
630 | + memcpy(pHost->h_addr_list[0], &((struct sockaddr_in*)p->ai_addr)->sin_addr, sizeof(struct in_addr)); | |
631 | + PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(sizeof(struct hostent) + sizeof(char*) * 2 + p->ai_addrlen)); | |
632 | + } | |
633 | + else | |
634 | + PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(WSAENOBUFS << 16)); | |
635 | + break; | |
636 | + case AF_INET6: | |
637 | + pHost = (struct hostent*)pData->buf; | |
638 | + if((size_t)pData->buflen >= sizeof(struct hostent) + sizeof(char*) * 2 + sizeof(struct in6_addr) | |
639 | + && p->ai_addrlen >= sizeof(struct sockaddr_in6)) | |
640 | + { | |
641 | + pHost->h_name = NULL; | |
642 | + pHost->h_aliases = NULL; | |
643 | + pHost->h_addrtype = p->ai_family; | |
644 | + pHost->h_length = sizeof(struct in6_addr); | |
645 | + pHost->h_addr_list = (char**)(&pHost[1]); | |
646 | + pHost->h_addr_list[0] = (char*)(&pHost->h_addr_list[2]); | |
647 | + pHost->h_addr_list[1] = NULL; | |
648 | + memcpy(pHost->h_addr_list[0], &((struct sockaddr_in6*)p->ai_addr)->sin6_addr, sizeof(struct in6_addr)); | |
649 | + PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(sizeof(struct hostent) + sizeof(char*) * 2 + p->ai_addrlen)); | |
650 | + } | |
651 | + else | |
652 | + PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(WSAENOBUFS << 16)); | |
653 | + break; | |
654 | + } | |
655 | + } | |
656 | + if(pHost) | |
657 | + break; | |
658 | + p = p->ai_next; | |
659 | + } | |
660 | + if(!p) | |
661 | + PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(ERROR_INVALID_FUNCTION << 16)); | |
662 | + freeaddrinfo(pAddr); | |
663 | + } | |
664 | + else | |
665 | + PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(ERROR_INVALID_FUNCTION << 16)); | |
666 | + free(pData->name); | |
667 | + free(pData); | |
668 | + // CreateThreadが返すハンドルが重複するのを回避 | |
669 | + Sleep(10000); | |
670 | + return 0; | |
671 | +} | |
672 | + | |
673 | +// IPv6対応のWSAAsyncGetHostByName相当の関数 | |
674 | +// FamilyにはAF_INETまたはAF_INET6を指定可能 | |
675 | +// ただしANSI用 | |
676 | +HANDLE WSAAsyncGetHostByNameIPv6(HWND hWnd, u_int wMsg, const char * name, char * buf, int buflen, short Family) | |
677 | +{ | |
678 | + HANDLE hResult; | |
679 | + GETHOSTBYNAMEDATA* pData; | |
680 | + hResult = NULL; | |
681 | + if(pData = malloc(sizeof(GETHOSTBYNAMEDATA))) | |
682 | + { | |
683 | + pData->hWnd = hWnd; | |
684 | + pData->wMsg = wMsg; | |
685 | + if(pData->name = malloc(sizeof(char) * (strlen(name) + 1))) | |
686 | + { | |
687 | + strcpy(pData->name, name); | |
688 | + pData->buf = buf; | |
689 | + pData->buflen = buflen; | |
690 | + pData->Family = Family; | |
691 | + if(pData->h = CreateThread(NULL, 0, WSAAsyncGetHostByNameIPv6ThreadProc, pData, CREATE_SUSPENDED, NULL)) | |
692 | + { | |
693 | + ResumeThread(pData->h); | |
694 | + hResult = pData->h; | |
695 | + } | |
696 | + } | |
697 | + } | |
698 | + if(!hResult) | |
699 | + { | |
700 | + if(pData) | |
701 | + { | |
702 | + if(pData->name) | |
703 | + free(pData->name); | |
704 | + free(pData); | |
705 | + } | |
706 | + } | |
707 | + return hResult; | |
708 | +} | |
709 | + | |
710 | +// WSAAsyncGetHostByNameIPv6用のWSACancelAsyncRequest相当の関数 | |
711 | +int WSACancelAsyncRequestIPv6(HANDLE hAsyncTaskHandle) | |
712 | +{ | |
713 | + int Result; | |
714 | + Result = SOCKET_ERROR; | |
715 | + if(TerminateThread(hAsyncTaskHandle, 0)) | |
716 | + Result = 0; | |
717 | + return Result; | |
718 | +} | |
719 | + | |
720 | +char* AddressToStringIPv6(char* str, void* in6) | |
721 | +{ | |
722 | + char* pResult; | |
723 | + unsigned char* p; | |
724 | + int MaxZero; | |
725 | + int MaxZeroLen; | |
726 | + int i; | |
727 | + int j; | |
728 | + char Tmp[5]; | |
729 | + pResult = str; | |
730 | + p = (unsigned char*)in6; | |
731 | + MaxZero = 8; | |
732 | + MaxZeroLen = 1; | |
733 | + for(i = 0; i < 8; i++) | |
734 | + { | |
735 | + for(j = i; j < 8; j++) | |
736 | + { | |
737 | + if(p[j * 2] != 0 || p[j * 2 + 1] != 0) | |
738 | + break; | |
739 | + } | |
740 | + if(j - i > MaxZeroLen) | |
741 | + { | |
742 | + MaxZero = i; | |
743 | + MaxZeroLen = j - i; | |
744 | + } | |
745 | + } | |
746 | + strcpy(str, ""); | |
747 | + for(i = 0; i < 8; i++) | |
748 | + { | |
749 | + if(i == MaxZero) | |
750 | + { | |
751 | + if(i == 0) | |
752 | + strcat(str, ":"); | |
753 | + strcat(str, ":"); | |
754 | + } | |
755 | + else if(i < MaxZero || i >= MaxZero + MaxZeroLen) | |
756 | + { | |
757 | + sprintf(Tmp, "%x", (((int)p[i * 2] & 0xff) << 8) | ((int)p[i * 2 + 1] & 0xff)); | |
758 | + strcat(str, Tmp); | |
759 | + if(i < 7) | |
760 | + strcat(str, ":"); | |
761 | + } | |
762 | + } | |
763 | + return pResult; | |
764 | +} | |
765 | + | |
766 | +// IPv6対応のinet_ntoa相当の関数 | |
767 | +// ただしANSI用 | |
768 | +char* inet6_ntoa(struct in6_addr in6) | |
769 | +{ | |
770 | + char* pResult; | |
771 | + static char Adrs[40]; | |
772 | + pResult = NULL; | |
773 | + memset(Adrs, 0, sizeof(Adrs)); | |
774 | + pResult = AddressToStringIPv6(Adrs, &in6); | |
775 | + return pResult; | |
776 | +} | |
777 | + | |
778 | +// IPv6対応のinet_addr相当の関数 | |
779 | +// ただしANSI用 | |
780 | +struct in6_addr inet6_addr(const char* cp) | |
781 | +{ | |
782 | + struct in6_addr Result; | |
783 | + int AfterZero; | |
784 | + int i; | |
785 | + char* p; | |
786 | + memset(&Result, 0, sizeof(Result)); | |
787 | + AfterZero = 0; | |
788 | + for(i = 0; i < 8; i++) | |
789 | + { | |
790 | + if(!cp) | |
791 | + { | |
792 | + memset(&Result, 0xff, sizeof(Result)); | |
793 | + break; | |
794 | + } | |
795 | + if(i >= AfterZero) | |
796 | + { | |
797 | + if(strncmp(cp, ":", 1) == 0) | |
798 | + { | |
799 | + cp = cp + 1; | |
800 | + if(i == 0 && strncmp(cp, ":", 1) == 0) | |
801 | + cp = cp + 1; | |
802 | + p = (char*)cp; | |
803 | + AfterZero = 7; | |
804 | + while(p = strstr(p, ":")) | |
805 | + { | |
806 | + p = p + 1; | |
807 | + AfterZero--; | |
808 | + } | |
809 | + } | |
810 | + else | |
811 | + { | |
812 | + Result.u.Word[i] = (USHORT)strtol(cp, &p, 16); | |
813 | + Result.u.Word[i] = ((Result.u.Word[i] & 0xff00) >> 8) | ((Result.u.Word[i] & 0x00ff) << 8); | |
814 | + if(strncmp(p, ":", 1) != 0 && strlen(p) > 0) | |
815 | + { | |
816 | + memset(&Result, 0xff, sizeof(Result)); | |
817 | + break; | |
818 | + } | |
819 | + if(cp = strstr(cp, ":")) | |
820 | + cp = cp + 1; | |
821 | + } | |
822 | + } | |
823 | + } | |
824 | + return Result; | |
825 | +} | |
826 | + | |
827 | +BOOL ConvertDomainNameToPunycode(LPSTR Output, DWORD Count, LPCSTR Input) | |
828 | +{ | |
829 | + BOOL bResult; | |
830 | + punycode_uint* pUnicode; | |
831 | + punycode_uint* p; | |
832 | + BOOL bNeeded; | |
833 | + LPCSTR InputString; | |
834 | + punycode_uint Length; | |
835 | + punycode_uint OutputLength; | |
836 | + bResult = FALSE; | |
837 | + if(pUnicode = malloc(sizeof(punycode_uint) * strlen(Input))) | |
838 | + { | |
839 | + p = pUnicode; | |
840 | + bNeeded = FALSE; | |
841 | + InputString = Input; | |
842 | + Length = 0; | |
843 | + while(*InputString != '\0') | |
844 | + { | |
845 | + *p = (punycode_uint)GetNextCharM(InputString, &InputString); | |
846 | + if(*p >= 0x80) | |
847 | + bNeeded = TRUE; | |
848 | + p++; | |
849 | + Length++; | |
850 | + } | |
851 | + if(bNeeded) | |
852 | + { | |
853 | + if(Count >= strlen("xn--") + 1) | |
854 | + { | |
855 | + strcpy(Output, "xn--"); | |
856 | + OutputLength = Count - strlen("xn--"); | |
857 | + if(punycode_encode(Length, pUnicode, NULL, (punycode_uint*)&OutputLength, Output + strlen("xn--")) == punycode_success) | |
858 | + { | |
859 | + Output[strlen("xn--") + OutputLength] = '\0'; | |
860 | + bResult = TRUE; | |
861 | + } | |
862 | + } | |
863 | + } | |
864 | + free(pUnicode); | |
865 | + } | |
866 | + if(!bResult) | |
867 | + { | |
868 | + if(Count >= strlen(Input) + 1) | |
869 | + { | |
870 | + strcpy(Output, Input); | |
871 | + bResult = TRUE; | |
872 | + } | |
873 | + } | |
874 | + return bResult; | |
875 | +} | |
876 | + | |
877 | +BOOL ConvertNameToPunycode(LPSTR Output, LPCSTR Input) | |
878 | +{ | |
879 | + BOOL bResult; | |
880 | + DWORD Length; | |
881 | + char* pm0; | |
882 | + char* pm1; | |
883 | + char* p; | |
884 | + char* pNext; | |
885 | + bResult = FALSE; | |
886 | + Length = strlen(Input); | |
887 | + if(pm0 = AllocateStringM(Length + 1)) | |
888 | + { | |
889 | + if(pm1 = AllocateStringM(Length * 4 + 1)) | |
890 | + { | |
891 | + strcpy(pm0, Input); | |
892 | + p = pm0; | |
893 | + while(p) | |
894 | + { | |
895 | + if(pNext = strchr(p, '.')) | |
896 | + { | |
897 | + *pNext = '\0'; | |
898 | + pNext++; | |
899 | + } | |
900 | + if(ConvertDomainNameToPunycode(pm1, Length * 4, p)) | |
901 | + strcat(Output, pm1); | |
902 | + if(pNext) | |
903 | + strcat(Output, "."); | |
904 | + p = pNext; | |
905 | + } | |
906 | + bResult = TRUE; | |
907 | + FreeDuplicatedString(pm1); | |
908 | + } | |
909 | + FreeDuplicatedString(pm0); | |
910 | + } | |
911 | + return bResult; | |
912 | +} | |
913 | + | |
914 | +HANDLE WSAAsyncGetHostByNameM(HWND hWnd, u_int wMsg, const char * name, char * buf, int buflen) | |
915 | +{ | |
916 | + HANDLE r = NULL; | |
917 | + char* pa0 = NULL; | |
918 | + if(pa0 = AllocateStringA(strlen(name) * 4)) | |
919 | + { | |
920 | + if(ConvertNameToPunycode(pa0, name)) | |
921 | + r = WSAAsyncGetHostByName(hWnd, wMsg, pa0, buf, buflen); | |
922 | + } | |
923 | + FreeDuplicatedString(pa0); | |
924 | + return r; | |
925 | +} | |
926 | + | |
927 | +HANDLE WSAAsyncGetHostByNameIPv6M(HWND hWnd, u_int wMsg, const char * name, char * buf, int buflen, short Family) | |
928 | +{ | |
929 | + HANDLE r = NULL; | |
930 | + char* pa0 = NULL; | |
931 | + if(pa0 = AllocateStringA(strlen(name) * 4)) | |
932 | + { | |
933 | + if(ConvertNameToPunycode(pa0, name)) | |
934 | + r = WSAAsyncGetHostByNameIPv6(hWnd, wMsg, pa0, buf, buflen, Family); | |
935 | + } | |
936 | + FreeDuplicatedString(pa0); | |
937 | + return r; | |
938 | +} | |
939 | + |
@@ -5,6 +5,9 @@ | ||
5 | 5 | #ifndef __SOCKETWRAPPER_H__ |
6 | 6 | #define __SOCKETWRAPPER_H__ |
7 | 7 | |
8 | +#include <ws2tcpip.h> | |
9 | +#include <windows.h> | |
10 | + | |
8 | 11 | #define USE_OPENSSL |
9 | 12 | |
10 | 13 | typedef BOOL (__stdcall* LPSSLTIMEOUTCALLBACK)(BOOL*); |
@@ -29,5 +32,13 @@ int closesocketS(SOCKET s); | ||
29 | 32 | int sendS(SOCKET s, const char * buf, int len, int flags); |
30 | 33 | int recvS(SOCKET s, char * buf, int len, int flags); |
31 | 34 | |
35 | +HANDLE WSAAsyncGetHostByNameIPv6(HWND hWnd, u_int wMsg, const char * name, char * buf, int buflen, short Family); | |
36 | +int WSACancelAsyncRequestIPv6(HANDLE hAsyncTaskHandle); | |
37 | +char* AddressToStringIPv6(char* str, void* in6); | |
38 | +char* inet6_ntoa(struct in6_addr in6); | |
39 | +struct in6_addr inet6_addr(const char* cp); | |
40 | +HANDLE WSAAsyncGetHostByNameM(HWND hWnd, u_int wMsg, const char * name, char * buf, int buflen); | |
41 | +HANDLE WSAAsyncGetHostByNameIPv6M(HWND hWnd, u_int wMsg, const char * name, char * buf, int buflen, short Family); | |
42 | + | |
32 | 43 | #endif |
33 | 44 |
@@ -28,6 +28,8 @@ | ||
28 | 28 | /============================================================================*/ |
29 | 29 | |
30 | 30 | #define STRICT |
31 | +// IPv6対応 | |
32 | +#include <winsock2.h> | |
31 | 33 | #include <windows.h> |
32 | 34 | #include <stdio.h> |
33 | 35 | #include <stdlib.h> |
@@ -37,7 +39,8 @@ | ||
37 | 39 | #include <windowsx.h> |
38 | 40 | #include <commctrl.h> |
39 | 41 | #include <stdarg.h> |
40 | -#include <winsock.h> | |
42 | +// IPv6対応 | |
43 | +//#include <winsock.h> | |
41 | 44 | |
42 | 45 | #include "common.h" |
43 | 46 | #include "resource.h" |
@@ -28,6 +28,8 @@ | ||
28 | 28 | /============================================================================*/ |
29 | 29 | |
30 | 30 | #define STRICT |
31 | +// IPv6対応 | |
32 | +#include <winsock2.h> | |
31 | 33 | #include <windows.h> |
32 | 34 | #include <stdio.h> |
33 | 35 | #include <stdlib.h> |
@@ -37,7 +39,8 @@ | ||
37 | 39 | #include <windowsx.h> |
38 | 40 | #include <commctrl.h> |
39 | 41 | #include <stdarg.h> |
40 | -#include <winsock.h> | |
42 | +// IPv6対応 | |
43 | +//#include <winsock.h> | |
41 | 44 | |
42 | 45 | #include "common.h" |
43 | 46 | #include "resource.h" |
@@ -28,6 +28,8 @@ | ||
28 | 28 | /============================================================================*/ |
29 | 29 | |
30 | 30 | #define STRICT |
31 | +// IPv6対応 | |
32 | +#include <winsock2.h> | |
31 | 33 | #include <windows.h> |
32 | 34 | #include <stdio.h> |
33 | 35 | #include <stdlib.h> |
@@ -28,6 +28,8 @@ | ||
28 | 28 | /============================================================================*/ |
29 | 29 | |
30 | 30 | #define STRICT |
31 | +// IPv6対応 | |
32 | +#include <winsock2.h> | |
31 | 33 | #include <windows.h> |
32 | 34 | #include <stdio.h> |
33 | 35 | #include <stdlib.h> |
@@ -37,7 +39,8 @@ | ||
37 | 39 | #include <windowsx.h> |
38 | 40 | #include <commctrl.h> |
39 | 41 | #include <stdarg.h> |
40 | -#include <winsock.h> | |
42 | +// IPv6対応 | |
43 | +//#include <winsock.h> | |
41 | 44 | |
42 | 45 | #include "common.h" |
43 | 46 | #include "resource.h" |
@@ -27,6 +27,8 @@ | ||
27 | 27 | /============================================================================*/ |
28 | 28 | |
29 | 29 | #define STRICT |
30 | +// IPv6対応 | |
31 | +#include <winsock2.h> | |
30 | 32 | #include <windows.h> |
31 | 33 | #include <stdio.h> |
32 | 34 | #include <stdlib.h> |
@@ -30,7 +30,9 @@ | ||
30 | 30 | #define STRICT |
31 | 31 | #include <stdio.h> |
32 | 32 | #include <stdlib.h> |
33 | -#include <winsock.h> | |
33 | +// IPv6対応 | |
34 | +//#include <winsock.h> | |
35 | +#include <winsock2.h> | |
34 | 36 | #include <windowsx.h> |
35 | 37 | |
36 | 38 | #include "common.h" |