From 79657a7f907797f280005a7f73bd5ca72620809a Mon Sep 17 00:00:00 2001 From: Appnor MSP <> Date: Thu, 3 Feb 2011 00:00:00 +0100 Subject: [PATCH] initial commit of vanilla WinMTR v0.92 from http://winmtr.net/ --- README.TXT | 88 +++ WinMTR.ico | Bin 0 -> 1078 bytes WinMTR.rc | 370 +++++++++++++ WinMTR.sln | 26 + WinMTR.suo | Bin 0 -> 8704 bytes WinMTR.vcxproj | 287 ++++++++++ WinMTRDialog.cpp | 1230 ++++++++++++++++++++++++++++++++++++++++++ WinMTRDialog.h | 132 +++++ WinMTRGlobal.cpp | 26 + WinMTRGlobal.h | 106 ++++ WinMTRHelp.cpp | 41 ++ WinMTRHelp.h | 22 + WinMTRLicense.cpp | 405 ++++++++++++++ WinMTRLicense.h | 40 ++ WinMTRMain.cpp | 209 +++++++ WinMTRMain.h | 43 ++ WinMTRNet.cpp | 455 ++++++++++++++++ WinMTRNet.h | 93 ++++ WinMTROptions.cpp | 112 ++++ WinMTROptions.h | 62 +++ WinMTRProperties.cpp | 91 ++++ WinMTRProperties.h | 64 +++ WinMTRStatusBar.cpp | 313 +++++++++++ WinMTRStatusBar.h | 126 +++++ resource.h | 53 ++ 25 files changed, 4394 insertions(+) create mode 100644 README.TXT create mode 100644 WinMTR.ico create mode 100644 WinMTR.rc create mode 100644 WinMTR.sln create mode 100644 WinMTR.suo create mode 100644 WinMTR.vcxproj create mode 100644 WinMTRDialog.cpp create mode 100644 WinMTRDialog.h create mode 100644 WinMTRGlobal.cpp create mode 100644 WinMTRGlobal.h create mode 100644 WinMTRHelp.cpp create mode 100644 WinMTRHelp.h create mode 100644 WinMTRLicense.cpp create mode 100644 WinMTRLicense.h create mode 100644 WinMTRMain.cpp create mode 100644 WinMTRMain.h create mode 100644 WinMTRNet.cpp create mode 100644 WinMTRNet.h create mode 100644 WinMTROptions.cpp create mode 100644 WinMTROptions.h create mode 100644 WinMTRProperties.cpp create mode 100644 WinMTRProperties.h create mode 100644 WinMTRStatusBar.cpp create mode 100644 WinMTRStatusBar.h create mode 100644 resource.h diff --git a/README.TXT b/README.TXT new file mode 100644 index 0000000..4e1b69f --- /dev/null +++ b/README.TXT @@ -0,0 +1,88 @@ +WinMTR – Appnor's Free Network Diagnostic Tool - http://winmtr.net + +Thank you for downloading WinMTR v0.91! + +*** About *** + +WinMTR is a free MS Windows visual application that combines the functionality of the traceroute and ping in a single network diagnostic tool. WinMTR is Open Source Software, maintained by Appnor MSP, a fully managed hosting & cloud provider. + +It was started in 2000 by Vasile Laurentiu Stanimir as a clone for the popular Matt’s Traceroute (hence MTR) Linux/UNIX utility. +Read more about WinMTR’s history: http://winmtr.net/history/ + +*** License & Redistribution *** + +WinMTR is offered as Open Source Software under GPL v2. +Read more about the licensing conditions: http://www.gnu.org/licenses/gpl-2.0.html +Download the code from: http://sourceforge.net/projects/winmtr/ + +*** Installation *** + +You will get a .zip archive containing two folders WinMTR-32 and WinMTR-64. +Both contain two files: WinMTR.exe and README.TXT. +Just extract the WinMTR.exe for your platform (32 or 64 bit) and click to run it. +If you don’t know what version you need, just click on both files and see which one works ;-) +As you can see, WinMTR requires no other installation effort. + +Trick: You can copy the WinMTR.exe file in Windows/System32 so it’s accessible via the command line – cmd! + +*** Usage *** + +Visual: + + * Start WinMTR. + * Write the name or IP of the host (e.g. google.com) + * Press the Options button to configure ping size, maximum hops and ping interval (the defaults are OK). + * Push the Start button and wait. + * Copy or export the results in text or HTML format. Useful if you want to document or file a complaint with your ISP. + * Click on Clear History to remove the hosts you have previously traced. + +Command line: + + * Run winmtr.exe --help to see what are the options + * Run winmtr hostname (e.g. winmtr www.yahoo.com) + +*** Troubleshooting *** + +a) I type in the address and nothing happens. + +Usually this has to do with lame anti-virus or firewall applications. Stop all that when doing debugging or when using WinMTR. Or, configure them properly. + +b) I get an error saying the program cannot be executed. + +You are running the 64 bit version on a 32 bit platform. Try the WinMTR.exe stored in the WinMTR_x32 folder. + +c) I get an error unspecified here. + +Please report it to us to make sure it’s not a bug in the application. + + +*** Changelog *** +31.01.2011 - Version v0.92 is out, fixing reporting errors for very slow connections. +11.01.2011 - Version v0.91 is out under GPL v2, by popular request. +24.12.2010 - New version! for 32 and 64 bit Operating Systems. Now works on Windows 7 as a regular user. Various bug fixes. License changed from GPL to commercial, but not for long ;-) (v0.9) +20.01.2002 - Last entered hosts an options are now hold in registry. Home page and development moved to Sourceforge. +05.09.2001 - Replace edit box with combo box which hold last entered host names. Fixed a memory leak which caused program to crash after a long time running. (v0.7) +11.27.2000 - Added resizing support and flat buttons. (v0.6) +11.26.2000 - Added copy data to clipboard and possibility to save data to file as text or HTML.(v0.5) +08.03.2000 - Added double-click on host name in list for detailed information. (v0.4) +08.02.2000 - Fixed ICMP error codes handling. Print an error message corresponding to ICP_HOST_UNREACHABLE error code instead of a empty line. (v0.3) +08.01.2000 - Support for full command-line operations. (v0.2) +07.28.2000 - First release. (v0.1) + +*** Bug Reports **** + +Let us know if you identify bugs. Make sure you mention the WinMTR version. Also, we need as much info as possible about your Operating System and current setup. +Before submitting a bug make sure it is not something related to your own specific configurations (e.g. anti-viruses, firewalls). + +*** Feature requests *** + +If you need some functionality from which others can also benefit, please let us know. We will try to integrate your request on our future releases. +Specific features can be implemented on request under a commercial support agreement. Costs depend on complexity and timing. Contact us for a custom quotation. +If you are a developer planning to extend the current open source code, please let us know, so we can integrate it in the official tree + + +*** Contact *** + +Use the form available at http://winmtr.net or write to us contact AT winmtr DOT net + +(c) GPL v2 - 2010-2010 Appnor MSP S.A. - http://www.appnor.com diff --git a/WinMTR.ico b/WinMTR.ico new file mode 100644 index 0000000000000000000000000000000000000000..d5fbf3d3c762739cad4f4a085ca6c85c4c6907aa GIT binary patch literal 1078 zcmcgrJC?&B3>+tU52}ri;3_Z2*dw`9t8RURy^fEPGG)qi>F|< literal 0 HcmV?d00001 diff --git a/WinMTR.rc b/WinMTR.rc new file mode 100644 index 0000000..20399b0 --- /dev/null +++ b/WinMTR.rc @@ -0,0 +1,370 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United States) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "#define _AFX_NO_SPLITTER_RESOURCES\r\n" + "#define _AFX_NO_OLE_RESOURCES\r\n" + "#define _AFX_NO_TRACKER_RESOURCES\r\n" + "#define _AFX_NO_PROPERTY_RESOURCES\r\n" + "\r\n" + "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n" + "#ifdef _WIN32\r\n" + "LANGUAGE 9, 1\r\n" + "#pragma code_page(1252)\r\n" + "#endif //_WIN32\r\n" + "#include ""afxres.rc"" // Standard components\r\n" + "#endif\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDR_MAINFRAME ICON "WinMTR.ico" + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_WINMTR_DIALOG DIALOGEX 0, 0, 390, 193 +STYLE DS_SETFONT | DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME +EXSTYLE WS_EX_APPWINDOW +FONT 8, "MS Sans Serif", 0, 0, 0x1 +BEGIN + DEFPUSHBUTTON "&Start",ID_RESTART,203,12,50,14,BS_FLAT + PUSHBUTTON "&Options",ID_OPTIONS,270,12,51,14,BS_FLAT + PUSHBUTTON "E&xit",IDCANCEL,328,12,49,14,BS_FLAT + PUSHBUTTON "&Copy Text to clipboard",ID_CTTC,14,39,89,14,BS_FLAT + PUSHBUTTON "Co&py HTML to clipboard",ID_CHTC,113,39,89,14,BS_FLAT + PUSHBUTTON "Export &TEXT",ID_EXPT,270,39,51,14,BS_FLAT + PUSHBUTTON "Export &HTML",ID_EXPH,328,39,49,14,BS_FLAT + CONTROL "List1",IDC_LIST_MTR,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,60,376,126 + LTEXT "Host:",IDC_STATIC,13,12,20,13,SS_CENTERIMAGE + GROUPBOX "",IDC_STATIC,7,3,251,29,BS_FLAT + GROUPBOX "",IDC_STATICS,263,3,120,29,BS_FLAT + GROUPBOX "",IDC_STATICJ,7,31,376,26,BS_FLAT + COMBOBOX IDC_COMBO_HOST,35,12,164,73,CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP +END + +IDD_DIALOG_OPTIONS DIALOGEX 0, 0, 251, 164 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Options" +FONT 8, "MS Sans Serif", 0, 0, 0x0 +BEGIN + DEFPUSHBUTTON "&OK",IDOK,53,143,50,14,BS_FLAT + PUSHBUTTON "&Cancel",IDCANCEL,141,143,50,14,BS_FLAT + GROUPBOX "",IDC_STATIC,7,91,237,46,BS_FLAT + ICON IDR_MAINFRAME,IDC_STATIC,15,12,20,20 + LTEXT "Interval (sec):",IDC_STATIC,15,102,45,10,NOT WS_GROUP + EDITTEXT IDC_EDIT_INTERVAL,71,99,34,13,ES_AUTOHSCROLL + LTEXT "Ping size (bytes):",IDC_STATIC,139,102,53,10,NOT WS_GROUP + EDITTEXT IDC_EDIT_SIZE,196,99,34,13,ES_AUTOHSCROLL | ES_NUMBER + CONTROL "Resolve names",IDC_CHECK_DNS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,167,119,63,8 + GROUPBOX "",IDC_STATIC,7,7,237,82,BS_FLAT + CTEXT "Get Fully Managed Dedicated and Cloud hosting in Europe and USA at killer prices.",IDC_STATIC,31,35,201,17 + CTEXT "WinMTR v0.92 is offered under GPL V2 by Appnor MSP",IDC_STATIC,42,14,194,17 + PUSHBUTTON "&License and Credits",ID_LICENSE,81,67,94,14,BS_FLAT + LTEXT "Max. hosts in LRU list:",IDC_STATIC,15,119,74,10,NOT WS_GROUP + EDITTEXT IDC_EDIT_MAX_LRU,90,116,34,13,ES_AUTOHSCROLL + CONTROL "www.appnor.com",IDC_MFCLINK1,"MfcLink",WS_TABSTOP,102,51,60,11 +END + +IDD_DIALOG_LICENSE DIALOGEX 0, 0, 175, 70 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "License & Credits" +FONT 8, "MS Sans Serif", 0, 0, 0x0 +BEGIN + DEFPUSHBUTTON "OK",IDOK,59,43,50,14 + LTEXT "Read more on",IDC_STATIC,36,27,46,8 + CONTROL "www.winmtr.net",IDC_MFCLINK1,"MfcLink",WS_TABSTOP,83,26,60,14 + LTEXT "WinMTR is licensed under GPL V2.",IDC_STATIC,33,14,113,8 +END + +IDD_DIALOG_PROPERTIES DIALOG 0, 0, 201, 159 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Host properties" +FONT 8, "MS Sans Serif" +BEGIN + DEFPUSHBUTTON "OK",IDOK,71,138,50,14,BS_FLAT + LTEXT "Name:",IDC_STATIC,15,18,24,8 + EDITTEXT IDC_EDIT_PHOST,48,16,136,12,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY + LTEXT "IP Address:",IDC_STATIC,14,32,40,9 + EDITTEXT IDC_EDIT_PIP,58,31,126,12,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY + GROUPBOX "Packets",IDC_STATIC,7,74,89,60,BS_FLAT + GROUPBOX "Ping time",IDC_STATIC,108,74,86,60,BS_FLAT + GROUPBOX "Host",IDC_STATIC,7,7,187,62,BS_FLAT + LTEXT "Loss (%):",IDC_STATIC,13,117,31,9 + LTEXT "Received:",IDC_STATIC,13,101,36,9 + LTEXT "Sent:",IDC_STATIC,13,85,21,9 + LTEXT "Last:",IDC_STATIC,114,84,18,9 + LTEXT "Best:",IDC_STATIC,114,96,20,8 + LTEXT "Average:",IDC_STATIC,114,107,32,8 + LTEXT "Worst:",IDC_STATIC,114,118,23,8 + EDITTEXT IDC_EDIT_PSENT,53,82,35,12,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY | ES_NUMBER + EDITTEXT IDC_EDIT_PRECV,53,99,35,12,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY | ES_NUMBER + EDITTEXT IDC_EDIT_PLOSS,53,116,35,12,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY | ES_NUMBER + EDITTEXT IDC_EDIT_PLAST,150,81,34,12,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY + EDITTEXT IDC_EDIT_PBEST,150,94,34,12,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY + EDITTEXT IDC_EDIT_PAVRG,150,106,34,12,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY + EDITTEXT IDC_EDIT_PWORST,150,118,34,12,ES_RIGHT | ES_AUTOHSCROLL | ES_READONLY + EDITTEXT IDC_EDIT_PCOMMENT,14,50,170,12,ES_AUTOHSCROLL | ES_READONLY +END + +IDD_DIALOG_HELP DIALOGEX 0, 0, 256, 122 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "WinMTR" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + DEFPUSHBUTTON "OK",IDOK,144,101,50,14 + CONTROL "www.appnor.com",IDC_MFCLINK1,"MfcLink",WS_TABSTOP,187,8,60,11 + LTEXT "WinMTR v0.92 is offered under GPL V2 by Appnor MSP",IDC_STATIC,7,9,176,10 + LTEXT "Usage: WinMTR [options] target_host_name",IDC_STATIC,7,29,144,8 + LTEXT "Options:",IDC_STATIC,7,39,28,8 + LTEXT " --interval, -i VALUE. Set ping interval.",IDC_STATIC,26,47,131,8 + LTEXT " --size, -s VALUE. Set ping size.",IDC_STATIC,26,57,109,8 + LTEXT " --maxLRU, -m VALUE. Set max hosts in LRU list.",IDC_STATIC,26,67,163,8 + LTEXT " --help, -h. Print this help.",IDC_STATIC,26,89,92,8 + LTEXT " --numeric, -n. Do not resolve names.",IDC_STATIC,26,78,129,8 +END + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 0,9,0,2 + PRODUCTVERSION 0,9,0,2 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x1L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "FileDescription", "WinMTR by Appnor MSP - www.winmtr.net" + VALUE "FileVersion", "0.9.0.2" + VALUE "InternalName", "WinMTR" + VALUE "LegalCopyright", "WinMTR 0.9 (c) 2010-2011 Appnor MSP - Fully Managed Hosting & Cloud Provider www.appnor.com" + VALUE "OriginalFilename", "WinMTR.EXE" + VALUE "ProductName", "WinMTR Application" + VALUE "ProductVersion", "0.9.0.2" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO +BEGIN + IDD_WINMTR_DIALOG, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 383 + VERTGUIDE, 270 + VERTGUIDE, 321 + VERTGUIDE, 328 + VERTGUIDE, 377 + TOPMARGIN, 7 + BOTTOMMARGIN, 186 + HORZGUIDE, 12 + HORZGUIDE, 39 + END + + IDD_DIALOG_OPTIONS, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 244 + TOPMARGIN, 7 + BOTTOMMARGIN, 157 + END + + IDD_DIALOG_LICENSE, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 168 + TOPMARGIN, 7 + BOTTOMMARGIN, 63 + END + + IDD_DIALOG_PROPERTIES, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 194 + TOPMARGIN, 7 + BOTTOMMARGIN, 152 + END + + IDD_DIALOG_HELP, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 249 + VERTGUIDE, 26 + TOPMARGIN, 7 + BOTTOMMARGIN, 115 + END +END +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog Info +// + +IDD_DIALOG_HELP DLGINIT +BEGIN + IDC_MFCLINK1, 0x37c, 238, 0 +0x4d3c, 0x4346, 0x694c, 0x6b6e, 0x555f, 0x6c72, 0x683e, 0x7474, 0x3a70, +0x2f2f, 0x7777, 0x2e77, 0x7061, 0x6e70, 0x726f, 0x632e, 0x6d6f, 0x3f2f, +0x7475, 0x5f6d, 0x6f73, 0x7275, 0x6563, 0x773d, 0x6e69, 0x746d, 0x2672, +0x7475, 0x5f6d, 0x656d, 0x6964, 0x6d75, 0x643d, 0x7365, 0x746b, 0x706f, +0x7526, 0x6d74, 0x635f, 0x6d61, 0x6170, 0x6769, 0x3d6e, 0x6f73, 0x7466, +0x6177, 0x6572, 0x2f3c, 0x464d, 0x4c43, 0x6e69, 0x5f6b, 0x7255, 0x3e6c, +0x4d3c, 0x4346, 0x694c, 0x6b6e, 0x555f, 0x6c72, 0x7250, 0x6665, 0x7869, +0x3c3e, 0x4d2f, 0x4346, 0x694c, 0x6b6e, 0x555f, 0x6c72, 0x7250, 0x6665, +0x7869, 0x3c3e, 0x464d, 0x4c43, 0x6e69, 0x5f6b, 0x6f54, 0x6c6f, 0x6974, +0x3e70, 0x2f3c, 0x464d, 0x4c43, 0x6e69, 0x5f6b, 0x6f54, 0x6c6f, 0x6974, +0x3e70, 0x4d3c, 0x4346, 0x694c, 0x6b6e, 0x465f, 0x6c75, 0x546c, 0x7865, +0x5474, 0x6f6f, 0x746c, 0x7069, 0x463e, 0x4c41, 0x4553, 0x2f3c, 0x464d, +0x4c43, 0x6e69, 0x5f6b, 0x7546, 0x6c6c, 0x6554, 0x7478, 0x6f54, 0x6c6f, +0x6974, 0x3e70, + 0 +END + +IDD_DIALOG_OPTIONS DLGINIT +BEGIN + IDC_MFCLINK1, 0x37c, 238, 0 +0x4d3c, 0x4346, 0x694c, 0x6b6e, 0x555f, 0x6c72, 0x683e, 0x7474, 0x3a70, +0x2f2f, 0x7777, 0x2e77, 0x7061, 0x6e70, 0x726f, 0x632e, 0x6d6f, 0x3f2f, +0x7475, 0x5f6d, 0x6f73, 0x7275, 0x6563, 0x773d, 0x6e69, 0x746d, 0x2672, +0x7475, 0x5f6d, 0x656d, 0x6964, 0x6d75, 0x643d, 0x7365, 0x746b, 0x706f, +0x7526, 0x6d74, 0x635f, 0x6d61, 0x6170, 0x6769, 0x3d6e, 0x6f73, 0x7466, +0x6177, 0x6572, 0x2f3c, 0x464d, 0x4c43, 0x6e69, 0x5f6b, 0x7255, 0x3e6c, +0x4d3c, 0x4346, 0x694c, 0x6b6e, 0x555f, 0x6c72, 0x7250, 0x6665, 0x7869, +0x3c3e, 0x4d2f, 0x4346, 0x694c, 0x6b6e, 0x555f, 0x6c72, 0x7250, 0x6665, +0x7869, 0x3c3e, 0x464d, 0x4c43, 0x6e69, 0x5f6b, 0x6f54, 0x6c6f, 0x6974, +0x3e70, 0x2f3c, 0x464d, 0x4c43, 0x6e69, 0x5f6b, 0x6f54, 0x6c6f, 0x6974, +0x3e70, 0x4d3c, 0x4346, 0x694c, 0x6b6e, 0x465f, 0x6c75, 0x546c, 0x7865, +0x5474, 0x6f6f, 0x746c, 0x7069, 0x463e, 0x4c41, 0x4553, 0x2f3c, 0x464d, +0x4c43, 0x6e69, 0x5f6b, 0x7546, 0x6c6c, 0x6554, 0x7478, 0x6f54, 0x6c6f, +0x6974, 0x3e70, + 0 +END + +IDD_DIALOG_LICENSE DLGINIT +BEGIN + IDC_MFCLINK1, 0x37c, 157, 0 +0x4d3c, 0x4346, 0x694c, 0x6b6e, 0x555f, 0x6c72, 0x3c3e, 0x4d2f, 0x4346, +0x694c, 0x6b6e, 0x555f, 0x6c72, 0x3c3e, 0x464d, 0x4c43, 0x6e69, 0x5f6b, +0x7255, 0x506c, 0x6572, 0x6966, 0x3e78, 0x2f3c, 0x464d, 0x4c43, 0x6e69, +0x5f6b, 0x7255, 0x506c, 0x6572, 0x6966, 0x3e78, 0x4d3c, 0x4346, 0x694c, +0x6b6e, 0x545f, 0x6f6f, 0x746c, 0x7069, 0x3c3e, 0x4d2f, 0x4346, 0x694c, +0x6b6e, 0x545f, 0x6f6f, 0x746c, 0x7069, 0x3c3e, 0x464d, 0x4c43, 0x6e69, +0x5f6b, 0x7546, 0x6c6c, 0x6554, 0x7478, 0x6f54, 0x6c6f, 0x6974, 0x3e70, +0x4146, 0x534c, 0x3c45, 0x4d2f, 0x4346, 0x694c, 0x6b6e, 0x465f, 0x6c75, +0x546c, 0x7865, 0x5474, 0x6f6f, 0x746c, 0x7069, "\076" + 0 +END + + +///////////////////////////////////////////////////////////////////////////// +// +// String Table +// + +STRINGTABLE +BEGIN + IDP_SOCKETS_INIT_FAILED "Windows sockets initialization failed." + IDS_STRING_SB_NAME "WinMTR v0.92 GPL V2 by Appnor MSP - Fully Managed Hosting & Cloud Provider" + IDS_STRING_SB_PING "0000000" + IDS_STRING_CLEAR_HISTORY "Clear History" +END + +#endif // English (United States) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// +#define _AFX_NO_SPLITTER_RESOURCES +#define _AFX_NO_OLE_RESOURCES +#define _AFX_NO_TRACKER_RESOURCES +#define _AFX_NO_PROPERTY_RESOURCES + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE 9, 1 +#pragma code_page(1252) +#endif //_WIN32 +#include "afxres.rc" // Standard components +#endif + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/WinMTR.sln b/WinMTR.sln new file mode 100644 index 0000000..c278cdd --- /dev/null +++ b/WinMTR.sln @@ -0,0 +1,26 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinMTR", "WinMTR.vcxproj", "{EE7B51B5-96FC-BED3-F2A6-0713CECBB579}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EE7B51B5-96FC-BED3-F2A6-0713CECBB579}.Debug|Win32.ActiveCfg = Debug|Win32 + {EE7B51B5-96FC-BED3-F2A6-0713CECBB579}.Debug|Win32.Build.0 = Debug|Win32 + {EE7B51B5-96FC-BED3-F2A6-0713CECBB579}.Debug|x64.ActiveCfg = Debug|x64 + {EE7B51B5-96FC-BED3-F2A6-0713CECBB579}.Debug|x64.Build.0 = Debug|x64 + {EE7B51B5-96FC-BED3-F2A6-0713CECBB579}.Release|Win32.ActiveCfg = Release|Win32 + {EE7B51B5-96FC-BED3-F2A6-0713CECBB579}.Release|Win32.Build.0 = Release|Win32 + {EE7B51B5-96FC-BED3-F2A6-0713CECBB579}.Release|x64.ActiveCfg = Release|x64 + {EE7B51B5-96FC-BED3-F2A6-0713CECBB579}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/WinMTR.suo b/WinMTR.suo new file mode 100644 index 0000000000000000000000000000000000000000..219788e8f3feef76fe3af819e9dea58519dbf21e GIT binary patch literal 8704 zcmeHM&vO%19RC)m{8kV}M8pWFC?zJ87Nk^%Chh1*X`mr^V01RgCN5oeJK0TX2buBa zNe>>pd-3i;FU~mX$r)w@$A3Ui-WbQTQa_)!``T@2l5G+knBklG=IxL7-uL^yzu(*2 zw|4&i<=1=vkOp{D*2~?+&GJ~}c^|Hc3U-LB!v*i}E-o$x4@GeK2p%E{{0m+;ggWd; zOMPzyZU$}wZUJrsZUsIL+zxyKNSzZO!NVX>!EX4nIXT)k*prFYGRygOq$qs7!awk}H9&u+D zQJ68$3uB;(SX{!BIItg8Abp*&fa{1ehAZ#qA0P`lMX5^_Kk{%1@z@9T4{_Hn_Huk8 zjDL(hap|*`VShp+{W0)hf`=JM#f3bW6I=0d81xw@Srf&j&wA<{kkCk<`H!+^7O=p9 z(~>%4<+?t`ZN}xe^jXL0{L>4gkC?eO`OqOUu5FtodM{0G16@QZelyd}4*n6Sk4`~5 zaW~_~FgPoxo%&1orGV2yXS6(qqH_ui~)aItI&HHw*x2PQs&#^k2iTj^PNYYmMg5F}l7w9vr zs)D_($S6+J2qSVF|JRX2#^r>J$q+n>|3~EwMC1v0&QaWtBPtK#YC?`7=M3X2h2CjA z%ivuGJvinB#@v86mJyv+(w$P(LzF5b?#e!zH`W_Ite^&)pvNy~3f;qmt@xnIT7*4U zRz#;dh<_{NuZ#KX@ZVtOXr#-jxWs*N^GYa%_{TFV?m6SezkTRSi4d}&(Tu)63&=t; z)az=H>~j6gv-Cv0#z4*$thkD&%-{OWYScxLfBLvTXH6G({m-NCTv&Vs+NG^*Qv2>+ z+U5vm?X|V@yo8kuPi;*32-Z6cpGqS7k11Jk=P-sIWl&!By0`8-AA#Kt!eiU4l9~R4A#+~ndN@d=u{R{sIjjggK@9W7~>1rC$xhDh(A0tM`tJX+;l%~vP;zZ3?a4kyt159FN(7j>-KU-}+VLuJw` z2eba*+Ifb-R`b=Wjmn?O-Ta9ge$L}AEFHGlg>8H`R7EXk*TfRAe{mwsM{Pz9d zUv1p=%gt}r^Z|&pi4|ZkYll(wW#ryWFNpn7Ank785UK@!0h>{JuA%jWd*Bp)X~c5= zw}SU>F^4_8Fr{iw8&SYfSdB!!ES_jPX|_Vdzcu^+ASPqYPH2>V+_)Qz7TMPUeeS{d zZHb`2^Xcz@)2JVr19%3_s=QqU>}35zpsUYc3ZRfz7HF%}u6f9xk#`QVZ+G@a{uzIF Qq2)d_uKy3CuReGD55Zod0ssI2 literal 0 HcmV?d00001 diff --git a/WinMTR.vcxproj b/WinMTR.vcxproj new file mode 100644 index 0000000..47bdbcf --- /dev/null +++ b/WinMTR.vcxproj @@ -0,0 +1,287 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + + + + + + Application + false + MultiByte + + + Application + false + MultiByte + + + Application + false + MultiByte + + + Application + false + MultiByte + + + + + + + + + + + + + + + + + + + + + + + .\Release_x32\ + .\Release_x32\ + false + + + .\Release_x64\ + .\Release_x64\ + false + + + .\Debug_x32\ + .\Debug_x32\ + true + + + .\Debug_x64\ + .\Debug_x64\ + true + + + + MultiThreaded + OnlyExplicitInline + true + true + MaxSpeed + true + Level3 + WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + .\Release\ + .\Release\WinMTR.pch + .\Release\ + .\Release\ + + + true + NDEBUG;%(PreprocessorDefinitions) + .\Release\WinMTR.tlb + true + Win32 + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + + + true + .\Release\WinMTR.bsc + + + true + Windows + .\Release_x32\WinMTR.exe + odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + AsInvoker + false + true + + + + + MultiThreaded + OnlyExplicitInline + true + true + MaxSpeed + true + Level3 + WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + .\Release\ + .\Release\WinMTR.pch + .\Release\ + .\Release\ + + + true + NDEBUG;%(PreprocessorDefinitions) + .\Release\WinMTR.tlb + true + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + + + true + .\Release\WinMTR.bsc + + + true + Windows + .\Release_x64\WinMTR.exe + odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + AsInvoker + false + true + + + + + MultiThreadedDebug + Default + false + Disabled + true + Level3 + true + EditAndContinue + WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + .\Debug\ + .\Debug\WinMTR.pch + .\Debug\ + .\Debug\ + EnableFastChecks + + + true + _DEBUG;%(PreprocessorDefinitions) + .\Debug\WinMTR.tlb + true + Win32 + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + + + true + .\Debug\WinMTR.bsc + + + true + true + Windows + .\Debug_x32\WinMTR.exe + odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + AsInvoker + false + true + + + + + MultiThreadedDebug + Default + false + Disabled + true + Level3 + ProgramDatabase + WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + .\Debug\ + .\Debug\WinMTR.pch + .\Debug\ + .\Debug\ + EnableFastChecks + + + true + _DEBUG;%(PreprocessorDefinitions) + .\Debug\WinMTR.tlb + true + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + + + true + .\Debug\WinMTR.bsc + + + true + true + Windows + .\Debug_x64\WinMTR.exe + odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + AsInvoker + false + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WinMTRDialog.cpp b/WinMTRDialog.cpp new file mode 100644 index 0000000..9fcc82e --- /dev/null +++ b/WinMTRDialog.cpp @@ -0,0 +1,1230 @@ +//***************************************************************************** +// FILE: WinMTRDialog.cpp +// +// +//***************************************************************************** + +#include "WinMTRGlobal.h" +#include "WinMTRDialog.h" +#include "WinMTROptions.h" +#include "WinMTRProperties.h" +#include "WinMTRNet.h" +#include +#include +#include "afxlinkctrl.h" + +#define TRACE_MSG(msg) \ + { \ + std::ostringstream dbg_msg(std::ostringstream::out); \ + dbg_msg << msg << std::endl; \ + OutputDebugString(dbg_msg.str().c_str()); \ + } + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +void PingThread(void *p); + +//***************************************************************************** +// BEGIN_MESSAGE_MAP +// +// +//***************************************************************************** +BEGIN_MESSAGE_MAP(WinMTRDialog, CDialog) + ON_WM_PAINT() + ON_WM_SIZE() + ON_WM_SIZING() + ON_WM_QUERYDRAGICON() + ON_BN_CLICKED(ID_RESTART, OnRestart) + ON_BN_CLICKED(ID_OPTIONS, OnOptions) + ON_BN_CLICKED(ID_CTTC, OnCTTC) + ON_BN_CLICKED(ID_CHTC, OnCHTC) + ON_BN_CLICKED(ID_EXPT, OnEXPT) + ON_BN_CLICKED(ID_EXPH, OnEXPH) + ON_NOTIFY(NM_DBLCLK, IDC_LIST_MTR, OnDblclkList) + ON_CBN_SELCHANGE(IDC_COMBO_HOST, &WinMTRDialog::OnCbnSelchangeComboHost) + ON_CBN_SELENDOK(IDC_COMBO_HOST, &WinMTRDialog::OnCbnSelendokComboHost) + ON_CBN_CLOSEUP(IDC_COMBO_HOST, &WinMTRDialog::OnCbnCloseupComboHost) + ON_WM_TIMER() + ON_WM_CLOSE() + ON_BN_CLICKED(IDCANCEL, &WinMTRDialog::OnBnClickedCancel) +END_MESSAGE_MAP() + + +//***************************************************************************** +// WinMTRDialog::WinMTRDialog +// +// +//***************************************************************************** +WinMTRDialog::WinMTRDialog(CWnd* pParent) + : CDialog(WinMTRDialog::IDD, pParent), + state(IDLE), + transition(IDLE_TO_IDLE) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); + m_autostart = 0; + useDNS = DEFAULT_DNS; + interval = DEFAULT_INTERVAL; + pingsize = DEFAULT_PING_SIZE; + maxLRU = DEFAULT_MAX_LRU; + nrLRU = 0; + + hasIntervalFromCmdLine = false; + hasPingsizeFromCmdLine = false; + hasMaxLRUFromCmdLine = false; + hasUseDNSFromCmdLine = false; + + traceThreadMutex = CreateMutex(NULL, FALSE, NULL); + wmtrnet = new WinMTRNet(this); +} + +WinMTRDialog::~WinMTRDialog() +{ + delete wmtrnet; + CloseHandle(traceThreadMutex); +} + +//***************************************************************************** +// WinMTRDialog::DoDataExchange +// +// +//***************************************************************************** +void WinMTRDialog::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + DDX_Control(pDX, ID_OPTIONS, m_buttonOptions); + DDX_Control(pDX, IDCANCEL, m_buttonExit); + DDX_Control(pDX, ID_RESTART, m_buttonStart); + DDX_Control(pDX, IDC_COMBO_HOST, m_comboHost); + DDX_Control(pDX, IDC_LIST_MTR, m_listMTR); + DDX_Control(pDX, IDC_STATICS, m_staticS); + DDX_Control(pDX, IDC_STATICJ, m_staticJ); + DDX_Control(pDX, ID_EXPH, m_buttonExpH); + DDX_Control(pDX, ID_EXPT, m_buttonExpT); +} + + +//***************************************************************************** +// WinMTRDialog::OnInitDialog +// +// +//***************************************************************************** +BOOL WinMTRDialog::OnInitDialog() +{ + CDialog::OnInitDialog(); + + #ifndef _WIN64 + char caption[] = {"WinMTR v0.92 32 bit by Appnor MSP - www.winmtr.net"}; + #else + char caption[] = {"WinMTR v0.92 64 bit by Appnor MSP - www.winmtr.net"}; + #endif + + SetTimer(1, WINMTR_DIALOG_TIMER, NULL); + SetWindowText(caption); + + SetIcon(m_hIcon, TRUE); + SetIcon(m_hIcon, FALSE); + + if(!statusBar.Create( this )) + AfxMessageBox("Error creating status bar"); + statusBar.GetStatusBarCtrl().SetMinHeight(23); + + UINT sbi[1]; + sbi[0] = IDS_STRING_SB_NAME; + statusBar.SetIndicators( sbi,1); + statusBar.SetPaneInfo(0, statusBar.GetItemID(0),SBPS_STRETCH, NULL ); + { // Add appnor URL + CMFCLinkCtrl* m_pWndButton = new CMFCLinkCtrl; + if (!m_pWndButton->Create(_T("www.appnor.com"), WS_CHILD|WS_VISIBLE|WS_TABSTOP, CRect(0,0,0,0), &statusBar, 1234)) { + TRACE(_T("Failed to create button control.\n")); + return FALSE; + } + + m_pWndButton->SetURL("http://www.appnor.com/?utm_source=winmtr&utm_medium=desktop&utm_campaign=software"); + + if(!statusBar.AddPane(1234,1)) { + AfxMessageBox(_T("Pane index out of range\nor pane with same ID already exists in the status bar"), MB_ICONERROR); + return FALSE; + } + + statusBar.SetPaneWidth(statusBar.CommandToIndex(1234), 100); + statusBar.AddPaneControl(m_pWndButton, 1234, true); + } + + for(int i = 0; i< MTR_NR_COLS; i++) + m_listMTR.InsertColumn(i, MTR_COLS[i], LVCFMT_LEFT, MTR_COL_LENGTH[i] , -1); + + m_comboHost.SetFocus(); + + // We need to resize the dialog to make room for control bars. + // First, figure out how big the control bars are. + CRect rcClientStart; + CRect rcClientNow; + GetClientRect(rcClientStart); + RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, + 0, reposQuery, rcClientNow); + + // Now move all the controls so they are in the same relative + // position within the remaining client area as they would be + // with no control bars. + CPoint ptOffset(rcClientNow.left - rcClientStart.left, + rcClientNow.top - rcClientStart.top); + + CRect rcChild; + CWnd* pwndChild = GetWindow(GW_CHILD); + while (pwndChild) + { + pwndChild->GetWindowRect(rcChild); + ScreenToClient(rcChild); + rcChild.OffsetRect(ptOffset); + pwndChild->MoveWindow(rcChild, FALSE); + pwndChild = pwndChild->GetNextWindow(); + } + + // Adjust the dialog window dimensions + CRect rcWindow; + GetWindowRect(rcWindow); + rcWindow.right += rcClientStart.Width() - rcClientNow.Width(); + rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height(); + MoveWindow(rcWindow, FALSE); + + // And position the control bars + RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0); + + InitRegistry(); + + if (m_autostart) { + m_comboHost.SetWindowText(msz_defaulthostname); + OnRestart(); + } + + return FALSE; +} + +//***************************************************************************** +// WinMTRDialog::InitRegistry +// +// +//***************************************************************************** +BOOL WinMTRDialog::InitRegistry() +{ + HKEY hKey, hKey_v; + DWORD res, tmp_dword, value_size; + LONG r; + + r = RegCreateKeyEx( HKEY_CURRENT_USER, + "Software", + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_ALL_ACCESS, + NULL, + &hKey, + &res); + if( r != ERROR_SUCCESS) + return FALSE; + + r = RegCreateKeyEx( hKey, + "WinMTR", + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_ALL_ACCESS, + NULL, + &hKey, + &res); + if( r != ERROR_SUCCESS) + return FALSE; + + RegSetValueEx(hKey,"Version", 0, REG_SZ, (const unsigned char *)WINMTR_VERSION, sizeof(WINMTR_VERSION)+1); + RegSetValueEx(hKey,"License", 0, REG_SZ, (const unsigned char *)WINMTR_LICENSE, sizeof(WINMTR_LICENSE)+1); + RegSetValueEx(hKey,"HomePage", 0, REG_SZ, (const unsigned char *)WINMTR_HOMEPAGE, sizeof(WINMTR_HOMEPAGE)+1); + + r = RegCreateKeyEx( hKey, + "Config", + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_ALL_ACCESS, + NULL, + &hKey_v, + &res); + if( r != ERROR_SUCCESS) + return FALSE; + + if(RegQueryValueEx(hKey_v, "PingSize", 0, NULL, (unsigned char *)&tmp_dword, &value_size) != ERROR_SUCCESS) { + tmp_dword = pingsize; + RegSetValueEx(hKey_v,"PingSize", 0, REG_DWORD, (const unsigned char *)&tmp_dword, sizeof(DWORD)); + } else { + if(!hasPingsizeFromCmdLine) pingsize = tmp_dword; + } + + if(RegQueryValueEx(hKey_v, "MaxLRU", 0, NULL, (unsigned char *)&tmp_dword, &value_size) != ERROR_SUCCESS) { + tmp_dword = maxLRU; + RegSetValueEx(hKey_v,"MaxLRU", 0, REG_DWORD, (const unsigned char *)&tmp_dword, sizeof(DWORD)); + } else { + if(!hasMaxLRUFromCmdLine) maxLRU = tmp_dword; + } + + if(RegQueryValueEx(hKey_v, "UseDNS", 0, NULL, (unsigned char *)&tmp_dword, &value_size) != ERROR_SUCCESS) { + tmp_dword = useDNS ? 1 : 0; + RegSetValueEx(hKey_v,"UseDNS", 0, REG_DWORD, (const unsigned char *)&tmp_dword, sizeof(DWORD)); + } else { + if(!hasUseDNSFromCmdLine) useDNS = (BOOL)tmp_dword; + } + + if(RegQueryValueEx(hKey_v, "Interval", 0, NULL, (unsigned char *)&tmp_dword, &value_size) != ERROR_SUCCESS) { + tmp_dword = (DWORD)(interval * 1000); + RegSetValueEx(hKey_v,"Interval", 0, REG_DWORD, (const unsigned char *)&tmp_dword, sizeof(DWORD)); + } else { + if(!hasIntervalFromCmdLine) interval = (float)tmp_dword / 1000.0; + } + + r = RegCreateKeyEx( hKey, + "LRU", + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_ALL_ACCESS, + NULL, + &hKey_v, + &res); + if( r != ERROR_SUCCESS) + return FALSE; + if(RegQueryValueEx(hKey_v, "NrLRU", 0, NULL, (unsigned char *)&tmp_dword, &value_size) != ERROR_SUCCESS) { + tmp_dword = nrLRU; + RegSetValueEx(hKey_v,"NrLRU", 0, REG_DWORD, (const unsigned char *)&tmp_dword, sizeof(DWORD)); + } else { + char key_name[20]; + unsigned char str_host[255]; + nrLRU = tmp_dword; + for(int i=0;iright)-(pRect->left); + int iHeight = (pRect->bottom)-(pRect->top); + + if (iWidth < 600) + pRect->right = pRect->left + 600; + if (iHeight <250) + pRect->bottom = pRect->top + 250; +} + + +//***************************************************************************** +// WinMTRDialog::OnSize +// +// +//***************************************************************************** +void WinMTRDialog::OnSize(UINT nType, int cx, int cy) +{ + CDialog::OnSize(nType, cx, cy); + CRect r; + GetClientRect(&r); + CRect lb; + + if (::IsWindow(m_staticS.m_hWnd)) { + m_staticS.GetWindowRect(&lb); + ScreenToClient(&lb); + m_staticS.SetWindowPos(NULL, lb.TopLeft().x, lb.TopLeft().y, r.Width()-lb.TopLeft().x-10, lb.Height() , SWP_NOMOVE | SWP_NOZORDER); + } + + if (::IsWindow(m_staticJ.m_hWnd)) { + m_staticJ.GetWindowRect(&lb); + ScreenToClient(&lb); + m_staticJ.SetWindowPos(NULL, lb.TopLeft().x, lb.TopLeft().y, r.Width() - 21, lb.Height(), SWP_NOMOVE | SWP_NOZORDER); + } + + if (::IsWindow(m_buttonExit.m_hWnd)) { + m_buttonExit.GetWindowRect(&lb); + ScreenToClient(&lb); + m_buttonExit.SetWindowPos(NULL, r.Width() - lb.Width()-21, lb.TopLeft().y, lb.Width(), lb.Height() , SWP_NOSIZE | SWP_NOZORDER); + } + + if (::IsWindow(m_buttonExpH.m_hWnd)) { + m_buttonExpH.GetWindowRect(&lb); + ScreenToClient(&lb); + m_buttonExpH.SetWindowPos(NULL, r.Width() - lb.Width()-21, lb.TopLeft().y, lb.Width(), lb.Height() , SWP_NOSIZE | SWP_NOZORDER); + } + if (::IsWindow(m_buttonExpT.m_hWnd)) { + m_buttonExpT.GetWindowRect(&lb); + ScreenToClient(&lb); + m_buttonExpT.SetWindowPos(NULL, r.Width() - lb.Width()- 103, lb.TopLeft().y, lb.Width(), lb.Height() , SWP_NOSIZE | SWP_NOZORDER); + } + + if (::IsWindow(m_listMTR.m_hWnd)) { + m_listMTR.GetWindowRect(&lb); + ScreenToClient(&lb); + m_listMTR.SetWindowPos(NULL, lb.TopLeft().x, lb.TopLeft().y, r.Width() - 21, r.Height() - lb.top - 25, SWP_NOMOVE | SWP_NOZORDER); + } + + RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, + 0, reposQuery, r); + + RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0); + +} + + +//***************************************************************************** +// WinMTRDialog::OnPaint +// +// +//***************************************************************************** +void WinMTRDialog::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); + + SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); + + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialog::OnPaint(); + } +} + + +//***************************************************************************** +// WinMTRDialog::OnQueryDragIcon +// +// +//***************************************************************************** +HCURSOR WinMTRDialog::OnQueryDragIcon() +{ + return (HCURSOR) m_hIcon; +} + + +//***************************************************************************** +// WinMTRDialog::OnDblclkList +// +//***************************************************************************** +void WinMTRDialog::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult) +{ + *pResult = 0; + + if(state == TRACING) { + + POSITION pos = m_listMTR.GetFirstSelectedItemPosition(); + if(pos!=NULL) { + int nItem = m_listMTR.GetNextSelectedItem(pos); + WinMTRProperties wmtrprop; + + if(wmtrnet->GetAddr(nItem)==0) { + strcpy(wmtrprop.host,""); + strcpy(wmtrprop.ip,""); + wmtrnet->GetName(nItem, wmtrprop.comment); + + wmtrprop.pck_loss = wmtrprop.pck_sent = wmtrprop.pck_recv = 0; + + wmtrprop.ping_avrg = wmtrprop.ping_last = 0.0; + wmtrprop.ping_best = wmtrprop.ping_worst = 0.0; + } else { + wmtrnet->GetName(nItem, wmtrprop.host); + int addr = wmtrnet->GetAddr(nItem); + sprintf ( wmtrprop.ip , "%d.%d.%d.%d", + (addr >> 24) & 0xff, + (addr >> 16) & 0xff, + (addr >> 8) & 0xff, + addr & 0xff + ); + strcpy(wmtrprop.comment , "Host alive."); + + wmtrprop.ping_avrg = (float)wmtrnet->GetAvg(nItem); + wmtrprop.ping_last = (float)wmtrnet->GetLast(nItem); + wmtrprop.ping_best = (float)wmtrnet->GetBest(nItem); + wmtrprop.ping_worst = (float)wmtrnet->GetWorst(nItem); + + wmtrprop.pck_loss = wmtrnet->GetPercent(nItem); + wmtrprop.pck_recv = wmtrnet->GetReturned(nItem); + wmtrprop.pck_sent = wmtrnet->GetXmit(nItem); + } + + wmtrprop.DoModal(); + } + } +} + + +//***************************************************************************** +// WinMTRDialog::SetHostName +// +//***************************************************************************** +void WinMTRDialog::SetHostName(const char *host) +{ + m_autostart = 1; + strncpy(msz_defaulthostname,host,1000); +} + + +//***************************************************************************** +// WinMTRDialog::SetPingSize +// +//***************************************************************************** +void WinMTRDialog::SetPingSize(int ps) +{ + pingsize = ps; +} + +//***************************************************************************** +// WinMTRDialog::SetMaxLRU +// +//***************************************************************************** +void WinMTRDialog::SetMaxLRU(int mlru) +{ + maxLRU = mlru; +} + + +//***************************************************************************** +// WinMTRDialog::SetInterval +// +//***************************************************************************** +void WinMTRDialog::SetInterval(float i) +{ + interval = i; +} + +//***************************************************************************** +// WinMTRDialog::SetUseDNS +// +//***************************************************************************** +void WinMTRDialog::SetUseDNS(BOOL udns) +{ + useDNS = udns; +} + + + + +//***************************************************************************** +// WinMTRDialog::OnRestart +// +// +//***************************************************************************** +void WinMTRDialog::OnRestart() +{ + // If clear history is selected, just clear the registry and listbox and return + if(m_comboHost.GetCurSel() == m_comboHost.GetCount() - 1) { + ClearHistory(); + return; + } + + CString sHost; + + if(state == IDLE) { + m_comboHost.GetWindowText(sHost); + sHost.TrimLeft(); + sHost.TrimLeft(); + + if(sHost.IsEmpty()) { + AfxMessageBox("No host specified!"); + m_comboHost.SetFocus(); + return ; + } + m_listMTR.DeleteAllItems(); + } + + if(state == IDLE) { + + if(InitMTRNet()) { + if(m_comboHost.FindString(-1, sHost) == CB_ERR) { + m_comboHost.InsertString(m_comboHost.GetCount() - 1,sHost); + + HKEY hKey; + DWORD tmp_dword; + LONG r; + char key_name[20]; + + r = RegOpenKeyEx( HKEY_CURRENT_USER, "Software", 0, KEY_ALL_ACCESS,&hKey); + r = RegOpenKeyEx( hKey, "WinMTR", 0, KEY_ALL_ACCESS, &hKey); + r = RegOpenKeyEx( hKey, "LRU", 0, KEY_ALL_ACCESS, &hKey); + + if(nrLRU >= maxLRU) + nrLRU = 0; + + nrLRU++; + sprintf(key_name, "Host%d", nrLRU); + r = RegSetValueEx(hKey,key_name, 0, REG_SZ, (const unsigned char *)(LPCTSTR)sHost, strlen((LPCTSTR)sHost)+1); + tmp_dword = nrLRU; + r = RegSetValueEx(hKey,"NrLRU", 0, REG_DWORD, (const unsigned char *)&tmp_dword, sizeof(DWORD)); + RegCloseKey(hKey); + } + Transit(TRACING); + } + } else { + Transit(STOPPING); + } +} + + +//***************************************************************************** +// WinMTRDialog::OnOptions +// +// +//***************************************************************************** +void WinMTRDialog::OnOptions() +{ + WinMTROptions optDlg; + + optDlg.SetPingSize(pingsize); + optDlg.SetInterval(interval); + optDlg.SetMaxLRU(maxLRU); + optDlg.SetUseDNS(useDNS); + + if(IDOK == optDlg.DoModal()) { + + pingsize = optDlg.GetPingSize(); + interval = optDlg.GetInterval(); + maxLRU = optDlg.GetMaxLRU(); + useDNS = optDlg.GetUseDNS(); + + HKEY hKey; + DWORD tmp_dword; + LONG r; + char key_name[20]; + + r = RegOpenKeyEx( HKEY_CURRENT_USER, "Software", 0, KEY_ALL_ACCESS,&hKey); + r = RegOpenKeyEx( hKey, "WinMTR", 0, KEY_ALL_ACCESS, &hKey); + r = RegOpenKeyEx( hKey, "Config", 0, KEY_ALL_ACCESS, &hKey); + tmp_dword = pingsize; + RegSetValueEx(hKey,"PingSize", 0, REG_DWORD, (const unsigned char *)&tmp_dword, sizeof(DWORD)); + tmp_dword = maxLRU; + RegSetValueEx(hKey,"MaxLRU", 0, REG_DWORD, (const unsigned char *)&tmp_dword, sizeof(DWORD)); + tmp_dword = useDNS ? 1 : 0; + RegSetValueEx(hKey,"UseDNS", 0, REG_DWORD, (const unsigned char *)&tmp_dword, sizeof(DWORD)); + tmp_dword = (DWORD)(interval * 1000); + RegSetValueEx(hKey,"Interval", 0, REG_DWORD, (const unsigned char *)&tmp_dword, sizeof(DWORD)); + RegCloseKey(hKey); + if(maxLRUGetMax(); + + strcpy(f_buf, "|------------------------------------------------------------------------------------------|\r\n"); + sprintf(t_buf, "| WinMTR statistics |\r\n"); + strcat(f_buf, t_buf); + sprintf(t_buf, "| Host - %% | Sent | Recv | Best | Avrg | Wrst | Last |\r\n" ); + strcat(f_buf, t_buf); + sprintf(t_buf, "|------------------------------------------------|------|------|------|------|------|------|\r\n" ); + strcat(f_buf, t_buf); + + for(int i=0;i GetName(i, buf); + if(strcmp(buf,"")==0) strcpy(buf,"No response from host"); + + sprintf(t_buf, "|%40s - %4d | %4d | %4d | %4d | %4d | %4d | %4d |\r\n" , + buf, wmtrnet->GetPercent(i), + wmtrnet->GetXmit(i), wmtrnet->GetReturned(i), wmtrnet->GetBest(i), + wmtrnet->GetAvg(i), wmtrnet->GetWorst(i), wmtrnet->GetLast(i)); + strcat(f_buf, t_buf); + } + + sprintf(t_buf, "|________________________________________________|______|______|______|______|______|______|\r\n" ); + strcat(f_buf, t_buf); + + CString cs_tmp((LPCSTR)IDS_STRING_SB_NAME); + strcat(f_buf, " "); + strcat(f_buf, (LPCTSTR)cs_tmp); + + CString source(f_buf); + + HGLOBAL clipbuffer; + char * buffer; + + OpenClipboard(); + EmptyClipboard(); + + clipbuffer = GlobalAlloc(GMEM_DDESHARE, source.GetLength()+1); + buffer = (char*)GlobalLock(clipbuffer); + strcpy(buffer, LPCSTR(source)); + GlobalUnlock(clipbuffer); + + SetClipboardData(CF_TEXT,clipbuffer); + CloseClipboard(); +} + + +//***************************************************************************** +// WinMTRDialog::OnCHTC +// +// +//***************************************************************************** +void WinMTRDialog::OnCHTC() +{ + char buf[255], t_buf[1000], f_buf[255*100]; + + int nh = wmtrnet->GetMax(); + + strcpy(f_buf, "WinMTR Statistics\r\n"); + sprintf(t_buf, "

