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

📄 ip.lst

📁 CP2201和51单片机实现ARP ICMP IP UDP协议
💻 LST
字号:
C51 COMPILER V7.06   IP                                                                    12/04/2007 13:46:19 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE IP
OBJECT MODULE PLACED IN ip.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ip.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          #include "ne2000.h"
   2          #include "eth.h"
   3          #include "arp.h"
   4          #include "icmp.h"
   5          #include "udp.h"
   6          #include <stdio.h>
   7          extern union NetNode xdata myNode;
   8          WAIT xdata wait;
   9          extern unsigned int chksum(unsigned char xdata *check,unsigned int length);
  10          void ip_rcve(INT8U xdata * inbuf, union ethernet_address_type eth_addr)
  11          {
  12   1         INT8U i;
  13   1         INT16U  reslaut;
  14   1         INT8U idata header_len, payload_len;
  15   1         union ip_address_type  xdata ip_source;
  16   1         ip_head *ip;
  17   1         ip=(ip_head *)(inbuf+14);
  18   1         header_len = 4 * (0x0F & ip->verandihl);
  19   1         payload_len = ip->totallength - header_len;
  20   1         reslaut=chksum(inbuf+14,header_len);
  21   1         if(reslaut!=0xffff)
  22   1          return;
  23   1         if(((ip->verandihl&0xf0) != 0x40)    
  24   1              || (ip->destip[0] != myNode.nodebytes.ipbytes[0])
  25   1              || (ip->destip[1] != myNode.nodebytes.ipbytes[1])
  26   1              || (ip->destip[2] != myNode.nodebytes.ipbytes[2])
  27   1              || (ip->destip[3] != myNode.nodebytes.ipbytes[3]))
  28   1          return;
  29   1          if(ip->segment&0x3fff!=0)
  30   1          return;
  31   1           arp_ip_mac(inbuf,eth_addr);
  32   1           for(i=0;i<4;i++)
  33   1            ip_source.bytes[i]=ip->sourceip[i];
  34   1            switch(ip->protocal)
  35   1                       {      
  36   2                          case 1:
  37   2                              if(inbuf[34] == 8)              
  38   2                              {
  39   3                              ping_answer(inbuf,ip_source,payload_len);
  40   3                              }          
  41   2                              break;
  42   2                              case 17:
  43   2                              udp_rcve(inbuf,payload_len);
  44   2                              break;
  45   2                              default:
  46   2                              break;
  47   2                  }
  48   1      }
  49          
  50          void ip_send(INT8U xdata * outbuf, union ip_address_type ipaddr, INT8U proto_id, INT16U len)
  51          {   
  52   1         ip_head xdata * ip;
  53   1         union ethernet_address_type xdata hwaddr;
  54   1         static INT16U ip_ident = 0;
  55   1         INT8U idata i;
C51 COMPILER V7.06   IP                                                                    12/04/2007 13:46:19 PAGE 2   

  56   1         ip=(ip_head xdata *)(outbuf+14);
  57   1         ip->verandihl= 0x45;   //版本号和头长度
  58   1         ip->typeofserver=0;   // 服务类型
  59   1         ip->totallength=len+20;    //IP报总长度
  60   1         ip->frameindex=ip_ident+1;    //标示字段
  61   1         ip->segment=0;                //分段标志
  62   1         ip->ttl=0x80;                 //  生存时间
  63   1         ip->protocal=proto_id;       //上层协议
  64   1         for(i=0;i<4;i++)        // 目的IP与源IP
  65   1              {
  66   2                 ip->sourceip[i]=myNode.nodebytes.ipbytes[i];
  67   2                 ip->destip[i]=ipaddr.bytes[i];
  68   2            }
  69   1         ip->crc=0;
  70   1         ip->crc=~chksum((outbuf+14), 20);    //校验和
  71   1         if(arp_find_mac(ipaddr,&hwaddr)) //如果ARP表中找到目的IP的MAC地址
  72   1          eth_send (outbuf, hwaddr, IP_PACKET, ip->totallength);
  73   1         else  
  74   1               {  
  75   2                  for(i=14;i<ip->totallength+14;i++)
  76   2              wait.bytebuf[i] =outbuf[i];
  77   2                      wait.ipaddr = ipaddr.dwords;
  78   2                      wait.proto_id = IP_PACKET;
  79   2                      wait.len = len+20;
  80   2                      arp_request(ipaddr);
  81   2                  return;
  82   2                }     
  83   1                   
  84   1      }     
  85             
  86                  
  87                  
  88                  
  89                  
  90                  
  91                  
  92                  
  93                  
  94                  
  95                  
  96                  
  97                  
  98                  
  99                  
 100                  
 101                  
 102                  


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    763    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =    350      10
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      2      22
   IDATA SIZE       =   ----       3
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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