Page1.cpp
上传用户:heseme
上传日期:2009-12-23
资源大小:228k
文件大小:18k
开发平台:

Visual C++

  1. // Page1.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "FireWall1.h"
  5. #include "global.h"
  6. #include "Page1.h"
  7. #include "authentication.h"
  8. #include <share.h>
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. extern CDataConvert gDataConvert;
  15. extern FILE * pfoutDeviceInit;
  16. static int NetNo;
  17. CString strNetName[8];
  18. NetCardProp myNetCardProp[8];
  19. static FILE *pfoutDevice;
  20. FILE *pwriteDevice;
  21. char tmpin[5];//用于存取网卡设备号
  22. char tmpout[5];
  23. char tmpdm[5];
  24. BYTE INNO;
  25. BYTE OUTNO;
  26. BYTE DMNO;
  27. char tmpinsel[5];//用于选取网卡设备号
  28. char tmpoutsel[5];
  29. char tmpdmsel[5];
  30. BOOL com2=0,com3=0,com4=0,nook1;
  31. extern int global_set;
  32. extern char NETMASK[20];
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CPage1 property page
  35. IMPLEMENT_DYNCREATE(CPage1, CPropertyPage)
  36. CPage1::CPage1() : CPropertyPage(CPage1::IDD)
  37. {
  38. //{{AFX_DATA_INIT(CPage1)
  39. m_OutNetIp = _T("");
  40. m_OutNetMask = _T("");
  41. m_InNetIp = _T("");
  42. m_InNetMask = _T("");
  43. m_DmIp = _T("");
  44. m_DmMask = _T("");
  45. m_UdpTimeOut = 0;
  46. m_PortEnd = 0;
  47. m_MaxPortNum = 0;
  48. m_PortBegin = 0;
  49. m_TcpTimeOut = 0;
  50. //}}AFX_DATA_INIT
  51. for(int i=0;i<8;i++)
  52. memset(&myNetCardProp[i],0,sizeof(NetCardProp));
  53. NetNo=0;
  54. memset(tmpinsel,0,5);
  55. memset(tmpoutsel,0,5);
  56. memset(tmpdmsel,0,5);
  57. nook1=1;
  58. }
  59. CPage1::~CPage1()
  60. {
  61. /* if(nook1)
  62. {
  63. INNO=tmpin[0];
  64. // TRACE(tmpin);
  65. OUTNO=tmpout[0];
  66. DMNO=tmpdm[0];
  67. }
  68. */
  69. }
  70. void CPage1::DoDataExchange(CDataExchange* pDX)
  71. {
  72. CPropertyPage::DoDataExchange(pDX);
  73. //{{AFX_DATA_MAP(CPage1)
  74. DDX_Control(pDX, IDC_EDIT15, m_StaticNatMap_tcp);
  75. DDX_Control(pDX, IDC_EDIT16, m_StaticNatMap_udp);
  76. DDX_Control(pDX, IDC_COMBO4, m_SelAdaptDm);
  77. DDX_Control(pDX, IDC_COMBO3, m_SelAdaptInNet);
  78. DDX_Control(pDX, IDC_COMBO2, m_SelAdaptOutNet);
  79. DDX_Text(pDX, IDC_EDIT3, m_OutNetIp);
  80. DDX_Text(pDX, IDC_EDIT4, m_OutNetMask);
  81. DDX_Text(pDX, IDC_EDIT5, m_InNetIp);
  82. DDX_Text(pDX, IDC_EDIT6, m_InNetMask);
  83. DDX_Text(pDX, IDC_EDIT7, m_DmIp);
  84. DDX_Text(pDX, IDC_EDIT8, m_DmMask);
  85. DDX_Text(pDX, IDC_EDIT10, m_UdpTimeOut);
  86. DDX_Text(pDX, IDC_EDIT11, m_PortEnd);
  87. DDX_Text(pDX, IDC_EDIT12, m_MaxPortNum);
  88. DDX_Text(pDX, IDC_EDIT2, m_PortBegin);
  89. DDX_Text(pDX, IDC_EDIT9, m_TcpTimeOut);
  90. //}}AFX_DATA_MAP
  91. }
  92. BEGIN_MESSAGE_MAP(CPage1, CPropertyPage)
  93. //{{AFX_MSG_MAP(CPage1)
  94. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  95. ON_CBN_SELCHANGE(IDC_COMBO2, OnSelchangeCombo2)
  96. ON_CBN_SELCHANGE(IDC_COMBO4, OnSelchangeCombo4)
  97. ON_CBN_SELCHANGE(IDC_COMBO3, OnSelchangeCombo3)
  98. //}}AFX_MSG_MAP
  99. END_MESSAGE_MAP()
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CPage1 message handlers
  102. void CPage1::OnButton1() 
  103. {
  104. nook1=0;
  105.  UpdateData(1);
  106.  strcpy(NETMASK,m_InNetMask.GetBuffer(m_InNetMask.GetLength ()));
  107.  if(!GetBestData())return;
  108.  strcpy(gDataConvert.m_alllinechar.FireWallCfg.csIntraIp,m_InNetIp.GetBuffer(m_InNetIp.GetLength())); 
  109.  strcpy(gDataConvert.m_alllinechar.FireWallCfg.csIntraMask,m_InNetMask.GetBuffer(m_InNetMask.GetLength()));
  110.  strcpy(gDataConvert.m_alllinechar.FireWallCfg.csMiddleIp,m_DmIp.GetBuffer(m_DmIp.GetLength()));
  111.  strcpy(gDataConvert.m_alllinechar.FireWallCfg.csMiddleMask,m_DmMask.GetBuffer(m_DmMask.GetLength()));
  112.  strcpy(gDataConvert.m_alllinechar.FireWallCfg.csOutsideIp,m_OutNetIp.GetBuffer(m_OutNetIp.GetLength()));
  113.  strcpy(gDataConvert.m_alllinechar.FireWallCfg.csOutsideMask,m_OutNetMask.GetBuffer(m_OutNetMask.GetLength()));
  114.  gDataConvert.m_alllinechar.FireWallCfg.sNatCfg.nHighPort=m_PortEnd;
  115.  gDataConvert.m_alllinechar.FireWallCfg.sNatCfg.nLowPort=m_PortBegin;
  116.  gDataConvert.m_alllinechar.FireWallCfg.sNatCfg.nMaxNatNumber=m_MaxPortNum;
  117.  gDataConvert.m_alllinechar.FireWallCfg.sNatCfg.nTimeOut_TCP=m_TcpTimeOut;
  118.  gDataConvert.m_alllinechar.FireWallCfg.sNatCfg.nTimeOut_UDP=m_UdpTimeOut;
  119.  gDataConvert.SaveChar(m_StaticNatMap_tcp,FALSE,MAPSTATIC_TCP);
  120.  gDataConvert.SaveChar(m_StaticNatMap_udp,FALSE,MAPSTATIC_UDP);
  121.  gDataConvert.InitFireWall();
  122. //存于文件,以便重新启动后可以直接显示网卡
  123.   if(com3) strcpy(tmpin,tmpinsel);
  124. if(com4) strcpy(tmpdm,tmpdmsel);
  125. if(com2) strcpy(tmpout,tmpoutsel);
  126. pwriteDevice=fopen("device.txt","w");
  127. if(pwriteDevice)
  128. {
  129. fprintf(pwriteDevice,_T("[InNet]n"));
  130. fprintf(pwriteDevice,tmpin);
  131. fprintf(pwriteDevice,"n");
  132. fprintf(pwriteDevice,"n");
  133. fprintf(pwriteDevice,_T("[OutNet]n"));
  134. fprintf(pwriteDevice,tmpout);
  135. fprintf(pwriteDevice,"n");
  136. fprintf(pwriteDevice,"n");
  137. fprintf(pwriteDevice,_T("[DM]n"));
  138. fprintf(pwriteDevice,tmpdm);
  139. fprintf(pwriteDevice,"n");
  140. fprintf(pwriteDevice,"n");
  141. fprintf(pwriteDevice,_T("[INNETMASK]n"));
  142. fprintf(pwriteDevice,NETMASK);
  143. fprintf(pwriteDevice,"n");
  144. fprintf(pwriteDevice,"n");
  145. fprintf(pwriteDevice,_T("[jl]n"));
  146. INNO=tmpin[0];
  147. OUTNO=tmpout[0];
  148. DMNO=tmpdm[0];
  149. }
  150. if(pwriteDevice!=NULL)
  151. int errrr=fclose(pwriteDevice);
  152. global_set|=0x1;
  153. }
  154. BOOL CPage1::OnInitDialog() 
  155. {
  156. CPropertyPage::OnInitDialog();
  157. GetNetCardName();
  158.     m_PortEnd=gDataConvert.m_alllinechar.FireWallCfg.sNatCfg.nHighPort;
  159.     m_PortBegin=gDataConvert.m_alllinechar.FireWallCfg.sNatCfg.nLowPort;
  160.     m_MaxPortNum=gDataConvert.m_alllinechar.FireWallCfg.sNatCfg.nMaxNatNumber;
  161.     m_TcpTimeOut=gDataConvert.m_alllinechar.FireWallCfg.sNatCfg.nTimeOut_TCP;
  162.     m_UdpTimeOut=gDataConvert.m_alllinechar.FireWallCfg.sNatCfg.nTimeOut_UDP;
  163.     gDataConvert.DisplayFireCfg(m_StaticNatMap_tcp,MAPSTATIC_TCP);
  164.     gDataConvert.DisplayFireCfg(m_StaticNatMap_udp,MAPSTATIC_UDP);
  165. // GetDataFromFile();
  166. // if(pfoutDeviceInit)
  167. {
  168. int aa;
  169. char tmp[50];
  170. memset(tmp,0,50);
  171. strcpy(tmp,"ImSampMP");
  172. if(tmpin[0]!=0)
  173. {
  174. // AfxMessageBox(tmpin);
  175. strcat(tmp,tmpin);
  176. aa=m_SelAdaptInNet.SelectString(-1,tmp);
  177. m_InNetIp=myNetCardProp[aa].IP;
  178. m_InNetMask=myNetCardProp[aa].IPMASK;
  179. }
  180. memset(tmp,0,50);
  181. strcpy(tmp,"ImSampMP");
  182. if(tmpout[0]!=0)
  183. {
  184. strcat(tmp,tmpout);
  185. aa=m_SelAdaptOutNet.SelectString(-1,tmp);
  186. m_OutNetIp=myNetCardProp[aa].IP;
  187. m_OutNetMask=myNetCardProp[aa].IPMASK;
  188. }
  189. memset(tmp,0,50);
  190. strcpy(tmp,"ImSampMP");
  191. if(tmpdm[0]!=0)
  192. {
  193. strcat(tmp,tmpdm);
  194. aa=m_SelAdaptDm.SelectString(-1,tmp);
  195. m_DmIp=myNetCardProp[aa].IP;
  196. m_DmMask=myNetCardProp[aa].IPMASK;
  197. }
  198. UpdateData(FALSE);
  199. }
  200. // if(pfoutDevice)
  201. // int errrr=fclose(pfoutDevice);
  202.     UpdateData(FALSE);
  203. return TRUE;  // return TRUE unless you set the focus to a control
  204.               // EXCEPTION: OCX Property Pages should return FALSE
  205. }
  206. void CPage1::GetNetCardName()
  207. {
  208. HKEY SoftwareKey;
  209. HKEY MicrosoftKey;
  210. HKEY WindowsNTKey;
  211. HKEY CurrentVersionKey;
  212. HKEY NetworkCardsKey;
  213. static HKEY NetCardNoKey;
  214. int no=0;
  215. // char * pStr=new char [20];
  216. // char * strtemp=new char [20];
  217. char            pStr[35];
  218. char            strtemp[35];
  219.     LONG            Status;
  220. BOOL enumover=1;
  221.     DWORD           RegType;
  222.     ULONG BufferSize;
  223. BufferSize=256;//128;
  224. // pStr=(char *)malloc(20);
  225. // strtemp=(char *)malloc(20);
  226. /////////////////////////////////
  227. //取得网卡名字
  228. /////////////////////////////////
  229. Status = RegOpenKeyEx(
  230.             HKEY_LOCAL_MACHINE,
  231.             TEXT("SOFTWARE"),
  232.             0,
  233.             KEY_READ,
  234.             &SoftwareKey
  235.             );
  236.     if (Status == ERROR_SUCCESS)
  237.     {
  238.         Status = RegOpenKeyEx(
  239.                 SoftwareKey,
  240.                 TEXT("Microsoft"),
  241.                 0,
  242.                 KEY_READ,
  243.                 &MicrosoftKey
  244.                 );
  245.         if (Status == ERROR_SUCCESS)
  246.         {
  247.             Status = RegOpenKeyEx(
  248.                     MicrosoftKey,
  249.                     TEXT("Windows NT"),
  250.                     0,
  251.                     KEY_READ,
  252.                     &WindowsNTKey
  253.                     );
  254.             if (Status == ERROR_SUCCESS)
  255.             {
  256.                 Status = RegOpenKeyEx(
  257.                         WindowsNTKey,
  258.                         TEXT("CurrentVersion"),
  259.                         0,
  260.                         KEY_READ,
  261.                         &CurrentVersionKey
  262.                         );
  263.                 if (Status == ERROR_SUCCESS)
  264.                 {
  265.                     Status = RegOpenKeyEx(
  266.                             CurrentVersionKey,
  267.                             TEXT("NetworkCards"),
  268.                             0,
  269.                             KEY_READ,
  270.                             &NetworkCardsKey
  271.                             );
  272.                     if (Status == ERROR_SUCCESS)
  273.                     {
  274. while(1)
  275. {
  276. memset((LPTSTR)&strtemp,0,20);
  277. Status=RegEnumKey(
  278. NetworkCardsKey,
  279. no++,
  280. (LPTSTR)&strtemp,
  281. 5);
  282. if(Status==ERROR_NO_MORE_ITEMS)break;
  283. if(Status==ERROR_SUCCESS)
  284. {
  285. Status=RegOpenKeyEx(
  286. NetworkCardsKey,
  287. TEXT((LPTSTR)&strtemp),
  288. 0,
  289. KEY_READ,
  290. &NetCardNoKey);
  291. if(Status==ERROR_SUCCESS)
  292. {
  293. Status=RegQueryValueEx(
  294. NetCardNoKey,
  295. TEXT("ProductName"),
  296. 0,
  297. &RegType,
  298. (LPBYTE) (LPTSTR)&pStr,
  299. &BufferSize);
  300. if(Status==ERROR_SUCCESS)
  301. {
  302. BufferSize=256;
  303. if(_stricmp((LPTSTR)&pStr,"ImSampMP")==0)//"DE22X")==0)ImSampMP
  304. {
  305. memset((LPTSTR)&pStr,0,20);
  306. Status=RegQueryValueEx(
  307. NetCardNoKey,
  308. TEXT("ServiceName"),
  309. 0,
  310. &RegType,
  311. (LPBYTE) (LPTSTR)&pStr,
  312. &BufferSize);
  313. if(Status==ERROR_SUCCESS)
  314. {
  315. int bbb;
  316. m_SelAdaptOutNet.InsertString(NetNo,(LPTSTR)&pStr);//
  317. bbb=m_SelAdaptInNet.InsertString(NetNo,(LPTSTR)&pStr);
  318. m_SelAdaptDm.InsertString(NetNo,(LPTSTR)&pStr);
  319. strcpy((char *)myNetCardProp[NetNo].name,(char *)(LPTSTR)&pStr);
  320. int aaa;
  321. aaa=strlen((char *)myNetCardProp[NetNo].name);
  322. myNetCardProp[NetNo].DeviceNo=atoi((char *)(LPTSTR)&pStr+aaa-1);
  323. // myNetCardProp[NetNo].DeviceNo=atoi((char *)(myNetCardProp[NetNo].name+aaa-1));
  324. GetNetCardIP((LPBYTE)(LPTSTR)&pStr);
  325. NetNo++;
  326. }
  327. }
  328. }
  329. }
  330. RegCloseKey(NetCardNoKey);
  331. NetCardNoKey=NULL;
  332. }
  333. }
  334. RegCloseKey(NetworkCardsKey);
  335. }
  336. RegCloseKey(CurrentVersionKey);
  337. }
  338. RegCloseKey(WindowsNTKey);
  339. }
  340. RegCloseKey(MicrosoftKey);
  341. }
  342. RegCloseKey(SoftwareKey);
  343. }
  344. // delete [](strtemp);
  345. // delete [](pStr);
  346. }
  347. void CPage1::GetNetCardIP(LPBYTE pStr)
  348. {
  349.     HKEY            SystemKey;
  350.     HKEY            ControlSetKey;
  351.     HKEY            ServicesKey;
  352.     HKEY            NdisPerfKey;
  353.     HKEY            ParametersKey;
  354. static HKEY TcpipKey;
  355.     LONG            Status;
  356. BYTE Data;
  357. // HKEY           
  358. static HANDLE hkeytmp;
  359. // LPTSTR ptemp;
  360. // ptemp=new char [20];
  361.  BYTE            ptemp[35];
  362. memset(ptemp,0,35);
  363.     DWORD           RegType;
  364. DWORD           RegType1;
  365.     DWORD BufferSize;
  366. BufferSize=128;
  367. char text[35];
  368. memset(text,0,35);
  369.     Status = RegOpenKeyEx(
  370.             HKEY_LOCAL_MACHINE,
  371.             TEXT("SYSTEM"),
  372.             0,
  373.             KEY_READ,
  374.             &SystemKey
  375.             );
  376.     if (Status == ERROR_SUCCESS)
  377.     {
  378.         Status = RegOpenKeyEx(
  379.                 SystemKey,
  380.                 TEXT("CurrentControlSet"),
  381.                 0,
  382.                 KEY_READ,
  383.                 &ControlSetKey
  384.                 );
  385.         if (Status == ERROR_SUCCESS)
  386.         {
  387.             Status = RegOpenKeyEx(
  388.                     ControlSetKey,
  389.                     TEXT("Services"),
  390.                     0,
  391.                     KEY_READ,
  392.                     &ServicesKey
  393.                     );
  394.             if (Status == ERROR_SUCCESS)
  395.             {
  396.                 Status = RegOpenKeyEx(
  397.                         ServicesKey,
  398.                         (LPCTSTR)pStr,
  399.                         0,
  400.                         KEY_READ,
  401.                         &NdisPerfKey
  402.                         );
  403.                 if (Status == ERROR_SUCCESS)
  404.                 {
  405.                     Status = RegOpenKeyEx(
  406.                             NdisPerfKey,
  407.                             TEXT("Parameters"),
  408.                             0,
  409.                             KEY_READ,
  410.                             &ParametersKey
  411.                             );
  412.                     if (Status == ERROR_SUCCESS)
  413.                     {
  414. Status=RegOpenKeyEx(
  415. ParametersKey,
  416. TEXT("Tcpip"),
  417. 0,
  418. KEY_READ,
  419. &TcpipKey);
  420. // memcpy((void *)&hkeytmp,(void*)TcpipKey,sizeof(HKEY));
  421. hkeytmp=TcpipKey;
  422. if(Status == ERROR_SUCCESS)
  423. {
  424.  Status = RegQueryValueEx(
  425. TcpipKey,
  426. TEXT("EnableDHCP"),
  427. NULL,
  428. &RegType,
  429. &Data,
  430. &BufferSize
  431. );
  432. //  Status=RegCloseKey(TcpipKey);
  433.  
  434.  BufferSize=256;
  435.  if(Data==0)//不允许DHCP
  436.  {
  437. /*  Status=RegOpenKeyEx(
  438. ParametersKey,
  439. TEXT("Tcpip"),
  440. 0,
  441. KEY_READ,
  442. &TcpipKey);
  443. */
  444. memset(ptemp,0,20);
  445. /* Status=RegQueryValue(
  446. TcpipKey,
  447. TEXT("IPAddress"),
  448. (char *)(LPBYTE)ptemp,
  449. (LONG *)&BufferSize);
  450. */
  451. strcpy(text,"IPAddress");
  452. Status = RegQueryValueEx(
  453. TcpipKey,
  454. (LPTSTR)text,//TEXT("SubnetMask"),//IPAddress
  455. NULL,
  456. &RegType,
  457. (LPBYTE)ptemp,
  458. &BufferSize
  459. );
  460. // TcpipKey=(HKEY)hkeytmp;
  461. // memcpy((void*)TcpipKey,(void *)&(hkeytmp),sizeof(HKEY));
  462. strcpy((char *)myNetCardProp[NetNo].IP,(char *)ptemp);
  463. BufferSize=256;
  464. memset(ptemp,0,20);
  465. /* Status=RegCloseKey(TcpipKey);
  466. Status=RegOpenKeyEx(
  467. ParametersKey,
  468. TEXT("Tcpip"),
  469. 0,
  470. KEY_READ,
  471. &TcpipKey);
  472. */
  473. Status = RegQueryValueEx(
  474. TcpipKey,
  475. TEXT("SubnetMask"),
  476. NULL,
  477. &RegType1,
  478. (LPBYTE)ptemp,
  479. &BufferSize
  480. );
  481. strcpy((char *)myNetCardProp[NetNo].IPMASK,(char *)ptemp);
  482.  }
  483.  else if(Data==1)//允许DHCP
  484.  {
  485.  BufferSize=256;
  486.  memset(ptemp,0,20);
  487.  Status = RegQueryValueEx(
  488. TcpipKey,
  489. TEXT("DhcpIPAddress"),
  490. NULL,
  491. &RegType,
  492. (LPBYTE)&ptemp,
  493. &BufferSize
  494. );
  495.  strcpy((char *)myNetCardProp[NetNo].IP,(char *)ptemp);
  496.  BufferSize=256;
  497.  memset(ptemp,0,20);
  498.  Status = RegQueryValueEx(
  499. TcpipKey,
  500. TEXT("DhcpSubnetMask"),
  501. NULL,
  502. &RegType1,
  503. (LPBYTE)&ptemp,
  504. &BufferSize
  505. );
  506.  strcpy((char *)myNetCardProp[NetNo].IPMASK,(char *)ptemp);
  507.  }
  508.                         RegCloseKey(TcpipKey);
  509. }
  510. RegCloseKey(ParametersKey);
  511.                     }
  512.                     RegCloseKey(NdisPerfKey);
  513.                 }
  514.                 RegCloseKey(ServicesKey);
  515.             }
  516.             RegCloseKey(ControlSetKey);
  517.         }
  518.         RegCloseKey(SystemKey);
  519.     }
  520.     return ;
  521. }
  522. void CPage1::OnSelchangeCombo2() 
  523. {
  524. // TODO: Add your control notification handler code here
  525. int item=m_SelAdaptOutNet.GetCurSel();
  526. memset(tmpoutsel,0,5);
  527. itoa(myNetCardProp[item].DeviceNo,tmpoutsel,10);
  528. // OUTNO=tmpoutsel[0];
  529. myNetCardProp[item].Flag=1;
  530. m_OutNetIp=myNetCardProp[item].IP;
  531. m_OutNetMask=myNetCardProp[item].IPMASK;
  532. com2=1;
  533. UpdateData(FALSE);
  534. }
  535. void CPage1::OnSelchangeCombo4() 
  536. {
  537. // TODO: Add your control notification handler code here
  538. int item=m_SelAdaptDm.GetCurSel();
  539. memset(tmpdmsel,0,5);
  540. itoa(myNetCardProp[item].DeviceNo,tmpdmsel,10);
  541. // DMNO=tmpdmsel[0];
  542. myNetCardProp[item].Flag=2;
  543. m_DmIp=myNetCardProp[item].IP;
  544. m_DmMask=myNetCardProp[item].IPMASK;
  545. com4=1;
  546. UpdateData(FALSE);
  547. }
  548. void CPage1::OnSelchangeCombo3() 
  549. {
  550. // TODO: Add your control notification handler code here
  551. int item=m_SelAdaptInNet.GetCurSel();
  552. memset(tmpinsel,0,5);
  553. itoa(myNetCardProp[item].DeviceNo,tmpinsel,10);
  554. // INNO=tmpinsel[0];
  555. myNetCardProp[item].Flag=0;
  556. m_InNetIp=myNetCardProp[item].IP;
  557. m_InNetMask=myNetCardProp[item].IPMASK;
  558. UpdateData(FALSE);
  559. com3=1;
  560. }
  561. WORD CPage1::GetDataFromFile()
  562. {
  563. char command[40];
  564. char *pbuf;
  565. pfoutDevice=NULL;
  566. pfoutDevice=fopen("device.txt","r");
  567. if(pfoutDevice==NULL)return 0;
  568. while(feof(pfoutDevice)==0)
  569. {
  570. ReadCommand(pfoutDevice,command);
  571. switch(GetCommand(command))
  572. {
  573. case INNET:
  574. ReadCommand(pfoutDevice,command);
  575. strcpy(tmpin,command);
  576. INNO=tmpin[0];
  577. // TRACE(tmpin);
  578. break;
  579. case OUTNET:
  580. ReadCommand(pfoutDevice,command);
  581. strcpy(tmpout,command);
  582. OUTNO=tmpout[0];
  583. break;
  584. case DM:
  585. ReadCommand(pfoutDevice,command);
  586. strcpy(tmpdm,command);
  587. DMNO=tmpdm[0];
  588. break;
  589. case INNETMASK:
  590. ReadCommand(pfoutDevice,command);
  591. strcpy(NETMASK,command);
  592. break;
  593. }
  594. }
  595. return 1;
  596. }
  597. void CPage1::ReadCommand(FILE *pf, char *pbuf)
  598. {
  599. while(feof(pf)==0) {
  600. *pbuf=fgetc(pf);
  601. if(*pbuf=='n') break;
  602. pbuf++;
  603. }
  604. *pbuf--=0;
  605. if(*pbuf=='r')*pbuf=0;
  606. }
  607. WORD CPage1::GetCommand(char *pbuf)
  608. {
  609. char buf[50];
  610. if(*pbuf==0) return INITIAL_END_SEGMENT;
  611. sscanf(pbuf,"%s",buf);
  612. if(strstr(buf,"[InNet]")!=NULL) return INNET;
  613. else if(strstr(buf,"[OutNet]")!=NULL) return OUTNET;
  614. else if(strstr(buf,"[DM]")!=NULL)return DM;
  615. else if(buf[0]=='#') return COMMENT;
  616. else if(strstr(buf,"[jl]")!=NULL) return INITIAL_END_SEGMENT;
  617. else return COMMAND_UNKNOWN;
  618. }
  619. int CPage1::GetBestData()
  620. {
  621. if(m_OutNetIp==m_InNetIp)
  622. {
  623. MessageBox("外网和内网有冲突,请重新选择");
  624. return 0;
  625. }
  626. if(m_OutNetIp==m_DmIp)
  627. {
  628. MessageBox("外网和DM有冲突,请重新选择");
  629. return 0;
  630. }
  631. if(m_InNetIp==m_DmIp)
  632. {
  633. MessageBox("内网和DM有冲突,请重新选择");
  634. return 0;
  635. }
  636. return 1;
  637. }