亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? arp.c

?? C51的tcpip源程序 包含了TCP,IP,ARP,ICMP等協(xié)議的接口
?? C
字號:
//-----------------------------------------------------------------------------
// Net ARP.C
//
// This module handles ARP messages and ARP resolution and manages
// the ARP cache. Refer to RFC 826 and RFC 1122
//-----------------------------------------------------------------------------
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "C8051f.h"
#include "net.h"
#include "eth.h"
#include "serial.h"
#include "ip.h"
#include "arp.h"



extern WAIT xdata wait;
extern UCHAR code my_hwaddr[];
extern UCHAR code broadcast_hwaddr[]; 
extern ULONG code my_ipaddr;
extern ULONG code my_subnet;
extern ULONG code gateway_ipaddr;
extern UCHAR idata debug;
ARP_CACHE xdata arp_cache[CACHESIZE];
UCHAR waiting_for_arp;



void init_arp(void)
{
  	memset(arp_cache, 0, sizeof(arp_cache)); 
	memset(&wait, 0, sizeof(wait));
	waiting_for_arp = FALSE;
}




//------------------------------------------------------------------------
//	This is called every 60 seconds to age the ARP cache
// If an entry times out then it is deleted from the cache
// See "TCP/IP Illustrated, Volume 1" Sect 4.3
//------------------------------------------------------------------------
void age_arp_cache(void)
{
 	UCHAR i;
    	
   for (i=0; i < CACHESIZE; i++)
   {
      if ((arp_cache[i].ipaddr != 0) && (arp_cache[i].timer))
      {
         arp_cache[i].timer--;
			if (arp_cache[i].timer == 0)
         {
				// Timed out so clear out cache entry
				// Do not need to zero hwaddr
				arp_cache[i].ipaddr = 0;
            if (debug) serial_send("ARP: Aged out a cache entry\r");
			}
		}
   }
}




//------------------------------------------------------------------------
// This allocates memory for the entire outgoing message,
// including eth and ip headers, then builds an outgoing
// ARP response message
// See "TCP/IP Illustrated, Volume 1" Sect 4.4
//------------------------------------------------------------------------
void arp_send(UCHAR * hwaddr, ULONG ipaddr, UCHAR msg_type)
{
	UCHAR xdata * outbuf;
	ARP_HEADER xdata * arp;
         
   
   // Allocate memory for entire outgoing message including
   // eth header. Always 42 bytes
   outbuf = (UCHAR xdata *)malloc(42);
   if (outbuf == NULL)
   {
      if (debug) serial_send("ARP: Oops, out of memory\r");
      return;
   }      
     
   // Allow 14 bytes for the ethernet header
   arp = (ARP_HEADER xdata *)(outbuf + 14);
 	
	arp->hardware_type = DIX_ETHERNET; 
   arp->protocol_type = IP_PACKET;
   arp->hwaddr_len = 6;
	arp->ipaddr_len = 4;               
   arp->message_type = (UINT)msg_type;
   
   // My hardware address and IP addresses 
   memcpy(arp->source_hwaddr, my_hwaddr, 6);
   arp->source_ipaddr = my_ipaddr;

   // Destination hwaddr and dest IP addr
   if (msg_type == ARP_REQUEST) memset(arp->dest_hwaddr, 0, 6);
   else memcpy(arp->dest_hwaddr, hwaddr, 6);
   
   arp->dest_ipaddr = ipaddr;
      
   // If request then the message is a brodcast, if a response then
   // send to specified hwaddr
   // ARP payload size is always 28 bytes
	if (msg_type == ARP_REQUEST) eth_send(outbuf, broadcast_hwaddr, ARP_PACKET, 28);
   else eth_send(outbuf, hwaddr, ARP_PACKET, 28);
}



