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

Visual C++

  1. #include "stdafx.h"
  2. #include "winsock2.h"
  3. #include "global.h"
  4. #ifdef _DEBUG
  5. #define new DEBUG_NEW
  6. #undef THIS_FILE
  7. static char THIS_FILE[] = __FILE__;
  8. #endif
  9. CDataConvert::CDataConvert()
  10. {
  11.   m_CurIp=0;
  12.   ZeroMemory(m_cCurIp,24);
  13. //  ZeroMemory(&m_alllinechar,sizeof(struct AllLineChar));
  14.   m_alllinechar.CurHostNum=0; 
  15. }
  16. CDataConvert::~CDataConvert()
  17. {
  18.   while(!m_ptrlistAllowIp.IsEmpty())
  19.   {
  20. struct IpaddrRange   *IpRange=(struct IpaddrRange *)m_ptrlistAllowIp.RemoveHead();
  21. delete IpRange;
  22.   }
  23.    while(!m_ptrlistRejectIp.IsEmpty())
  24.   {
  25. struct IpaddrRange   *IpRange=(struct IpaddrRange *)m_ptrlistRejectIp.RemoveHead();
  26. delete IpRange;
  27.   }
  28.   //先删除m_ptrlistHostPort里面的struct PortList的pPortList所指向的内容 
  29.   while(!m_ptrlistUlong.IsEmpty())
  30.   {
  31. ULONG  *LON=(ULONG*)m_ptrlistUlong.RemoveHead();
  32. delete LON;
  33.   }
  34.   while(!m_ptrlistIcmp.IsEmpty())
  35.   {
  36. struct IcmpList   *icmprange=(struct IcmpList *)m_ptrlistIcmp.RemoveHead();
  37. delete icmprange;
  38.   }
  39.    while(!m_ptrlistIcmpOut.IsEmpty())
  40.   {
  41. struct IcmpList   *icmprange=(struct IcmpList *)m_ptrlistIcmpOut.RemoveHead();
  42. delete icmprange;
  43.   }
  44.   while(!m_ptrlistPort.IsEmpty())
  45.   {
  46. struct PortList   *portlist=(struct PortList *)m_ptrlistPort.RemoveHead();
  47. delete portlist;
  48.   }
  49.   //后删除主结构
  50.   while(!m_ptrlistHostPort.IsEmpty())
  51.   {
  52. struct HostList   *phostlist=(struct HostList *)m_ptrlistHostPort.RemoveHead();
  53. delete phostlist;
  54.   }
  55.   while(!m_listInHttp.IsEmpty())
  56.   {
  57. struct IpaddrRange   *IpRange=(struct IpaddrRange *)m_listInHttp.RemoveHead();
  58. delete IpRange;
  59.   }
  60.    while(!m_listOutHttp.IsEmpty())
  61.   {
  62. struct IpaddrRange   *IpRange=(struct IpaddrRange *)m_listOutHttp.RemoveHead();
  63. delete IpRange;
  64.   }
  65. //delete []natcfg->StaticTable.item;
  66. }
  67. //将用户的需要回显的数据还要以字符形式保存,便于现示
  68. //调用SetHostIp后,不能调用SaveChar
  69. //仅对CEdit型EDIT控件调用该函数
  70. //对CString型EDIT控件直接付值
  71. //主机ip的存取在SetHostIp()函数中直接进行了付值
  72. VOID CDataConvert::SaveChar(CEdit &edit,BOOL ishostCfg,UCHAR type)
  73. {
  74.    int  Lines=edit.GetLineCount();
  75. char tempchar[20];
  76. CString csPort;
  77. int pos;
  78. pos=m_alllinechar.CurHostNum;
  79. //考虑修改的情况
  80. if(ishostCfg)
  81. {
  82.   for(int ii=0;ii<m_alllinechar.CurHostNum;ii++)
  83.   {
  84. if(strcmp(m_cCurIp,m_alllinechar.Hostchar[ii].HostIp)==0)
  85. {
  86. pos=ii;
  87. break;
  88. }
  89.   }
  90. }
  91. switch(type)
  92. {
  93. case MAPSTATIC_UDP:
  94. {
  95. m_alllinechar.FireWallCfg.sNatCfg.us_PortNumberUdp=0;
  96. memset(m_alllinechar.FireWallCfg.sNatCfg.MapStaticUdp,0,sizeof(m_alllinechar.FireWallCfg.sNatCfg.MapStaticUdp));
  97. for(int i=0;i<Lines;i++)
  98. {
  99.          int nret=edit.GetLine(i,tempchar); 
  100.    if(nret==0)continue;
  101.  csPort=(CString)tempchar;
  102.  int len=csPort.GetLength();
  103.      csPort.Delete(nret,len-nret);//不能超过缓冲区大小
  104.          strcpy(m_alllinechar.FireWallCfg.sNatCfg.MapStaticUdp[i],csPort.GetBuffer(len));
  105.  m_alllinechar.FireWallCfg.sNatCfg.us_PortNumberUdp++;
  106. }
  107. }
  108. break;
  109. case MAPSTATIC_TCP:
  110. {
  111. m_alllinechar.FireWallCfg.sNatCfg.us_PortNumberTcp=0;
  112. memset(m_alllinechar.FireWallCfg.sNatCfg.MapStaticTcp,0,sizeof(m_alllinechar.FireWallCfg.sNatCfg.MapStaticTcp));
  113. for(int i=0;i<Lines;i++)
  114. {
  115.          int nret=edit.GetLine(i,tempchar); 
  116.    if(nret==0)continue;
  117.  csPort=(CString)tempchar;
  118.  int len=csPort.GetLength();
  119.      csPort.Delete(nret,len-nret);//不能超过缓冲区大小
  120.          strcpy(m_alllinechar.FireWallCfg.sNatCfg.MapStaticTcp[i],csPort.GetBuffer(len));
  121.  m_alllinechar.FireWallCfg.sNatCfg.us_PortNumberTcp++;
  122. }
  123. }
  124. break;
  125. case TCPSRCOUT:
  126. {
  127. m_alllinechar.Hostchar[pos].nPos[TCPSRCOUT]=0;
  128. memset(m_alllinechar.Hostchar[pos].TcpSrcOut,0,sizeof(m_alllinechar.Hostchar[pos].TcpSrcOut));
  129. for(int i=0;i<Lines;i++)
  130. {
  131.          int nret=edit.GetLine(i,tempchar); 
  132.  if(nret==0)continue;
  133.  csPort=(CString)tempchar;
  134.  int len=csPort.GetLength();
  135.      csPort.Delete(nret,len-nret);//不能超过缓冲区大小
  136.          strcpy(m_alllinechar.Hostchar[pos].TcpSrcOut[i],csPort.GetBuffer(len));
  137.          m_alllinechar.Hostchar[pos].nPos[TCPSRCOUT]++;
  138. }
  139. }
  140. break;
  141.     case TCPDSTOUT:
  142. {
  143. m_alllinechar.Hostchar[pos].nPos[TCPDSTOUT]=0;
  144. memset(m_alllinechar.Hostchar[pos].TcpDstOut,0,sizeof(m_alllinechar.Hostchar[pos].TcpDstOut));
  145. // m_alllinechar.TcpDstOut=new  char[Lines][30];
  146. for(int i=0;i<Lines;i++)
  147. {
  148.          int nret=edit.GetLine(i,tempchar); 
  149.  if(nret==0)continue;
  150.  csPort=(CString)tempchar;
  151.  int len=csPort.GetLength();
  152.      csPort.Delete(nret,len-nret);//不能超过缓冲区大小
  153.          strcpy(m_alllinechar.Hostchar[pos].TcpDstOut[i],csPort.GetBuffer(len));
  154.  m_alllinechar.Hostchar[pos].nPos[TCPDSTOUT]++;
  155. }
  156. }
  157. break;
  158. case UDPSRCOUT:
  159. {
  160. m_alllinechar.Hostchar[pos].nPos[UDPSRCOUT]=0;
  161. memset(m_alllinechar.Hostchar[pos].UdpSrcOut,0,sizeof(m_alllinechar.Hostchar[pos].UdpSrcOut));
  162. // m_alllinechar.UdpSrcOut=new  char[Lines][30];
  163. for(int i=0;i<Lines;i++)
  164. {
  165.          int nret=edit.GetLine(i,tempchar); 
  166.  if(nret==0)continue;
  167.  csPort=(CString)tempchar;
  168.  int len=csPort.GetLength();
  169.      csPort.Delete(nret,len-nret);//不能超过缓冲区大小
  170.          strcpy(m_alllinechar.Hostchar[pos].UdpSrcOut[i],csPort.GetBuffer(len));
  171.  m_alllinechar.Hostchar[pos].nPos[UDPSRCOUT]++;
  172. }
  173. }
  174. break;
  175. case UDPDSTOUT:
  176. {
  177. m_alllinechar.Hostchar[pos].nPos[UDPDSTOUT]=0;
  178. memset(m_alllinechar.Hostchar[pos].UdpDstOut,0,sizeof(m_alllinechar.Hostchar[pos].UdpDstOut));
  179. // m_alllinechar.TcpDstIn=new  char[Lines][30];
  180. for(int i=0;i<Lines;i++)
  181. {
  182.          int nret=edit.GetLine(i,tempchar); 
  183.  if(nret==0)continue;
  184.  csPort=(CString)tempchar;
  185.  int len=csPort.GetLength();
  186.      csPort.Delete(nret,len-nret);//不能超过缓冲区大小
  187.          strcpy(m_alllinechar.Hostchar[pos].UdpDstOut[i],csPort.GetBuffer(len));
  188.  m_alllinechar.Hostchar[pos].nPos[UDPDSTOUT]++;
  189. }
  190. }
  191. break;
  192. case ICMPTYPEIN:
  193. {
  194. m_alllinechar.Hostchar[pos].nPos[ICMPTYPEIN]=0;
  195. memset(m_alllinechar.Hostchar[pos].IcmpTypeIn,0,sizeof(m_alllinechar.Hostchar[pos].IcmpTypeIn));
  196. // m_alllinechar.IcmpTypeIn=new  char[Lines][30];
  197. for(int i=0;i<Lines;i++)
  198. {
  199.           int nret=edit.GetLine(i,tempchar); 
  200.  if(nret==0)continue;
  201.  csPort=(CString)tempchar;
  202.  int len=csPort.GetLength();
  203.      csPort.Delete(nret,len-nret);//不能超过缓冲区大小
  204.          strcpy(m_alllinechar.Hostchar[pos].IcmpTypeIn[i],csPort.GetBuffer(len));
  205. m_alllinechar.Hostchar[pos].nPos[ICMPTYPEIN]++;
  206. }
  207. }
  208. break;
  209. case ICMPTYPEOUT:
  210. {
  211. m_alllinechar.Hostchar[pos].nPos[ICMPTYPEOUT]=0;
  212. memset(m_alllinechar.Hostchar[pos].IcmpTypeOut,0,sizeof(m_alllinechar.Hostchar[pos].IcmpTypeOut));
  213.    //     m_alllinechar.IcmpTypeOut=new  char[Lines][30];
  214. for(int i=0;i<Lines;i++)
  215. {
  216.          int nret=edit.GetLine(i,tempchar); 
  217.  if(nret==0)continue;
  218.  csPort=(CString)tempchar;
  219.  int len=csPort.GetLength();
  220.      csPort.Delete(nret,len-nret);//不能超过缓冲区大小
  221.          strcpy(m_alllinechar.Hostchar[pos].IcmpTypeOut[i],csPort.GetBuffer(len));
  222.  m_alllinechar.Hostchar[pos].nPos[ICMPTYPEOUT]++;
  223. }
  224. }
  225. break;
  226. case INDM:
  227. {
  228. m_alllinechar.InDmPos=Lines;
  229. memset(m_alllinechar.InDmIpTab,0,sizeof(m_alllinechar.InDmIpTab));
  230.        // m_alllinechar.AllowIpTab=new  char[Lines][30];
  231. for(int i=0;i<Lines;i++)
  232. {
  233.          int nret=edit.GetLine(i,tempchar); 
  234.  if(nret==0)
  235.  {
  236.  m_alllinechar.InDmPos--;
  237.  continue;
  238.  }
  239.  csPort=(CString)tempchar;
  240.  int len=csPort.GetLength();
  241.      csPort.Delete(nret,len-nret);//不能超过缓冲区大小
  242.          strcpy(m_alllinechar.InDmIpTab[i],csPort.GetBuffer(len));
  243. }
  244. }
  245. break;
  246. case OUTDM:
  247. {
  248. m_alllinechar.OutDmPos=0;
  249. memset(m_alllinechar.OutDmIpTab,0,sizeof(m_alllinechar.OutDmIpTab));
  250.        // m_alllinechar.AllowIpTab=new  char[Lines][30];
  251. for(int i=0;i<Lines;i++)
  252. {
  253.          int nret=edit.GetLine(i,tempchar); 
  254.  if(nret==0)
  255. continue;
  256.  csPort=(CString)tempchar;
  257.  int len=csPort.GetLength();
  258.      csPort.Delete(nret,len-nret);//不能超过缓冲区大小
  259.          strcpy(m_alllinechar.OutDmIpTab[i],csPort.GetBuffer(len));
  260.  m_alllinechar.OutDmPos++;
  261. }
  262. }
  263. break;
  264. case  ALLOWIPTAB:
  265. {
  266. m_alllinechar.AllowPos=0;
  267. memset(m_alllinechar.AllowIpTab,0,sizeof(m_alllinechar.AllowIpTab));
  268.        // m_alllinechar.AllowIpTab=new  char[Lines][30];
  269. for(int i=0;i<Lines;i++)
  270. {
  271.          int nret=edit.GetLine(i,tempchar); 
  272.  if(nret==0)
  273.  continue;
  274.  csPort=(CString)tempchar;
  275.  int len=csPort.GetLength();
  276.      csPort.Delete(nret,len-nret);//不能超过缓冲区大小
  277.          strcpy(m_alllinechar.AllowIpTab[i],csPort.GetBuffer(len));
  278.  m_alllinechar.AllowPos++;
  279. }
  280. }
  281. break;
  282. case  REJIPTAB:
  283. {
  284. m_alllinechar.RejPos=0;
  285. memset(m_alllinechar.RejIpTab,0,sizeof(m_alllinechar.RejIpTab));
  286.       //  m_alllinechar.RejIpTab=new  char[Lines][30];
  287. for(int i=0;i<Lines;i++)
  288. {
  289.          int nret=edit.GetLine(i,tempchar); 
  290.  if(nret==0)
  291.  continue;
  292.  csPort=(CString)tempchar;
  293.  int len=csPort.GetLength();
  294.      csPort.Delete(nret,len-nret);//不能超过缓冲区大小
  295.          strcpy(m_alllinechar.RejIpTab[i],csPort.GetBuffer(len));
  296. m_alllinechar.RejPos++;
  297. }
  298. }
  299. break;
  300. default:
  301. return;
  302. }
  303. }
  304. VOID CDataConvert::WriteToFile()
  305. {
  306.    CFile myFile;
  307. myFile.Open("UserSet.txt",CFile::modeCreate|CFile::modeWrite,NULL);
  308.     ULONG size=sizeof(struct AllLineChar);
  309. myFile.WriteHuge(&m_alllinechar,size);
  310. myFile.Close();
  311. }
  312. VOID CDataConvert::ReadFromFile()
  313. {
  314.    CFile myFile;
  315. if(myFile.Open("UserSet.txt",CFile::modeRead,NULL)==0)
  316. return;
  317.     ULONG size=sizeof(struct AllLineChar);
  318. myFile.ReadHuge(&m_alllinechar,size);
  319. myFile.Close();
  320. }
  321. //添加拒绝IP表和允许IP表
  322. VOID CDataConvert::AddIpTable(UCHAR type,CEdit &edit)
  323. {
  324. // TODO: Add extra validation here
  325. BOOL  bFirst=TRUE;
  326. char Ipaddr[20];
  327. ULONG   nIpaddr;
  328. char pIpaddr[30];
  329. int  IpCount=0;
  330. int  Lines;
  331. //begin系统初始化时装载以前的用户设置数据,(也可以:无需!当用户重新设置后生效)
  332. switch(type)
  333. {
  334. case INITALLOWIPTAB:
  335. Lines=m_alllinechar.AllowPos;
  336. break;
  337. case INITREJIPTAB:
  338. Lines=m_alllinechar.RejPos;
  339. break;
  340. case INITINDMTAB:
  341. Lines=m_alllinechar.InDmPos;
  342. break;
  343. case INITOUTDMTAB:
  344. Lines=m_alllinechar.OutDmPos;
  345. break;
  346. case ALLOWIPTAB:
  347. while(!m_ptrlistAllowIp.IsEmpty())
  348. {
  349.           struct IpaddrRange   *IpRange1=(struct IpaddrRange *)m_ptrlistAllowIp.RemoveHead();
  350.           delete IpRange1;
  351. }
  352.         Lines=edit.GetLineCount();
  353. break;
  354.     case REJIPTAB:
  355. while(!m_ptrlistRejectIp.IsEmpty())//重新设定后先清空
  356. {
  357.          struct IpaddrRange   *IpRange2=(struct IpaddrRange *)m_ptrlistRejectIp.RemoveHead();
  358.          delete IpRange2;
  359. }
  360.         Lines=edit.GetLineCount();
  361. break;
  362. case INDM:
  363.      while(!m_listInHttp.IsEmpty())
  364.  { 
  365. struct IpaddrRange   *IpRange=(struct IpaddrRange *)m_ptrlistRejectIp.RemoveHead();
  366. delete IpRange;
  367.  } 
  368.  break;
  369. case OUTDM:
  370.     while(!m_listOutHttp.IsEmpty())
  371. struct IpaddrRange   *IpRange=(struct IpaddrRange *)m_ptrlistRejectIp.RemoveHead();
  372. delete IpRange;
  373. }  
  374. break;
  375.   default:
  376. return;
  377. }
  378.    //end
  379.    //     Lines=edit.GetLineCount();
  380.     CString  csIpaddr;
  381.     int nret;
  382. for(int i=0;i<Lines;i++)
  383. {
  384.   csIpaddr.Empty();
  385.   memset(Ipaddr,0,20);
  386.  //begin系统初始化时装载以前的用户设置数据,(也可以:无需!当用户重新设置后生效)
  387.  switch(type)
  388.  {
  389.  case INITALLOWIPTAB:
  390. memcpy(pIpaddr,m_alllinechar.AllowIpTab[i],30);
  391. nret=strlen(pIpaddr);
  392. break;
  393.  case INITREJIPTAB:
  394. memcpy(pIpaddr,m_alllinechar.RejIpTab[i],30);
  395. nret=strlen(pIpaddr);
  396. break;
  397.  case INITINDMTAB:
  398. memcpy(pIpaddr,m_alllinechar.InDmIpTab[i],30);
  399. nret=strlen(pIpaddr);
  400. break;
  401.  case INITOUTDMTAB:
  402. memcpy(pIpaddr,m_alllinechar.OutDmIpTab[i],30);
  403. nret=strlen(pIpaddr);
  404. break;
  405.  default:
  406.  {
  407.        nret=edit.GetLine(i,pIpaddr);
  408.        if(nret==0)continue;//空行
  409.  }
  410.  }
  411.    //end
  412. //  int nret=edit.GetLine(i,pIpaddr);
  413.  // if(nret==0)continue;//空行
  414.       csIpaddr=(CString)pIpaddr;
  415.   int pos,nrem;
  416.       csIpaddr.Delete(nret,29-nret);//不能超过缓冲区大小
  417.   pos=csIpaddr.Find(':');
  418.   nrem=csIpaddr.Remove(' ');
  419.   struct IpaddrRange   *IpRange=new  struct IpaddrRange;
  420.   if(pos!=-1)
  421.   {
  422.     CString str1;
  423.     str1=csIpaddr.SpanExcluding(":");
  424.    // Ipaddr=str1.GetBuffer(str1.GetLength());
  425. int i5=str1.GetLength();
  426. memcpy(Ipaddr,str1.GetBuffer(i5),i5);
  427.         nIpaddr=inet_addr(Ipaddr);
  428. if(nIpaddr==INADDR_NONE)
  429. {
  430. AfxMessageBox("有不正确的IP地址格式,请重新输入!");
  431. delete IpRange;
  432. break;
  433. }
  434.     CString  str;
  435.     int i2=nret-pos;
  436. //if()
  437.     str=csIpaddr.Mid(pos-nrem+1,i2);
  438. IpRange->nIpAddr=nIpaddr;
  439.         IpRange->nIpaddrNum=atoi(str.GetBuffer(i2));
  440.   //  IpRange->nIpMask=;.................add
  441.   }
  442.   else
  443.   {
  444.   //  IpRange->nIpMask=;.................add
  445. memcpy(Ipaddr,csIpaddr.GetBufferSetLength(nret-nrem),nret-nrem);
  446.         nIpaddr=inet_addr(Ipaddr);
  447. if(nIpaddr==INADDR_NONE)
  448. {
  449. AfxMessageBox("有不正确的IP地址格式,请重新输入!");
  450. delete IpRange;
  451. break;
  452. }
  453.         IpRange->nIpAddr=nIpaddr;
  454.         IpRange->nIpaddrNum=1;
  455.   }
  456.   switch(type)
  457.   {
  458.   case INITALLOWIPTAB:
  459.   case ALLOWIPTAB:
  460.      m_ptrlistAllowIp.AddHead(IpRange);
  461.  break;
  462.   case INITREJIPTAB:
  463.   case REJIPTAB:
  464.   m_ptrlistRejectIp.AddHead(IpRange);
  465.  break;
  466.   case  INITINDMTAB:
  467.   case INDM:
  468.   m_listInHttp.AddHead(IpRange);
  469.   break;
  470.   case INITOUTDMTAB:
  471.   case OUTDM:
  472.   m_listOutHttp.AddHead(IpRange);
  473.   break;
  474.   }
  475. }
  476. }
  477. VOID CDataConvert:: DeleteHost(CString m_HostIp)
  478. {
  479.     int nrem=m_HostIp.Remove(' ');
  480.     int pos=m_HostIp.Find(':');
  481.     int i1=m_HostIp.GetLength();
  482. BOOL bhave=FALSE;
  483. for(int i=0;i<m_alllinechar.CurHostNum;i++)
  484. {
  485.  if(strcmp(m_alllinechar.Hostchar[i].HostIp,m_HostIp.GetBufferSetLength(24))==0)
  486.  {//循环移位,填充删除的主机信息
  487.  int k=i;
  488.  bhave=TRUE;
  489.  memset((struct HostChar*)&m_alllinechar.Hostchar[i],0,sizeof(struct HostChar));
  490.  for(int j=i+1;j<m_alllinechar.CurHostNum;j++)
  491.  {
  492.                 memcpy((struct HostChar*)&m_alllinechar.Hostchar[k],(struct HostChar*)&m_alllinechar.Hostchar[j],sizeof(struct HostChar));
  493. k++;
  494.     memset((struct HostChar*)&m_alllinechar.Hostchar[k],0,sizeof(struct HostChar));
  495.  }
  496.            m_alllinechar.CurHostNum--;
  497.  //  break;
  498.  }
  499. }
  500. //删除链表中的对应项
  501. if(bhave)
  502. {
  503.      struct HostList*  phostlist;
  504.      int nIp;
  505.  if(pos!=-1)
  506.  {
  507.     CString str1;
  508.     str1=m_HostIp.SpanExcluding(":");
  509.     nIp=inet_addr(str1.GetBuffer(str1.GetLength()));
  510. if(nIp==INADDR_NONE)
  511. {
  512. AfxMessageBox("有不正确的IP地址格式,请重新输入!");
  513. return;
  514. }
  515.    POSITION pos,curpos;
  516.    pos=m_ptrlistHostPort.GetHeadPosition();
  517.    while(pos!=NULL)
  518.    {
  519.   curpos=pos;
  520.           phostlist=(struct HostList*)m_ptrlistHostPort.GetNext(pos);
  521.       if(phostlist->sIpRange.nIpAddr==nIp)
  522.   {//所有的端口列表在退出时删除
  523.                m_ptrlistHostPort.RemoveAt(curpos);
  524.    delete phostlist;
  525.        break;
  526.   }
  527.    }
  528.  }
  529.      else
  530.  {
  531.    nIp=inet_addr(m_HostIp.GetBuffer(i1));
  532.    if(nIp==INADDR_NONE)
  533.    {
  534. AfxMessageBox("有不正确的IP地址格式,请重新输入!");
  535. return;
  536.    }
  537.    POSITION pos,curpos;
  538.    pos=m_ptrlistHostPort.GetHeadPosition();
  539.    while(pos!=NULL)
  540.    {
  541.   curpos=pos;
  542.           phostlist=(struct HostList*)m_ptrlistHostPort.GetNext(pos);
  543.       if(phostlist->sIpRange.nIpAddr==nIp)
  544.   {
  545.                m_ptrlistHostPort.RemoveAt(curpos);
  546.    delete phostlist;
  547.        break;
  548.   }
  549.    }
  550.  } 
  551. }
  552. //设定主机IP或IP范围;决定了SetPortList()函数中的端口列表
  553. //如果bhaved为TRUE,则取得具体的主机;以让用户修改主机的所有信息
  554. //调用函数中无需对phost分配空间
  555. VOID CDataConvert::SetHostIp(CString m_HostIp,BOOL &bhaved,struct  HostChar *phostchar)
  556. {
  557.     //初始化,有效的区分tcp,udp与ftp,http,telnet对端口的相应设置
  558. bhaved=FALSE;
  559.     int nrem=m_HostIp.Remove(' ');
  560.     int pos=m_HostIp.Find(':');
  561.     int i1=m_HostIp.GetLength();
  562. BOOL bhave=FALSE;
  563. memset(m_cCurIp,0,24);
  564. strcpy(m_cCurIp,m_HostIp.GetBufferSetLength(24));
  565.     struct  HostList *pHostList;
  566. for(int i=0;i<m_alllinechar.CurHostNum;i++)
  567. {
  568.  if(strcmp(m_alllinechar.Hostchar[i].HostIp,m_HostIp.GetBufferSetLength(24))==0)
  569.  {
  570.            bhave=TRUE;
  571.    bhaved=TRUE;
  572.            memcpy(phostchar,(struct HostChar*)&m_alllinechar.Hostchar[i],sizeof(struct HostChar));
  573.    break;
  574.  }
  575. }
  576. if(!bhave)
  577. {
  578.        strcpy(m_alllinechar.Hostchar[i].HostIp,m_HostIp.GetBufferSetLength(24));
  579.        m_alllinechar.CurHostNum++; 
  580. }
  581. if(pos!=-1)
  582. {
  583.     CString str1;
  584.     str1=m_HostIp.SpanExcluding(":");
  585. int nIp=inet_addr(str1.GetBuffer(str1.GetLength()));
  586. if(nIp==INADDR_NONE)
  587. {
  588. AfxMessageBox("有不正确的IP地址格式,请重新输入!");
  589. return;
  590. }
  591. CString  str;
  592. int i2=i1-pos;
  593. str=m_HostIp.Mid(pos+1,i2);
  594. m_CurIp=nIp;
  595. if(!bhave)
  596. {
  597.      pHostList=new struct  HostList;
  598.  pHostList->sIpRange.nIpAddr=nIp;    
  599.      pHostList->sIpRange.nIpaddrNum=atoi(str.GetBuffer(i2));
  600. }
  601. }
  602.     else
  603. {
  604.    int nIp1=inet_addr(m_HostIp.GetBuffer(i1));
  605.    if(nIp1==INADDR_NONE)
  606.    {
  607. AfxMessageBox("有不正确的IP地址格式,请重新输入!");
  608. return;
  609.    }
  610.    m_CurIp=nIp1;
  611.    //当第一次配置以后,如果设定的主机已经配置,则直接修改链表
  612. if(!bhave)
  613. {
  614.     pHostList=new struct  HostList;
  615. pHostList->sIpRange.nIpAddr=nIp1; 
  616. pHostList->sIpRange.nIpaddrNum=1;
  617. }
  618. }
  619. if(!bhave)
  620.      m_ptrlistHostPort.AddHead(pHostList);
  621. }
  622. VOID CDataConvert::SetPortList(CEdit &edit,USHORT type)
  623. {
  624. char port[20];
  625. BOOL bFirst=TRUE;
  626. int  Lines=edit.GetLineCount();
  627.     CString  csPort;
  628.     struct HostList *pHostList;//先取出链表中的对应项;借此添加端口列表到链表的对应项
  629. //先取出链表中的对应项;
  630. POSITION pos;
  631. pos=m_ptrlistHostPort.GetHeadPosition();
  632. while(pos!=NULL)
  633. {
  634.           pHostList=(struct HostList*)m_ptrlistHostPort.GetNext(pos);
  635.       if(pHostList->sIpRange.nIpAddr==m_CurIp)     
  636.   break;
  637. }
  638. //清空先前配置
  639.     switch(type)
  640. {
  641. //begin:拒绝的ICMP类型设定
  642. case ICMPTYPEIN:
  643. {
  644.               while(!m_ptrlistIcmp.IsEmpty())
  645.   {
  646.              struct IcmpList   *icmprange=(struct IcmpList *)m_ptrlistIcmp.RemoveHead();
  647.             delete icmprange;
  648.   }
  649. break;
  650. case ICMPTYPEOUT:
  651. {
  652.               while(!m_ptrlistIcmpOut.IsEmpty())
  653.   {
  654.              struct IcmpList   *icmprange=(struct IcmpList *)m_ptrlistIcmpOut.RemoveHead();
  655.             delete icmprange;
  656.   }
  657. }
  658. break;
  659.         //end:拒绝的ICMP类型设定
  660. //begin:允许TCP端口设定
  661. case TCPSRCOUT:
  662. {
  663.               while(!pHostList->sTcpPortSet.sAllowOutSrcPortList.IsEmpty())
  664.   {
  665.              struct PortList   *pportlist=(struct PortList *)pHostList->sTcpPortSet.sAllowOutSrcPortList.RemoveHead();
  666.             delete pportlist;
  667.   }
  668. }
  669. break;
  670. case TCPDSTOUT:
  671. {
  672.               while(!pHostList->sTcpPortSet.sAllowOutDstPortList.IsEmpty())
  673.   {
  674.              struct PortList   *pportlist=(struct PortList *)pHostList->sTcpPortSet.sAllowOutDstPortList.RemoveHead();
  675.             delete pportlist;
  676.   }
  677. }
  678. break;
  679. //end:允许的TCP端口设定
  680.    //begin:允许的udp端口设定
  681. case UDPSRCOUT:
  682. {
  683.               while(!pHostList->sTcpPortSet.sAllowOutSrcPortList.IsEmpty())
  684.   {
  685.              struct PortList   *pportlist=(struct PortList *)pHostList->sTcpPortSet.sAllowOutSrcPortList.RemoveHead();
  686.             delete pportlist;
  687.   }
  688. }
  689. break;
  690. case UDPDSTOUT:
  691. {
  692.               while(!pHostList->sTcpPortSet.sAllowOutDstPortList.IsEmpty())
  693.   {
  694.              struct PortList   *pportlist=(struct PortList *)pHostList->sTcpPortSet.sAllowOutDstPortList.RemoveHead();
  695.             delete pportlist;
  696.   }
  697. }
  698. break;
  699. //end:允许的udp端口设定
  700. default:
  701. return;
  702. }
  703. for(int i=0;i<Lines;i++)
  704. {
  705.   csPort.Empty();
  706.     //memset(port,0,20);
  707. //memset(pIpaddr,0,30);
  708.   int nret=edit.GetLine(i,port);
  709.   if(nret==0)continue;//空行
  710.       csPort=(CString)port;
  711.   csPort.Delete(nret,csPort.GetLength()-nret);//不能超过缓冲区大小
  712.   int pos=csPort.Find(':');
  713.   int nrem=csPort.Remove(' ');
  714.   //m_ptrlistPort有利于内存回收
  715. //      struct HostList *pHostList;//先取出链表中的对应项;借此添加端口列表到链表的对应项
  716.   if(pos!=-1)
  717.   {//端口用范围表示法
  718.     CString str1;
  719.     str1=csPort.SpanExcluding(":");
  720. CString  str;
  721.     int i2=nret-pos;
  722.     str=csPort.Mid(pos-nrem+1,i2);
  723.  
  724.         USHORT portbegin=atoi(str1.GetBuffer(pos));
  725. USHORT portend=atoi(str.GetBuffer(i2));
  726. /*     //先取出链表中的对应项;
  727. POSITION pos;
  728.     pos=m_ptrlistHostPort.GetHeadPosition();
  729.     while(pos!=NULL)
  730. {
  731.           pHostList=(struct HostList*)m_ptrlistHostPort.GetNext(pos);
  732.       if(pHostList->sIpRange.nIpAddr==m_CurIp)     
  733.   break;
  734. }
  735. */
  736. switch(type)
  737. {
  738. //begin:拒绝的ICMP类型设定
  739. case ICMPTYPEIN:
  740. {
  741.             struct  IcmpList *picmplist=new struct IcmpList;
  742.     picmplist->bRange=TRUE;
  743.             picmplist->sIcmpRange.nIcmpBegin=portbegin;
  744.             picmplist->sIcmpRange.nIcmpEnd=portend;
  745.         m_ptrlistIcmp.AddHead(picmplist);//注意:m_ptrlistIcmp只是为了删除空间
  746.     pHostList->sInIcmpSet.AddHead(picmplist);
  747. }
  748. break;
  749. case ICMPTYPEOUT:
  750. {
  751.             struct  IcmpList *picmplist=new struct IcmpList;
  752.     picmplist->bRange=TRUE;
  753.             picmplist->sIcmpRange.nIcmpBegin=portbegin;
  754.             picmplist->sIcmpRange.nIcmpEnd=portend;
  755.         m_ptrlistIcmpOut.AddHead(picmplist);//注意:m_ptrlistIcmp只是为了删除空间
  756.     pHostList->sOutIcmpSet.AddHead(picmplist);
  757. }
  758. break;
  759.         //end:拒绝的ICMP类型设定
  760. //begin:允许TCP端口设定
  761. case TCPSRCOUT:
  762. {
  763.             struct  PortList *pportlist=new struct PortList;
  764. pportlist->bRange=TRUE;
  765. pportlist->sPortRange.nPortBegin=portbegin;
  766. pportlist->sPortRange.nPortEnd=portend;
  767.             pHostList->sTcpPortSet.sAllowOutSrcPortList.AddHead(pportlist);
  768.         m_ptrlistPort.AddHead(pportlist);//注意:m_ptrlistPort只是为了删除空间
  769. }
  770. break;
  771. case TCPDSTOUT:
  772. {
  773.             struct  PortList *pportlist=new struct PortList;
  774. pportlist->bRange=TRUE;
  775. pportlist->sPortRange.nPortBegin=portbegin;
  776. pportlist->sPortRange.nPortEnd=portend;
  777.             pHostList->sTcpPortSet.sAllowOutDstPortList.AddHead(pportlist);
  778.         m_ptrlistPort.AddHead(pportlist);//注意:m_ptrlistPort只是为了删除空间
  779. }
  780. break;
  781. //end:允许的TCP端口设定
  782.    //begin:允许的udp端口设定
  783. case UDPSRCOUT:
  784. {
  785.             struct  PortList *pportlist=new struct PortList;
  786. pportlist->bRange=TRUE;
  787. pportlist->sPortRange.nPortBegin=portbegin;
  788. pportlist->sPortRange.nPortEnd=portend;
  789.             pHostList->sUdpPortSet.sAllowOutSrcPortList.AddHead(pportlist);
  790.         m_ptrlistPort.AddHead(pportlist);//注意:m_ptrlistPort只是为了删除空间
  791. }
  792. break;
  793. case UDPDSTOUT:
  794. {
  795.             struct  PortList *pportlist=new struct PortList;
  796. pportlist->bRange=TRUE;
  797. pportlist->sPortRange.nPortBegin=portbegin;
  798. pportlist->sPortRange.nPortEnd=portend;
  799.             pHostList->sUdpPortSet.sAllowOutDstPortList.AddHead(pportlist);
  800.         m_ptrlistPort.AddHead(pportlist);//注意:m_ptrlistPort只是为了删除空间
  801. }
  802. break;
  803. //end:允许的udp端口设定
  804. default:
  805. return;
  806. }
  807.   }
  808.   else//具体的端口表示法
  809.   {
  810. /*  POSITION pos;
  811.      pos=m_ptrlistHostPort.GetHeadPosition();
  812.      while(pos!=NULL)
  813.  {
  814.             pHostList=(struct HostList*)m_ptrlistHostPort.GetNext(pos);
  815.         if(pHostList->sIpRange.nIpAddr==m_CurIp)     
  816.     break;
  817.  }
  818.  */
  819. USHORT portbegin=atoi(csPort.GetBufferSetLength(nret-nrem));
  820. switch(type)
  821. {
  822. case ICMPTYPEIN:
  823.             {
  824.              struct IcmpList *picmplist=new struct IcmpList;
  825.      picmplist->bRange=FALSE;
  826.              picmplist->nIcmpType=portbegin;
  827.          m_ptrlistIcmp.AddHead(picmplist);
  828.      pHostList->sInIcmpSet.AddHead(picmplist);
  829. }
  830. break;
  831. case ICMPTYPEOUT:
  832.            {
  833.              struct IcmpList *picmplist=new struct IcmpList;
  834.      picmplist->bRange=FALSE;
  835.              picmplist->nIcmpType=portbegin;
  836.          m_ptrlistIcmpOut.AddHead(picmplist);
  837.      pHostList->sOutIcmpSet.AddHead(picmplist);
  838. }
  839.    break;
  840. case TCPSRCOUT:
  841.   { 
  842.              struct PortList *pportlist=new struct PortList;
  843.      pportlist->bRange=FALSE;
  844.              pportlist->nPort=portbegin;
  845.          m_ptrlistPort.AddHead(pportlist);
  846.  pHostList->sTcpPortSet.sAllowOutSrcPortList.AddHead(pportlist);
  847. }
  848. break;
  849. case TCPDSTOUT:
  850.   { 
  851.              struct PortList *pportlist=new struct PortList;
  852.      pportlist->bRange=FALSE;
  853.              pportlist->nPort=portbegin;
  854.          m_ptrlistPort.AddHead(pportlist);
  855.  pHostList->sTcpPortSet.sAllowOutDstPortList.AddHead(pportlist);
  856. }
  857. break;
  858. case UDPSRCOUT:
  859.   { 
  860.              struct PortList *pportlist=new struct PortList;
  861.      pportlist->bRange=FALSE;
  862.              pportlist->nPort=portbegin;
  863.          m_ptrlistPort.AddHead(pportlist);
  864.  pHostList->sUdpPortSet.sAllowOutSrcPortList.AddHead(pportlist);
  865. }
  866. break;
  867. case UDPDSTOUT:
  868.              struct PortList *pportlist=new struct PortList;
  869.      pportlist->bRange=FALSE;
  870.              pportlist->nPort=portbegin;
  871.          m_ptrlistPort.AddHead(pportlist);
  872.  pHostList->sUdpPortSet.sAllowOutDstPortList.AddHead(pportlist);
  873. }
  874. break;
  875. default:
  876.             return;
  877. }
  878.   } 
  879.   bFirst=FALSE;
  880.    }
  881. }
  882. //填充NAT配置信息,注意:分配的空间尚未释放
  883. VOID CDataConvert::SetNatCfg(struct  NAT_Cfg *natcfg)
  884. {
  885.    natcfg->nGlobalAddress=m_firewallconfig.nOutsideIp;
  886.    natcfg->us_HighPort=m_alllinechar.FireWallCfg.sNatCfg.nHighPort;
  887.    natcfg->us_LowPort=m_alllinechar.FireWallCfg.sNatCfg.nLowPort;
  888.    natcfg->us_MaxNatNumber=m_alllinechar.FireWallCfg.sNatCfg.nMaxNatNumber;
  889.    natcfg->nTimeOut_TCP=m_alllinechar.FireWallCfg.sNatCfg.nTimeOut_TCP;
  890.    natcfg->nTimeOut_UDP=m_alllinechar.FireWallCfg.sNatCfg.nTimeOut_UDP;
  891.    //静态端口NAT映射
  892.    int tcpnum=m_alllinechar.FireWallCfg.sNatCfg.us_PortNumberTcp;
  893.    int udpnum=m_alllinechar.FireWallCfg.sNatCfg.us_PortNumberUdp;
  894.    int itemnum=0;
  895.    natcfg->StaticTable.count=tcpnum+udpnum;
  896.    natcfg->StaticTable.item=new struct  STATICTABLEITEM[natcfg->StaticTable.count];
  897.    for(int i=0;i<tcpnum;i++)
  898.    {
  899.      natcfg->StaticTable.item[itemnum].type=1;//tcp
  900.      ConvertEditChar(m_alllinechar.FireWallCfg.sNatCfg.MapStaticTcp[i],natcfg->StaticTable.item[itemnum].ulIpadress, natcfg->StaticTable.item[itemnum].usPort,TRUE);
  901.  itemnum++;
  902.    }
  903.    for(int j=0;j<udpnum;j++)
  904.    {
  905.      natcfg->StaticTable.item[itemnum].type=2;//udp
  906.      ConvertEditChar(m_alllinechar.FireWallCfg.sNatCfg.MapStaticUdp[j],natcfg->StaticTable.item[itemnum].ulIpadress, natcfg->StaticTable.item[itemnum].usPort,TRUE);
  907.  itemnum++;
  908.    }
  909. }
  910. VOID CDataConvert::InitFireWall()
  911. {
  912. //begin初始化全局标志
  913.     globalFlags=m_alllinechar.sGlobalFlags;
  914. //end初始化全局标志
  915. m_firewallconfig.nIntraIp=inet_addr(m_alllinechar.FireWallCfg.csIntraIp);
  916.     m_firewallconfig.nIntraMask=inet_addr(m_alllinechar.FireWallCfg.csIntraMask);
  917.     m_firewallconfig.nMiddleIp=inet_addr(m_alllinechar.FireWallCfg.csMiddleIp);
  918.     m_firewallconfig.nMiddleMask=inet_addr(m_alllinechar.FireWallCfg.csMiddleMask);
  919.     m_firewallconfig.nOutsideIp=inet_addr(m_alllinechar.FireWallCfg.csOutsideIp);
  920.     m_firewallconfig.nOutsideMask=inet_addr(m_alllinechar.FireWallCfg.csOutsideMask);
  921. //    memcpy(&m_firewallconfig.sFilterdrvCfg,&m_alllinechar.FireWallCfg.sFilterdrvCfg,sizeof(struct  Filterdrv_Cfg));
  922. }
  923. VOID CDataConvert::ConvertEditChar(char *pchar,ULONG &mylong,USHORT &mynum,BOOL bIp)
  924. {
  925.     CString  csPort;
  926.     csPort=(CString)pchar;
  927. int nrem=csPort.Remove(' ');
  928. int pos=csPort.Find(':');
  929. CString str1;
  930. if(pos!=-1)
  931. {//端口用范围表示法
  932.     str1=csPort.SpanExcluding(":");
  933. CString  str;
  934.     int i2=csPort.GetLength()-pos+1;
  935.     str=csPort.Mid(pos+1,i2);
  936.     if(bIp)//是IP
  937. {
  938.          mylong=inet_addr(str1.GetBuffer(str1.GetLength()));
  939.  mynum=atoi(str.GetBuffer(i2));
  940. }
  941. else//是端口
  942. {
  943.          mylong=atoi(str1.GetBuffer(str1.GetLength()));
  944.  mynum=atoi(str.GetBuffer(i2));
  945. }
  946. }
  947. else
  948. {
  949.     if(bIp)//是IP
  950. {
  951.          mylong=inet_addr(pchar);
  952.  mynum=1;
  953. }
  954. else//是端口
  955. {
  956.         mylong=atoi(pchar);
  957. mynum=1;
  958. }
  959. /* char tempchar[30];
  960. unsigned char*uchar=(unsigned char*)pchar;
  961. int len=strlen((const char *)pchar);
  962. int i=0;
  963. for(i;i<30;i++)
  964. {
  965. if(uchar[i]!=0xCC)
  966. {
  967. tempchar[i]=uchar[i];
  968. }
  969. else
  970. break;
  971. }
  972. tempchar[i]=0x0;
  973.     if(bIp)//是IP
  974. {
  975.          mylong=inet_addr(tempchar);
  976.  mynum=1;
  977. }
  978. else//是端口
  979. {
  980.         mylong=atoi(tempchar);
  981. mynum=1;
  982. }
  983. */
  984. }
  985. }
  986. VOID CDataConvert::DisplayHost(struct HostChar *phostchar,USHORT type,CEdit &edit)
  987. {
  988. int len=phostchar->nPos[type];
  989. CString *str=new CString[len];
  990. CString tstr;
  991. for(int i=0;i<len;i++)
  992. {
  993. switch(type)
  994. {
  995.       case TCPSRCOUT:  
  996.     str[i]=(CString)phostchar->TcpSrcOut[i];
  997.             break;
  998.       case TCPDSTOUT:  
  999.     str[i]=(CString)phostchar->TcpDstOut[i];
  1000.             break;
  1001.       case UDPSRCOUT: 
  1002.     str[i]=(CString)phostchar->UdpSrcOut[i];
  1003.             break;
  1004.       case UDPDSTOUT:
  1005.     str[i]=(CString)phostchar->UdpDstOut[i];
  1006.             break;
  1007.       case ICMPTYPEIN:  
  1008.     str[i]=(CString)phostchar->IcmpTypeIn[i];
  1009.             break;
  1010.       case ICMPTYPEOUT: 
  1011.     str[i]=(CString)phostchar->IcmpTypeOut[i];
  1012.             break;
  1013.   default:
  1014.   {
  1015.     delete []str;
  1016.     return;
  1017.   }
  1018. str[i]+="rn";
  1019. tstr+=str[i];
  1020. }
  1021. edit.SetWindowText(tstr.GetBuffer(tstr.GetLength()));
  1022. delete []str;
  1023. }
  1024. /*
  1025. VOID CDataConvert::ConvertToStr(char *pchar,CString &str,int nret,int &strlen,CEdit *edit)
  1026. {
  1027.  str=(CString)tempchar;
  1028.  int strlen=str.GetLength();
  1029.      str.Delete(nret,strlen-nret);//不能超过缓冲区大小
  1030. }
  1031. */
  1032. VOID CDataConvert::DisplayFireCfg(CEdit &edit,USHORT type)
  1033. {
  1034. int num;
  1035. switch(type)
  1036. {
  1037. case ALLOWIPTAB:
  1038. num=m_alllinechar.AllowPos;
  1039. break;
  1040. case REJIPTAB:
  1041. num=m_alllinechar.RejPos;
  1042. break;
  1043. case MAPSTATIC_UDP:
  1044. num=m_alllinechar.FireWallCfg.sNatCfg.us_PortNumberUdp;
  1045. break;
  1046. case MAPSTATIC_TCP:
  1047. num=m_alllinechar.FireWallCfg.sNatCfg.us_PortNumberTcp;
  1048. break;
  1049.  case INDM:
  1050. num=m_alllinechar.InDmPos;
  1051. break;
  1052.  case OUTDM:
  1053. num=m_alllinechar.OutDmPos;
  1054. break;
  1055. }
  1056. if(num>=0)
  1057. {
  1058. CString *str=new CString[num];
  1059. CString tstr;
  1060. for(int i=0;i<num;i++)
  1061.   switch(type)
  1062.   {
  1063.     case ALLOWIPTAB:
  1064.    str[i]=(CString)m_alllinechar.AllowIpTab[i];
  1065. break;
  1066.     case REJIPTAB:
  1067.    str[i]=(CString)m_alllinechar.RejIpTab[i];
  1068.    break;
  1069. case MAPSTATIC_UDP:
  1070.    str[i]=(CString)m_alllinechar.FireWallCfg.sNatCfg.MapStaticUdp[i];
  1071.            break;
  1072. case MAPSTATIC_TCP:
  1073.    str[i]=(CString)m_alllinechar.FireWallCfg.sNatCfg.MapStaticTcp[i];
  1074.            break;
  1075.  case INDM:
  1076.    str[i]=(CString)m_alllinechar.InDmIpTab[i];
  1077. break;
  1078.  case OUTDM:
  1079.    str[i]=(CString)m_alllinechar.OutDmIpTab[i];
  1080. break;
  1081.   }
  1082. str[i]+="rn";
  1083. tstr+=str[i];
  1084.     edit.SetWindowText(tstr.GetBuffer(tstr.GetLength()));
  1085. }
  1086.      delete []str;
  1087. }
  1088. }
  1089. VOID CDataConvert::InitPortList(USHORT type,int &ii,struct HostList *pHostList)
  1090. {
  1091. int  Lines;
  1092. switch(type)
  1093. {
  1094. case TCPSRCOUT:
  1095.   Lines=m_alllinechar.Hostchar[ii].nPos[TCPSRCOUT];
  1096. break;
  1097. case TCPDSTOUT:  
  1098.   Lines=m_alllinechar.Hostchar[ii].nPos[TCPDSTOUT];
  1099. break;
  1100. case UDPSRCOUT: 
  1101.   Lines=m_alllinechar.Hostchar[ii].nPos[UDPSRCOUT];
  1102. break;
  1103. case UDPDSTOUT: 
  1104.   Lines=m_alllinechar.Hostchar[ii].nPos[UDPDSTOUT];
  1105. break;
  1106. case ICMPTYPEIN:  
  1107.   Lines=m_alllinechar.Hostchar[ii].nPos[ICMPTYPEIN];
  1108. break;
  1109. case ICMPTYPEOUT:
  1110.   Lines=m_alllinechar.Hostchar[ii].nPos[ICMPTYPEOUT];
  1111. break;
  1112. default:
  1113. return;
  1114. }
  1115. ULONG  portbegin;
  1116. USHORT  portend;
  1117. for(int i=0;i<Lines;i++)// jl1222
  1118. {
  1119. switch(type)
  1120. {
  1121. case TCPSRCOUT:
  1122.         ConvertEditChar(m_alllinechar.Hostchar[ii].TcpSrcOut[i],portbegin,portend,FALSE);
  1123. break;
  1124. case TCPDSTOUT:  
  1125.         ConvertEditChar(m_alllinechar.Hostchar[ii].TcpDstOut[i],portbegin,portend,FALSE);
  1126. break;
  1127. case UDPSRCOUT: 
  1128.         ConvertEditChar(m_alllinechar.Hostchar[ii].UdpSrcOut[i],portbegin,portend,FALSE);
  1129. break;
  1130. case UDPDSTOUT: 
  1131.         ConvertEditChar(m_alllinechar.Hostchar[ii].UdpDstOut[i],portbegin,portend,FALSE);
  1132. break;
  1133. case ICMPTYPEIN:  
  1134.         ConvertEditChar(m_alllinechar.Hostchar[ii].IcmpTypeIn[i],portbegin,portend,FALSE);
  1135. break;
  1136. case ICMPTYPEOUT:
  1137.         ConvertEditChar(m_alllinechar.Hostchar[ii].IcmpTypeOut[i],portbegin,portend,FALSE);
  1138. break;
  1139. default:
  1140. return;
  1141. }
  1142. if(portend>1)//范围表示法
  1143. {
  1144.      switch(type)
  1145. {
  1146. //begin:拒绝的ICMP类型设定
  1147. case ICMPTYPEIN:
  1148. {
  1149.             struct  IcmpList *picmplist=new struct IcmpList;
  1150.     picmplist->bRange=TRUE;
  1151.             picmplist->sIcmpRange.nIcmpBegin=portbegin;
  1152.             picmplist->sIcmpRange.nIcmpEnd=portend;
  1153.         m_ptrlistIcmp.AddHead(picmplist);//注意:m_ptrlistIcmp只是为了删除空间
  1154.     pHostList->sInIcmpSet.AddHead(picmplist);
  1155. }
  1156. break;
  1157. case ICMPTYPEOUT:
  1158. {
  1159.             struct  IcmpList *picmplist=new struct IcmpList;
  1160.     picmplist->bRange=TRUE;
  1161.             picmplist->sIcmpRange.nIcmpBegin=portbegin;
  1162.             picmplist->sIcmpRange.nIcmpEnd=portend;
  1163.         m_ptrlistIcmpOut.AddHead(picmplist);//注意:m_ptrlistIcmp只是为了删除空间
  1164.     pHostList->sOutIcmpSet.AddHead(picmplist);
  1165. }
  1166. break;
  1167.         //end:拒绝的ICMP类型设定
  1168. //begin:允许TCP端口设定
  1169. case TCPSRCOUT:
  1170. {
  1171.             struct  PortList *pportlist=new struct PortList;
  1172. pportlist->bRange=TRUE;
  1173. pportlist->sPortRange.nPortBegin=portbegin;
  1174. pportlist->sPortRange.nPortEnd=portend;
  1175.             pHostList->sTcpPortSet.sAllowOutSrcPortList.AddHead(pportlist);
  1176.         m_ptrlistPort.AddHead(pportlist);//注意:m_ptrlistPort只是为了删除空间
  1177. }
  1178. break;
  1179. case TCPDSTOUT:
  1180. {
  1181.             struct  PortList *pportlist=new struct PortList;
  1182. pportlist->bRange=TRUE;
  1183. pportlist->sPortRange.nPortBegin=portbegin;
  1184. pportlist->sPortRange.nPortEnd=portend;
  1185.             pHostList->sTcpPortSet.sAllowOutDstPortList.AddHead(pportlist);
  1186.         m_ptrlistPort.AddHead(pportlist);//注意:m_ptrlistPort只是为了删除空间
  1187. }
  1188. break;
  1189. //end:允许的TCP端口设定
  1190.    //begin:允许的udp端口设定
  1191. case UDPSRCOUT:
  1192. {
  1193.             struct  PortList *pportlist=new struct PortList;
  1194. pportlist->bRange=TRUE;
  1195. pportlist->sPortRange.nPortBegin=portbegin;
  1196. pportlist->sPortRange.nPortEnd=portend;
  1197.             pHostList->sUdpPortSet.sAllowOutSrcPortList.AddHead(pportlist);
  1198.         m_ptrlistPort.AddHead(pportlist);//注意:m_ptrlistPort只是为了删除空间
  1199. }
  1200. break;
  1201. case UDPDSTOUT:
  1202. {
  1203.             struct  PortList *pportlist=new struct PortList;
  1204. pportlist->bRange=TRUE;
  1205. pportlist->sPortRange.nPortBegin=portbegin;
  1206. pportlist->sPortRange.nPortEnd=portend;
  1207.             pHostList->sUdpPortSet.sAllowOutDstPortList.AddHead(pportlist);
  1208.         m_ptrlistPort.AddHead(pportlist);//注意:m_ptrlistPort只是为了删除空间
  1209. }
  1210. break;
  1211. //end:允许的udp端口设定
  1212. default:
  1213. return;
  1214.  }
  1215.  }   
  1216.  else//具体的端口表示法
  1217.  {
  1218. switch(type)
  1219. {
  1220. case ICMPTYPEIN:
  1221.             {
  1222.              struct IcmpList *picmplist=new struct IcmpList;
  1223.      picmplist->bRange=FALSE;
  1224.              picmplist->nIcmpType=portbegin;
  1225.          m_ptrlistIcmp.AddHead(picmplist);
  1226.      pHostList->sInIcmpSet.AddHead(picmplist);
  1227. }
  1228. break;
  1229. case ICMPTYPEOUT:
  1230.            {
  1231.              struct IcmpList *picmplist=new struct IcmpList;
  1232.      picmplist->bRange=FALSE;
  1233.              picmplist->nIcmpType=portbegin;
  1234.          m_ptrlistIcmpOut.AddHead(picmplist);
  1235.      pHostList->sOutIcmpSet.AddHead(picmplist);
  1236. }
  1237.    break;
  1238. case TCPSRCOUT:
  1239.   { 
  1240.              struct PortList *pportlist=new struct PortList;
  1241.      pportlist->bRange=FALSE;
  1242.              pportlist->nPort=portbegin;
  1243.          m_ptrlistPort.AddHead(pportlist);
  1244.  pHostList->sTcpPortSet.sAllowOutSrcPortList.AddHead(pportlist);
  1245. }
  1246. break;
  1247. case TCPDSTOUT:
  1248.   { 
  1249.              struct PortList *pportlist=new struct PortList;
  1250.      pportlist->bRange=FALSE;
  1251.              pportlist->nPort=portbegin;
  1252.          m_ptrlistPort.AddHead(pportlist);
  1253.  pHostList->sTcpPortSet.sAllowOutDstPortList.AddHead(pportlist);
  1254. }
  1255. break;
  1256. case UDPSRCOUT:
  1257.   { 
  1258.              struct PortList *pportlist=new struct PortList;
  1259.      pportlist->bRange=FALSE;
  1260.              pportlist->nPort=portbegin;
  1261.          m_ptrlistPort.AddHead(pportlist);
  1262.  pHostList->sUdpPortSet.sAllowOutSrcPortList.AddHead(pportlist);
  1263. }
  1264. break;
  1265. case UDPDSTOUT:
  1266.              struct PortList *pportlist=new struct PortList;
  1267.      pportlist->bRange=FALSE;
  1268.              pportlist->nPort=portbegin;
  1269.          m_ptrlistPort.AddHead(pportlist);
  1270.  pHostList->sUdpPortSet.sAllowOutDstPortList.AddHead(pportlist);
  1271. }
  1272. break;
  1273. default:
  1274.             return;
  1275. }
  1276.   } 
  1277.    }
  1278. }
  1279. VOID CDataConvert::InitHostList()
  1280. {
  1281.  for(int ii=0;ii<m_alllinechar.CurHostNum;ii++)// jl1222
  1282.  {
  1283. struct HostList *phostlist=new struct HostList ;
  1284. for(int i=0;i<6;i++)//i:对应于宏定义
  1285. {
  1286.          InitPortList(i,ii,phostlist);
  1287. }
  1288.     ULONG hostip;
  1289. USHORT ipnum; 
  1290.     ConvertEditChar(m_alllinechar.Hostchar[ii].HostIp,hostip,ipnum,TRUE);
  1291. phostlist->sIpRange.nIpAddr=hostip;  
  1292.     phostlist->sIpRange.nIpaddrNum=ipnum;
  1293.     m_ptrlistHostPort.AddHead(phostlist);  
  1294.  }
  1295. }