home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / NETTOOLS.ZIP / PingDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-12-16  |  8.3 KB  |  321 lines

  1. // PingDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "nettools.h"
  6. #include "pingparmlist.h"
  7. #include "PingDlg.h"
  8.  
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. #define IPOPT_TOS_LOW_DELAY    16
  16. #define IPOPT_TOS_HIGH_RELIAB  4
  17. #define IPOPT_TOS_HIGH_THRU    8 
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CPingDlg dialog
  20.  
  21.  
  22. CPingDlg::CPingDlg(CWnd* pParent /*=NULL*/)
  23.     : CDialog(CPingDlg::IDD, pParent)
  24. {
  25.     //{{AFX_DATA_INIT(CPingDlg)
  26.     m_ping_hostname = _T("");
  27.     m_ping_opt_resolve = FALSE;
  28.     m_ping_opt_ttl_val = 0;
  29.     m_ping_opt_dontfragment = FALSE;
  30.     m_ping_opt_packetlen_val = 64;
  31.     m_ping_opt_numpackets_val = 4;
  32.     m_ping_opt_rroute_val = 0;
  33.     m_ping_opt_timestamp_val = 0;
  34.     m_ping_opt_interrupt = FALSE;
  35.     m_ping_opt_tos_high_reliab = FALSE;
  36.     m_ping_opt_tos_high_thru = FALSE;
  37.     m_ping_opt_tos_low_delay = FALSE;
  38.     m_ping_opt_tos_none = TRUE;
  39.     m_ping_opt_timeout_val = 0;
  40.     m_ping_opt_rrloose = FALSE;
  41.     m_ping_opt_rrstrict = FALSE;
  42.     m_ping_opt_routes = _T("");
  43.     m_ping_opt_tracert = FALSE;
  44.     //}}AFX_DATA_INIT
  45. }
  46.  
  47.  
  48. void CPingDlg::DoDataExchange(CDataExchange* pDX)
  49. {
  50.     CDialog::DoDataExchange(pDX);
  51.     //{{AFX_DATA_MAP(CPingDlg)
  52.     DDX_Text(pDX, IDC_PING_HOSTNAME, m_ping_hostname);
  53.     DDX_Check(pDX, IDC_PING_OPT_A, m_ping_opt_resolve);
  54.     DDX_Text(pDX, IDC_PING_OPT_I_VAL, m_ping_opt_ttl_val);
  55.     DDV_MinMaxUInt(pDX, m_ping_opt_ttl_val, 0, 255);
  56.     DDX_Check(pDX, IDC_PING_OPT_F, m_ping_opt_dontfragment);
  57.     DDX_Text(pDX, IDC_PING_OPT_L_VAL, m_ping_opt_packetlen_val);
  58.     DDV_MinMaxUInt(pDX, m_ping_opt_packetlen_val, 64, 8192);
  59.     DDX_Text(pDX, IDC_PING_OPT_N_VAL, m_ping_opt_numpackets_val);
  60.     DDV_MinMaxUInt(pDX, m_ping_opt_numpackets_val, 4, 64);
  61.     DDX_Text(pDX, IDC_PING_OPT_R_VAL, m_ping_opt_rroute_val);
  62.     DDV_MinMaxUInt(pDX, m_ping_opt_rroute_val, 0, 9);
  63.     DDX_Text(pDX, IDC_PING_OPT_S_VAL, m_ping_opt_timestamp_val);
  64.     DDV_MinMaxUInt(pDX, m_ping_opt_timestamp_val, 0, 4);
  65.     DDX_Check(pDX, IDC_PING_OPT_T, m_ping_opt_interrupt);
  66.     DDX_Check(pDX, IDC_PING_OPT_TOS_HIGH_RELIAB, m_ping_opt_tos_high_reliab);
  67.     DDX_Check(pDX, IDC_PING_OPT_TOS_HIGH_THRU, m_ping_opt_tos_high_thru);
  68.     DDX_Check(pDX, IDC_PING_OPT_TOS_LOW_DELAY, m_ping_opt_tos_low_delay);
  69.     DDX_Check(pDX, IDC_PING_OPT_TOS_NONE, m_ping_opt_tos_none);
  70.     DDX_Text(pDX, IDC_PING_OPT_W_VAL, m_ping_opt_timeout_val);
  71.     DDV_MinMaxUInt(pDX, m_ping_opt_timeout_val, 0, 10000);
  72.     DDX_Check(pDX, IDC_PING_OPT_RRLOOSE, m_ping_opt_rrloose);
  73.     DDX_Check(pDX, IDC_PING_OPT_RRSTRICT, m_ping_opt_rrstrict);
  74.     DDX_Text(pDX, IDC_PING_OPT_RROUTE_LRSR, m_ping_opt_routes);
  75.     DDV_MaxChars(pDX, m_ping_opt_routes, 200);
  76.     DDX_Check(pDX, IDC_PING_OPT_TRACERT, m_ping_opt_tracert);
  77.     //}}AFX_DATA_MAP
  78. }
  79.  
  80.  
  81. BEGIN_MESSAGE_MAP(CPingDlg, CDialog)
  82.     //{{AFX_MSG_MAP(CPingDlg)
  83.     ON_BN_CLICKED(IDC_PING_OPT_TOS_NONE, OnPingOptTosNone)
  84.     ON_BN_CLICKED(IDC_PING_OPT_TOS_HIGH_RELIAB, OnPingOptTosHighReliab)
  85.     ON_BN_CLICKED(IDC_PING_OPT_TOS_HIGH_THRU, OnPingOptTosHighThru)
  86.     ON_BN_CLICKED(IDC_PING_OPT_TOS_LOW_DELAY, OnPingOptTosLowDelay)
  87.     ON_BN_CLICKED(IDC_PING_OPT_RRLOOSE, OnPingOptRrloose)
  88.     ON_BN_CLICKED(IDC_PING_OPT_RRSTRICT, OnPingOptRrstrict)
  89.     ON_EN_CHANGE(IDC_PING_OPT_R_VAL, OnChangePingOptRVal)
  90.     //}}AFX_MSG_MAP
  91. END_MESSAGE_MAP()
  92.  
  93. /////////////////////////////////////////////////////////////////////////////
  94. // CPingDlg message handlers
  95.  
  96. BOOL CPingDlg::OnInitDialog() 
  97. {
  98.     CDialog::OnInitDialog();
  99.     
  100.     
  101.     
  102.     return TRUE;  // return TRUE unless you set the focus to a control
  103.                   // EXCEPTION: OCX Property Pages should return FALSE
  104. }
  105.  
  106. void CPingDlg::OnOK() 
  107. {
  108.     
  109.     CHAR SrchBuff[256];
  110.     CHAR HoldBuff[256];
  111.     CHAR *pSrchBuff;
  112.     CHAR *pSrchMax;
  113.     CHAR *pHoldBuff;
  114.     CHAR *pcsLine;
  115.     CHAR *SrchArg = ", ";
  116.     int HitOffset;
  117.     
  118.     CString csLine;
  119.  
  120.  
  121.  
  122.  
  123.     if (!UpdateData(TRUE))  // retrieve and validate data
  124.         return;                // validate failed
  125.  
  126.     
  127.     if (m_ping_hostname.IsEmpty())
  128.     {
  129.         AfxMessageBox("Please enter a Hostname");
  130.         return;
  131.     }
  132.  
  133.     if ((m_ping_opt_rrloose) || (m_ping_opt_rrstrict))
  134.     {
  135.         
  136.         if (m_ping_opt_routes.IsEmpty())
  137.         {
  138.             AfxMessageBox("Must Specify Addr's Routing");
  139.             return;
  140.         }
  141.         else
  142.         {
  143.             pSrchBuff = SrchBuff;
  144.             pHoldBuff = HoldBuff;
  145.             strcpy(pSrchBuff,m_ping_opt_routes);
  146.             pSrchMax = pSrchBuff + strlen(SrchBuff);
  147.             m_lpPingParms->opt_rrdata.RemoveAll();
  148.             while(TRUE)
  149.             {
  150.                 HitOffset = strcspn(pSrchBuff,SrchArg);
  151.                 pcsLine = csLine.GetBuffer(HitOffset);
  152.                 memcpy(pcsLine,pSrchBuff,HitOffset);
  153.                 csLine.ReleaseBuffer(HitOffset);
  154.                 m_lpPingParms->opt_rrdata.Add(csLine);
  155.                 HitOffset ++;  //bump past ',' or blank
  156.                 pSrchBuff += HitOffset;
  157.                 if (pSrchBuff >= pSrchMax)
  158.                     break;
  159.             }
  160.             if (m_lpPingParms->opt_rrdata.GetSize() > 9)
  161.             {
  162.                 AfxMessageBox("Too Many Routes Max 9");
  163.                 m_lpPingParms->opt_rrdata.RemoveAll();
  164.                 return;
  165.             }
  166.  
  167.  
  168.  
  169.         }
  170.  
  171.     }
  172.  
  173.  
  174.     // initialize the threads parmslist with
  175.     // the data from the dialog box.
  176.     //
  177.  
  178.     m_lpPingParms->opt_tos_val = 0;
  179.  
  180.     if (m_ping_opt_tos_high_reliab)
  181.         m_lpPingParms->opt_tos_val |= IPOPT_TOS_HIGH_RELIAB;
  182.  
  183.     if (m_ping_opt_tos_high_thru)
  184.         m_lpPingParms->opt_tos_val |= IPOPT_TOS_HIGH_THRU;
  185.  
  186.     if (m_ping_opt_tos_low_delay)
  187.         m_lpPingParms->opt_tos_val |= IPOPT_TOS_LOW_DELAY;
  188.  
  189.     if (m_ping_opt_tos_none)
  190.         m_lpPingParms->opt_tos_val = 0;
  191.  
  192.     memset(m_lpPingParms->hostname,
  193.            0,
  194.            sizeof(m_lpPingParms->hostname));
  195.  
  196.     strcat(m_lpPingParms->hostname,m_ping_hostname);
  197.     m_lpPingParms->opt_resolve = m_ping_opt_resolve;
  198.     m_lpPingParms->opt_dontfragment =    m_ping_opt_dontfragment;
  199.     m_lpPingParms->opt_interrupt = m_ping_opt_interrupt;
  200.     m_lpPingParms->opt_ttl_val = m_ping_opt_ttl_val;
  201.     m_lpPingParms->opt_packetlen_val = m_ping_opt_packetlen_val;
  202.     m_lpPingParms->opt_numpackets_val = m_ping_opt_numpackets_val;
  203.     m_lpPingParms->opt_rroute_val = m_ping_opt_rroute_val;
  204.     m_lpPingParms->opt_timestamp_val = m_ping_opt_timestamp_val;
  205.     m_lpPingParms->opt_timeout_val = m_ping_opt_timeout_val;
  206.     m_lpPingParms->opt_rrloose = m_ping_opt_rrloose;
  207.     m_lpPingParms->opt_rrstrict = m_ping_opt_rrstrict;
  208.     m_lpPingParms->opt_tracert = m_ping_opt_tracert;
  209.  
  210.     //
  211.     //
  212.     //
  213.     //
  214.  
  215.     
  216.  
  217.     //while(lbcount)
  218.     //{
  219.     //    lbcount = m_ping_opt_routes_lb.GetLine(lbline,
  220.     //                                           lbbuf,
  221.     //                                           sizeof(lbbuf));
  222.     //    if (lbcount == 0)
  223.     //        break;
  224.     //    lp_line = cs_line.GetBuffer(lbcount);
  225.     //    memcpy(lp_line,lbbuf,lbcount);
  226.     //    cs_line.ReleaseBuffer(lbcount);
  227.     //    m_lpPingParms->opt_rrdata.Add(cs_line);
  228.     //    lbline++;
  229.     //}
  230.     
  231.     
  232.  
  233.     CDialog::OnOK();
  234.     // TODO: Add extra validation here
  235.     
  236.     
  237. }
  238.  
  239. void CPingDlg::OnPingOptTosNone() 
  240. {
  241.     CheckDlgButton(IDC_PING_OPT_TOS_HIGH_THRU,0);
  242.     CheckDlgButton(IDC_PING_OPT_TOS_HIGH_RELIAB,0);
  243.     CheckDlgButton(IDC_PING_OPT_TOS_LOW_DELAY,0);
  244.     CheckDlgButton(IDC_PING_OPT_TOS_NONE,1);
  245.     
  246.     
  247.     // TODO: Add your control notification handler code here
  248.     
  249. }
  250.  
  251. void CPingDlg::OnPingOptTosHighReliab() 
  252. {
  253.     CheckDlgButton(IDC_PING_OPT_TOS_HIGH_RELIAB,1);
  254.     CheckDlgButton(IDC_PING_OPT_TOS_NONE,0);
  255.     
  256.     
  257.     // TODO: Add your control notification handler code here
  258.     
  259. }
  260.  
  261. void CPingDlg::OnPingOptTosHighThru() 
  262. {
  263.     CheckDlgButton(IDC_PING_OPT_TOS_HIGH_THRU,1);
  264.     CheckDlgButton(IDC_PING_OPT_TOS_NONE,0);
  265.     
  266.     // TODO: Add your control notification handler code here
  267.     
  268. }
  269.  
  270. void CPingDlg::OnPingOptTosLowDelay() 
  271. {
  272.     CheckDlgButton(IDC_PING_OPT_TOS_LOW_DELAY,1);
  273.     CheckDlgButton(IDC_PING_OPT_TOS_NONE,0);
  274.  
  275.     // TODO: Add your control notification handler code here
  276.     
  277. }
  278.  
  279.  
  280. void CPingDlg::OnPingOptRrloose() 
  281. {
  282.     CheckDlgButton(IDC_PING_OPT_RRLOOSE,1);
  283.     CheckDlgButton(IDC_PING_OPT_RRSTRICT,0);
  284.     SetDlgItemInt(IDC_PING_OPT_R_VAL,0,FALSE);
  285.   
  286.  
  287.     // TODO: Add your control notification handler code here
  288.     
  289. }
  290.  
  291. void CPingDlg::OnPingOptRrstrict() 
  292. {
  293.     CheckDlgButton(IDC_PING_OPT_RRLOOSE,0);
  294.     CheckDlgButton(IDC_PING_OPT_RRSTRICT,1);
  295.     SetDlgItemInt(IDC_PING_OPT_R_VAL,0,FALSE);
  296.     // TODO: Add your control notification handler code here
  297.     
  298. }
  299.  
  300. void CPingDlg::OnChangePingOptRVal() 
  301. {
  302.     BOOL m_btrans;
  303.     BOOL *m_pbtrans;
  304.     UINT m_editint;
  305.     m_btrans = TRUE;  // check for errors
  306.     m_pbtrans = &m_btrans;
  307.  
  308.     m_editint = GetDlgItemInt(IDC_PING_OPT_R_VAL,
  309.                        m_pbtrans,
  310.                        FALSE);
  311.   
  312.     if ((m_btrans) && (m_editint > 0))
  313.     {
  314.         CheckDlgButton(IDC_PING_OPT_RRLOOSE,0);
  315.         CheckDlgButton(IDC_PING_OPT_RRSTRICT,0);
  316.     }
  317.         
  318.     // TODO: Add your control notification handler code here
  319.     
  320. }
  321.