//------------------------------------------------------------------------
// This re-sends an ARP request if there was no response to
// the first one.	 It is called every 0.5 seconds.  If there
// is no response after 2 re-tries, the datagram that IP was 
// trying to send is deleted
//-----------------------------------------------------------------------
void arp_retransmit(void)
{
	static UCHAR idata retries = 0; 
	
	if ((waiting_for_arp) && (wait.timer))
	{
		wait.timer--;
		if (wait.timer == 0)
		{
			retries++;
			if (retries <= 2)
			{
				if (debug) serial_send("ARP: Re-sending ARP broadcast\r");
	 			arp_send(NULL, wait.ipaddr, ARP_REQUEST);
				wait.timer = ARP_TIMEOUT;
			}
			else
			{	
				if (debug) serial_send("ARP: Gave up waiting for response\r");
	 			wait.timer = 0;
				waiting_for_arp = 0;
				free(wait.buf);
			}
		}
	}
}




//------------------------------------------------------------------------
// Find the ethernet hardware address for the given ip address
// If destination IP is on my subnet then we want the eth
// address	of destination, otherwise we want eth addr of gateway. 
// Look in ARP cache first.  If not found there, send ARP request.
// Return pointer to the hardware address or NULL if not found
// See "TCP/IP Illustrated, Volume 1" Sect 4.5
//------------------------------------------------------------------------
UCHAR xdata * arp_resolve(ULONG dest_ipaddr)
{
   UCHAR i;
      
   // If destination IP is not on my subnet then we really want eth addr
	// of gateway, not destination IP
	if ((dest_ipaddr ^ my_ipaddr) & my_subnet)
	{
		if (gateway_ipaddr == 0)
		{
			if (debug) serial_send("ARP: Error, gateway addr not set\r");
			return (NULL);	
	 	}
	 	else dest_ipaddr = gateway_ipaddr;
	}
	
	   
   // See if IP addr of interest is in ARP cache
   for (i=0; i < CACHESIZE; i++)
   {
      if (arp_cache[i].ipaddr == dest_ipaddr)
         return (&arp_cache[i].hwaddr[0]);
   }

	if (debug) serial_send("ARP: IP addr not found in cache\r");
	if (debug) serial_send("ARP: Sending an ARP broadcast\r");
	// Not in cache so broadcast ARP request
  	arp_send(NULL, dest_ipaddr, ARP_REQUEST);
     	   
   // Set a flag to indicate that an IP datagram is waiting
   // to be sent
   waiting_for_arp = TRUE;
				      
   // Null means that we have sent an ARP request
   return (NULL); 
}





//------------------------------------------------------------------------
// This handles incoming ARP messages
// See "TCP/IP Illustrated, Volume 1" Sect 4.4
// Todo:  Resolve problem of trying to add to a full cache
//------------------------------------------------------------------------
void arp_rcve(UCHAR xdata * inbuf)
{
   UCHAR idata i, cached, oldest;
   UINT idata minimum;
   ARP_HEADER xdata * arp;
      
   arp = (ARP_HEADER xdata *)(inbuf + 14);
   cached = FALSE;
   
   // Print message
   if (debug)
   {
      if (arp->message_type == ARP_REQUEST)
         serial_send("ARP: Request rcvd\r");
      else serial_send("ARP: Response rcvd\r");
   }
         
   // Validate incoming frame
   if ((arp->hardware_type != DIX_ETHERNET) ||
       (arp->protocol_type != IP_PACKET)) return;

   // Search ARP cache for senders IP address
   // If found, update entry and restart timer
   for (i=0; i < CACHESIZE; i++)
   {
      if (arp_cache[i].ipaddr == arp->source_ipaddr)
      {
         memcpy(&arp_cache[i].hwaddr[0], &arp->source_hwaddr[0], 6);
         arp_cache[i].timer = CACHETIME;		
         cached = TRUE;
         if (debug) serial_send("ARP: Cache entry updated\r");
                  
         break;  
      }
   }
   
   if (arp->dest_ipaddr != my_ipaddr) return;
   
   // At this point we know the the frame is addressed to me
   // If not already in cache then add entry and start timer
   if (cached == FALSE)
   {
      // Find first blank space and add entry
		// Blank entries are indicated by ip addr = 0
      for (i=0; i < CACHESIZE; i++)
      {
         if (arp_cache[i].ipaddr == 0) 
         {
            arp_cache[i].ipaddr = arp->source_ipaddr;
            memcpy(&arp_cache[i].hwaddr[0], &arp->source_hwaddr[0], 6);   
            arp_cache[i].timer = CACHETIME;
         	if (debug) serial_send("ARP: New cache entry added\r");
         	break;
         }
      }

		// If no blank entries in arp cache	then sort cache
		// to find oldest entry and replace it
		if (i == CACHESIZE)
		{
			// Oldest entry is the one with lowest timer value			
			minimum = 0xFFFF;
			for (i=0; i < CACHESIZE; i++)
      	{
				if (arp_cache[i].timer < minimum) 
				{
					minimum = arp_cache[i].timer;
					oldest = i;
				}
			}
      	
			// "oldest" is now index of oldest entry, so replace it
			arp_cache[oldest].ipaddr = arp->source_ipaddr;
         memcpy(&arp_cache[oldest].hwaddr[0], &arp->source_hwaddr[0], 6);   
         arp_cache[oldest].timer = CACHETIME;
        if (debug) serial_send("ARP: Cache full, so replaced oldest\r");
   	}
	}

   
   // If we are waiting for an arp response and the arp response
  	// that just came in is addressed to me and is from the host
  	// we are waiting for, then send	the message-in-waiting
   if (arp->message_type == ARP_RESPONSE)
   {
   	if ((waiting_for_arp) && (wait.ipaddr == arp->source_ipaddr))
   	{
   		waiting_for_arp = FALSE;
		  	ip_send(wait.buf, wait.ipaddr, wait.proto_id, wait.len);
		}
	}
	else if (arp->message_type == ARP_REQUEST)
   {
    	// Send ARP response 
    	if (debug) serial_send("ARP: Sending response\r");
    	arp_send(arp->source_hwaddr, arp->source_ipaddr, ARP_RESPONSE);
	}
}