WinMTR statistics

\r\n"); + strcat(f_buf, t_buf); + + sprintf(t_buf, "

\r\n" ); + strcat(f_buf, t_buf); + + sprintf(t_buf, "\r\n" ); + strcat(f_buf, t_buf); + + for(int i=0;i GetName(i, buf); + if( strcmp(buf,"")==0 ) strcpy(buf,"No response from host"); + + sprintf(t_buf, "\r\n" , + buf, wmtrnet->GetPercent(i), + wmtrnet->GetXmit(i), wmtrnet->GetReturned(i), wmtrnet->GetBest(i), + wmtrnet->GetAvg(i), wmtrnet->GetWorst(i), wmtrnet->GetLast(i)); + strcat(f_buf, t_buf); + } + + sprintf(t_buf, "
Host %% Sent Recv Best Avrg Wrst Last
%s %4d %4d %4d %4d %4d %4d %4d
\r\n"); + strcat(f_buf, t_buf); + + CString source(f_buf); + + HGLOBAL clipbuffer; + char * buffer; + + OpenClipboard(); + EmptyClipboard(); + + clipbuffer = GlobalAlloc(GMEM_DDESHARE, source.GetLength()+1); + buffer = (char*)GlobalLock(clipbuffer); + strcpy(buffer, LPCSTR(source)); + GlobalUnlock(clipbuffer); + + SetClipboardData(CF_TEXT,clipbuffer); + CloseClipboard(); +} + + +//***************************************************************************** +// WinMTRDialog::OnEXPT +// +// +//***************************************************************************** +void WinMTRDialog::OnEXPT() +{ + TCHAR BASED_CODE szFilter[] = _T("Text Files (*.txt)|*.txt|All Files (*.*)|*.*||"); + + CFileDialog dlg(FALSE, + _T("TXT"), + NULL, + OFN_HIDEREADONLY | OFN_EXPLORER, + szFilter, + this); + if(dlg.DoModal() == IDOK) { + + char buf[255], t_buf[1000], f_buf[255*100]; + + int nh = wmtrnet->GetMax(); + + strcpy(f_buf, "|------------------------------------------------------------------------------------------|\r\n"); + sprintf(t_buf, "| WinMTR statistics |\r\n"); + strcat(f_buf, t_buf); + sprintf(t_buf, "| Host - %% | Sent | Recv | Best | Avrg | Wrst | Last |\r\n" ); + strcat(f_buf, t_buf); + sprintf(t_buf, "|------------------------------------------------|------|------|------|------|------|------|\r\n" ); + strcat(f_buf, t_buf); + + for(int i=0;i GetName(i, buf); + if( strcmp(buf,"")==0 ) strcpy(buf,"No response from host"); + + sprintf(t_buf, "|%40s - %4d | %4d | %4d | %4d | %4d | %4d | %4d |\r\n" , + buf, wmtrnet->GetPercent(i), + wmtrnet->GetXmit(i), wmtrnet->GetReturned(i), wmtrnet->GetBest(i), + wmtrnet->GetAvg(i), wmtrnet->GetWorst(i), wmtrnet->GetLast(i)); + strcat(f_buf, t_buf); + } + + sprintf(t_buf, "|________________________________________________|______|______|______|______|______|______|\r\n" ); + strcat(f_buf, t_buf); + + + CString cs_tmp((LPCSTR)IDS_STRING_SB_NAME); + strcat(f_buf, " "); + strcat(f_buf, (LPCTSTR)cs_tmp); + + FILE *fp = fopen(dlg.GetPathName(), "wt"); + if(fp != NULL) { + fprintf(fp, "%s", f_buf); + fclose(fp); + } + } +} + + +//***************************************************************************** +// WinMTRDialog::OnEXPH +// +// +//***************************************************************************** +void WinMTRDialog::OnEXPH() +{ + TCHAR BASED_CODE szFilter[] = _T("HTML Files (*.htm, *.html)|*.htm;*.html|All Files (*.*)|*.*||"); + + CFileDialog dlg(FALSE, + _T("HTML"), + NULL, + OFN_HIDEREADONLY | OFN_EXPLORER, + szFilter, + this); + + if(dlg.DoModal() == IDOK) { + + char buf[255], t_buf[1000], f_buf[255*100]; + + int nh = wmtrnet->GetMax(); + + strcpy(f_buf, "WinMTR Statistics\r\n"); + sprintf(t_buf, "

