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

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

?? arp.c

?? 這是為51單片機(jī)編的tcpip協(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 "AT89X52.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一区二区三区免费野_久草精品视频
欧美国产日本视频| 欧美日韩精品一区二区三区四区| 91精品国产综合久久久久久| 一级做a爱片久久| 欧美人体做爰大胆视频| 婷婷久久综合九色综合伊人色| 欧美日韩黄色一区二区| 美腿丝袜在线亚洲一区| 久久看人人爽人人| 不卡的av网站| 亚洲第一搞黄网站| 精品日韩欧美在线| 成人中文字幕电影| 亚洲综合丝袜美腿| 日韩一区二区三区在线视频| 国产乱子伦一区二区三区国色天香| 久久久久国色av免费看影院| 成+人+亚洲+综合天堂| 夜夜精品视频一区二区| 欧美丰满少妇xxxxx高潮对白| 久久精品国产99| 国产精品欧美极品| 在线亚洲人成电影网站色www| 亚洲自拍都市欧美小说| 欧美mv日韩mv| 色综合亚洲欧洲| 日韩成人一级片| 亚洲国产精品国自产拍av| 91麻豆精品视频| 免费欧美高清视频| 国产精品传媒视频| 日韩一区二区视频在线观看| 成人av在线资源| 视频一区二区欧美| 国产欧美va欧美不卡在线| 欧美优质美女网站| 国产美女在线精品| 午夜视频在线观看一区二区| 久久久久久久久久久久久久久99| 色婷婷一区二区| 久久精品国产澳门| 亚洲在线免费播放| 中文字幕精品一区二区精品绿巨人 | 日韩欧美一区二区久久婷婷| 国产成人av影院| 日韩黄色一级片| 中文字幕在线观看一区| 日韩精品影音先锋| 在线免费视频一区二区| 国产成人在线网站| 日韩黄色片在线观看| 亚洲视频免费在线观看| 国产亚洲综合性久久久影院| 91精品国产色综合久久不卡蜜臀| 99久久精品一区| 国产精品一级片| 老司机免费视频一区二区| 亚洲一区视频在线| 亚洲天堂中文字幕| 国产精品―色哟哟| 久久精品一区二区三区四区| 欧美大尺度电影在线| 欧美人动与zoxxxx乱| 欧美亚洲愉拍一区二区| 色综合天天性综合| 91免费视频大全| 99视频精品全部免费在线| 丁香六月综合激情| 国产精品白丝av| 国产精品一级在线| 国产在线精品国自产拍免费| 久久机这里只有精品| 日本成人中文字幕在线视频| 视频在线在亚洲| 亚洲成人自拍一区| 香蕉影视欧美成人| 五月天婷婷综合| 亚洲不卡在线观看| 午夜电影久久久| 亚洲综合小说图片| 一区二区三区av电影 | 国产**成人网毛片九色| 精品亚洲免费视频| 国内精品免费**视频| 国内偷窥港台综合视频在线播放| 美国三级日本三级久久99| 青青草原综合久久大伊人精品| 日本视频免费一区| 狠狠狠色丁香婷婷综合激情| 国产久卡久卡久卡久卡视频精品| 国产精品中文欧美| 成人av资源网站| 日本丰满少妇一区二区三区| 欧美性猛片xxxx免费看久爱| 欧美日本国产视频| 日韩欧美国产高清| 久久先锋资源网| 国产精品成人网| 一区二区视频免费在线观看| 亚洲一区二区精品视频| 日韩高清电影一区| 国产麻豆成人传媒免费观看| 成人黄色av电影| 欧美中文字幕一二三区视频| 91精品免费在线| 久久久久久久电影| 亚洲精品国产一区二区精华液 | 日韩高清一级片| 国产精品一区二区三区网站| 国产成人精品免费网站| 色嗨嗨av一区二区三区| 欧美一区二区三区系列电影| 2023国产精华国产精品| 成人免费在线观看入口| 日韩av中文字幕一区二区三区| 精一区二区三区| 91婷婷韩国欧美一区二区| 日韩一二三区视频| 一区在线观看视频| 日韩av一二三| 白白色 亚洲乱淫| 久久精品这里都是精品| 亚洲国产精品欧美一二99| 久久国产日韩欧美精品| 色综合天天综合在线视频| 欧美一级久久久| 1区2区3区国产精品| 卡一卡二国产精品 | 亚洲一区二区中文在线| 精品一区二区久久| 在线观看亚洲专区| 国产视频一区二区在线| 日韩精品乱码av一区二区| 国产精品亚洲一区二区三区妖精 | 91美女视频网站| 欧美精品一区二| 亚洲二区在线观看| 99久久久久久| 精品国产免费人成在线观看| 一区二区三区.www| 成人免费高清在线| 精品国产区一区| 日韩精品免费视频人成| 91蝌蚪porny| 亚洲国产精品高清| 精品亚洲国内自在自线福利| 欧美精品在线观看播放| 一区二区三区在线看| 成人网页在线观看| 久久综合久久久久88| 日韩av一级电影| 欧美日韩高清在线播放| 亚洲日本欧美天堂| 成人av资源下载| 亚洲国产激情av| 国产麻豆视频一区| 亚洲精品一区在线观看| 美女尤物国产一区| 91精品国产aⅴ一区二区| 亚洲成人7777| 欧美视频你懂的| 亚洲一本大道在线| 欧美三日本三级三级在线播放| 亚洲精品成人悠悠色影视| 91视频一区二区| 亚洲色图色小说| 色伊人久久综合中文字幕| 中文字幕在线免费不卡| 91麻豆视频网站| 一区二区三区欧美日| 91福利视频久久久久| 一区二区三区成人| 欧美精品自拍偷拍| 午夜精品123| 欧美一区二区女人| 久久精品国产一区二区三| 2021中文字幕一区亚洲| 欧美在线一区二区| 久久久久久久网| 丁香六月综合激情| 亚洲色图视频网站| 欧洲一区在线观看| 一本一本大道香蕉久在线精品| 国产精品拍天天在线| 色婷婷av一区| 日韩不卡一二三区| 国产偷国产偷精品高清尤物| 成人深夜在线观看| 一区二区三区成人| 日韩一区二区在线看| 国产成人亚洲综合a∨婷婷图片| 国产精品乱码一区二区三区软件 | 久久久电影一区二区三区| 国产成人免费视频网站| 综合久久综合久久| 91精品欧美久久久久久动漫| 国内精品在线播放| 亚洲激情成人在线| 日韩欧美在线网站| 成人aaaa免费全部观看|