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

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

?? arp.c

?? 這是新華龍(www.xhl.xom.xn)開發(fā)的
?? C
字號(hào):
//-----------------------------------------------------------------------------
// Copyright (c) 2002 Jim Brady
// Do not use commercially without author's permission
// Last revised August 2002
// 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);
	}
}


?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲一区二区三区在线| 久久蜜桃av一区精品变态类天堂 | 亚洲欧美一区二区在线观看| 日韩亚洲欧美一区| 欧美一区二区三区四区在线观看| 在线亚洲免费视频| 91在线你懂得| 在线看一区二区| 欧美日韩不卡一区| 911精品国产一区二区在线| 欧美日韩国产精品成人| 欧美日韩dvd在线观看| 欧美精品日韩综合在线| 欧美一区二区人人喊爽| 欧美mv日韩mv| 国产精品美女一区二区| 亚洲欧美日韩中文字幕一区二区三区 | 欧美无人高清视频在线观看| 色综合久久久久综合体桃花网| 99久久国产综合精品女不卡| 91视频你懂的| 欧美欧美午夜aⅴ在线观看| 91麻豆精品国产91久久久资源速度 | 久久国产乱子精品免费女| 黑人巨大精品欧美一区| 成人免费高清视频| 欧洲精品一区二区| 欧美v国产在线一区二区三区| 久久久精品tv| 一区二区三区欧美亚洲| 美女高潮久久久| 成人av网址在线| 欧美日韩国产精选| 国产日韩欧美高清| 亚洲综合成人在线| 国产精品综合一区二区三区| 99久久伊人精品| 日韩一二三四区| 国产一区欧美日韩| 91视视频在线直接观看在线看网页在线看 | 久久精品一区八戒影视| 一区二区在线看| 蜜桃传媒麻豆第一区在线观看| 成人免费av网站| 欧美精品久久久久久久久老牛影院| 久久久综合视频| 亚洲观看高清完整版在线观看| 国产一区二区精品在线观看| 欧美在线一区二区| 中文字幕av不卡| 免费观看一级特黄欧美大片| 91麻豆精东视频| 国产日韩精品一区二区三区| 首页国产欧美久久| 一本色道久久综合亚洲aⅴ蜜桃 | 欧美大片在线观看| 一区二区三区产品免费精品久久75| 韩国在线一区二区| 欧美乱妇23p| 一区二区三区在线不卡| 成人性生交大片| 精品久久免费看| 日韩电影一区二区三区四区| 欧洲中文字幕精品| 樱花草国产18久久久久| www.欧美.com| 中文字幕不卡的av| 国产成人精品影视| 久久综合九色综合97婷婷| 亚洲第一电影网| 欧美日韩精品电影| 一区二区三区.www| 在线亚洲一区观看| 一区二区三区在线看| 99精品黄色片免费大全| 中文字幕制服丝袜一区二区三区| 国产成人午夜视频| 国产精品日韩成人| av成人动漫在线观看| |精品福利一区二区三区| 成人动漫一区二区三区| 中文字幕乱码久久午夜不卡| 国产激情视频一区二区三区欧美 | 国产喂奶挤奶一区二区三区| 久热成人在线视频| 精品国产乱码久久| 国产一区二区在线观看免费 | 国产精品久久久久婷婷| 99久久精品国产麻豆演员表| 国产精品国产成人国产三级 | 欧美丝袜自拍制服另类| 午夜欧美大尺度福利影院在线看| 欧美日韩国产电影| 青青草91视频| 久久久久久久网| av欧美精品.com| 亚洲另类在线制服丝袜| 欧美午夜电影网| 美女视频免费一区| 久久久国产精华| 91在线高清观看| 日精品一区二区三区| 欧美变态tickling挠脚心| 国产一区二区91| 亚洲欧美日本韩国| 制服.丝袜.亚洲.中文.综合| 久久丁香综合五月国产三级网站| 精品国精品国产尤物美女| 国产99久久久精品| 亚洲国产中文字幕在线视频综合 | 91在线观看美女| 午夜成人免费电影| 国产欧美综合在线| 91福利视频网站| 韩国中文字幕2020精品| 亚洲精品午夜久久久| 日韩欧美国产午夜精品| 99久久99精品久久久久久 | 日本一区二区三区四区在线视频| 色视频一区二区| 韩国视频一区二区| 亚洲一区二区三区四区的| 久久久综合视频| 337p亚洲精品色噜噜狠狠| 国产aⅴ精品一区二区三区色成熟| 一区二区在线免费| 国产性色一区二区| 日韩视频免费直播| 一本到三区不卡视频| 韩国精品在线观看| 日韩精品亚洲一区| 亚洲精品五月天| 国产精品欧美精品| 精品国产一区a| 欧美高清dvd| 91成人在线精品| 成人av网站大全| 国产高清不卡一区| 美女一区二区三区| 天天综合日日夜夜精品| 亚洲男人的天堂网| 亚洲欧美综合网| 日本一区二区三区在线观看| 日韩精品专区在线影院观看| 欧美日韩免费在线视频| 色菇凉天天综合网| av成人老司机| av资源网一区| 成人免费毛片片v| 国产精品一二三四五| 精品一区精品二区高清| 同产精品九九九| 亚洲妇熟xx妇色黄| 亚洲一卡二卡三卡四卡五卡| 亚洲精品中文字幕在线观看| 国产精品剧情在线亚洲| 日本一区二区在线不卡| 久久精品一区二区三区不卡牛牛| 久久日韩粉嫩一区二区三区| 精品噜噜噜噜久久久久久久久试看| 欧美日韩在线免费视频| 欧美日本一区二区三区| 欧美一区二区视频在线观看2020| 91精品一区二区三区久久久久久| 4438成人网| 久久精品视频免费观看| 国产精品视频yy9299一区| 国产精品蜜臀在线观看| 亚洲欧美激情插| 日韩国产高清在线| 国产美女精品人人做人人爽 | 一二三区精品视频| 成人精品视频网站| 色综合咪咪久久| 欧美日本国产视频| 久久视频一区二区| 亚洲精品视频在线观看网站| 日韩av一区二区三区四区| 国产在线观看免费一区| 91一区在线观看| 欧美一区二区日韩一区二区| 久久精品网站免费观看| 亚洲综合999| 国产精品自拍一区| 99视频精品全部免费在线| 色天天综合色天天久久| 成人av影院在线| 欧美二区在线观看| 欧美成人欧美edvon| 1000部国产精品成人观看| 亚洲一区二区成人在线观看| 亚洲精品国产第一综合99久久| 青青青伊人色综合久久| 国产精品一区二区无线| 久久爱另类一区二区小说| 成人aa视频在线观看| 欧美日韩在线播放一区| 久久久99精品久久| 一区二区三区小说| 久久99久久精品|