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

📄 ip.lst

📁 我的网口控制程序
💻 LST
字号:
C51 COMPILER V7.06   IP                                                                    11/06/2008 08:54:10 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 ..\TCPIP\IP.c BROWSE DEBUG OBJECTEXTEND PRINT(.\IP.lst) OBJECT(.\IP.obj)

stmt level    source

   1          #include "..\GloblDef\GloblDef.h"
   2          #include "..\TCPIP\TCPIPmem.h"
   3          #include "..\TCPIP\IP.h"
   4          #include "..\TCPIP\icmp.h"
   5          #include "..\TCPIP\Netif.h"
   6          #include "..\TCPIP\TCP.h"
   7          
   8          /* Check sum calulation. data in buff, size, InSum is initial sum */
   9          WORD CheckSum(WORD DT_XDATA * buff,WORD size,DWORD InSum) REENTRANT_SIG
  10          {
  11   1              /* TO DO:in packet memory high part of short is in low memory. add all data in 
  12   1              form of 16 bits get a result of 32 bits, add high 16 bits to low 16 bits two 
  13   1              times.  get a 16 bits result then complement it. */
  14   1      
  15   1              DWORD cksum = InSum; 
  16   1      
  17   1              /* sum all word except the last odd byte(if size is a odd num) */
  18   1              WORD DT_XDATA * EndBuf = buff + size/2;
  19   1              while(buff < EndBuf)
  20   1              { 
  21   2                      /* net order is equeal as host order in mirochip, so no need to change */
  22   2                      cksum += *(buff++); 
  23   2              } 
  24   1              
  25   1              /**((WORD xdata *)CheckSumInParam) = size;
  26   1              *((WORD xdata *)(CheckSumInParam+2)) = buff;
  27   1              asmAddCheckSum();
  28   1              cksum = CheckSumOutParm;
  29   1              */
  30   1              
  31   1              /* if has last odd byte. use this byte as the high part of 16 bits, and add. */
  32   1              if((size & 0x0001) != 0) 
  33   1                      cksum += (*buff) & 0xff00;
  34   1      
  35   1              cksum = (cksum >> 16) + (cksum & 0xffff); 
  36   1              cksum += (cksum >>16); 
  37   1              return (WORD)(~cksum); 
  38   1      }
  39          
  40          /* IP input process */
  41          void IPInput(struct SMemHead DT_XDATA *MemHead) REENTRANT_MUL
  42          {
  43   1              struct SIPHead DT_XDATA *pIPHead;
  44   1              struct SNetIf  DT_XDATA *pNetIf;                /* for search netif list */
  45   1      
  46   1              pIPHead = (struct SIPHead DT_XDATA *)(MemHead->pStart);
  47   1      
  48   1              /* check ip version */
  49   1              if(IP_VERSION(pIPHead) != IP_VERSION_4)
  50   1              {
  51   2                      MemFree(MemHead);
  52   2                      return;
  53   2              }
  54   1      
  55   1              /* if checksum is ok */
C51 COMPILER V7.06   IP                                                                    11/06/2008 08:54:10 PAGE 2   

  56   1              if(CheckSum((WORD DT_XDATA *)pIPHead,(WORD)IP_HEAD_LEN(pIPHead),0) != 0)
  57   1              {
  58   2                      MemFree(MemHead);
  59   2                      return;
  60   2              }
  61   1      
  62   1              /* ip packet with options is not supported */
  63   1              if(IP_HEAD_LEN(pIPHead) != IP_HEAD_MIN_LEN)
  64   1              {
  65   2                      MemFree(MemHead);
  66   2                      return;
  67   2              }
  68   1      
  69   1              /* ip packet fragmented is not supported */
  70   1              if((pIPHead->FragmentFlag_Offset & IP_FRAGMENT_OFFSET_MASK)!= 0)
  71   1              {
  72   2                      MemFree(MemHead);
  73   2                      return;
  74   2              }
  75   1      
  76   1              
  77   1              /* if this packet for us. check all the netif. if a host
  78   1              has tow device(tow ip). This packet may come from one device
  79   1              but send for the IP of the other deviec. In this case we should
  80   1              not drop or forward this packet */
  81   1              
  82   1              /* if this packet is not for us. forward it */
  83   1              if((pNetIf = NetIfFindIP(pIPHead->IPDest)) == NULL)
  84   1              {
  85   2                      #ifdef IP_ENABLE_FORWARD        /* if act as a router */
                              /* We should decrease the IPHead->ttl */
                              if(pIPHead->LifeLength != 0)
                              {
                                      pIPHead->LifeLength--;
                                              
                                      /* recaculate IP head checksum. there is a easy method
                                      to recaculate, leave for later version improvment */
                                      CheckSum((WORD DT_XDATA *)pIPHead,(WORD)IP_HEAD_LEN(pIPHead),0);
              
                                      /* find a rout( a interface ) */
                                      if((pNetIf = NetIfFindRout(pIPHead->IPDest)) != NULL)
                                      {
                                              /* forward. send it through this interface. if return FALSE, we
                                              do not care, the soure of the packet will deel with it. */
                                              pNetIf->output(MemHead,pNetIf,pIPHead->IPDest);
                                      }
                              }
                              #endif
 104   2                      
 105   2                      MemFree(MemHead);
 106   2                      return;
 107   2              }
 108   1              else
 109   1              {
 110   2                      /* MemHead->pStart set to point uper layer */
 111   2                      MemHead->pStart += sizeof(struct SIPHead);
 112   2      
 113   2                      /* pass to the uper layer */
 114   2                      switch(pIPHead->Protocol)
 115   2                      {
 116   3                      case IP_PROTOCOL_TCP:
 117   3                              TCPInput(MemHead);
C51 COMPILER V7.06   IP                                                                    11/06/2008 08:54:10 PAGE 3   

 118   3                              break;
 119   3      #if     ICMP_EN
 120   3                      case IP_PROTOCOL_ICMP:
 121   3                              ICMPInput(MemHead);
 122   3                              break;
 123   3      #endif
 124   3                      default:
 125   3                              MemFree(MemHead);
 126   3                      }
 127   2              }
 128   1      }
 129          
 130          /* out put a ip packet,NOTE:MemHead->pStart point to IPHead.
 131          IPScr IPDest Protocol TotalLen is already filled at uper layer.
 132          To do so TCPCheckSum is easy to generate and pass augument to 
 133          IPOutput is easyer. 
 134          return :
 135                  TURE: send the packt successful. */
 136          BOOL IPOutput(struct SMemHead DT_XDATA * MemHead) REENTRANT_SIG
 137          {
 138   1              struct SNetIf  DT_XDATA *pNetIf;
 139   1              struct SIPHead DT_XDATA *pIPHead;
 140   1              WORD tCheckSum;
 141   1              
 142   1              pIPHead = (struct SIPHead DT_XDATA *)(MemHead->pStart);
 143   1      
 144   1              /* found a rout */
 145   1              if((pNetIf = NetIfFindRout(pIPHead->IPDest)) != NULL)
 146   1              {
 147   2                      /* fill IP head */
 148   2                      pIPHead->CheckSum                               = 0;
 149   2                      pIPHead->FragmentFlag_Offset    = 0;
 150   2                      pIPHead->FragmentID                             = 0;
 151   2                      pIPHead->LifeLength                             = IP_INITIAL_LIFE;
 152   2                      pIPHead->ServeType                              = 0;
 153   2                      pIPHead->Ver_HeadLen                    = (IP_VERSION_4 << 4) + IP_HEAD_MIN_LEN/4;
 154   2      
 155   2                      /* checksum */
 156   2                      tCheckSum = CheckSum((WORD DT_XDATA *)pIPHead,(WORD)IP_HEAD_LEN(pIPHead),0);
 157   2                      pIPHead->CheckSum = htons(tCheckSum);
 158   2      
 159   2                      /* output it */
 160   2                      return pNetIf->output(MemHead,pNetIf,pIPHead->IPDest);
 161   2              }
 162   1              else
 163   1                      return FALSE;
 164   1              /* 'MemHead' freeing is at tcp model when it is acked */
 165   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    935    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       6
   IDATA SIZE       =   ----    ----
   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 + -