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

📄 arp.lst

📁 无线控制器 控制电梯永久在线 控制电梯
💻 LST
字号:
C51 COMPILER V6.12  ARP                                                                    05/19/2009 14:55:35 PAGE 1   


C51 COMPILER V6.12, COMPILATION OF MODULE ARP
OBJECT MODULE PLACED IN .\ARP.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\Netif\ARP.c BROWSE DEBUG OBJECTEXTEND PRINT(.\ARP.lst) OBJECT(.\ARP.obj)
                    - 

stmt level    source

   1          /*
   2           * Copyright (c) 2003 Electric Application Laboratory of NAN KAI University
   3           * All rights reserved.
   4           *
   5           * Redistribution and use in source and binary forms, with or without modification,
   6           * are permitted provided that the following conditions are met:
   7           *
   8           * 1. Redistributions of source code must retain the above copyright notice,
   9           *    this list of conditions and the following disclaimer.
  10           * 2. Redistributions in binary form must reproduce the above copyright notice,
  11           *    this list of conditions and the following disclaimer in the documentation
  12           *    and/or other materials provided with the distribution.
  13           * 3. The name of the author may not be used to endorse or promote products
  14           *    derived from this software without specific prior written permission.
  15           *
  16           * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17           * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18           * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  19           * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20           * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  21           * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22           * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23           * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  24           * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  25           * OF SUCH DAMAGE.
  26           *
  27           * Author: Li Zhanglin <wzzlin@nankai.edu.cn>
  28           *
  29           */
  30          
  31          #include "..\GloblDef\GloblDef.h"
  32          #include "..\TCPIP\TCPIPmem.h"
  33          #include "..\TCPIP\IP.h"
  34          #include "..\Netif\etherif.h"
  35          #include "..\Netif\ARP.h"
  36          #include "..\TCPIP\Netif.h"
  37          
  38          BYTE DT_XDATA EtherAddrAny[ETHER_ADDR_LEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
  39          
  40          /* entry table */
  41          struct SARPEntry DT_XDATA ARPTable[ARP_ENTRY_MAX_NUM];
  42          
  43          /* arp init */
  44          void ARPInit() REENTRANT_MUL
  45          {
  46   1      	BYTE i;
  47   1      
  48   1      	/* set every unit in arp tabel invalid */
  49   1      	for(i = 0; i < ARP_ENTRY_MAX_NUM; i++)
  50   1      		ARPTable[i].time = 0;
  51   1      }
  52          
  53          /* construct a arp query packet and return it */
  54          struct SMemHead DT_XDATA * ARPQuery(struct SNetIf DT_XDATA *NetIf,IP_ADDR DestIP) REENTRANT_SIG
C51 COMPILER V6.12  ARP                                                                    05/19/2009 14:55:35 PAGE 2   

  55          {
  56   1      	struct SMemHead DT_XDATA *MemHead;
  57   1      	struct SEtherHead DT_XDATA *EtherHead;
  58   1      	struct SARPPacket DT_XDATA *ARPPacket;
  59   1      
  60   1      	/* allocate a packet mem */
  61   1      	if((MemHead = MemAllocate(sizeof(struct SARPPacket) + 
  62   1      		sizeof(struct SEtherHead))) == NULL)
  63   1      		return NULL;
  64   1      	
  65   1      	EtherHead = (struct SEtherHead DT_XDATA *)(MemHead->pStart);
  66   1      	ARPPacket = (struct SARPPacket DT_XDATA *)(MemHead->pStart + 
  67   1      		sizeof(struct SEtherHead));
  68   1      
  69   1      	/* fill Ether head */
  70   1      	MemCopy(EtherHead->DestAddr,EtherAddrAny,ETHER_ADDR_LEN);
  71   1      	MemCopy(EtherHead->ScrAddr ,
  72   1      		((struct SEtherDevice DT_XDATA *)(NetIf->Info))->Addr,ETHER_ADDR_LEN);
  73   1      	EtherHead->type = htons(ETHER_TYPE_ARP);
  74   1      
  75   1      	/* fill arp head */
  76   1      	ARPPacket->HardWareAddrLen	= ARP_HARDWARE_ADDR_LEN_ETHER;
  77   1      	ARPPacket->HardwareType		= htons(ARP_HARDWARE_TYPE_ETHER);
  78   1      	ARPPacket->ProtocolAddrLen	= ARP_PROTOCOL_ADDR_LEN_IP;
  79   1      	ARPPacket->ProtocolType		= htons(ARP_PROTOCOL_TYPE_IP);
  80   1      	ARPPacket->type				= htons(ARP_TYPE_ARP_REQUEST);
  81   1      
  82   1      	/* fill arp content */
  83   1      	ARPPacket->IPDestAddr	= DestIP;
  84   1      	ARPPacket->IPScrAddr	= NetIf->IPAddr;
  85   1      	MemCopy(ARPPacket->EtherDestAddr,EtherAddrAny,ETHER_ADDR_LEN);
  86   1      	MemCopy(ARPPacket->EtherScrAddr,
  87   1      		((struct SEtherDevice DT_XDATA *)(NetIf->Info))->Addr,ETHER_ADDR_LEN);
  88   1      
  89   1      	return MemHead;
  90   1      }
  91          
  92          /* deel with a input arp packet. if send a reply is needed return 
  93          this replay packet, oterhwise return NULL  */
  94          struct SMemHead DT_XDATA *ARPInput(struct SMemHead DT_XDATA *MemHead, struct SNetIf DT_XDATA *NetIf) REENT
             -RANT_MUL
  95          {
  96   1      	struct SEtherHead DT_XDATA *EtherHead;
  97   1      	struct SARPPacket DT_XDATA *ARPPacket;
  98   1      
  99   1      	EtherHead = (struct SEtherHead DT_XDATA *)(MemHead->pStart);
 100   1      	ARPPacket = (struct SARPPacket DT_XDATA *)(MemHead->pStart + 
 101   1      		sizeof(struct SEtherHead));
 102   1      
 103   1      	/* which type of arp */
 104   1      	switch(ntohs(ARPPacket->type))
 105   1      	{
 106   2      	case ARP_TYPE_ARP_REQUEST:
 107   2      
 108   2      		/* if arp request to local host */
 109   2      		if(ARPPacket->IPDestAddr == NetIf->IPAddr)
 110   2      		{
 111   3      			/* send arp replay */
 112   3      
 113   3      			/* fill Ether head */
 114   3      			MemCopy(EtherHead->DestAddr,ARPPacket->EtherScrAddr,ETHER_ADDR_LEN);
 115   3      			MemCopy(EtherHead->ScrAddr,
C51 COMPILER V6.12  ARP                                                                    05/19/2009 14:55:35 PAGE 3   

 116   3      				((struct SEtherDevice DT_XDATA *)(NetIf->Info))->Addr,ETHER_ADDR_LEN);
 117   3      			EtherHead->type = htons(ETHER_TYPE_ARP);
 118   3      
 119   3      			/* copy source part to dest part. include Ether addr and 
 120   3      			Ip addr */
 121   3      			MemCopy(ARPPacket->EtherDestAddr,ARPPacket->EtherScrAddr,
 122   3      				(sizeof(IP_ADDR) + ETHER_ADDR_LEN));
 123   3      
 124   3      			/* fill source part. include Ether addr and Ip addr*/
 125   3      			ARPPacket->IPScrAddr = NetIf->IPAddr;
 126   3      			MemCopy(ARPPacket->EtherScrAddr,
 127   3      				((struct SEtherDevice DT_XDATA *)(NetIf->Info))->Addr,ETHER_ADDR_LEN);
 128   3      
 129   3      			/* arp type */
 130   3      			ARPPacket->type = htons(ARP_TYPE_ARP_REPLY);
 131   3      
 132   3      			return MemHead;
 133   3      		}
 134   2      		break;
 135   2      
 136   2      	case ARP_TYPE_ARP_REPLY:
 137   2      		/* add to arp table */
 138   2      		ARPAddEntry(ARPPacket);
 139   2      		break;
 140   2      	}
 141   1      				
 142   1      	/* for any case except ARP_TYPE_ARP_REQUEST for this IP, 
 143   1      	arp packet is released */
 144   1      	MemFree(MemHead);
 145   1      
 146   1      	/* no packet need send */
 147   1      	return NULL;
 148   1      }
 149          
 150          /* add a entry to arp table */
 151          void ARPAddEntry(struct SARPPacket DT_XDATA *ARPPacket) REENTRANT_MUL
 152          {
 153   1      	BYTE i;
 154   1      	WORD MinTime;
 155   1      	BYTE iToReplace;	/* index of entry going to be replace */
 156   1      
 157   1      	/* find a free entry */
 158   1      	for(i = 0; i<ARP_ENTRY_MAX_NUM; i++)
 159   1      	{
 160   2      		if(ARPTable[i].time == 0)
 161   2      		{
 162   3      			iToReplace = i;
 163   3      			break;
 164   3      		}
 165   2      	}
 166   1      
 167   1      	/* if no free entry, find the oldest entry */
 168   1      	if(i == ARP_ENTRY_MAX_NUM)
 169   1      	{	
 170   2      		for(i = 0, MinTime = ARP_ENTRY_TIME_OUT, iToReplace = 0;
 171   2      			i<ARP_ENTRY_MAX_NUM; i++)
 172   2      		{
 173   3      			if(MinTime > ARPTable[i].time)
 174   3      			{
 175   4      				MinTime = ARPTable[i].time;
 176   4      				iToReplace = i;
 177   4      			}
C51 COMPILER V6.12  ARP                                                                    05/19/2009 14:55:35 PAGE 4   

 178   3      		}
 179   2      	}
 180   1      
 181   1      	/* replace the entry */
 182   1      	MemCopy(ARPTable[iToReplace].EtherAddr,ARPPacket->EtherScrAddr,
 183   1      		ETHER_ADDR_LEN);
 184   1      	ARPTable[iToReplace].IPAddr = ARPPacket->IPScrAddr;
 185   1      
 186   1      	/* start timer */
 187   1      	ARPTable[iToReplace].time = ARP_ENTRY_TIME_OUT;
 188   1      }
 189          
 190          /* find IPAddr in arptable copy it to EtherAddr. if can't find return
 191          false */
 192          BOOL ARPFind(BYTE EtherAddr[],IP_ADDR IPAddr) REENTRANT_SIG
 193          {
 194   1      	BYTE i;
 195   1      	for(i = 0; i<ARP_ENTRY_MAX_NUM; i++)
 196   1      	{
 197   2      		/* check only valid entry */
 198   2      		if(ARPTable[i].time != 0)
 199   2      		{
 200   3      			if(ARPTable[i].IPAddr == IPAddr)
 201   3      			{
 202   4      				MemCopy(EtherAddr,ARPTable[i].EtherAddr,ETHER_ADDR_LEN);
 203   4      
 204   4      				return TRUE;
 205   4      			}
 206   3      		}
 207   2      	}
 208   1      	return FALSE;
 209   1      }
 210          
 211          void ARPTimer() REENTRANT_MUL
 212          {
 213   1      	BYTE i;
 214   1      
 215   1      	/* decrease every entry timer */
 216   1      	for(i = 0; i<ARP_ENTRY_MAX_NUM; i++)
 217   1      	{
 218   2      		/* check only valid entry */
 219   2      		if(ARPTable[i].time != 0)
 220   2      		{
 221   3      			ARPTable[i].time--;
 222   3      		}
 223   2      	}
 224   1      }
 225          	
 226          
 227          
 228          		
 229          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1147    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =     54    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      11
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
C51 COMPILER V6.12  ARP                                                                    05/19/2009 14:55:35 PAGE 5   

END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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