WinMTR statistics

\r\n"); + strcat(f_buf, t_buf); + + sprintf(t_buf, "

\r\n" ); + strcat(f_buf, t_buf); + + sprintf(t_buf, "\r\n" ); + strcat(f_buf, t_buf); + + for(int i=0;i GetName(i, buf); + if( strcmp(buf,"")==0 ) strcpy(buf,"No response from host"); + + sprintf(t_buf, "\r\n" , + buf, wmtrnet->GetPercent(i), + wmtrnet->GetXmit(i), wmtrnet->GetReturned(i), wmtrnet->GetBest(i), + wmtrnet->GetAvg(i), wmtrnet->GetWorst(i), wmtrnet->GetLast(i)); + strcat(f_buf, t_buf); + } + + sprintf(t_buf, "
Host %% Sent Recv Best Avrg Wrst Last
%s %4d %4d %4d %4d %4d %4d %4d
\r\n"); + strcat(f_buf, t_buf); + + FILE *fp = fopen(dlg.GetPathName(), "wt"); + if(fp != NULL) { + fprintf(fp, "%s", f_buf); + fclose(fp); + } + } + + +} + + +//***************************************************************************** +// WinMTRDialog::WinMTRDialog +// +// +//***************************************************************************** +void WinMTRDialog::OnCancel() +{ +} + + +//***************************************************************************** +// WinMTRDialog::DisplayRedraw +// +// +//***************************************************************************** +int WinMTRDialog::DisplayRedraw() +{ + char buf[255], nr_crt[255]; + int nh = wmtrnet->GetMax(); + while( m_listMTR.GetItemCount() > nh ) m_listMTR.DeleteItem(m_listMTR.GetItemCount() - 1); + + for(int i=0;i GetName(i, buf); + if( strcmp(buf,"")==0 ) strcpy(buf,"No response from host"); + + sprintf(nr_crt, "%d", i+1); + if(m_listMTR.GetItemCount() <= i ) + m_listMTR.InsertItem(i, buf); + else + m_listMTR.SetItem(i, 0, LVIF_TEXT, buf, 0, 0, 0, 0); + + m_listMTR.SetItem(i, 1, LVIF_TEXT, nr_crt, 0, 0, 0, 0); + + sprintf(buf, "%d", wmtrnet->GetPercent(i)); + m_listMTR.SetItem(i, 2, LVIF_TEXT, buf, 0, 0, 0, 0); + + sprintf(buf, "%d", wmtrnet->GetXmit(i)); + m_listMTR.SetItem(i, 3, LVIF_TEXT, buf, 0, 0, 0, 0); + + sprintf(buf, "%d", wmtrnet->GetReturned(i)); + m_listMTR.SetItem(i, 4, LVIF_TEXT, buf, 0, 0, 0, 0); + + sprintf(buf, "%d", wmtrnet->GetBest(i)); + m_listMTR.SetItem(i, 5, LVIF_TEXT, buf, 0, 0, 0, 0); + + sprintf(buf, "%d", wmtrnet->GetAvg(i)); + m_listMTR.SetItem(i, 6, LVIF_TEXT, buf, 0, 0, 0, 0); + + sprintf(buf, "%d", wmtrnet->GetWorst(i)); + m_listMTR.SetItem(i, 7, LVIF_TEXT, buf, 0, 0, 0, 0); + + sprintf(buf, "%d", wmtrnet->GetLast(i)); + m_listMTR.SetItem(i, 8, LVIF_TEXT, buf, 0, 0, 0, 0); + + + } + + return 0; +} + + +//***************************************************************************** +// WinMTRDialog::InitMTRNet +// +// +//***************************************************************************** +int WinMTRDialog::InitMTRNet() +{ + char strtmp[255]; + char *Hostname = strtmp; + char buf[255]; + struct hostent *host; + m_comboHost.GetWindowText(strtmp, 255); + + if (Hostname == NULL) Hostname = "localhost"; + + int isIP=1; + char *t = Hostname; + while(*t) { + if(!isdigit(*t) && *t!='.') { + isIP=0; + break; + } + t++; + } + + if(!isIP) { + sprintf(buf, "Resolving host %s...", strtmp); + statusBar.SetPaneText(0,buf); + host = gethostbyname(Hostname); + if(host == NULL) { + statusBar.SetPaneText(0, CString((LPCSTR)IDS_STRING_SB_NAME) ); + AfxMessageBox("Unable to resolve hostname."); + return 0; + } + } + + return 1; +} + + +//***************************************************************************** +// PingThread +// +// +//***************************************************************************** +void PingThread(void *p) +{ + WinMTRDialog *wmtrdlg = (WinMTRDialog *)p; + WaitForSingleObject(wmtrdlg->traceThreadMutex, INFINITE); + + struct hostent *host, *lhost; + char strtmp[255]; + char *Hostname = strtmp; + int traddr; + int localaddr; + + wmtrdlg->m_comboHost.GetWindowText(strtmp, 255); + + if (Hostname == NULL) Hostname = "localhost"; + + int isIP=1; + char *t = Hostname; + while(*t) { + if(!isdigit(*t) && *t!='.') { + isIP=0; + break; + } + t++; + } + + if(!isIP) { + host = gethostbyname(Hostname); + traddr = *(int *)host->h_addr; + } else + traddr = inet_addr(Hostname); + + lhost = gethostbyname("localhost"); + if(lhost == NULL) { + AfxMessageBox("Unable to get local IP address."); + ReleaseMutex(wmtrdlg->traceThreadMutex); + return; + } + localaddr = *(int *)lhost->h_addr; + + wmtrdlg->wmtrnet->DoTrace(traddr); + + ReleaseMutex(wmtrdlg->traceThreadMutex); + _endthread(); +} + + + +void WinMTRDialog::OnCbnSelchangeComboHost() +{ +} + +void WinMTRDialog::ClearHistory() +{ + HKEY hKey; + DWORD tmp_dword; + LONG r; + char key_name[20]; + + r = RegOpenKeyEx( HKEY_CURRENT_USER, "Software", 0, KEY_ALL_ACCESS,&hKey); + r = RegOpenKeyEx( hKey, "WinMTR", 0, KEY_ALL_ACCESS, &hKey); + r = RegOpenKeyEx( hKey, "LRU", 0, KEY_ALL_ACCESS, &hKey); + + for(int i = 0; i<=nrLRU; i++) { + sprintf(key_name, "Host%d", i); + r = RegDeleteValue(hKey,key_name); + } + nrLRU = 0; + tmp_dword = nrLRU; + r = RegSetValueEx(hKey,"NrLRU", 0, REG_DWORD, (const unsigned char *)&tmp_dword, sizeof(DWORD)); + RegCloseKey(hKey); + + m_comboHost.Clear(); + m_comboHost.ResetContent(); + m_comboHost.AddString(CString((LPCSTR)IDS_STRING_CLEAR_HISTORY)); +} + +void WinMTRDialog::OnCbnSelendokComboHost() +{ +} + + +void WinMTRDialog::OnCbnCloseupComboHost() +{ + if(m_comboHost.GetCurSel() == m_comboHost.GetCount() - 1) { + ClearHistory(); + } +} + +void WinMTRDialog::Transit(STATES new_state) +{ + switch(new_state) { + case IDLE: + switch (state) { + case STOPPING: + transition = STOPPING_TO_IDLE; + break; + case IDLE: + transition = IDLE_TO_IDLE; + break; + default: + TRACE_MSG("Received state IDLE after " << state); + return; + } + state = IDLE; + break; + case TRACING: + switch (state) { + case IDLE: + transition = IDLE_TO_TRACING; + break; + case TRACING: + transition = TRACING_TO_TRACING; + break; + default: + TRACE_MSG("Received state TRACING after " << state); + return; + } + state = TRACING; + break; + case STOPPING: + switch (state) { + case STOPPING: + transition = STOPPING_TO_STOPPING; + break; + case TRACING: + transition = TRACING_TO_STOPPING; + break; + default: + TRACE_MSG("Received state STOPPING after " << state); + return; + } + state = STOPPING; + break; + case EXIT: + switch (state) { + case IDLE: + transition = IDLE_TO_EXIT; + break; + case STOPPING: + transition = STOPPING_TO_EXIT; + break; + case TRACING: + transition = TRACING_TO_EXIT; + break; + case EXIT: + break; + default: + TRACE_MSG("Received state EXIT after " << state); + return; + } + state = EXIT; + break; + default: + TRACE_MSG("Received state " << state); + } + + // modify controls according to new state + switch(transition) { + case IDLE_TO_TRACING: + m_buttonStart.EnableWindow(FALSE); + m_buttonStart.SetWindowText("Stop"); + m_comboHost.EnableWindow(FALSE); + m_buttonOptions.EnableWindow(FALSE); + statusBar.SetPaneText(0, "Double click on host name for more information."); + _beginthread(PingThread, 0 , this); + m_buttonStart.EnableWindow(TRUE); + break; + case IDLE_TO_IDLE: + // nothing to be done + break; + case STOPPING_TO_IDLE: + m_buttonStart.EnableWindow(TRUE); + statusBar.SetPaneText(0, CString((LPCSTR)IDS_STRING_SB_NAME) ); + m_buttonStart.SetWindowText("Start"); + m_comboHost.EnableWindow(TRUE); + m_buttonOptions.EnableWindow(TRUE); + m_comboHost.SetFocus(); + break; + case STOPPING_TO_STOPPING: + DisplayRedraw(); + break; + case TRACING_TO_TRACING: + DisplayRedraw(); + break; + case TRACING_TO_STOPPING: + m_buttonStart.EnableWindow(FALSE); + m_comboHost.EnableWindow(FALSE); + m_buttonOptions.EnableWindow(FALSE); + wmtrnet->StopTrace(); + statusBar.SetPaneText(0, "Waiting for last packets in order to stop trace ..."); + DisplayRedraw(); + break; + case IDLE_TO_EXIT: + m_buttonStart.EnableWindow(FALSE); + m_comboHost.EnableWindow(FALSE); + m_buttonOptions.EnableWindow(FALSE); + break; + case TRACING_TO_EXIT: + m_buttonStart.EnableWindow(FALSE); + m_comboHost.EnableWindow(FALSE); + m_buttonOptions.EnableWindow(FALSE); + wmtrnet->StopTrace(); + statusBar.SetPaneText(0, "Waiting for last packets in order to stop trace ..."); + break; + case STOPPING_TO_EXIT: + m_buttonStart.EnableWindow(FALSE); + m_comboHost.EnableWindow(FALSE); + m_buttonOptions.EnableWindow(FALSE); + break; + default: + TRACE_MSG("Unknown transition " << transition); + } +} + + +void WinMTRDialog::OnTimer(UINT_PTR nIDEvent) +{ + static unsigned int call_count = 0; + call_count += 1; + + if(state == EXIT && WaitForSingleObject(traceThreadMutex, 0) == WAIT_OBJECT_0) { + ReleaseMutex(traceThreadMutex); + OnOK(); + } + + + if( WaitForSingleObject(traceThreadMutex, 0) == WAIT_OBJECT_0 ) { + ReleaseMutex(traceThreadMutex); + Transit(IDLE); + } else if( (call_count % 10 == 0) && (WaitForSingleObject(traceThreadMutex, 0) == WAIT_TIMEOUT) ) { + ReleaseMutex(traceThreadMutex); + if( state == TRACING) Transit(TRACING); + else if( state == STOPPING) Transit(STOPPING); + } + + CDialog::OnTimer(nIDEvent); +} + + +void WinMTRDialog::OnClose() +{ + Transit(EXIT); +} + + +void WinMTRDialog::OnBnClickedCancel() +{ + Transit(EXIT); +} diff --git a/WinMTRDialog.h b/WinMTRDialog.h new file mode 100644 index 0000000..a214d7b --- /dev/null +++ b/WinMTRDialog.h @@ -0,0 +1,132 @@ +//***************************************************************************** +// FILE: WinMTRDialog.h +// +// +// DESCRIPTION: +// +// +// NOTES: +// +// +//***************************************************************************** + +#ifndef WINMTRDIALOG_H_ +#define WINMTRDIALOG_H_ + +#define WINMTR_DIALOG_TIMER 100 + +#include "WinMTRStatusBar.h" +#include "WinMTRNet.h" + +//***************************************************************************** +// CLASS: WinMTRDialog +// +// +//***************************************************************************** + +class WinMTRDialog : public CDialog +{ +public: + WinMTRDialog(CWnd* pParent = NULL); + ~WinMTRDialog(); + + enum { IDD = IDD_WINMTR_DIALOG }; + + afx_msg BOOL InitRegistry(); + + WinMTRStatusBar statusBar; + + enum STATES { + IDLE, + TRACING, + STOPPING, + EXIT + }; + + enum STATE_TRANSITIONS { + IDLE_TO_IDLE, + IDLE_TO_TRACING, + IDLE_TO_EXIT, + TRACING_TO_TRACING, + TRACING_TO_STOPPING, + TRACING_TO_EXIT, + STOPPING_TO_IDLE, + STOPPING_TO_STOPPING, + STOPPING_TO_EXIT + }; + + CButton m_buttonOptions; + CButton m_buttonExit; + CButton m_buttonStart; + CComboBox m_comboHost; + CListCtrl m_listMTR; + + CStatic m_staticS; + CStatic m_staticJ; + + CButton m_buttonExpT; + CButton m_buttonExpH; + + int InitMTRNet(); + + int DisplayRedraw(); + void Transit(STATES new_state); + + STATES state; + STATE_TRANSITIONS transition; + HANDLE traceThreadMutex; + double interval; + bool hasIntervalFromCmdLine; + int pingsize; + bool hasPingsizeFromCmdLine; + int maxLRU; + bool hasMaxLRUFromCmdLine; + int nrLRU; + BOOL useDNS; + bool hasUseDNSFromCmdLine; + WinMTRNet* wmtrnet; + + void SetHostName(const char *host); + void SetInterval(float i); + void SetPingSize(int ps); + void SetMaxLRU(int mlru); + void SetUseDNS(BOOL udns); + +protected: + virtual void DoDataExchange(CDataExchange* pDX); + + int m_autostart; + char msz_defaulthostname[1000]; + + HICON m_hIcon; + + virtual BOOL OnInitDialog(); + afx_msg void OnPaint(); + afx_msg void OnSize(UINT, int, int); + afx_msg void OnSizing(UINT, LPRECT); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnRestart(); + afx_msg void OnOptions(); + virtual void OnCancel(); + + afx_msg void OnCTTC(); + afx_msg void OnCHTC(); + afx_msg void OnEXPT(); + afx_msg void OnEXPH(); + + afx_msg void OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult); + + DECLARE_MESSAGE_MAP() +public: + afx_msg void OnCbnSelchangeComboHost(); + afx_msg void OnCbnSelendokComboHost(); +private: + void ClearHistory(); +public: + afx_msg void OnCbnCloseupComboHost(); + afx_msg void OnTimer(UINT_PTR nIDEvent); + afx_msg void OnClose(); + afx_msg void OnBnClickedCancel(); +}; + +#endif // ifndef WINMTRDIALOG_H_ diff --git a/WinMTRGlobal.cpp b/WinMTRGlobal.cpp new file mode 100644 index 0000000..0f435c8 --- /dev/null +++ b/WinMTRGlobal.cpp @@ -0,0 +1,26 @@ +//***************************************************************************** +// FILE: WinMTRGlobal.cpp +// +// +//***************************************************************************** + +#include "WinMTRGlobal.h" + +//***************************************************************************** +// gettimeofday +// +// win32 port of unix gettimeofday +//***************************************************************************** +int gettimeofday(struct timeval* tv, struct timezone *tz) +{ + if(!tv) + return -1; + struct _timeb timebuffer; + + _ftime(&timebuffer); + + tv->tv_sec = timebuffer.time; + tv->tv_usec = timebuffer.millitm * 1000 + 500; + return 0; +} + diff --git a/WinMTRGlobal.h b/WinMTRGlobal.h new file mode 100644 index 0000000..53524ee --- /dev/null +++ b/WinMTRGlobal.h @@ -0,0 +1,106 @@ +//***************************************************************************** +// FILE: WinMTRGlobal.h +// +// +// DESCRIPTION: +// +// +// NOTES: +// +// +//***************************************************************************** + +#ifndef GLOBAL_H_ +#define GLOBAL_H_ + +#ifndef _WIN64 +#define _USE_32BIT_TIME_T +#endif + +#define VC_EXTRALEAN + +#include +#include +#include +#include + +#ifndef _AFX_NO_AFXCMN_SUPPORT + #include +#endif +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "resource.h" + +#define WINMTR_VERSION "0.9" +#define WINMTR_LICENSE "GPL - GNU Public License" +#define WINMTR_COPYRIGHT "WinMTR 0.9 (c) 2010-2011 Appnor MSP - Fully Managed Hosting & Cloud Provider www.appnor.com" +#define WINMTR_HOMEPAGE "http://WinMTR.sourceforge.net" + +#define DEFAULT_PING_SIZE 64 +#define DEFAULT_INTERVAL 1.0 +#define DEFAULT_MAX_LRU 128 +#define DEFAULT_DNS TRUE + +#define SAVED_PINGS 100 +#define MaxHost 256 +//#define MaxSequence 65536 +#define MaxSequence 32767 +//#define MaxSequence 5 + +#define MAXPACKET 4096 +#define MINPACKET 64 + +#define MaxTransit 4 + + +#define ICMP_ECHO 8 +#define ICMP_ECHOREPLY 0 + +#define ICMP_TSTAMP 13 +#define ICMP_TSTAMPREPLY 14 + +#define ICMP_TIME_EXCEEDED 11 + +#define ICMP_HOST_UNREACHABLE 3 + +#define MAX_UNKNOWN_HOSTS 10 + +#define IP_HEADER_LENGTH 20 + + +#define MTR_NR_COLS 9 + +const char MTR_COLS[ MTR_NR_COLS ][10] = { + "Hostname", + "Nr", + "Loss %", + "Sent", + "Recv", + "Best", + "Avrg", + "Worst", + "Last" +}; + +const int MTR_COL_LENGTH[ MTR_NR_COLS ] = { + 190, 30, 50, 40, 40, 50, 50, 50, 50 +}; + +int gettimeofday(struct timeval* tv, struct timezone *tz); + +#endif // ifndef GLOBAL_H_ diff --git a/WinMTRHelp.cpp b/WinMTRHelp.cpp new file mode 100644 index 0000000..408f9e9 --- /dev/null +++ b/WinMTRHelp.cpp @@ -0,0 +1,41 @@ +// WinMTRHelp.cpp : implementation file +// + +#include "WinMTRGlobal.h" +#include "WinMTRHelp.h" +#include "afxdialogex.h" + + +// WinMTRHelp dialog + +IMPLEMENT_DYNAMIC(WinMTRHelp, CDialog) + +WinMTRHelp::WinMTRHelp(CWnd* pParent /*=NULL*/) + : CDialog(WinMTRHelp::IDD, pParent) +{ + +} + +WinMTRHelp::~WinMTRHelp() +{ +} + +void WinMTRHelp::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); +} + + +BEGIN_MESSAGE_MAP(WinMTRHelp, CDialog) + ON_BN_CLICKED(IDOK, &WinMTRHelp::OnBnClickedOk) +END_MESSAGE_MAP() + + +// WinMTRHelp message handlers + + +void WinMTRHelp::OnBnClickedOk() +{ + // TODO: Add your control notification handler code here + CDialog::OnOK(); +} diff --git a/WinMTRHelp.h b/WinMTRHelp.h new file mode 100644 index 0000000..e9ccbf2 --- /dev/null +++ b/WinMTRHelp.h @@ -0,0 +1,22 @@ +#pragma once + +// WinMTRHelp dialog + +class WinMTRHelp : public CDialog +{ + DECLARE_DYNAMIC(WinMTRHelp) + +public: + WinMTRHelp(CWnd* pParent = NULL); // standard constructor + virtual ~WinMTRHelp(); + +// Dialog Data + enum { IDD = IDD_DIALOG_HELP }; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + + DECLARE_MESSAGE_MAP() +public: + afx_msg void OnBnClickedOk(); +}; diff --git a/WinMTRLicense.cpp b/WinMTRLicense.cpp new file mode 100644 index 0000000..8f8f388 --- /dev/null +++ b/WinMTRLicense.cpp @@ -0,0 +1,405 @@ +//***************************************************************************** +// FILE: WinMTRLicense.cpp +// +// +//***************************************************************************** + +#include "WinMTRGlobal.h" +#include "WinMTRLicense.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +static const char LICENCE_TEXT_1[]={ +" GNU GENERAL PUBLIC LICENSE\r\n\ + Version 2, June 1991\r\n\ + \r\n\ + Copyright (C) 1989, 1991 Free Software Foundation, Inc.\r\n\ + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r\n\ + Everyone is permitted to copy and distribute verbatim copies\r\n\ + of this license document, but changing it is not allowed.\r\n\ +\r\n\ + Preamble\r\n\ +\r\n\ + The licenses for most software are designed to take away your\r\n\ +freedom to share and change it. By contrast, the GNU General Public\r\n\ +License is intended to guarantee your freedom to share and change free\r\n\ +software--to make sure the software is free for all its users. This\r\n\ +General Public License applies to most of the Free Software\r\n\ +Foundation's software and to any other program whose authors commit to\r\n\ +using it. (Some other Free Software Foundation software is covered by\r\n\ +the GNU Library General Public License instead.) You can apply it to\r\n\ +your programs, too.\r\n\ +\r\n\ + When we speak of free software, we are referring to freedom, not\r\n\ +price. Our General Public Licenses are designed to make sure that you\r\n\ +have the freedom to distribute copies of free software (and charge for\r\n\ +this service if you wish), that you receive source code or can get it\r\n\ +if you want it, that you can change the software or use pieces of it\r\n\ +in new free programs; and that you know you can do these things.\r\n\ +\r\n\ + To protect your rights, we need to make restrictions that forbid\r\n\ +anyone to deny you these rights or to ask you to surrender the rights.\r\n\ +These restrictions translate to certain responsibilities for you if you\r\n\ +distribute copies of the software, or if you modify it.\r\n\ +\r\n\ + For example, if you distribute copies of such a program, whether\r\n\ +gratis or for a fee, you must give the recipients all the rights that\r\n\ +you have. You must make sure that they, too, receive or can get the\r\n\ +source code. And you must show them these terms so they know their\r\n\ +rights.\r\n\ +\r\n\ + We protect your rights with two steps: (1) copyright the software, and\r\n\ +(2) offer you this license which gives you legal permission to copy,\r\n\ +distribute and/or modify the software.\r\n\ +\r\n\ + Also, for each author's protection and ours, we want to make certain\r\n\ +that everyone understands that there is no warranty for this free\r\n\ +software. If the software is modified by someone else and passed on, we\r\n\ +want its recipients to know that what they have is not the original, so\r\n\ +that any problems introduced by others will not reflect on the original\r\n\ +authors' reputations.\r\n\ +\r\n\ + Finally, any free program is threatened constantly by software\r\n\ +patents. We wish to avoid the danger that redistributors of a free\r\n\ +program will individually obtain patent licenses, in effect making the\r\n\ +program proprietary. To prevent this, we have made it clear that any\r\n\ +patent must be licensed for everyone's free use or not licensed at all.\r\n\ +\r\n\ + The precise terms and conditions for copying, distribution and\r\n\ +modification follow.\r\n\ +\r\n\ + GNU GENERAL PUBLIC LICENSE\r\n\ + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\r\n\ +\r\n\ + 0. This License applies to any program or other work which contains\r\n\ +a notice placed by the copyright holder saying it may be distributed\r\n\ +under the terms of this General Public License. The \"Program\", below,\r\n\ +refers to any such program or work, and a \"work based on the Program\"\r\n\ +means either the Program or any derivative work under copyright law:\r\n\ +that is to say, a work containing the Program or a portion of it,\r\n\ +either verbatim or with modifications and/or translated into another\r\n\ +language. (Hereinafter, translation is included without limitation in\r\n\ +the term \"modification\".) Each licensee is addressed as \"you\".\r\n\ +\r\n\ +Activities other than copying, distribution and modification are not\r\n\ +covered by this License; they are outside its scope. The act of\r\n\ +running the Program is not restricted, and the output from the Program\r\n\ +is covered only if its contents constitute a work based on the\r\n\ +Program (independent of having been made by running the Program).\r\n\ +Whether that is true depends on what the Program does.\r\n\ +\r\n\ + 1. You may copy and distribute verbatim copies of the Program's\r\n\ +source code as you receive it, in any medium, provided that you\r\n\ +conspicuously and appropriately publish on each copy an appropriate\r\n\ +copyright notice and disclaimer of warranty; keep intact all the\r\n\ +notices that refer to this License and to the absence of any warranty;\r\n\ +and give any other recipients of the Program a copy of this License\r\n\ +along with the Program.\r\n\ +\r\n\ +You may charge a fee for the physical act of transferring a copy, and\r\n\ +you may at your option offer warranty protection in exchange for a fee.\r\n\ +\r\n\ + 2. You may modify your copy or copies of the Program or any portion\r\n\ +of it, thus forming a work based on the Program, and copy and\r\n\ +distribute such modifications or work under the terms of Section 1\r\n\ +above, provided that you also meet all of these conditions:\r\n\ +\r\n\ + a) You must cause the modified files to carry prominent notices\r\n\ + stating that you changed the files and the date of any change.\r\n\ +\r\n\ + b) You must cause any work that you distribute or publish, that in\r\n\ + whole or in part contains or is derived from the Program or any\r\n\ + part thereof, to be licensed as a whole at no charge to all third\r\n\ + parties under the terms of this License.\r\n\ +\r\n\ + c) If the modified program normally reads commands interactively\r\n\ + when run, you must cause it, when started running for such\r\n\ + interactive use in the most ordinary way, to print or display an\r\n\ + announcement including an appropriate copyright notice and a\r\n\ + notice that there is no warranty (or else, saying that you provide\r\n\ + a warranty) and that users may redistribute the program under\r\n\ + these conditions, and telling the user how to view a copy of this\r\n\ + License. (Exception: if the Program itself is interactive but\r\n\ + does not normally print such an announcement, your work based on\r\n\ + the Program is not required to print an announcement.)\r\n\ +\r\n\ +These requirements apply to the modified work as a whole. If\r\n\ +identifiable sections of that work are not derived from the Program,\r\n\ +and can be reasonably considered independent and separate works in\r\n\ +themselves, then this License, and its terms, do not apply to those\r\n\ +sections when you distribute them as separate works. But when you\r\n\ +distribute the same sections as part of a whole which is a work based\r\n\ +on the Program, the distribution of the whole must be on the terms of\r\n\ +this License, whose permissions for other licensees extend to the\r\n\ +entire whole, and thus to each and every part regardless of who wrote it.\r\n\ +\r\n\ +Thus, it is not the intent of this section to claim rights or contest\r\n\ +your rights to work written entirely by you; rather, the intent is to\r\n\ +exercise the right to control the distribution of derivative or\r\n\ +collective works based on the Program.\r\n\ +\r\n\ +In addition, mere aggregation of another work not based on the Program\r\n\ +with the Program (or with a work based on the Program) on a volume of\r\n\ +a storage or distribution medium does not bring the other work under\r\n\ +the scope of this License.\r\n\ +\r\n\ + 3. You may copy and distribute the Program (or a work based on it,\r\n\ +under Section 2) in object code or executable form under the terms of\r\n\ +Sections 1 and 2 above provided that you also do one of the following:\r\n\ +\r\n\ + a) Accompany it with the complete corresponding machine-readable\r\n\ + source code, which must be distributed under the terms of Sections\r\n\ + 1 and 2 above on a medium customarily used for software interchange; or,\r\n\ +\r\n\ + b) Accompany it with a written offer, valid for at least three\r\n\ + years, to give any third party, for a charge no more than your\r\n\ + cost of physically performing source distribution, a complete\r\n\ + machine-readable copy of the corresponding source code, to be\r\n\ + distributed under the terms of Sections 1 and 2 above on a medium\r\n\ + customarily used for software interchange; or,\r\n\ +\r\n\ + c) Accompany it with the information you received as to the offer\r\n\ + to distribute corresponding source code. (This alternative is\r\n\ + allowed only for noncommercial distribution and only if you\r\n\ + received the program in object code or executable form with such\r\n\ + an offer, in accord with Subsection b above.)\r\n\ +\r\n\ +The source code for a work means the preferred form of the work for\r\n\ +making modifications to it. For an executable work, complete source\r\n\ +code means all the source code for all modules it contains, plus any\r\n\ +associated interface definition files, plus the scripts used to\r\n\ +control compilation and installation of the executable. However, as a\r\n\ +special exception, the source code distributed need not include\r\n\ +anything that is normally distributed (in either source or binary\r\n\ +form) with the major components (compiler, kernel, and so on) of the\r\n\ +operating system on which the executable runs, unless that component\r\n\ +itself accompanies the executable.\r\n\ +\r\n\ +If distribution of executable or object code is made by offering\r\n\ +access to copy from a designated place, then offering equivalent\r\n\ +access to copy the source code from the same place counts as\r\n\ +distribution of the source code, even though third parties are not\r\n\ +compelled to copy the source along with the object code.\r\n\ +\r\n\ + 4. You may not copy, modify, sublicense, or distribute the Program\r\n\ +except as expressly provided under this License. Any attempt\r\n\ +otherwise to copy, modify, sublicense or distribute the Program is\r\n\ +void, and will automatically terminate your rights under this License.\r\n\ +However, parties who have received copies, or rights, from you under\r\n\ +this License will not have their licenses terminated so long as such\r\n\ +parties remain in full compliance.\r\n\ +\r\n\ + 5. You are not required to accept this License, since you have not\r\n\ +signed it. However, nothing else grants you permission to modify or\r\n\ +distribute the Program or its derivative works. These actions are\r\n\ +prohibited by law if you do not accept this License. Therefore, by\r\n\ +modifying or distributing the Program (or any work based on the\r\n\ +Program), you indicate your acceptance of this License to do so, and\r\n\ +all its terms and conditions for copying, distributing or modifying\r\n\ +the Program or works based on it.\r\n\ +\r\n\ + 6. Each time you redistribute the Program (or any work based on the\r\n\ +Program), the recipient automatically receives a license from the\r\n\ +original licensor to copy, distribute or modify the Program subject to\r\n\ +these terms and conditions. You may not impose any further\r\n\ +restrictions on the recipients' exercise of the rights granted herein.\r\n\ +You are not responsible for enforcing compliance by third parties to\r\n\ +this License.\r\n\ +\r\n\ + 7. If, as a consequence of a court judgment or allegation of patent\r\n\ +infringement or for any other reason (not limited to patent issues),\r\n\ +conditions are imposed on you (whether by court order, agreement or\r\n\ +otherwise) that contradict the conditions of this License, they do not\r\n\ +excuse you from the conditions of this License. If you cannot\r\n\ +distribute so as to satisfy simultaneously your obligations under this\r\n\ +License and any other pertinent obligations, then as a consequence you\r\n\ +may not distribute the Program at all. For example, if a patent\r\n\ +license would not permit royalty-free redistribution of the Program by\r\n\ +all those who receive copies directly or indirectly through you, then\r\n\ +the only way you could satisfy both it and this License would be to\r\n\ +refrain entirely from distribution of the Program.\r\n\ +\r\n\ +If any portion of this section is held invalid or unenforceable under\r\n\ +any particular circumstance, the balance of the section is intended to\r\n\ +apply and the section as a whole is intended to apply in other\r\n\ +circumstances.\r\n\ +\r\n\ +It is not the purpose of this section to induce you to infringe any\r\n\ +patents or other property right claims or to contest validity of any\r\n\ +such claims; this section has the sole purpose of protecting the\r\n\ +integrity of the free software distribution system, which is\r\n\ +implemented by public license practices. Many people have made\r\n\ +generous contributions to the wide range of software distributed\r\n\ +through that system in reliance on consistent application of that\r\n\ +system; it is up to the author/donor to decide if he or she is willing\r\n\ +to distribute software through any other system and a licensee cannot\r\n\ +impose that choice.\r\n\ +\r\n\ +This section is intended to make thoroughly clear what is believed to\r\n\ +be a consequence of the rest of this License.\r\n\ +\r\n\ + 8. If the distribution and/or use of the Program is restricted in\r\n\ +certain countries either by patents or by copyrighted interfaces, the\r\n\ +original copyright holder who places the Program under this License\r\n\ +may add an explicit geographical distribution limitation excluding\r\n\ +those countries, so that distribution is permitted only in or among\r\n\ +countries not thus excluded. In such case, this License incorporates\r\n\ +the limitation as if written in the body of this License.\r\n\ +\r\n\ + 9. The Free Software Foundation may publish revised and/or new versions\r\n\ +of the General Public License from time to time. Such new versions will\r\n\ +be similar in spirit to the present version, but may differ in detail to\r\n\ +address new problems or concerns.\r\n\ +\r\n\ +Each version is given a distinguishing version number. If the Program\r\n\ +specifies a version number of this License which applies to it and \"any\r\n\ +later version\", you have the option of following the terms and conditions\r\n\ +either of that version or of any later version published by the Free\r\n\ +Software Foundation. If the Program does not specify a version number of\r\n\ +this License, you may choose any version ever published by the Free Software\r\n\ +Foundation.\r\n\ +\r\n\ + 10. If you wish to incorporate parts of the Program into other free\r\n\ +programs whose distribution conditions are different, write to the author\r\n\ +to ask for permission. For software which is copyrighted by the Free\r\n\ +Software Foundation, write to the Free Software Foundation; we sometimes\r\n\ +make exceptions for this. Our decision will be guided by the two goals\r\n\ +of preserving the free status of all derivatives of our free software and\r\n\ +of promoting the sharing and reuse of software generally.\r\n\ +\r\n\ + NO WARRANTY\r\n\ +\r\n\ + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\r\n\ +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN\r\n\ +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\r\n\ +PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\r\n\ +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r\n\ +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS\r\n\ +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE\r\n\ +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\r\n\ +REPAIR OR CORRECTION.\r\n\ +\r\n\ + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\r\n\ +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\r\n\ +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\r\n\ +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\r\n\ +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\r\n\ +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\r\n\ +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\r\n\ +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\r\n\ +POSSIBILITY OF SUCH DAMAGES.\r\n\ +\r\n\ + END OF TERMS AND CONDITIONS\r\n"}; +static const char LICENCE_TEXT_2[]={ +"\r\n\ + How to Apply These Terms to Your New Programs\r\n\ +\r\n\ + If you develop a new program, and you want it to be of the greatest\r\n\ +possible use to the public, the best way to achieve this is to make it\r\n\ +free software which everyone can redistribute and change under these terms.\r\n\ +\r\n\ + To do so, attach the following notices to the program. It is safest\r\n\ +to attach them to the start of each source file to most effectively\r\n\ +convey the exclusion of warranty; and each file should have at least\r\n\ +the \"copyright\" line and a pointer to where the full notice is found.\r\n\ +\r\n\ + \r\n\ + Copyright (C) 19yy \r\n\ +\r\n\ + This program is free software; you can redistribute it and/or modify\r\n\ + it under the terms of the GNU General Public License as published by\r\n\ + the Free Software Foundation; either version 2 of the License, or\r\n\ + (at your option) any later version.\r\n\ +\r\n\ + This program is distributed in the hope that it will be useful,\r\n\ + but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n\ + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r\n\ + GNU General Public License for more details.\r\n\ +\r\n\ + You should have received a copy of the GNU General Public License\r\n\ + along with this program; if not, write to the Free Software\r\n\ + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r\n\ +\r\n\ +\r\n\ +Also add information on how to contact you by electronic and paper mail.\r\n\ +\r\n\ +If the program is interactive, make it output a short notice like this\r\n\ +when it starts in an interactive mode:\r\n\ +\r\n\ + Gnomovision version 69, Copyright (C) 19yy name of author\r\n\ + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\r\n\ + This is free software, and you are welcome to redistribute it\r\n\ + under certain conditions; type `show c' for details.\r\n\ +\r\n\ +The hypothetical commands `show w' and `show c' should show the appropriate\r\n\ +parts of the General Public License. Of course, the commands you use may\r\n\ +be called something other than `show w' and `show c'; they could even be\r\n\ +mouse-clicks or menu items--whatever suits your program.\r\n\ +\r\n\ +You should also get your employer (if you work as a programmer) or your\r\n\ +school, if any, to sign a \"copyright disclaimer\" for the program, if\r\n\ +necessary. Here is a sample; alter the names:\r\n\ +\r\n\ + Yoyodyne, Inc., hereby disclaims all copyright interest in the program\r\n\ + `Gnomovision' (which makes passes at compilers) written by James Hacker.\r\n\ +\r\n\ + , 1 April 1989\r\n\ + Ty Coon, President of Vice\r\n\ +\r\n\ +This General Public License does not permit incorporating your program into\r\n\ +proprietary programs. If your program is a subroutine library, you may\r\n\ +consider it more useful to permit linking proprietary applications with the\r\n\ +library. If this is what you want to do, use the GNU Library General\r\n\ +Public License instead of this License."}; + +//***************************************************************************** +// BEGIN_MESSAGE_MAP +// +// +//***************************************************************************** +BEGIN_MESSAGE_MAP(WinMTRLicense, CDialog) +END_MESSAGE_MAP() + + +//***************************************************************************** +// WinMTRLicense::WinMTRLicense +// +// +//***************************************************************************** +WinMTRLicense::WinMTRLicense(CWnd* pParent) : CDialog(WinMTRLicense::IDD, pParent) +{ +} + + +//***************************************************************************** +// WinMTRLicense::DoDataExchange +// +// +//***************************************************************************** +void WinMTRLicense::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); +} + + +//***************************************************************************** +// WinMTRLicense::OnInitDialog +// +// +//***************************************************************************** +BOOL WinMTRLicense::OnInitDialog() +{ + CDialog::OnInitDialog(); + /* + m_editLicense.SetSel(-1, -1); + m_editLicense.ReplaceSel(LICENCE_TEXT_1); + m_editLicense.SetSel(-1, -1); + m_editLicense.ReplaceSel(LICENCE_TEXT_2); + */ + return FALSE; +} + diff --git a/WinMTRLicense.h b/WinMTRLicense.h new file mode 100644 index 0000000..b087d7b --- /dev/null +++ b/WinMTRLicense.h @@ -0,0 +1,40 @@ +//***************************************************************************** +// FILE: WinMTRLicense.h +// +// +// DESCRIPTION: +// +// +// NOTES: +// +// +//***************************************************************************** + +#ifndef WINMTRLICENSE_H_ +#define WINMTRLICENSE_H_ + + + +//***************************************************************************** +// CLASS: WinMTRLicense +// +// +//***************************************************************************** + +class WinMTRLicense : public CDialog +{ +public: + WinMTRLicense(CWnd* pParent = NULL); + + + enum { IDD = IDD_DIALOG_LICENSE }; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); + + virtual BOOL OnInitDialog(); + + DECLARE_MESSAGE_MAP() +}; + +#endif // ifndef WINMTRLICENSE_H_ diff --git a/WinMTRMain.cpp b/WinMTRMain.cpp new file mode 100644 index 0000000..7e740fe --- /dev/null +++ b/WinMTRMain.cpp @@ -0,0 +1,209 @@ +//***************************************************************************** +// FILE: WinMTRMain.cpp +// +// +// HISTORY: +// +// +// -- versions 0.8 +// +// - 01.18.2002 - Store LRU hosts in registry (v0.8) +// - 05.08.2001 - Replace edit box with combo box which hold last entered hostnames. +// Fixed a memory leak which caused program to crash after a long +// time running. (v0.7) +// - 11.27.2000 - Added resizing support and flat buttons. (v0.6) +// - 11.26.2000 - Added copy data to clipboard and posibility to save data to file as text or HTML.(v0.5) +// - 08.03.2000 - added double-click on hostname for detailed information (v0.4) +// - 08.02.2000 - fix icmp error codes handling. (v0.3) +// - 08.01.2000 - support for full command-line parameter specification (v0.2) +// - 07.30.2000 - support for command-line host specification +// by Silviu Simen (ssimen@ubisoft.ro) (v0.1b) +// - 07.28.2000 - first release (v0.1) +//***************************************************************************** + +#include "WinMTRGlobal.h" +#include "WinMTRMain.h" +#include "WinMTRDialog.h" +#include "WinMTRHelp.h" +#include +#include + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +WinMTRMain WinMTR; + +//***************************************************************************** +// BEGIN_MESSAGE_MAP +// +// +//***************************************************************************** +BEGIN_MESSAGE_MAP(WinMTRMain, CWinApp) + ON_COMMAND(ID_HELP, CWinApp::OnHelp) +END_MESSAGE_MAP() + +//***************************************************************************** +// WinMTRMain::WinMTRMain +// +// +//***************************************************************************** +WinMTRMain::WinMTRMain() +{ +} + +//***************************************************************************** +// WinMTRMain::InitInstance +// +// +//***************************************************************************** +BOOL WinMTRMain::InitInstance() +{ + if (!AfxSocketInit()) + { + AfxMessageBox(IDP_SOCKETS_INIT_FAILED); + return FALSE; + } + + AfxEnableControlContainer(); + +#ifdef _AFXDLL + Enable3dControls(); // Call this when using MFC in a shared DLL +#endif + + + WinMTRDialog mtrDialog; + m_pMainWnd = &mtrDialog; + + if (strlen(m_lpCmdLine)) { + strcat(m_lpCmdLine," "); + ParseCommandLineParams(m_lpCmdLine, &mtrDialog); + } + + int nResponse = mtrDialog.DoModal(); + + + return FALSE; +} + + +//***************************************************************************** +// WinMTRMain::ParseCommandLineParams +// +// +//***************************************************************************** +void WinMTRMain::ParseCommandLineParams(LPTSTR cmd, WinMTRDialog *wmtrdlg) +{ + char value[1024]; + std::string host_name = ""; + + if(GetParamValue(cmd, "help",'h', value)) { + WinMTRHelp mtrHelp; + m_pMainWnd = &mtrHelp; + mtrHelp.DoModal(); + exit(0); + } + + if(GetHostNameParamValue(cmd, host_name)) { + wmtrdlg->SetHostName(host_name.c_str()); + } + if(GetParamValue(cmd, "interval",'i', value)) { + wmtrdlg->SetInterval((float)atof(value)); + wmtrdlg->hasIntervalFromCmdLine = true; + } + if(GetParamValue(cmd, "size",'s', value)) { + wmtrdlg->SetPingSize(atoi(value)); + wmtrdlg->hasPingsizeFromCmdLine = true; + } + if(GetParamValue(cmd, "maxLRU",'m', value)) { + wmtrdlg->SetMaxLRU(atoi(value)); + wmtrdlg->hasMaxLRUFromCmdLine = true; + } + if(GetParamValue(cmd, "numeric",'n', value)) { + wmtrdlg->SetUseDNS(FALSE); + wmtrdlg->hasUseDNSFromCmdLine = true; + } +} + +//***************************************************************************** +// WinMTRMain::GetParamValue +// +// +//***************************************************************************** +int WinMTRMain::GetParamValue(LPTSTR cmd, char * param, char sparam, char *value) +{ + char *p; + + char p_long[1024]; + char p_short[1024]; + + sprintf(p_long,"--%s ", param); + sprintf(p_short,"-%c ", sparam); + + if( (p=strstr(cmd, p_long)) ) ; + else + p=strstr(cmd, p_short); + + if(p == NULL) + return 0; + + if(strcmp(param,"numeric")==0) + return 1; + + while(*p && *p!=' ') + p++; + while(*p==' ') p++; + + int i = 0; + while(*p && *p!=' ') + value[i++] = *p++; + value[i]='\0'; + + return 1; +} + +//***************************************************************************** +// WinMTRMain::GetHostNameParamValue +// +// +//***************************************************************************** +int WinMTRMain::GetHostNameParamValue(LPTSTR cmd, std::string& host_name) +{ +// WinMTR -h -i 1 -n google.com + int size = strlen(cmd); + std::string name = ""; + while(cmd[--size] == ' '); + + size++; + while(size-- && cmd[size] != ' ' && (cmd[size] != '-' || cmd[size - 1] != ' ')) { + name = cmd[size ] + name; + } + + if(size == -1) { + if(name.length() == 0) { + return 0; + } else { + host_name = name; + return 1; + } + } + if(cmd[size] == '-' && cmd[size - 1] == ' ') { + // no target specified + return 0; + } + + std::string possible_argument = ""; + + while(size-- && cmd[size] != ' ') { + possible_argument = cmd[size] + possible_argument; + } + + if(possible_argument.length() && (possible_argument[0] != '-' || possible_argument == "-n" || possible_argument == "--numeric")) { + host_name = name; + return 1; + } + + return 0; +} diff --git a/WinMTRMain.h b/WinMTRMain.h new file mode 100644 index 0000000..e9b4863 --- /dev/null +++ b/WinMTRMain.h @@ -0,0 +1,43 @@ +//***************************************************************************** +// FILE: WinMTRMain.h +// +// +// DESCRIPTION: +// +// +// NOTES: +// +// +//***************************************************************************** + +#ifndef WINMTRMAIN_H_ +#define WINMTRMAIN_H_ + +#include "WinMTRDialog.h" +#include + + +//***************************************************************************** +// CLASS: WinMTRMain +// +// +//***************************************************************************** + +class WinMTRMain : public CWinApp +{ +public: + WinMTRMain(); + + virtual BOOL InitInstance(); + + DECLARE_MESSAGE_MAP() + +private: + void ParseCommandLineParams(LPTSTR cmd, WinMTRDialog *wmtrdlg); + int GetParamValue(LPTSTR cmd, char * param, char sparam, char *value); + int GetHostNameParamValue(LPTSTR cmd, std::string& value); + +}; + +#endif // ifndef WINMTRMAIN_H_ + diff --git a/WinMTRNet.cpp b/WinMTRNet.cpp new file mode 100644 index 0000000..7c5e8ae --- /dev/null +++ b/WinMTRNet.cpp @@ -0,0 +1,455 @@ +//***************************************************************************** +// FILE: WinMTRNet.cpp +// +//***************************************************************************** +#include "WinMTRGlobal.h" +#include "WinMTRNet.h" +#include "WinMTRDialog.h" +#include +#include + +#define TRACE_MSG(msg) \ + { \ + std::ostringstream dbg_msg(std::ostringstream::out); \ + dbg_msg << msg << std::endl; \ + OutputDebugString(dbg_msg.str().c_str()); \ + } + +#define IPFLAG_DONT_FRAGMENT 0x02 +#define MAX_HOPS 30 + +struct trace_thread { + int address; + WinMTRNet *winmtr; + int ttl; +}; + +struct dns_resolver_thread { + int index; + WinMTRNet *winmtr; +}; + +void TraceThread(void *p); +void DnsResolverThread(void *p); + +WinMTRNet::WinMTRNet(WinMTRDialog *wp) { + + ghMutex = CreateMutex(NULL, FALSE, NULL); + tracing=false; + initialized = false; + wmtrdlg = wp; + WSADATA wsaData; + + if( WSAStartup(MAKEWORD(2, 2), &wsaData) ) { + AfxMessageBox("Failed initializing windows sockets library!"); + return; + } + + hICMP_DLL = LoadLibrary(_T("ICMP.DLL")); + if (hICMP_DLL == 0) { + AfxMessageBox("Failed: Unable to locate ICMP.DLL!"); + return; + } + + /* + * Get pointers to ICMP.DLL functions + */ + lpfnIcmpCreateFile = (LPFNICMPCREATEFILE)GetProcAddress(hICMP_DLL,"IcmpCreateFile"); + lpfnIcmpCloseHandle = (LPFNICMPCLOSEHANDLE)GetProcAddress(hICMP_DLL,"IcmpCloseHandle"); + lpfnIcmpSendEcho = (LPFNICMPSENDECHO)GetProcAddress(hICMP_DLL,"IcmpSendEcho"); + if ((!lpfnIcmpCreateFile) || (!lpfnIcmpCloseHandle) || (!lpfnIcmpSendEcho)) { + AfxMessageBox("Wrong ICMP.DLL system library !"); + return; + } + + /* + * IcmpCreateFile() - Open the ping service + */ + hICMP = (HANDLE) lpfnIcmpCreateFile(); + if (hICMP == INVALID_HANDLE_VALUE) { + AfxMessageBox("Error in ICMP.DLL !"); + return; + } + + ResetHops(); + + initialized = true; + return; +} + +WinMTRNet::~WinMTRNet() +{ + if(initialized) { + /* + * IcmpCloseHandle - Close the ICMP handle + */ + lpfnIcmpCloseHandle(hICMP); + + // Shut down... + FreeLibrary(hICMP_DLL); + + WSACleanup(); + + CloseHandle(ghMutex); + } +} + +void WinMTRNet::ResetHops() +{ + for(int i = 0; i < MaxHost;i++) { + host[i].addr = 0; + host[i].xmit = 0; + host[i].returned = 0; + host[i].total = 0; + host[i].last = 0; + host[i].best = 0; + host[i].worst = 0; + memset(host[i].name,0,sizeof(host[i].name)); + } +} + +void WinMTRNet::DoTrace(int address) +{ + HANDLE hThreads[MAX_HOPS]; + tracing = true; + + ResetHops(); + + last_remote_addr = address; + + // one thread per TTL value + for(int i = 0; i < MAX_HOPS; i++) { + trace_thread *current = new trace_thread; + current->address = address; + current->winmtr = this; + current->ttl = i + 1; + hThreads[i] = (HANDLE)_beginthread(TraceThread, 0 , current); + } + + WaitForMultipleObjects(MAX_HOPS, hThreads, TRUE, INFINITE); +} + +void WinMTRNet::StopTrace() +{ + tracing = false; +} + +void TraceThread(void *p) +{ + trace_thread* current = (trace_thread*)p; + WinMTRNet *wmtrnet = current->winmtr; + TRACE_MSG("Threaad with TTL=" << current->ttl << " started."); + + IPINFO stIPInfo, *lpstIPInfo; + DWORD dwReplyCount; + char achReqData[8192]; + int nDataLen = wmtrnet->wmtrdlg->pingsize; + char achRepData[sizeof(ICMPECHO) + 8192]; + + + /* + * Init IPInfo structure + */ + lpstIPInfo = &stIPInfo; + stIPInfo.Ttl = current->ttl; + stIPInfo.Tos = 0; + stIPInfo.Flags = IPFLAG_DONT_FRAGMENT; + stIPInfo.OptionsSize = 0; + stIPInfo.OptionsData = NULL; + + for (int i=0; itracing) { + + // For some strange reason, ICMP API is not filling the TTL for icmp echo reply + // Check if the current thread should be closed + if( current->ttl > wmtrnet->GetMax() ) break; + + // NOTE: some servers does not respond back everytime, if TTL expires in transit; e.g. : + // ping -n 20 -w 5000 -l 64 -i 7 www.chinapost.com.tw -> less that half of the replies are coming back from 219.80.240.93 + // but if we are pinging ping -n 20 -w 5000 -l 64 219.80.240.93 we have 0% loss + // A resolution would be: + // - as soon as we get a hop, we start pinging directly that hop, with a greater TTL + // - a drawback would be that, some servers are configured to reply for TTL transit expire, but not to ping requests, so, + // for these servers we'll have 100% loss + dwReplyCount = wmtrnet->lpfnIcmpSendEcho(wmtrnet->hICMP, current->address, achReqData, nDataLen, lpstIPInfo, achRepData, sizeof(achRepData), ECHO_REPLY_TIMEOUT); + + PICMPECHO icmp_echo_reply = (PICMPECHO)achRepData; + + wmtrnet->AddXmit(current->ttl - 1); + if (dwReplyCount != 0) { + TRACE_MSG("TTL " << current->ttl << " reply TTL " << icmp_echo_reply->Options.Ttl << " Status " << icmp_echo_reply->Status << " Reply count " << dwReplyCount); + + switch(icmp_echo_reply->Status) { + case IP_SUCCESS: + case IP_TTL_EXPIRED_TRANSIT: + wmtrnet->SetLast(current->ttl - 1, icmp_echo_reply->RoundTripTime); + wmtrnet->SetBest(current->ttl - 1, icmp_echo_reply->RoundTripTime); + wmtrnet->SetWorst(current->ttl - 1, icmp_echo_reply->RoundTripTime); + wmtrnet->AddReturned(current->ttl - 1); + wmtrnet->SetAddr(current->ttl - 1, icmp_echo_reply->Address); + break; + case IP_BUF_TOO_SMALL: + wmtrnet->SetName(current->ttl - 1, "Reply buffer too small."); + break; + case IP_DEST_NET_UNREACHABLE: + wmtrnet->SetName(current->ttl - 1, "Destination network unreachable."); + break; + case IP_DEST_HOST_UNREACHABLE: + wmtrnet->SetName(current->ttl - 1, "Destination host unreachable."); + break; + case IP_DEST_PROT_UNREACHABLE: + wmtrnet->SetName(current->ttl - 1, "Destination protocol unreachable."); + break; + case IP_DEST_PORT_UNREACHABLE: + wmtrnet->SetName(current->ttl - 1, "Destination port unreachable."); + break; + case IP_NO_RESOURCES: + wmtrnet->SetName(current->ttl - 1, "Insufficient IP resources were available."); + break; + case IP_BAD_OPTION: + wmtrnet->SetName(current->ttl - 1, "Bad IP option was specified."); + break; + case IP_HW_ERROR: + wmtrnet->SetName(current->ttl - 1, "Hardware error occurred."); + break; + case IP_PACKET_TOO_BIG: + wmtrnet->SetName(current->ttl - 1, "Packet was too big."); + break; + case IP_REQ_TIMED_OUT: + wmtrnet->SetName(current->ttl - 1, "Request timed out."); + break; + case IP_BAD_REQ: + wmtrnet->SetName(current->ttl - 1, "Bad request."); + break; + case IP_BAD_ROUTE: + wmtrnet->SetName(current->ttl - 1, "Bad route."); + break; + case IP_TTL_EXPIRED_REASSEM: + wmtrnet->SetName(current->ttl - 1, "The time to live expired during fragment reassembly."); + break; + case IP_PARAM_PROBLEM: + wmtrnet->SetName(current->ttl - 1, "Parameter problem."); + break; + case IP_SOURCE_QUENCH: + wmtrnet->SetName(current->ttl - 1, "Datagrams are arriving too fast to be processed and datagrams may have been discarded."); + break; + case IP_OPTION_TOO_BIG: + wmtrnet->SetName(current->ttl - 1, "An IP option was too big."); + break; + case IP_BAD_DESTINATION: + wmtrnet->SetName(current->ttl - 1, "Bad destination."); + break; + case IP_GENERAL_FAILURE: + wmtrnet->SetName(current->ttl - 1, "General failure."); + break; + default: + wmtrnet->SetName(current->ttl - 1, "General failure."); + } + + if(wmtrnet->wmtrdlg->interval * 1000 > icmp_echo_reply->RoundTripTime) + Sleep(wmtrnet->wmtrdlg->interval * 1000 - icmp_echo_reply->RoundTripTime); + } + + } /* end ping loop */ + + TRACE_MSG("Thread with TTL=" << current->ttl << " stopped."); + + delete p; + _endthread(); +} + +int WinMTRNet::GetAddr(int at) +{ + WaitForSingleObject(ghMutex, INFINITE); + int addr = ntohl(host[at].addr); + ReleaseMutex(ghMutex); + return addr; +} + +int WinMTRNet::GetName(int at, char *n) +{ + WaitForSingleObject(ghMutex, INFINITE); + if(!strcmp(host[at].name, "")) { + int addr = GetAddr(at); + sprintf ( n, "%d.%d.%d.%d", + (addr >> 24) & 0xff, + (addr >> 16) & 0xff, + (addr >> 8) & 0xff, + addr & 0xff + ); + if(addr==0) + strcpy(n,""); + } else { + strcpy(n, host[at].name); + } + ReleaseMutex(ghMutex); + return 0; +} + +int WinMTRNet::GetBest(int at) +{ + WaitForSingleObject(ghMutex, INFINITE); + int ret = host[at].best; + ReleaseMutex(ghMutex); + return ret; +} + +int WinMTRNet::GetWorst(int at) +{ + WaitForSingleObject(ghMutex, INFINITE); + int ret = host[at].worst; + ReleaseMutex(ghMutex); + return ret; +} + +int WinMTRNet::GetAvg(int at) +{ + WaitForSingleObject(ghMutex, INFINITE); + int ret = host[at].returned == 0 ? 0 : host[at].total / host[at].returned; + ReleaseMutex(ghMutex); + return ret; +} + +int WinMTRNet::GetPercent(int at) +{ + WaitForSingleObject(ghMutex, INFINITE); + int ret = (host[at].xmit == 0) ? 0 : (100 - (100 * host[at].returned / host[at].xmit)); + ReleaseMutex(ghMutex); + return ret; +} + +int WinMTRNet::GetLast(int at) +{ + WaitForSingleObject(ghMutex, INFINITE); + int ret = host[at].last; + ReleaseMutex(ghMutex); + return ret; +} + +int WinMTRNet::GetReturned(int at) +{ + WaitForSingleObject(ghMutex, INFINITE); + int ret = host[at].returned; + ReleaseMutex(ghMutex); + return ret; +} + +int WinMTRNet::GetXmit(int at) +{ + WaitForSingleObject(ghMutex, INFINITE); + int ret = host[at].xmit; + ReleaseMutex(ghMutex); + return ret; +} + +int WinMTRNet::GetMax() +{ + WaitForSingleObject(ghMutex, INFINITE); + int max = MAX_HOPS; + + // first match: traced address responds on ping requests, and the address is in the hosts list + for(int i = 0; i < MAX_HOPS; i++) { + if(host[i].addr == last_remote_addr) { + max = i + 1; + break; + } + } + + // second match: traced address doesn't responds on ping requests + if(max == MAX_HOPS) { + while((max > 1) && (host[max - 1].addr == host[max - 2].addr) && (host[max - 1].addr != 0) ) max--; + } + + ReleaseMutex(ghMutex); + return max; +} + +void WinMTRNet::SetAddr(int at, __int32 addr) +{ + WaitForSingleObject(ghMutex, INFINITE); + if(host[at].addr == 0 && addr != 0) { + TRACE_MSG("Start DnsResolverThread for new address " << addr << ". Old addr value was " << host[at].addr); + host[at].addr = addr; + dns_resolver_thread *dnt = new dns_resolver_thread; + dnt->index = at; + dnt->winmtr = this; + if(wmtrdlg->useDNS) _beginthread(DnsResolverThread, 0, dnt); + } + + ReleaseMutex(ghMutex); +} + +void WinMTRNet::SetName(int at, char *n) +{ + WaitForSingleObject(ghMutex, INFINITE); + strcpy(host[at].name, n); + ReleaseMutex(ghMutex); +} + +void WinMTRNet::SetBest(int at, int current) +{ + WaitForSingleObject(ghMutex, INFINITE); + if(host[at].best > current || host[at].xmit == 1) { + host[at].best = current; + }; + if(host[at].worst < current) { + host[at].worst = current; + } + + ReleaseMutex(ghMutex); +} + +void WinMTRNet::SetWorst(int at, int current) +{ + WaitForSingleObject(ghMutex, INFINITE); + ReleaseMutex(ghMutex); +} + +void WinMTRNet::SetLast(int at, int last) +{ + WaitForSingleObject(ghMutex, INFINITE); + host[at].last = last; + host[at].total += last; + ReleaseMutex(ghMutex); +} + +void WinMTRNet::AddReturned(int at) +{ + WaitForSingleObject(ghMutex, INFINITE); + host[at].returned++; + ReleaseMutex(ghMutex); +} + +void WinMTRNet::AddXmit(int at) +{ + WaitForSingleObject(ghMutex, INFINITE); + host[at].xmit++; + ReleaseMutex(ghMutex); +} + +void DnsResolverThread(void *p) +{ + TRACE_MSG("DNS resolver thread started."); + dns_resolver_thread *dnt = (dns_resolver_thread*)p; + WinMTRNet* wn = dnt->winmtr; + + struct hostent *phent ; + + char buf[100]; + int addr = wn->GetAddr(dnt->index); + sprintf (buf, "%d.%d.%d.%d", (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff); + + int haddr = htonl(addr); + phent = gethostbyaddr( (const char*)&haddr, sizeof(int), AF_INET); + + if(phent) { + wn->SetName(dnt->index, phent->h_name); + } else { + wn->SetName(dnt->index, buf); + } + + delete p; + TRACE_MSG("DNS resolver thread stopped."); + _endthread(); +} diff --git a/WinMTRNet.h b/WinMTRNet.h new file mode 100644 index 0000000..a372a57 --- /dev/null +++ b/WinMTRNet.h @@ -0,0 +1,93 @@ +//***************************************************************************** +// FILE: WinMTRNet.h +// +// +// DESCRIPTION: +// +// +// NOTES: +// +// +//***************************************************************************** + +#ifndef WINMTRNET_H_ +#define WINMTRNET_H_ + + +class WinMTRDialog; + +typedef ip_option_information IPINFO, *PIPINFO, FAR *LPIPINFO; + +#ifdef _WIN64 +typedef icmp_echo_reply32 ICMPECHO, *PICMPECHO, FAR *LPICMPECHO; +#else +typedef icmp_echo_reply ICMPECHO, *PICMPECHO, FAR *LPICMPECHO; +#endif + +#define ECHO_REPLY_TIMEOUT 5000 + +struct s_nethost { + __int32 addr; // IP as a decimal, big endian + int xmit; // number of PING packets sent + int returned; // number of ICMP echo replies received + unsigned long total; // total time + int last; // last time + int best; // best time + int worst; // worst time + char name[255]; +}; + +//***************************************************************************** +// CLASS: WinMTRNet +// +// +//***************************************************************************** + +class WinMTRNet { + typedef HANDLE (WINAPI *LPFNICMPCREATEFILE)(VOID); + typedef BOOL (WINAPI *LPFNICMPCLOSEHANDLE)(HANDLE); + typedef DWORD (WINAPI *LPFNICMPSENDECHO)(HANDLE, u_long, LPVOID, WORD, LPVOID, LPVOID, DWORD, DWORD); + +public: + + WinMTRNet(WinMTRDialog *wp); + ~WinMTRNet(); + void DoTrace(int address); + void ResetHops(); + void StopTrace(); + + int GetAddr(int at); + int GetName(int at, char *n); + int GetBest(int at); + int GetWorst(int at); + int GetAvg(int at); + int GetPercent(int at); + int GetLast(int at); + int GetReturned(int at); + int GetXmit(int at); + int GetMax(); + + void SetAddr(int at, __int32 addr); + void SetName(int at, char *n); + void SetBest(int at, int current); + void SetWorst(int at, int current); + void SetLast(int at, int last); + void AddReturned(int at); + void AddXmit(int at); + + WinMTRDialog *wmtrdlg; + __int32 last_remote_addr; + bool tracing; + bool initialized; + HANDLE hICMP; + LPFNICMPCREATEFILE lpfnIcmpCreateFile; + LPFNICMPCLOSEHANDLE lpfnIcmpCloseHandle; + LPFNICMPSENDECHO lpfnIcmpSendEcho; +private: + HINSTANCE hICMP_DLL; + + struct s_nethost host[MaxHost]; + HANDLE ghMutex; +}; + +#endif // ifndef WINMTRNET_H_ diff --git a/WinMTROptions.cpp b/WinMTROptions.cpp new file mode 100644 index 0000000..395ad6e --- /dev/null +++ b/WinMTROptions.cpp @@ -0,0 +1,112 @@ +//***************************************************************************** +// FILE: WinMTROptions.cpp +// +// +//***************************************************************************** + +#include "WinMTRGlobal.h" +#include "WinMTROptions.h" +#include "WinMTRLicense.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + + +//***************************************************************************** +// BEGIN_MESSAGE_MAP +// +// +//***************************************************************************** +BEGIN_MESSAGE_MAP(WinMTROptions, CDialog) + ON_BN_CLICKED(ID_LICENSE, OnLicense) +END_MESSAGE_MAP() + + +//***************************************************************************** +// WinMTROptions::WinMTROptions +// +// +//***************************************************************************** +WinMTROptions::WinMTROptions(CWnd* pParent) : CDialog(WinMTROptions::IDD, pParent) +{ +} + + +//***************************************************************************** +// WinMTROptions::DoDataExchange +// +// +//***************************************************************************** +void WinMTROptions::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + DDX_Control(pDX, IDC_EDIT_SIZE, m_editSize); + DDX_Control(pDX, IDC_EDIT_INTERVAL, m_editInterval); + DDX_Control(pDX, IDC_EDIT_MAX_LRU, m_editMaxLRU); + DDX_Control(pDX, IDC_CHECK_DNS, m_checkDNS); +} + + +//***************************************************************************** +// WinMTROptions::OnInitDialog +// +// +//***************************************************************************** +BOOL WinMTROptions::OnInitDialog() +{ + CDialog::OnInitDialog(); + + char strtmp[20]; + + sprintf(strtmp, "%.1f", interval); + m_editInterval.SetWindowText(strtmp); + + sprintf(strtmp, "%d", pingsize); + m_editSize.SetWindowText(strtmp); + + sprintf(strtmp, "%d", maxLRU); + m_editMaxLRU.SetWindowText(strtmp); + + m_checkDNS.SetCheck(useDNS); + + m_editInterval.SetFocus(); + return FALSE; +} + + +//***************************************************************************** +// WinMTROptions::OnOK +// +// +//***************************************************************************** +void WinMTROptions::OnOK() +{ + char tmpstr[20]; + + useDNS = m_checkDNS.GetCheck(); + + m_editInterval.GetWindowText(tmpstr, 20); + interval = atof(tmpstr); + + m_editSize.GetWindowText(tmpstr, 20); + pingsize = atoi(tmpstr); + + m_editMaxLRU.GetWindowText(tmpstr, 20); + maxLRU = atoi(tmpstr); + + CDialog::OnOK(); +} + +//***************************************************************************** +// WinMTROptions::OnLicense +// +// +//***************************************************************************** +void WinMTROptions::OnLicense() +{ + WinMTRLicense mtrlicense; + mtrlicense.DoModal(); +} diff --git a/WinMTROptions.h b/WinMTROptions.h new file mode 100644 index 0000000..62ea54f --- /dev/null +++ b/WinMTROptions.h @@ -0,0 +1,62 @@ +//***************************************************************************** +// FILE: WinMTROptions.h +// +// +// DESCRIPTION: +// +// +// NOTES: +// +// +//***************************************************************************** + +#ifndef WINMTROPTIONS_H_ +#define WINMTROPTIONS_H_ + + + +//***************************************************************************** +// CLASS: WinMTROptions +// +// +//***************************************************************************** + +class WinMTROptions : public CDialog +{ +public: + WinMTROptions(CWnd* pParent = NULL); + + void SetUseDNS(BOOL udns) { useDNS = udns; }; + void SetInterval(double i) { interval = i; }; + void SetPingSize(int ps) { pingsize = ps; }; + void SetMaxLRU(int mlru) { maxLRU = mlru; }; + + double GetInterval() { return interval; }; + int GetPingSize() { return pingsize; }; + int GetMaxLRU() { return maxLRU; }; + BOOL GetUseDNS() { return useDNS; }; + + enum { IDD = IDD_DIALOG_OPTIONS }; + CEdit m_editSize; + CEdit m_editInterval; + CEdit m_editMaxLRU; + CButton m_checkDNS; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); + + virtual BOOL OnInitDialog(); + virtual void OnOK(); + + afx_msg void OnLicense(); + + DECLARE_MESSAGE_MAP() + +private: + double interval; + int pingsize; + int maxLRU; + BOOL useDNS; +}; + +#endif // ifndef WINMTROPTIONS_H_ diff --git a/WinMTRProperties.cpp b/WinMTRProperties.cpp new file mode 100644 index 0000000..e6a0f25 --- /dev/null +++ b/WinMTRProperties.cpp @@ -0,0 +1,91 @@ +//***************************************************************************** +// FILE: WinMTRProperties.cpp +// +// +//***************************************************************************** + +#include "WinMTRGlobal.h" +#include "WinMTRProperties.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + + +//***************************************************************************** +// BEGIN_MESSAGE_MAP +// +// +//***************************************************************************** +BEGIN_MESSAGE_MAP(WinMTRProperties, CDialog) +END_MESSAGE_MAP() + + +//***************************************************************************** +// WinMTRProperties::WinMTRProperties +// +// +//***************************************************************************** +WinMTRProperties::WinMTRProperties(CWnd* pParent) : CDialog(WinMTRProperties::IDD, pParent) +{ +} + + +//***************************************************************************** +// WinMTRroperties::DoDataExchange +// +// +//***************************************************************************** +void WinMTRProperties::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + DDX_Control(pDX, IDC_EDIT_PHOST, m_editHost); + DDX_Control(pDX, IDC_EDIT_PIP, m_editIP); + DDX_Control(pDX, IDC_EDIT_PCOMMENT, m_editComment); + + DDX_Control(pDX, IDC_EDIT_PLOSS, m_editLoss); + DDX_Control(pDX, IDC_EDIT_PSENT, m_editSent); + DDX_Control(pDX, IDC_EDIT_PRECV, m_editRecv); + + DDX_Control(pDX, IDC_EDIT_PLAST, m_editLast); + DDX_Control(pDX, IDC_EDIT_PBEST, m_editBest); + DDX_Control(pDX, IDC_EDIT_PWORST, m_editWorst); + DDX_Control(pDX, IDC_EDIT_PAVRG, m_editAvrg); +} + + +//***************************************************************************** +// WinMTRProperties::OnInitDialog +// +// +//***************************************************************************** +BOOL WinMTRProperties::OnInitDialog() +{ + CDialog::OnInitDialog(); + char buf[255]; + + m_editIP.SetWindowText(ip); + m_editHost.SetWindowText(host); + m_editComment.SetWindowText(comment); + + sprintf(buf, "%d", pck_loss); + m_editLoss.SetWindowText(buf); + sprintf(buf, "%d", pck_sent); + m_editSent.SetWindowText(buf); + sprintf(buf, "%d", pck_recv); + m_editRecv.SetWindowText(buf); + + sprintf(buf, "%.1f", ping_last); + m_editLast.SetWindowText(buf); + sprintf(buf, "%.1f", ping_best); + m_editBest.SetWindowText(buf); + sprintf(buf, "%.1f", ping_worst); + m_editWorst.SetWindowText(buf); + sprintf(buf, "%.1f", ping_avrg); + m_editAvrg.SetWindowText(buf); + + return FALSE; +} + diff --git a/WinMTRProperties.h b/WinMTRProperties.h new file mode 100644 index 0000000..8a7dafc --- /dev/null +++ b/WinMTRProperties.h @@ -0,0 +1,64 @@ +//***************************************************************************** +// FILE: WinMTRProperties.h +// +// +// DESCRIPTION: +// +// +// NOTES: +// +// +//***************************************************************************** + +#ifndef WINMTRPROPERTIES_H_ +#define WINMTRPROPERTIES_H_ + + + +//***************************************************************************** +// CLASS: WinMTRLicense +// +// +//***************************************************************************** + +class WinMTRProperties : public CDialog +{ +public: + WinMTRProperties(CWnd* pParent = NULL); + + + enum { IDD = IDD_DIALOG_PROPERTIES }; + + char host[255]; + char ip[16]; + char comment[255]; + + float ping_last; + float ping_best; + float ping_avrg; + float ping_worst; + + int pck_sent; + int pck_recv; + int pck_loss; + + CEdit m_editHost, + m_editIP, + m_editComment, + m_editSent, + m_editRecv, + m_editLoss, + m_editLast, + m_editBest, + m_editWorst, + m_editAvrg; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); + + virtual BOOL OnInitDialog(); + + DECLARE_MESSAGE_MAP() +}; + +#endif // ifndef WINMTRLICENSE_H_ diff --git a/WinMTRStatusBar.cpp b/WinMTRStatusBar.cpp new file mode 100644 index 0000000..5d6ba1d --- /dev/null +++ b/WinMTRStatusBar.cpp @@ -0,0 +1,313 @@ +#include "WinMTRGlobal.h" +#include "WinMTRStatusBar.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +WinMTRStatusBar::WinMTRStatusBar() +{ +} + +WinMTRStatusBar::~WinMTRStatusBar() +{ + for ( int i = 0; i < m_arrPaneControls.GetSize(); i++ ){ + if( m_arrPaneControls[i]->hWnd && ::IsWindow(m_arrPaneControls[i]->hWnd) ) { + ::ShowWindow(m_arrPaneControls[i]->hWnd, SW_HIDE); + if( m_arrPaneControls[i]->bAutoDestroy ) { + ::DestroyWindow(m_arrPaneControls[i]->hWnd); + } + } + _STATUSBAR_PANE_CTRL_ *pPaneCtrl = m_arrPaneControls[i]; + if( pPaneCtrl ) + delete pPaneCtrl; + } +} + +BEGIN_MESSAGE_MAP(WinMTRStatusBar, CStatusBar) + //{{AFX_MSG_MAP(WinMTRStatusBar) + ON_WM_CREATE() + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + + +///////////////////////////////////////////////////////////////////////////// +// WinMTRStatusBar message handlers +////////////////////////////////////////////////////////////////////////// + +int WinMTRStatusBar::OnCreate(LPCREATESTRUCT lpCreateStruct) +{ + if( CStatusBar::OnCreate(lpCreateStruct) == -1 ) + return -1; + + return 0; +} + +////////////////////////////////////////////////////////////////////////// + +LRESULT WinMTRStatusBar::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + LRESULT lResult =CStatusBar::WindowProc(message, wParam, lParam); + if( message == WM_SIZE ){ + RepositionControls(); + } + return lResult; +} + +////////////////////////////////////////////////////////////////////////// + +void WinMTRStatusBar::RepositionControls() +{ + HDWP _hDWP = ::BeginDeferWindowPos( m_arrPaneControls.GetSize() ); + + CRect rcClient; + GetClientRect(&rcClient); + for (int i = 0; i < m_arrPaneControls.GetSize(); i++ ) + { + int iIndex = CommandToIndex(m_arrPaneControls[i]->nID); + HWND hWnd = m_arrPaneControls[i]->hWnd; + + CRect rcPane; + GetItemRect(iIndex, &rcPane); + + // CStatusBar::GetItemRect() sometimes returns invalid size + // of the last pane - we will re-compute it + int cx = ::GetSystemMetrics( SM_CXEDGE ); + DWORD dwPaneStyle = GetPaneStyle( iIndex ); + if( iIndex == (m_nCount-1) ) + { + if( (dwPaneStyle & SBPS_STRETCH ) == 0 ) + { + UINT nID, nStyle; + int cxWidth; + GetPaneInfo( iIndex, nID, nStyle, cxWidth ); + rcPane.right = rcPane.left + cxWidth + cx*3; + } // if( (dwPaneStyle & SBPS_STRETCH ) == 0 ) + else + { + CRect rcClient; + GetClientRect( &rcClient ); + rcPane.right = rcClient.right; + if( (GetStyle() & SBARS_SIZEGRIP) == SBARS_SIZEGRIP ) + { + int cxSmIcon = ::GetSystemMetrics( SM_CXSMICON ); + rcPane.right -= cxSmIcon + cx; + } // if( (GetStyle() & SBARS_SIZEGRIP) == SBARS_SIZEGRIP ) + } // else from if( (dwPaneStyle & SBPS_STRETCH ) == 0 ) + } // if( iIndex == (m_nCount-1) ) + + if ((GetPaneStyle (iIndex) & SBPS_NOBORDERS) == 0){ + rcPane.DeflateRect(cx,cx); + }else{ + rcPane.DeflateRect(cx,1,cx,1); + } + + if (hWnd && ::IsWindow(hWnd)){ + _hDWP = ::DeferWindowPos( + _hDWP, + hWnd, + NULL, + rcPane.left, + rcPane.top, + rcPane.Width(), + rcPane.Height(), + SWP_NOZORDER|SWP_NOOWNERZORDER|SWP_SHOWWINDOW + ); + + ::RedrawWindow( + hWnd, + NULL, + NULL, + RDW_INVALIDATE|RDW_UPDATENOW + |RDW_ERASE|RDW_ERASENOW + ); + + } // if (hWnd && ::IsWindow(hWnd)){ + } + + VERIFY( ::EndDeferWindowPos( _hDWP ) ); +}; + +////////////////////////////////////////////////////////////////////////// + +BOOL WinMTRStatusBar::AddPane( + UINT nID, // ID of the pane + int nIndex // index of the pane + ) +{ + if (nIndex < 0 || nIndex > m_nCount){ + ASSERT(FALSE); + return FALSE; + } + + if (CommandToIndex(nID) != -1){ + ASSERT(FALSE); + return FALSE; + } + + CArray<_STATUSBAR_PANE_*,_STATUSBAR_PANE_*> arrPanesTmp; + int iIndex = 0; + for (iIndex = 0; iIndex < m_nCount+1; iIndex++) + { + _STATUSBAR_PANE_* pNewPane = new _STATUSBAR_PANE_; + + if (iIndex == nIndex){ + pNewPane->nID = nID; + pNewPane->nStyle = SBPS_NORMAL; + }else{ + int idx = iIndex; + if (iIndex > nIndex) idx--; + + _STATUSBAR_PANE_* pOldPane = GetPanePtr(idx); + pNewPane->cxText = pOldPane->cxText; + pNewPane->nFlags = pOldPane->nFlags; + pNewPane->nID = pOldPane->nID; + pNewPane->nStyle = pOldPane->nStyle; + pNewPane->strText = pOldPane->strText; + } + arrPanesTmp.Add(pNewPane); + } + + int nPanesCount = arrPanesTmp.GetSize(); + UINT* lpIDArray = new UINT[ nPanesCount ]; + for (iIndex = 0; iIndex < nPanesCount; iIndex++) { + lpIDArray[iIndex] = arrPanesTmp[iIndex]->nID; + } + + // set the indicators + SetIndicators(lpIDArray, nPanesCount); + // free memory + for (iIndex = 0; iIndex < nPanesCount; iIndex++){ + _STATUSBAR_PANE_* pPane = arrPanesTmp[iIndex]; + if (iIndex != nIndex) + PaneInfoSet(iIndex, pPane); + if(pPane) + delete pPane; + } + + arrPanesTmp.RemoveAll(); + if(lpIDArray) + delete []lpIDArray; + + RepositionControls(); + + return TRUE; +} + +////////////////////////////////////////////////////////////////////////// + +BOOL WinMTRStatusBar::RemovePane( + UINT nID // ID of the pane + ) +{ + if ( CommandToIndex(nID) == -1 || m_nCount == 1 ){ + ASSERT(FALSE); + return FALSE; + } + + CArray<_STATUSBAR_PANE_*,_STATUSBAR_PANE_*> arrPanesTmp; + int nIndex; + for (nIndex = 0; nIndex < m_nCount; nIndex++) + { + _STATUSBAR_PANE_* pOldPane = GetPanePtr(nIndex); + + if (pOldPane->nID == nID) + continue; + + _STATUSBAR_PANE_* pNewPane = new _STATUSBAR_PANE_; + + pNewPane->cxText = pOldPane->cxText; + pNewPane->nFlags = pOldPane->nFlags; + pNewPane->nID = pOldPane->nID; + pNewPane->nStyle = pOldPane->nStyle; + pNewPane->strText = pOldPane->strText; + arrPanesTmp.Add(pNewPane); + } + + UINT* lpIDArray = new UINT[arrPanesTmp.GetSize()]; + for (nIndex = 0; nIndex < arrPanesTmp.GetSize(); nIndex++) { + lpIDArray[nIndex] = arrPanesTmp[nIndex]->nID; + } + + // set the indicators + SetIndicators(lpIDArray, arrPanesTmp.GetSize()); + // free memory + for (nIndex = 0; nIndex < arrPanesTmp.GetSize(); nIndex++){ + _STATUSBAR_PANE_* pPane = arrPanesTmp[nIndex]; + PaneInfoSet(nIndex, pPane); + if(pPane) + delete pPane; + } + + for ( int i = 0; i < m_arrPaneControls.GetSize(); i++ ){ + if (m_arrPaneControls[i]->nID == nID){ + if( m_arrPaneControls[i]->hWnd && ::IsWindow(m_arrPaneControls[i]->hWnd) ) { + ::ShowWindow(m_arrPaneControls[i]->hWnd, SW_HIDE); + if( m_arrPaneControls[i]->bAutoDestroy ) { + ::DestroyWindow(m_arrPaneControls[i]->hWnd); + } + } + _STATUSBAR_PANE_CTRL_ *pPaneCtrl = m_arrPaneControls[i]; + if( pPaneCtrl ) + delete pPaneCtrl; + m_arrPaneControls.RemoveAt(i); + break; + } + } + + arrPanesTmp.RemoveAll(); + if(lpIDArray) + delete []lpIDArray; + + RepositionControls(); + + return TRUE; +} + +////////////////////////////////////////////////////////////////////////// + +BOOL WinMTRStatusBar::AddPaneControl(HWND hWnd, UINT nID, BOOL bAutoDestroy) +{ + if (CommandToIndex (nID) == -1) { + return FALSE; + } + + _STATUSBAR_PANE_CTRL_* pPaneCtrl = new _STATUSBAR_PANE_CTRL_; + pPaneCtrl->nID = nID; + pPaneCtrl->hWnd = hWnd; + pPaneCtrl->bAutoDestroy = bAutoDestroy; + + m_arrPaneControls.Add(pPaneCtrl); + + RepositionControls(); + return TRUE; +} + +////////////////////////////////////////////////////////////////////////// + +BOOL WinMTRStatusBar::PaneInfoGet(int nIndex, _STATUSBAR_PANE_* pPane) +{ + if( nIndex < m_nCount && nIndex >= 0 ) + { + GetPaneInfo( nIndex, pPane->nID, pPane->nStyle, pPane->cxText ); + CString strPaneText; + GetPaneText( nIndex , strPaneText ); + pPane->strText = LPCTSTR(strPaneText); + return TRUE; + } + return FALSE; +} + +////////////////////////////////////////////////////////////////////////// + +BOOL WinMTRStatusBar::PaneInfoSet(int nIndex, _STATUSBAR_PANE_* pPane) +{ + if( nIndex < m_nCount && nIndex >= 0 ){ + SetPaneInfo( nIndex, pPane->nID, pPane->nStyle, pPane->cxText ); + SetPaneText( nIndex, LPCTSTR( pPane->strText) ); + return TRUE; + } + return FALSE; +} diff --git a/WinMTRStatusBar.h b/WinMTRStatusBar.h new file mode 100644 index 0000000..d15dbb8 --- /dev/null +++ b/WinMTRStatusBar.h @@ -0,0 +1,126 @@ +#ifndef WINMTRSTATUSBAR_H_ +#define WINMTRSTATUSBAR_H_ + +class WinMTRStatusBar : public CStatusBar +{ +// Construction +public: + + WinMTRStatusBar(); + +// Attributes +public: + + // Operations +public: + + int GetPanesCount() const{ + return m_nCount; + } + + void SetPaneWidth(int nIndex, int nWidth) + { + _STATUSBAR_PANE_ pane; + PaneInfoGet(nIndex, &pane); + pane.cxText = nWidth; + PaneInfoSet(nIndex, &pane); + } + + BOOL AddPane( + UINT nID, // ID of the pane + int nIndex // index of the pane + ); + + BOOL RemovePane( + UINT nID // ID of the pane + ); + + BOOL AddPaneControl(CWnd* pWnd, UINT nID, BOOL bAutoDestroy) + { + return AddPaneControl( pWnd->GetSafeHwnd(), nID, bAutoDestroy); + } + + BOOL AddPaneControl(HWND hWnd, UINT nID, BOOL bAutoDestroy); + + void DisableControl( int nIndex, BOOL bDisable=TRUE) + { + UINT uItemID = GetItemID(nIndex); + for ( int i = 0; i < m_arrPaneControls.GetSize(); i++ ){ + if( uItemID == m_arrPaneControls[i]->nID ){ + if( m_arrPaneControls[i]->hWnd && ::IsWindow(m_arrPaneControls[i]->hWnd) ) { + ::EnableWindow(m_arrPaneControls[i]->hWnd, bDisable); + } + } + } + } + + void SetPaneInfo(int nIndex, UINT nID, UINT nStyle, int cxWidth) + { + CStatusBar::SetPaneInfo(nIndex, nID, nStyle, cxWidth); + BOOL bDisabled = ((nStyle&SBPS_DISABLED) == 0); + DisableControl(nIndex, bDisabled); + } + + void SetPaneStyle(int nIndex, UINT nStyle) + { + CStatusBar::SetPaneStyle(nIndex, nStyle); + BOOL bDisabled = ((nStyle&SBPS_DISABLED) == 0); + DisableControl(nIndex, bDisabled); + } + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(WinMTRStatusBar) + //}}AFX_VIRTUAL + +// Implementation +public: + virtual ~WinMTRStatusBar(); + +protected: + + struct _STATUSBAR_PANE_ + { + _STATUSBAR_PANE_(){ + nID = cxText = nStyle = nFlags = 0; + } + + UINT nID; // IDC of indicator: 0 => normal text area + int cxText; // width of string area in pixels + // on both sides there is a 3 pixel gap and + // a one pixel border, making a pane 6 pixels wider + UINT nStyle; // style flags (SBPS_*) + UINT nFlags; // state flags (SBPF_*) + CString strText; // text in the pane + }; + + struct _STATUSBAR_PANE_CTRL_ + { + HWND hWnd; + UINT nID; + BOOL bAutoDestroy; + }; + + CArray < _STATUSBAR_PANE_CTRL_*, _STATUSBAR_PANE_CTRL_* > m_arrPaneControls; + + _STATUSBAR_PANE_* GetPanePtr(int nIndex) const + { + ASSERT((nIndex >= 0 && nIndex < m_nCount) || m_nCount == 0); + return ((_STATUSBAR_PANE_*)m_pData) + nIndex; + } + + BOOL PaneInfoGet(int nIndex, _STATUSBAR_PANE_* pPane); + BOOL PaneInfoSet(int nIndex, _STATUSBAR_PANE_* pPane); + + void RepositionControls(); + + // Generated message map functions +protected: + //{{AFX_MSG(WinMTRStatusBar) + afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() + virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); +}; + +#endif // WINMTRSTATUSBAR_H_ diff --git a/resource.h b/resource.h new file mode 100644 index 0000000..1ca45e3 --- /dev/null +++ b/resource.h @@ -0,0 +1,53 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by WinMTR.rc +// +#define IDD_WINMTR_DIALOG 102 +#define IDP_SOCKETS_INIT_FAILED 103 +#define IDS_STRING_SB_NAME 104 +#define IDS_STRING_SB_PING 105 +#define IDS_STRING_CLEAR_HISTORY 106 +#define IDR_MAINFRAME 128 +#define IDD_DIALOG_OPTIONS 129 +#define IDD_DIALOG_LICENSE 130 +#define IDD_DIALOG_PROPERTIES 131 +#define IDD_DIALOG_HELP 132 +#define IDC_EDIT_HOST 1000 +#define IDC_LIST_MTR 1001 +#define ID_RESTART 1002 +#define ID_OPTIONS 1003 +#define IDC_EDIT_INTERVAL 1004 +#define ID_CTTC 1004 +#define IDC_EDIT_SIZE 1005 +#define ID_CHTC 1005 +#define IDC_CHECK_DNS 1006 +#define ID_EXPT 1006 +#define ID_EXPH 1007 +#define ID_LICENSE 1008 +#define IDC_EDIT_LICENSE 1011 +#define IDC_EDIT_PHOST 1012 +#define IDC_EDIT_PIP 1013 +#define IDC_EDIT_PSENT 1014 +#define IDC_EDIT_PRECV 1015 +#define IDC_EDIT_PLOSS 1016 +#define IDC_EDIT_PLAST 1017 +#define IDC_EDIT_PBEST 1018 +#define IDC_EDIT_PAVRG 1019 +#define IDC_EDIT_PWORST 1020 +#define IDC_EDIT_PCOMMENT 1021 +#define IDC_STATICS 1022 +#define IDC_STATICJ 1023 +#define IDC_COMBO_HOST 1024 +#define IDC_EDIT_MAX_LRU 1025 +#define IDC_MFCLINK1 1026 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 135 +#define _APS_NEXT_COMMAND_VALUE 32771 +#define _APS_NEXT_CONTROL_VALUE 1027 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif