Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

771 lines
20 KiB

  1. //============================================================================
  2. // Copyright(c) 1996, Microsoft Corporation
  3. //
  4. // File: ipadd.cpp
  5. //
  6. // History:
  7. // 08/30/96 Ram Cherala Created
  8. //
  9. // Implementation of IP Filter Add/Edit dialog code
  10. //============================================================================
  11. #include "stdafx.h"
  12. #include "rtrfiltr.h"
  13. #include "ipfltr.h"
  14. #include "ipadd.h"
  15. extern "C" {
  16. #include <winsock.h>
  17. #include <fltdefs.h>
  18. #include <iprtinfo.h>
  19. }
  20. #include "ipaddr.h"
  21. #include "rtradmin.hm"
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. static enum {
  28. PROTOCOL_TCP = 0,
  29. PROTOCOL_TCP_ESTABLISHED,
  30. PROTOCOL_UDP,
  31. PROTOCOL_ICMP,
  32. PROTOCOL_ANY,
  33. PROTOCOL_OTHER,
  34. };
  35. static UINT g_aPROTOCOLS[][2] = {
  36. {IDS_PROTOCOL_TCP, PROTOCOL_TCP},
  37. {IDS_PROTOCOL_TCP_ESTABLISHED, PROTOCOL_TCP_ESTABLISHED},
  38. {IDS_PROTOCOL_UDP, PROTOCOL_UDP},
  39. {IDS_PROTOCOL_ICMP, PROTOCOL_ICMP},
  40. {IDS_PROTOCOL_ANY, PROTOCOL_ANY},
  41. {IDS_PROTOCOL_OTHER, PROTOCOL_OTHER},
  42. };
  43. #define IDS_ICMP_ECHO 1
  44. #define IDS_ICMP_REDIRECT 2
  45. #if 0
  46. // TODO sample ICMP types - need to update with actual list
  47. static UINT g_aICMPTYPE[][2] = {
  48. {1, IDS_ICMP_ECHO},
  49. {2, IDS_ICMP_REDIRECT}
  50. };
  51. #endif
  52. HRESULT MultiEnableWindow(HWND hWndParent, BOOL fEnable, UINT first, ...)
  53. {
  54. UINT nCtrlId = first;
  55. HWND hWndCtrl;
  56. va_list marker;
  57. va_start(marker, first);
  58. while (nCtrlId != 0)
  59. {
  60. hWndCtrl = ::GetDlgItem(hWndParent, nCtrlId);
  61. Assert(hWndCtrl);
  62. if (hWndCtrl)
  63. ::EnableWindow(hWndCtrl, fEnable);
  64. // get the next item
  65. nCtrlId = va_arg(marker, UINT);
  66. }
  67. va_end(marker);
  68. return hrOK;
  69. }
  70. /////////////////////////////////////////////////////////////////////////////
  71. // CIpFltrAddEdit dialog
  72. CIpFltrAddEdit::CIpFltrAddEdit(CWnd* pParent,
  73. FilterListEntry ** ppFilterEntry,
  74. DWORD dwFilterType)
  75. : CBaseDialog(CIpFltrAddEdit::IDD, pParent),
  76. m_ppFilterEntry( ppFilterEntry ),
  77. m_dwFilterType ( dwFilterType )
  78. {
  79. //{{AFX_DATA_INIT(CIpFltrAddEdit)
  80. m_sProtocol = _T("");
  81. m_sSrcPort = _T("");
  82. m_sDstPort = _T("");
  83. //}}AFX_DATA_INIT
  84. // SetHelpMap(m_dwHelpMap);
  85. }
  86. void CIpFltrAddEdit::DoDataExchange(CDataExchange* pDX)
  87. {
  88. CBaseDialog::DoDataExchange(pDX);
  89. //{{AFX_DATA_MAP(CIpFltrAddEdit)
  90. DDX_Control(pDX, IDC_AEIP_ST_DEST_PORT, m_stDstPort);
  91. DDX_Control(pDX, IDC_AEIP_ST_SRC_PORT, m_stSrcPort);
  92. DDX_Control(pDX, IDC_AEIP_CB_SRC_PORT, m_cbSrcPort);
  93. DDX_Control(pDX, IDC_AEIP_CB_DEST_PORT, m_cbDstPort);
  94. DDX_Control(pDX, IDC_AEIP_CB_PROTOCOL, m_cbProtocol);
  95. DDX_CBString(pDX, IDC_AEIP_CB_PROTOCOL, m_sProtocol);
  96. DDV_MaxChars(pDX, m_sProtocol, 32);
  97. DDX_CBString(pDX, IDC_AEIP_CB_SRC_PORT, m_sSrcPort);
  98. DDV_MaxChars(pDX, m_sSrcPort, 16);
  99. DDX_CBString(pDX, IDC_AEIP_CB_DEST_PORT, m_sDstPort);
  100. DDV_MaxChars(pDX, m_sDstPort, 16);
  101. DDX_Check(pDX, IDC_AEIP_CB_SOURCE, m_bSrc);
  102. DDX_Check(pDX, IDC_AEIP_CB_DEST, m_bDst);
  103. //}}AFX_DATA_MAP
  104. }
  105. BEGIN_MESSAGE_MAP(CIpFltrAddEdit, CBaseDialog)
  106. //{{AFX_MSG_MAP(CIpFltrAddEdit)
  107. ON_CBN_SELCHANGE(IDC_AEIP_CB_PROTOCOL, OnSelchangeProtocol)
  108. ON_BN_CLICKED(IDC_AEIP_CB_SOURCE, OnCbSourceClicked)
  109. ON_BN_CLICKED(IDC_AEIP_CB_DEST, OnCbDestClicked)
  110. //}}AFX_MSG_MAP
  111. END_MESSAGE_MAP()
  112. DWORD CIpFltrAddEdit::m_dwHelpMap[] =
  113. {
  114. // IDC_AEIP_ST_SOURCE, HIDC_AEIP_ST_SOURCE,
  115. // IDC_AEIP_CB_SOURCE, HIDC_AEIP_CB_SOURCE,
  116. // IDC_AEIP_ST_SOURCE_ADDRESS, HIDC_AEIP_ST_SOURCE_ADDRESS,
  117. // IDC_AEIP_EB_SOURCE_ADDRESS, HIDC_AEIP_EB_SOURCE_ADDRESS,
  118. // IDC_AEIP_ST_SOURCE_MASK, HIDC_AEIP_ST_SOURCE_MASK,
  119. // IDC_AEIP_EB_SOURCE_MASK, HIDC_AEIP_EB_SOURCE_MASK,
  120. // IDC_AEIP_ST_DEST, HIDC_AEIP_ST_DEST,
  121. // IDC_AEIP_CB_DEST, HIDC_AEIP_CB_DEST,
  122. // IDC_AEIP_ST_DEST_ADDRESS, HIDC_AEIP_ST_DEST_ADDRESS,
  123. // IDC_AEIP_EB_DEST_ADDRESS, HIDC_AEIP_EB_DEST_ADDRESS,
  124. // IDC_AEIP_ST_DEST_MASK, HIDC_AEIP_ST_DEST_MASK,
  125. // IDC_AEIP_EB_DEST_MASK, HIDC_AEIP_EB_DEST_MASK,
  126. // IDC_AEIP_ST_PROTOCOL, HIDC_AEIP_ST_PROTOCOL,
  127. // IDC_AEIP_CB_PROTOCOL, HIDC_AEIP_CB_PROTOCOL,
  128. // IDC_AEIP_ST_SRC_PORT, HIDC_AEIP_ST_SRC_PORT,
  129. // IDC_AEIP_CB_SRC_PORT, HIDC_AEIP_CB_SRC_PORT,
  130. // IDC_AEIP_ST_DEST_PORT, HIDC_AEIP_ST_DEST_PORT,
  131. // IDC_AEIP_CB_DEST_PORT, HIDC_AEIP_CB_DEST_PORT,
  132. 0,0,
  133. };
  134. /////////////////////////////////////////////////////////////////////////////
  135. // CIpFltrAddEdit message handlers
  136. //-----------------------------------------------------------------------------
  137. // Function: CIpFltrAddEdit::OnSelchangeProtocol
  138. //
  139. // Handles 'CBN_SELCHANGE' notification from Protocols combo box
  140. //------------------------------------------------------------------------------
  141. void CIpFltrAddEdit::OnSelchangeProtocol()
  142. {
  143. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  144. CWnd * hWnd;
  145. CString cStr;
  146. // if tcp or udp, then enable src/dest port
  147. // if icmp, rename strings and enable type/code
  148. // if Other enable src port
  149. // if Any disable everything
  150. switch(QueryCurrentProtocol()) {
  151. case PROTOCOL_TCP:
  152. case PROTOCOL_TCP_ESTABLISHED:
  153. case PROTOCOL_UDP:
  154. VERIFY(cStr.LoadString(IDS_SRC_PORT));
  155. m_stSrcPort.SetWindowText(cStr);
  156. VERIFY(cStr.LoadString(IDS_DST_PORT));
  157. m_stDstPort.SetWindowText(cStr);
  158. m_cbSrcPort.ShowWindow(SW_SHOW);
  159. m_cbDstPort.ShowWindow(SW_SHOW);
  160. m_stSrcPort.ShowWindow(SW_SHOW);
  161. m_stDstPort.ShowWindow(SW_SHOW);
  162. break;
  163. case PROTOCOL_ICMP:
  164. VERIFY(cStr.LoadString(IDS_ICMP_TYPE));
  165. m_stSrcPort.SetWindowText(cStr);
  166. VERIFY(cStr.LoadString(IDS_ICMP_CODE));
  167. m_stDstPort.SetWindowText(cStr);
  168. m_cbSrcPort.ShowWindow(SW_SHOW);
  169. m_cbDstPort.ShowWindow(SW_SHOW);
  170. m_stSrcPort.ShowWindow(SW_SHOW);
  171. m_stDstPort.ShowWindow(SW_SHOW);
  172. break;
  173. case PROTOCOL_ANY:
  174. m_cbSrcPort.ShowWindow(SW_HIDE);
  175. m_cbDstPort.ShowWindow(SW_HIDE);
  176. VERIFY(hWnd = GetDlgItem(IDC_AEIP_ST_SRC_PORT));
  177. hWnd->ShowWindow(SW_HIDE);
  178. VERIFY(hWnd = GetDlgItem(IDC_AEIP_ST_DEST_PORT));
  179. hWnd->ShowWindow(SW_HIDE);
  180. break;
  181. case PROTOCOL_OTHER:
  182. VERIFY(cStr.LoadString(IDS_OTHER_PROTOCOL));
  183. m_stSrcPort.SetWindowText(cStr);
  184. m_cbSrcPort.ShowWindow(SW_SHOW);
  185. m_stSrcPort.ShowWindow(SW_SHOW);
  186. m_cbDstPort.ShowWindow(SW_HIDE);
  187. VERIFY(hWnd = GetDlgItem(IDC_AEIP_ST_DEST_PORT));
  188. hWnd->ShowWindow(SW_HIDE);
  189. break;
  190. }
  191. }
  192. //------------------------------------------------------------------------------
  193. // Function: CIpFltrAddEdit::OnInitDialog
  194. //
  195. // Handles 'WM_INITDIALOG' notification from the dialog
  196. //------------------------------------------------------------------------------
  197. BOOL CIpFltrAddEdit::OnInitDialog()
  198. {
  199. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  200. CString st;
  201. CBaseDialog::OnInitDialog();
  202. // determine if a new filter is being added or if an
  203. // existing filter is being modified.
  204. m_bEdit = ( *m_ppFilterEntry != NULL );
  205. st.LoadString(m_bEdit ? IDS_IP_EDIT_FILTER : IDS_IP_ADD_FILTER);
  206. SetWindowText(st);
  207. // create the IP controls
  208. m_ipSrcAddress.Create(m_hWnd, IDC_AEIP_EB_SOURCE_ADDRESS);
  209. m_ipSrcMask.Create(m_hWnd, IDC_AEIP_EB_SOURCE_MASK);
  210. IpAddr_ForceContiguous((HWND) m_ipSrcMask);
  211. m_ipDstAddress.Create(m_hWnd, IDC_AEIP_EB_DEST_ADDRESS);
  212. m_ipDstMask.Create(m_hWnd, IDC_AEIP_EB_DEST_MASK);
  213. IpAddr_ForceContiguous((HWND) m_ipDstMask);
  214. // disable IP controls by default
  215. CheckDlgButton(IDC_AEIP_CB_SOURCE, FALSE);
  216. OnCbSourceClicked();
  217. CheckDlgButton(IDC_AEIP_CB_DEST, FALSE);
  218. OnCbDestClicked();
  219. CString sProtocol;
  220. // fill up the protocol combo box with list of protocols
  221. UINT count = sizeof(g_aPROTOCOLS)/sizeof(g_aPROTOCOLS[0]);
  222. for ( UINT i = 0; i < count; i++ ) {
  223. sProtocol.LoadString(g_aPROTOCOLS[i][0]);
  224. UINT item = m_cbProtocol.AddString(sProtocol);
  225. m_cbProtocol.SetItemData(item, g_aPROTOCOLS[i][1]);
  226. if( g_aPROTOCOLS[i][1] == PROTOCOL_ANY )
  227. {
  228. m_cbProtocol.SetCurSel(item);
  229. }
  230. }
  231. // Fill in the controls if the user is editing a filter
  232. if(m_bEdit)
  233. {
  234. FilterListEntry * pfle = *m_ppFilterEntry;
  235. if( pfle->dwSrcAddr == 0 &&
  236. pfle->dwSrcMask == 0 )
  237. {
  238. m_bSrc = FALSE;
  239. CheckDlgButton( IDC_AEIP_CB_SOURCE, 0);
  240. }
  241. else
  242. {
  243. m_bSrc = TRUE;
  244. CheckDlgButton( IDC_AEIP_CB_SOURCE, 1);
  245. m_ipSrcAddress.SetAddress(INET_NTOA(pfle->dwSrcAddr));
  246. m_ipSrcMask.SetAddress(INET_NTOA(pfle->dwSrcMask));
  247. GetDlgItem(IDC_AEIP_EB_SOURCE_ADDRESS)->EnableWindow(TRUE);
  248. GetDlgItem(IDC_AEIP_EB_SOURCE_MASK)->EnableWindow(TRUE);
  249. }
  250. if( pfle->dwDstAddr == 0 &&
  251. pfle->dwDstMask == 0 )
  252. {
  253. m_bDst = FALSE;
  254. CheckDlgButton( IDC_AEIP_CB_DEST, 0);
  255. }
  256. else
  257. {
  258. m_bDst = TRUE;
  259. CheckDlgButton( IDC_AEIP_CB_DEST, 1);
  260. m_ipDstAddress.SetAddress(INET_NTOA(pfle->dwDstAddr));
  261. m_ipDstMask.SetAddress(INET_NTOA(pfle->dwDstMask));
  262. GetDlgItem(IDC_AEIP_EB_DEST_ADDRESS)->EnableWindow(TRUE);
  263. GetDlgItem(IDC_AEIP_EB_DEST_MASK)->EnableWindow(TRUE);
  264. }
  265. if ( pfle->dwProtocol == FILTER_PROTO_ANY )
  266. {
  267. SetProtocolSelection(IDS_PROTOCOL_ANY);
  268. }
  269. else if ( pfle->dwProtocol == FILTER_PROTO_ICMP )
  270. {
  271. SetProtocolSelection(IDS_PROTOCOL_ICMP);
  272. m_cbSrcPort.SetWindowText(GetIcmpTypeString( pfle->wSrcPort));
  273. m_cbDstPort.SetWindowText(GetIcmpCodeString( pfle->wDstPort));
  274. }
  275. else if ( pfle->dwProtocol == FILTER_PROTO_TCP )
  276. {
  277. if(pfle->fLateBound & TCP_ESTABLISHED_FLAG)
  278. {
  279. SetProtocolSelection(IDS_PROTOCOL_TCP_ESTABLISHED);
  280. }
  281. else
  282. {
  283. SetProtocolSelection(IDS_PROTOCOL_TCP);
  284. }
  285. m_cbSrcPort.SetWindowText(GetPortString( pfle->dwProtocol, pfle->wSrcPort));
  286. m_cbDstPort.SetWindowText(GetPortString( pfle->dwProtocol, pfle->wDstPort));
  287. }
  288. else if ( pfle->dwProtocol == FILTER_PROTO_UDP )
  289. {
  290. SetProtocolSelection(IDS_PROTOCOL_UDP);
  291. m_cbSrcPort.SetWindowText(GetPortString( pfle->dwProtocol, pfle->wSrcPort));
  292. m_cbDstPort.SetWindowText(GetPortString( pfle->dwProtocol, pfle->wDstPort));
  293. }
  294. else
  295. {
  296. WCHAR buffer[16+1];
  297. SetProtocolSelection(IDS_PROTOCOL_OTHER);
  298. m_cbSrcPort.SetWindowText(_itow(pfle->dwProtocol, buffer, 10) );
  299. }
  300. }
  301. // enable/disable controls based on filter type
  302. if (m_dwFilterType == FILTER_PERUSER_OUT)
  303. {
  304. MultiEnableWindow(GetSafeHwnd(), FALSE,
  305. IDC_AEIP_CB_SOURCE,
  306. IDC_AEIP_ST_SOURCE_ADDRESS,
  307. IDC_AEIP_EB_SOURCE_ADDRESS,
  308. IDC_AEIP_ST_SOURCE_MASK,
  309. IDC_AEIP_EB_SOURCE_MASK,
  310. 0);
  311. }
  312. else if (m_dwFilterType == FILTER_PERUSER_IN)
  313. {
  314. MultiEnableWindow(GetSafeHwnd(), FALSE,
  315. IDC_AEIP_CB_DEST,
  316. IDC_AEIP_ST_DEST_ADDRESS,
  317. IDC_AEIP_EB_DEST_ADDRESS,
  318. IDC_AEIP_ST_DEST_MASK,
  319. IDC_AEIP_EB_DEST_MASK,
  320. 0);
  321. }
  322. // enable disable controls depending on selection
  323. OnSelchangeProtocol();
  324. return TRUE; // return TRUE unless you set the focus to a control
  325. // EXCEPTION: OCX Property Pages should return FALSE
  326. }
  327. //------------------------------------------------------------------------------
  328. // Function: CIpFltrAddEdit::SetProtocolSelection
  329. //
  330. // Select the proper Protocol in the protocol
  331. //------------------------------------------------------------------------------
  332. void CIpFltrAddEdit::SetProtocolSelection( UINT idProto )
  333. {
  334. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  335. CString cStr;
  336. if(!cStr.LoadString(idProto))
  337. {
  338. AfxMessageBox(_T("Error loading resource"));
  339. }
  340. m_cbProtocol.GetItemData(m_cbProtocol.GetCurSel());
  341. UINT item = m_cbProtocol.FindStringExact(-1, cStr);
  342. if(item != CB_ERR)
  343. m_cbProtocol.SetCurSel(item);
  344. else
  345. m_cbProtocol.SetCurSel(0);
  346. }
  347. //------------------------------------------------------------------------------
  348. // Function: CIpFltrAddEdit::GetIcmpTypeString
  349. //
  350. // returns a CString representing ICMP type (if known) or a string version
  351. // of the Type number.
  352. //------------------------------------------------------------------------------
  353. CString CIpFltrAddEdit::GetIcmpTypeString( WORD dwPort )
  354. {
  355. WCHAR buffer[16];
  356. CString s = _T("");
  357. // look through our list of ICMP types and if we know the type, load
  358. // the corresponding string, else convert the port number to string
  359. // and return the string.
  360. #if 0
  361. UINT count = sizeof(g_aICMPTYPE)/sizeof(g_aICMPTYPE[0]);
  362. for(UINT i = 0; i < count; i++)
  363. {
  364. if(g_aICMPTYPE[i][0] == dwPort)
  365. {
  366. VERIFY(s.LoadString(g_aICMPTYPE[i][1]));
  367. return (s);
  368. }
  369. }
  370. #endif
  371. return (CString((LPWSTR)_itow(dwPort, buffer, 10)));
  372. }
  373. //------------------------------------------------------------------------------
  374. // Function: CIpFltrAddEdit::GetIcmpCodeString
  375. //
  376. // returns a CString representing ICMP code (if known) or a string version
  377. // of the Code number.
  378. //------------------------------------------------------------------------------
  379. CString CIpFltrAddEdit::GetIcmpCodeString( WORD dwPort )
  380. {
  381. WCHAR buffer[16];
  382. return (CString((LPWSTR)_itow(dwPort, buffer, 10)));
  383. }
  384. //------------------------------------------------------------------------------
  385. // Function: CIpFltrAddEdit::GetPortString
  386. //
  387. // returns a CString representing port type (eg., FTP, ECHO) (if known) or a string
  388. // version of the port number
  389. //------------------------------------------------------------------------------
  390. CString CIpFltrAddEdit::GetPortString( DWORD dwProtocol, WORD dwPort )
  391. {
  392. WCHAR buffer[16];
  393. return (CString((LPWSTR)_itow(dwPort, buffer, 10)));
  394. }
  395. //------------------------------------------------------------------------------
  396. // Function: CIpFltrAddEdit::GetPortNumber
  397. //
  398. // converts the port string name to port number and returns it
  399. //------------------------------------------------------------------------------
  400. WORD CIpFltrAddEdit::GetPortNumber( DWORD dwProtocol, CString& cStr)
  401. {
  402. return ((WORD)(_wtoi((const wchar_t *)cStr.GetBuffer(10))));
  403. }
  404. //------------------------------------------------------------------------------
  405. // Function: CIpFltrAddEdit::GetIcmpType
  406. //
  407. // returns a number version of the ICMP type string
  408. //------------------------------------------------------------------------------
  409. WORD CIpFltrAddEdit::GetIcmpType( CString& cStr)
  410. {
  411. return ((WORD)(_wtoi((const wchar_t *)cStr.GetBuffer(10))));
  412. }
  413. //------------------------------------------------------------------------------
  414. // Function: CIpFltrAddEdit::GetIcmpCode
  415. //
  416. // returns a number version of the ICMP code string
  417. //------------------------------------------------------------------------------
  418. WORD CIpFltrAddEdit::GetIcmpCode( CString& cStr)
  419. {
  420. return ((WORD)(_wtoi((const wchar_t *)cStr.GetBuffer(10))));
  421. }
  422. //------------------------------------------------------------------------------
  423. // Function: CIpFltrAddEdit::OnOK
  424. //
  425. // handles 'BN_CLICKED' notification from "OK" button
  426. //------------------------------------------------------------------------------
  427. void CIpFltrAddEdit::OnOK()
  428. {
  429. FilterListEntry * pfle = new FilterListEntry;
  430. if ( !pfle )
  431. {
  432. AfxMessageBox( IDS_ERROR_NO_MEMORY );
  433. return;
  434. }
  435. ZeroMemory( pfle, sizeof(FilterListEntry) );
  436. //
  437. // Error breakout loop.
  438. //
  439. do {
  440. CString sAddr;
  441. //
  442. // if source network filter is specified, verify and
  443. // save data.
  444. //
  445. if ( m_bSrc = IsDlgButtonChecked(IDC_AEIP_CB_SOURCE) )
  446. {
  447. if(m_ipSrcAddress.GetAddress(sAddr) != 4)
  448. {
  449. AfxMessageBox(IDS_ENTER_SRC_ADDRESS);
  450. ::SetFocus((HWND)m_ipSrcAddress);
  451. break;
  452. }
  453. pfle->dwSrcAddr = INET_ADDR(sAddr);
  454. if( m_ipSrcMask.GetAddress(sAddr) != 4)
  455. {
  456. AfxMessageBox(IDS_ENTER_SRC_MASK);
  457. ::SetFocus((HWND)m_ipSrcMask);
  458. break;
  459. }
  460. pfle->dwSrcMask = INET_ADDR(sAddr);
  461. if ((pfle->dwSrcAddr & pfle->dwSrcMask) != pfle->dwSrcAddr)
  462. {
  463. AfxMessageBox(IDS_INVALID_SRC_MASK);
  464. ::SetFocus((HWND)m_ipSrcMask);
  465. break;
  466. }
  467. }
  468. else
  469. {
  470. pfle->dwSrcAddr = 0;
  471. pfle->dwSrcMask = 0;
  472. }
  473. //
  474. // if destination network filter is specified,
  475. // verify and save data.
  476. //
  477. if ( m_bDst = IsDlgButtonChecked(IDC_AEIP_CB_DEST) )
  478. {
  479. if(m_ipDstAddress.GetAddress(sAddr) != 4)
  480. {
  481. AfxMessageBox(IDS_ENTER_DST_ADDRESS);
  482. ::SetFocus((HWND)m_ipDstAddress);
  483. break;
  484. }
  485. pfle->dwDstAddr = INET_ADDR(sAddr);
  486. if(m_ipDstMask.GetAddress(sAddr) != 4)
  487. {
  488. AfxMessageBox(IDS_ENTER_DST_MASK);
  489. ::SetFocus((HWND)m_ipDstMask);
  490. break;
  491. }
  492. pfle->dwDstMask = INET_ADDR(sAddr);
  493. if ((pfle->dwDstAddr & pfle->dwDstMask) != pfle->dwDstAddr)
  494. {
  495. AfxMessageBox(IDS_INVALID_DST_MASK);
  496. ::SetFocus((HWND)m_ipDstMask);
  497. break;
  498. }
  499. }
  500. else
  501. {
  502. pfle->dwDstAddr = 0;
  503. pfle->dwDstMask = 0;
  504. }
  505. //
  506. // verify and save protocol specific data
  507. //
  508. CString cStr = _T("");
  509. CString cStr2 = _T("");
  510. int index;
  511. switch(QueryCurrentProtocol()) {
  512. case PROTOCOL_TCP:
  513. pfle->dwProtocol = FILTER_PROTO_TCP;
  514. m_cbSrcPort.GetWindowText(cStr);
  515. pfle->wSrcPort = GetPortNumber(PROTOCOL_TCP, cStr);
  516. m_cbDstPort.GetWindowText(cStr);
  517. pfle->wDstPort = GetPortNumber(PROTOCOL_TCP, cStr);
  518. break;
  519. case PROTOCOL_TCP_ESTABLISHED:
  520. pfle->dwProtocol = FILTER_PROTO_TCP;
  521. pfle->fLateBound |= TCP_ESTABLISHED_FLAG;
  522. m_cbSrcPort.GetWindowText(cStr);
  523. pfle->wSrcPort = GetPortNumber(PROTOCOL_TCP_ESTABLISHED, cStr);
  524. m_cbDstPort.GetWindowText(cStr);
  525. pfle->wDstPort = GetPortNumber(PROTOCOL_TCP_ESTABLISHED, cStr);
  526. break;
  527. case PROTOCOL_UDP:
  528. pfle->dwProtocol = FILTER_PROTO_UDP;
  529. m_cbSrcPort.GetWindowText(cStr);
  530. pfle->wSrcPort = GetPortNumber(PROTOCOL_UDP, cStr);
  531. m_cbDstPort.GetWindowText(cStr);
  532. pfle->wDstPort = GetPortNumber(PROTOCOL_UDP, cStr);
  533. break;
  534. case PROTOCOL_ICMP:
  535. pfle->dwProtocol = FILTER_PROTO_ICMP;
  536. m_cbSrcPort.GetWindowText(cStr);
  537. m_cbDstPort.GetWindowText(cStr2);
  538. // Windows NT bugs: 83110
  539. // Default is 0xFF if none of the fields have data
  540. if (cStr.IsEmpty() && cStr2.IsEmpty())
  541. {
  542. pfle->wSrcPort = FILTER_ICMP_TYPE_ANY;
  543. pfle->wDstPort = FILTER_ICMP_CODE_ANY;
  544. }
  545. else
  546. {
  547. pfle->wSrcPort = GetIcmpType(cStr);
  548. pfle->wDstPort = GetIcmpCode(cStr2);
  549. }
  550. break;
  551. case PROTOCOL_ANY:
  552. pfle->dwProtocol = FILTER_PROTO_ANY;
  553. pfle->wSrcPort = pfle->wDstPort = 0;
  554. break;
  555. case PROTOCOL_OTHER:
  556. m_cbSrcPort.GetWindowText(cStr);
  557. pfle->dwProtocol = FILTER_PROTO(_wtoi((const wchar_t*)cStr.GetBuffer(16+1)));
  558. if(pfle->dwProtocol == 0)
  559. {
  560. AfxMessageBox(IDS_ENTER_OTHER_PROTOCOL);
  561. ::SetFocus((HWND)m_cbSrcPort);
  562. delete pfle;
  563. return;
  564. }
  565. pfle->wSrcPort = pfle->wDstPort = 0;
  566. break;
  567. default:
  568. AfxMessageBox( IDS_ERROR_SETTING_BLOCK );
  569. delete pfle;
  570. return;
  571. }
  572. //
  573. // if this is a new filter, add it to m_ppFilterEntry
  574. //
  575. if (!*m_ppFilterEntry)
  576. {
  577. *m_ppFilterEntry = pfle;
  578. }
  579. else
  580. {
  581. FilterListEntry *pfleDst = *m_ppFilterEntry;
  582. pfleDst-> dwSrcAddr = pfle-> dwSrcAddr;
  583. pfleDst-> dwSrcMask = pfle-> dwSrcMask;
  584. pfleDst-> dwDstAddr = pfle-> dwDstAddr;
  585. pfleDst-> dwDstMask = pfle-> dwDstMask;
  586. pfleDst-> dwProtocol = pfle-> dwProtocol;
  587. pfleDst-> wSrcPort = pfle-> wSrcPort;
  588. pfleDst-> wDstPort = pfle-> wDstPort;
  589. pfleDst-> fLateBound = pfle-> fLateBound;
  590. delete pfle;
  591. }
  592. // end the dialog
  593. CBaseDialog::OnOK();
  594. return;
  595. }while(FALSE);
  596. //
  597. // error condition
  598. //
  599. delete pfle;
  600. return;
  601. }
  602. //------------------------------------------------------------------------------
  603. // Function: CIpFltrAddEdit::OnCancel
  604. //
  605. // handles 'BN_CLICKED' notification from the Cancel button
  606. //------------------------------------------------------------------------------
  607. void CIpFltrAddEdit::OnCancel()
  608. {
  609. CBaseDialog::OnCancel();
  610. }
  611. //------------------------------------------------------------------------------
  612. // Function: CIpFltrAddEdit::GetIcmpTypeString
  613. //
  614. // Handles BN_CLICKED notification from "Source network" checkbox
  615. //------------------------------------------------------------------------------
  616. void CIpFltrAddEdit::OnCbSourceClicked()
  617. {
  618. m_bSrc = IsDlgButtonChecked(IDC_AEIP_CB_SOURCE);
  619. GetDlgItem(IDC_AEIP_EB_SOURCE_ADDRESS)->EnableWindow( m_bSrc );
  620. GetDlgItem(IDC_AEIP_EB_SOURCE_MASK)->EnableWindow( m_bSrc );
  621. }
  622. //------------------------------------------------------------------------------
  623. // Function: CIpFltrAddEdit::GetIcmpTypeString
  624. //
  625. // Handles BN_CLICKED notification from "Destination network" checkbox
  626. //------------------------------------------------------------------------------
  627. void CIpFltrAddEdit::OnCbDestClicked()
  628. {
  629. m_bDst = IsDlgButtonChecked(IDC_AEIP_CB_DEST);
  630. GetDlgItem(IDC_AEIP_EB_DEST_ADDRESS)->EnableWindow( m_bDst );
  631. GetDlgItem(IDC_AEIP_EB_DEST_MASK)->EnableWindow( m_bDst );
  632. }