?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99久久夜色精品国产网站| 不卡的av网站| 日韩一区二区三区在线观看| 欧美三级视频在线| 欧美一区二视频| 国产欧美精品一区| 亚洲老妇xxxxxx| 日韩av电影免费观看高清完整版在线观看| 亚洲成人自拍偷拍| 久久99九九99精品| 粉嫩欧美一区二区三区高清影视| 91在线观看地址| 在线播放中文一区| 国产精品久久久久久久久免费丝袜| 一区二区三区在线免费观看| 麻豆精品视频在线| 色噜噜久久综合| 精品久久免费看| 中文字幕字幕中文在线中不卡视频| 日韩精品亚洲一区| 不卡电影一区二区三区| 中国色在线观看另类| 亚洲一区二区三区美女| 丁香婷婷综合激情五月色| 国产日韩三级在线| 99久久精品免费| 又紧又大又爽精品一区二区| 在线观看日韩电影| 自拍偷拍国产精品| 一本久久a久久精品亚洲| 亚洲精品在线电影| 亚洲午夜一二三区视频| 成人性色生活片免费看爆迷你毛片| 91农村精品一区二区在线| 一区二区三区四区不卡在线| 欧美精品 国产精品| 久国产精品韩国三级视频| 国产婷婷色一区二区三区四区 | 日韩在线一二三区| 欧美tickling挠脚心丨vk| 国产一区在线不卡| 91精品欧美一区二区三区综合在| 亚洲人快播电影网| 成人蜜臀av电影| 亚洲一区二区精品视频| 日韩欧美国产一区在线观看| 亚洲丰满少妇videoshd| www激情久久| 国产一区二区在线免费观看| 国产精品久久久久久亚洲伦| 欧美日韩不卡视频| 亚洲大片在线观看| 久久人人爽人人爽| 国产精品888| 国产偷v国产偷v亚洲高清| 欧美系列日韩一区| 午夜精品国产更新| 欧美高清视频在线高清观看mv色露露十八| 经典一区二区三区| 亚洲高清久久久| 国产精品美女久久久久久| 91精品国产综合久久精品app| 成人爽a毛片一区二区免费| 天天综合天天综合色| 中日韩免费视频中文字幕| 日韩三级高清在线| 欧美色区777第一页| 成人国产精品免费| 久久精品99国产精品| 久久夜色精品一区| 欧美日韩一区二区在线观看| 成人精品电影在线观看| 久久国产精品99久久人人澡| 亚瑟在线精品视频| 亚洲精品成人天堂一二三| 国产亚洲精品精华液| 日韩片之四级片| 欧美另类videos死尸| 91色视频在线| 不卡一区二区三区四区| 国产一区二区日韩精品| 人人狠狠综合久久亚洲| 久久久久久久久免费| 欧美一区二区三区视频在线| 欧美性猛交xxxx乱大交退制版| 丰满少妇久久久久久久| 国产精品综合在线视频| 看电影不卡的网站| 蜜臀av一区二区在线免费观看| 亚洲va韩国va欧美va精品| 亚洲欧美视频一区| 亚洲精品国产一区二区精华液| 国产精品久久久久久久久久久免费看| 久久精品视频免费观看| 久久免费电影网| 久久久久成人黄色影片| 视频一区在线播放| 色综合色狠狠综合色| 国产mv日韩mv欧美| 国产呦萝稀缺另类资源| 久久99国产乱子伦精品免费| 久久精品国产亚洲a| 国产一区二区三区日韩| 国产精品一二三区在线| 国产成人激情av| 亚洲精品午夜久久久| 亚洲欧美日韩国产成人精品影院| 中文字幕日韩一区二区| 精品日产卡一卡二卡麻豆| 日韩亚洲欧美一区二区三区| 日韩一级大片在线观看| 久久综合色天天久久综合图片| 久久久久久97三级| 国产精品女主播av| 亚洲欧美日韩久久| 尤物视频一区二区| 亚洲自拍另类综合| 亚洲视频每日更新| 国产精品卡一卡二| 国产精品一二三四区| 肉丝袜脚交视频一区二区| 免费xxxx性欧美18vr| 免费高清在线视频一区·| 午夜精品久久久| 久久99深爱久久99精品| 黄色资源网久久资源365| 久久久久久久久97黄色工厂| 国产欧美日韩亚州综合| 中文字幕免费观看一区| 欧美精选在线播放| 日韩视频免费观看高清完整版 | 欧美一区二区三区四区久久| 欧美一级高清大全免费观看| 精品久久五月天| 国产精品天美传媒| 一区二区三区美女视频| 捆绑调教一区二区三区| 国产成人8x视频一区二区 | 2023国产精品视频| 亚洲精品久久7777| 国产精品18久久久久久久久| 在线成人av网站| 日韩一级高清毛片| 中文字幕国产精品一区二区| 亚洲丝袜自拍清纯另类| 午夜婷婷国产麻豆精品| 麻豆传媒一区二区三区| 亚洲国产精品视频| 国产精品一区免费视频| 91网站视频在线观看| 欧美日本一区二区在线观看| 久久久久亚洲综合| 亚洲精品免费在线播放| 亚洲第一综合色| 喷白浆一区二区| 成人avav影音| 91精品国产综合久久精品app| 国产日产欧产精品推荐色| 国产精品网站在线观看| 老司机精品视频线观看86| 91热门视频在线观看| 精品乱码亚洲一区二区不卡| 亚洲日本va午夜在线电影| 久久99精品国产麻豆婷婷| 在线观看www91| 激情小说亚洲一区| 国产成人精品免费看| 欧美丰满一区二区免费视频| 欧美韩国日本一区| 免费观看在线综合| 欧美精品一二三| 国产精品高潮呻吟久久| 麻豆91精品91久久久的内涵| 91香蕉视频mp4| 欧美国产日本韩| 久久国产精品99久久人人澡| 欧美性欧美巨大黑白大战| 国产精品日韩精品欧美在线| 日韩av中文字幕一区二区| 欧美日韩一区二区三区在线看| 国产精品传媒入口麻豆| 精品一区二区三区在线视频| 欧美视频日韩视频在线观看| 中文字幕欧美国产| 成人一区二区三区视频在线观看 | 日韩亚洲欧美在线| 亚洲国产wwwccc36天堂| 91丨porny丨中文| 中文字幕av不卡| 国产成人在线视频网站| 亚洲欧美电影院| 久久电影网电视剧免费观看| 欧美变态凌虐bdsm| 日韩不卡在线观看日韩不卡视频| 色婷婷综合久久久中文一区二区| 日本一区二区免费在线| av一区二区三区四区| 国产日韩精品一区二区浪潮av| 国内精品在线播放| 精品国产一区二区三区四区四 |