⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 icmp.lst

📁 本程序是一个RS232转网口的。是一个透明传输的模块
💻 LST
📖 第 1 页 / 共 2 页
字号:
 117   2              txdnet.etherframe.uSourceID[2]=rxdnet.etherframe.uDestID[2];
 118   2      
 119   2                  txdnet.ipframe.ttl=txdnet.ipframe.ttl-1;                     //生存时间
 120   2              txdnet.ipframe.crc=0;
 121   2                  txdnet.ipframe.destip[0]=rxdnet.ipframe.sourceip[0];  
 122   2              txdnet.ipframe.destip[1]=rxdnet.ipframe.sourceip[1];
 123   2                  txdnet.ipframe.sourceip[0]=my_ip_address.words[0];
 124   2              txdnet.ipframe.sourceip[1]=my_ip_address.words[1];
 125   2                  txdnet.ipframe.crc=createipheadcrc(&txdnet);
 126   2              txdnet.icmpframe.type=0x00;                                  // 0:ACK  8:请求
 127   2                      txdnet.icmpframe.option=0x00;                                // 固定为0配合TYPE
 128   2                  txdnet.icmpframe.crc=0;
 129   2                      txdnet.icmpframe.crc=createicmpcrc();
 130   2              send_packet(&txdnet,rxdnet.etherframe.uLength);
 131   2              }
 132   1      }
 133          
 134          /*
 135          *****************************************************************************************************
 136          *FUNC: 重新建立PING数据包
 137          *NOTE: 入参:   需要重构的表索引 
 138          //注意:        在进行ping时,如果要先发送一个ARP数据包,则会对由ping_requeset()函数形成的
 139          //                      PING包进行破坏,该函数的功能就是重新构造PING包。构造该包的信息在PING_TABLE里
 140          *****************************************************************************************************
 141          */
 142          void reconstruct_ping(unsigned char table_index)
 143          {
 144   1              txdnet.etherframe.protocal=0x0800;
 145   1              txdnet.ipframe.verandihl=0x45;
 146   1              txdnet.ipframe.typeofserver=0x00;
 147   1              txdnet.ipframe.totallength=60;
 148   1          txdnet.ipframe.ttl=0x80;
 149   1              txdnet.ipframe.frameindex=frameindex;
 150   1              frameindex++;
 151   1              txdnet.ipframe.segment=0x0000;
 152   1              txdnet.ipframe.protocal=0x0001;//icmp
 153   1          txdnet.ipframe.crc=0;
 154   1          txdnet.ipframe.destip[0]=ping_table[table_index].ip.words[0];
 155   1          txdnet.ipframe.destip[1]=ping_table[table_index].ip.words[1];
 156   1          txdnet.ipframe.sourceip[0]=my_ip_address.words[0];
 157   1          txdnet.ipframe.sourceip[1]=my_ip_address.words[1];
 158   1          txdnet.ipframe.crc=createipheadcrc(&txdnet);
 159   1          txdnet.icmpframe.type=0x08;// is icmp request;
 160   1              txdnet.icmpframe.option=0x00;           //该句由Mingtree加
 161   1          txdnet.icmpframe.crc=0;
 162   1              txdnet.icmpframe.id=0x0300;
 163   1              txdnet.icmpframe.seq=frameindex;
 164   1          txdnet.icmpframe.crc=createicmpcrc();
 165   1      }
 166          
 167          /*
 168          *****************************************************************************************************
 169          *FUNC: PING回显,该函数在收到包,判断包为PING回显后调用,对PING表里的状态进行改变
 170          *NOTE: //PING应答收到后回显
 171          *****************************************************************************************************
 172          */
 173          void PingEcho(void)
 174          {
 175   1              unsigned char i;
 176   1      
 177   1              temp_ip_address.words[0]=rxdnet.ipframe.sourceip[0];
 178   1              temp_ip_address.words[1]=rxdnet.ipframe.sourceip[1];
C51 COMPILER V7.06   ICMP                                                                  09/26/2008 13:36:00 PAGE 4   

 179   1      
 180   1              for (i=0; i<MaxLenPingBuf; i++) {
 181   2                  if ((ping_table[i].status == 1) && (ping_table[i].ip.dwords == temp_ip_address.dwords)) {
 182   3                          ping_table[i].status=2;
 183   3                          break;
 184   3                      }
 185   2              }
 186   1              HintMsg(1,PingIpStr);
 187   1      }
 188          
 189          /*
 190          *****************************************************************************************************
 191          *FUNC: 定时操作,放在1秒循环任务中
 192          *NOTE: 用于对PING_TABLE进行操作,该函数是处理PING的最重要函数 
 193                  for (i=0; i<MaxLenPingBuf; i++) {                        //将该包登记入ping表里
 194                  if (ping_table[i].status == 0) {
 195                      ping_table[i].times=0x4;                                             //测试4次
 196                      ping_table[i].ip.dwords=ping_ip_address.dwords;      //ping命令传入的IP地址;
 197                      ping_table[i].pack=&txdnet;                                          //发送缓冲区地址
 198                      ping_table[i].status=4;                                                      //第一次准备发(用于同步1秒时钟)
 199                      break;
 200                  }
 201              }
 202          
 203                  1:准备PIN时,置状态为4:
 204                  2:要4时,如果有对应的MAC,置1,如果没有发ARP请求,置3
 205                  3:下一秒进来时,如果是3,查找对应的MAC,如果没有说明ARP没响应,状态置1
 206              4:发完一包,状态置1
 207                  如果收到PING应答包,会处理void PingEcho(void),如果是该PING IP的应答包,置2说明PING成功
 208          *****************************************************************************************************
 209          */
 210          void CopyMac2PingTable(unsigned char num)
 211          {
 212   1          unsigned char i;
 213   1      
 214   1              for (i=0; i<3; i++) {
 215   2                      ping_table[num].pack->etherframe.uDestID[i]=ping_ethernet_address.words[i]; //填写发送包的MAC地址
 216   2                      ping_table[num].pack->etherframe.uSourceID[i]=my_ethernet_address.words[i];  //网卡地址
 217   2              }
 218   1      
 219   1              #if 0
                              ping_table[i].pack->etherframe.uDestID[0]=ping_ethernet_address.words[0]; //填写发送包的MAC地址
                              ping_table[i].pack->etherframe.uDestID[1]=ping_ethernet_address.words[1];
                              ping_table[i].pack->etherframe.uDestID[2]=ping_ethernet_address.words[2];
                              ping_table[i].pack->etherframe.uSourceID[0]=my_ethernet_address.words[0];  //网卡地址
                          ping_table[i].pack->etherframe.uSourceID[1]=my_ethernet_address.words[1];
                          ping_table[i].pack->etherframe.uSourceID[2]=my_ethernet_address.words[2];
                      #endif
 227   1      }
 228          
 229          void PingCycle(void)                                          //定时操作,放在1秒循环任务中
 230          {
 231   1              unsigned char  i;
 232   1      
 233   1              for (i=0; i<MaxLenPingBuf; i++) {                         //对PING_TABLE表进行扫
 234   2                      switch (ping_table[i].status) {
 235   3                          case 0:                                           //空闲,直接返回
 236   3                                   break;
 237   3                          case 1:                                                   //已发出但无应答(过了1s还未应答),输出超时
 238   3                                   HintMsg(2,PingIpStr);                        //在这里添加串口发送代码,先上位机显示主机不可达      
             -                    
 239   3                                   //break;                                     //失败PING 4 次
C51 COMPILER V7.06   ICMP                                                                  09/26/2008 13:36:00 PAGE 5   

 240   3                          case 2:                                                   //发出且应答.注意,如果收到回显应答,则在PING_ECHO里进

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -