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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? arp.c

?? 嵌入式web平臺
?? 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);
	}
}


?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本韩国欧美国产| 国产蜜臀97一区二区三区| 男女男精品视频| 日韩欧美中文字幕精品| 精品视频在线看| 日韩精品一区第一页| 欧美大片一区二区| 国产原创一区二区| 国产亚洲成av人在线观看导航| 成人动漫一区二区| 一区二区三区视频在线看| 777奇米四色成人影色区| 久久精品国产999大香线蕉| 国产拍欧美日韩视频二区| 9人人澡人人爽人人精品| 亚洲五码中文字幕| 日韩欧美另类在线| 成人免费高清在线观看| 亚洲一区二区三区四区不卡| 欧美一区二区视频在线观看2020 | 欧美videos大乳护士334| 国产一区二区在线看| 国产精品白丝在线| 欧美美女bb生活片| 国产精品影视在线| 亚洲日本免费电影| 欧美精品v日韩精品v韩国精品v| 狠狠色丁香婷综合久久| 日韩毛片精品高清免费| 在线综合视频播放| 国产福利视频一区二区三区| 伊人色综合久久天天| 欧美变态tickle挠乳网站| 99精品久久免费看蜜臀剧情介绍| 视频一区欧美日韩| 国产精品色在线观看| 欧美精品第一页| 国产a级毛片一区| 亚洲国产日韩av| 久久久夜色精品亚洲| 91蜜桃传媒精品久久久一区二区| 日产欧产美韩系列久久99| 国产精品久久一级| 欧美一级淫片007| 91啪亚洲精品| 久久99国产精品尤物| 亚洲欧美激情在线| 精品福利一区二区三区| 91美女片黄在线观看91美女| 九色|91porny| 一区二区三区欧美在线观看| 2023国产精华国产精品| 欧美视频一区在线| 国产iv一区二区三区| 日韩电影在线一区| 国产精品国产三级国产a| 日韩欧美色电影| 在线看日韩精品电影| 国产精品88av| 久久精品久久久精品美女| 一区二区三区四区不卡在线| 国产日韩亚洲欧美综合| 日韩精品一区二区三区四区视频 | 日本韩国精品在线| 国产美女精品在线| 日本少妇一区二区| 亚洲综合在线电影| 国产精品视频免费| 精品1区2区在线观看| 欧美日韩亚洲综合在线 | 欧美日韩一区二区不卡| 成人激情视频网站| 黑人巨大精品欧美黑白配亚洲| 亚洲丰满少妇videoshd| 成人网在线播放| 六月婷婷色综合| 偷拍日韩校园综合在线| 亚洲免费在线电影| 国产蜜臀av在线一区二区三区| 日韩精品一区二区三区中文不卡| 欧美美女视频在线观看| 欧美亚洲综合久久| 99精品久久只有精品| 成人午夜激情视频| 国产成人午夜精品影院观看视频 | 色香蕉久久蜜桃| 国产黄色91视频| 韩国欧美一区二区| 麻豆一区二区在线| 日本亚洲天堂网| 日韩影视精彩在线| 日日摸夜夜添夜夜添精品视频| 一区二区三区久久久| 亚洲三级小视频| 亚洲天堂免费在线观看视频| 国产精品网站在线播放| 中文字幕av免费专区久久| 国产精品无人区| 国产精品理论片在线观看| 中文字幕不卡在线| 中文字幕av免费专区久久| 日本一区二区免费在线观看视频 | 一本到一区二区三区| 99久久99久久精品国产片果冻| 成人av电影免费观看| 不卡视频免费播放| www.性欧美| 99久久伊人精品| caoporn国产精品| 91亚洲国产成人精品一区二区三 | 日本电影欧美片| 91极品美女在线| 欧美日韩一级片在线观看| 欧美乱妇20p| 欧美一级理论性理论a| 日韩手机在线导航| 精品国产乱码久久久久久久| 久久免费看少妇高潮| 国产偷国产偷精品高清尤物| 国产色爱av资源综合区| 国产精品网站导航| 亚洲色图视频网| 亚洲综合视频在线观看| 午夜精品一区在线观看| 日本女优在线视频一区二区| 国产自产视频一区二区三区| 国产一区二区电影| 成人福利视频在线看| 在线精品视频免费观看| 欧美日本精品一区二区三区| 日韩天堂在线观看| 精品粉嫩超白一线天av| 国产精品乱码一区二三区小蝌蚪| 日韩一区欧美一区| 亚洲一区二区在线免费看| 免费人成精品欧美精品| 国产精品白丝jk白祙喷水网站 | 欧洲精品一区二区三区在线观看| 欧美日韩国产一二三| 日韩三级在线观看| 国产午夜亚洲精品理论片色戒| 国产精品毛片大码女人| 亚洲黄色在线视频| 蜜桃av一区二区| 国产不卡高清在线观看视频| 91电影在线观看| 欧美成人猛片aaaaaaa| 国产精品国产三级国产普通话99| 99国产精品视频免费观看| 欧美亚洲一区二区三区四区| 欧美不卡一区二区| 国产精品午夜免费| 亚洲成人精品影院| 韩国v欧美v亚洲v日本v| av中文字幕亚洲| 欧美日韩极品在线观看一区| 337p日本欧洲亚洲大胆精品| 亚洲天堂成人在线观看| 日韩国产成人精品| 成人av电影免费在线播放| 欧美精品免费视频| 欧美韩国日本一区| 午夜视频一区在线观看| 粉嫩一区二区三区性色av| 欧美日韩精品一区二区三区四区 | 成人欧美一区二区三区黑人麻豆| 五月激情综合色| 国产成人综合在线观看| 欧美日韩不卡一区二区| 国产欧美一区二区精品忘忧草 | 欧美美女一区二区在线观看| 国产午夜精品久久久久久久| 亚洲韩国一区二区三区| 国产69精品一区二区亚洲孕妇| 欧美日韩一区二区欧美激情| 欧美国产日韩在线观看| 日本午夜一区二区| 91视频在线看| 久久一留热品黄| 亚洲福利一二三区| 成人免费电影视频| 日韩欧美国产一区二区在线播放| 国产精品国产馆在线真实露脸| 日韩成人伦理电影在线观看| hitomi一区二区三区精品| 欧美不卡一二三| 亚洲国产精品久久久男人的天堂 | 91亚洲国产成人精品一区二区三| 中文字幕一区二区三区视频| 亚洲素人一区二区| 日韩黄色片在线观看| 91色在线porny| 中文字幕电影一区| 亚洲第一主播视频| 99国产欧美另类久久久精品| 久久亚洲综合av| 天天操天天干天天综合网| 99免费精品视频| 久久久综合网站| 天天色天天爱天天射综合|