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

📄 icmp.lst

📁 本程序是一个RS232转网口的。是一个透明传输的模块
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.06   ICMP                                                                  09/26/2008 13:36:00 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE ICMP
OBJECT MODULE PLACED IN ..\OUT\Icmp.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\Source\Icmp.C BROWSE DEBUG OBJECTEXTEND PRINT(..\OUT\Icmp.lst) OBJECT(..
                    -\OUT\Icmp.obj)

stmt level    source

   1          /*
   2          *****************************************************************************************************
   3          *
   4          *  File name: icmp.c
   5          *****************************************************************************************************
   6          */
   7          #include "..\head\includes.h"
   8          
   9          
  10          #define MaxLenPingBuf   10                      //PING缓冲区长度
  11          
  12          xdata struct ping_table_type ping_table[MaxLenPingBuf];    //ping表,在外部RAM里
  13          xdata union Ethernet_address ping_ethernet_address;            //用来ping的以太网地址
  14          xdata union IP_address ping_ip_address;                    //用于ping命令
  15          
  16          /*
  17          *****************************************************************************************************
  18          *FUNC: 初始化PING表
  19          *NOTE: 
  20          *****************************************************************************************************
  21          */
  22          void InitPingTable(void)
  23          {
  24   1              unsigned char i;
  25   1              for (i=0; i<MaxLenPingBuf; i++) {
  26   2                      ping_table[i].status=0;
  27   2              }
  28   1      }
  29          /*
  30          *****************************************************************************************************
  31          *FUNC: 生成ICMP包头CRC校验
  32          *NOTE: 返回值: CRC校验值
  33          *****************************************************************************************************
  34          */
  35          unsigned int createicmpcrc()//生成ICMP包CRC校验
  36          {
  37   1              unsigned char i;
  38   1              union w crctemp;
  39   1      
  40   1              crctemp.dwords=0;
  41   1              for(i=19;i<39;i++)
  42   1                      crctemp.dwords=crctemp.dwords+txdnet.words.wordbuf[i];
  43   1              while(crctemp.words.high>0)
  44   1              crctemp.dwords=(unsigned long)(crctemp.words.high+crctemp.words.low);
  45   1              crctemp.words.low=0xffff-crctemp.words.low;
  46   1              return(crctemp.words.low);
  47   1      }
  48          
  49          /*
  50          *****************************************************************************************************
  51          *FUNC: PING请求,实际上,该函数只是在缓冲区里构造一个ICMP包,然后在PING_TABLE里登记该PING
  52          //                      记录,该ICMP包的发送是在PING_CYCLE里实现的
  53          *NOTE: 在PING_CYCLE里添查表添加PINGIP的MAC
  54          *****************************************************************************************************
C51 COMPILER V7.06   ICMP                                                                  09/26/2008 13:36:00 PAGE 2   

  55          */
  56          void PingRequest(void)
  57          {
  58   1              unsigned char  i;
  59   1      //      txdnet.etherframe.destnodeid[0]=ping_ethernet_address.words[0];
  60   1      //      txdnet.etherframe.destnodeid[1]=ping_ethernet_address.words[1];
  61   1      //      txdnet.etherframe.destnodeid[2]=ping_ethernet_address.words[2];
  62   1              txdnet.etherframe.protocal=0x0800;
  63   1              txdnet.ipframe.verandihl=0x45;
  64   1              txdnet.ipframe.typeofserver=0x00;
  65   1              txdnet.ipframe.totallength=60;
  66   1          txdnet.ipframe.ttl=0x80;
  67   1              txdnet.ipframe.frameindex=frameindex;
  68   1              frameindex++;
  69   1              txdnet.ipframe.segment=0x0000;
  70   1              txdnet.ipframe.protocal=0x0001;                     //icmp
  71   1          txdnet.ipframe.crc=0;
  72   1          txdnet.ipframe.destip[0]=ping_ip_address.words[0];  //PING ip
  73   1          txdnet.ipframe.destip[1]=ping_ip_address.words[1];
  74   1          txdnet.ipframe.sourceip[0]=my_ip_address.words[0];
  75   1          txdnet.ipframe.sourceip[1]=my_ip_address.words[1];
  76   1          txdnet.ipframe.crc=createipheadcrc(&txdnet);
  77   1          txdnet.icmpframe.type=0x08;         // is icmp request;
  78   1              txdnet.icmpframe.option=0x00;           //该句由Mingtree加
  79   1          txdnet.icmpframe.crc=0;
  80   1              txdnet.icmpframe.id=0x0300;
  81   1              txdnet.icmpframe.seq=frameindex;
  82   1          txdnet.icmpframe.crc=createicmpcrc();
  83   1              
  84   1              for (i=0; i<MaxLenPingBuf; i++) {                        //将该包登记入ping表里
  85   2              if (ping_table[i].status == 0) {
  86   3                  ping_table[i].times=0x3;                                             //测试4次
  87   3                  ping_table[i].ip.dwords=ping_ip_address.dwords;      //ping命令传入的IP地址;
  88   3                  ping_table[i].pack=&txdnet;                                          //发送缓冲区地址
  89   3                  ping_table[i].status=4;                                                      //第一次准备发(用于同步1秒时钟)
  90   3                  break;
  91   3              }
  92   2          }
  93   1      }
  94          
  95          
  96          /*
  97          *****************************************************************************************************
  98          *FUNC: PING应答
  99          *NOTE:          //从16开始的原因:1字节的接收状态,1字节下一页指针,2字节以太网包长度,
 100                          //12字节MAC地址,加起来为16字节.接着的信息为包类型,可以拷贝
 101          *****************************************************************************************************
 102          */
 103          void PingAnswer(void)
 104          {
 105   1              unsigned char i;
 106   1      
 107   1              if (rxdnet.icmpframe.type == 0x08) {                             //表示是ping请求
 108   2              for (i=16;i<rxdnet.etherframe.uLength;i++) {                 //将数据复制到发送缓冲区
 109   3                      txdnet.bytes.bytebuf[i]=rxdnet.bytes.bytebuf[i];
 110   3                      }
 111   2              txdnet.etherframe.uDestID[0]=rxdnet.etherframe.uSourceID[0]; //目的MAC
 112   2                  txdnet.etherframe.uDestID[1]=rxdnet.etherframe.uSourceID[1];
 113   2              txdnet.etherframe.uDestID[2]=rxdnet.etherframe.uSourceID[2];
 114   2      
 115   2                      txdnet.etherframe.uSourceID[0]=rxdnet.etherframe.uDestID[0]; //源MAC
 116   2                  txdnet.etherframe.uSourceID[1]=rxdnet.etherframe.uDestID[1];
C51 COMPILER V7.06   ICMP                                                                  09/26/2008 13:36:00 PAGE 3   

⌨️ 快捷键说明

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