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

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

?? arp.c

?? 工業以太網測控用戶系統
?? C
字號:
//-----------------------------------------------------------------------------
// 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);
	}
}


?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产亚洲欧美激情| 欧美一区二区免费| 国产成人在线观看| 国产揄拍国内精品对白| 看电视剧不卡顿的网站| 久久99精品国产麻豆婷婷洗澡| 开心九九激情九九欧美日韩精美视频电影 | 风间由美一区二区三区在线观看| 久久99国产精品麻豆| 国产老肥熟一区二区三区| 国产一区二区在线电影| 丁香桃色午夜亚洲一区二区三区| 国产麻豆精品在线观看| 成人a级免费电影| 欧洲精品视频在线观看| 制服丝袜激情欧洲亚洲| 精品久久国产字幕高潮| 国产日韩综合av| 一区二区三区中文字幕| 日本成人超碰在线观看| 韩国一区二区三区| 97久久精品人人澡人人爽| 欧美日韩一区二区电影| 精品粉嫩aⅴ一区二区三区四区| 久久久久久久久97黄色工厂| 亚洲男人的天堂网| 日本在线播放一区二区三区| 国产精品一区2区| 欧美自拍丝袜亚洲| 久久久久久久综合日本| 亚洲精品乱码久久久久久日本蜜臀| 亚洲h动漫在线| 国产高清精品网站| 欧美日韩国产一级| 国产色爱av资源综合区| 亚洲高清免费一级二级三级| 国产在线日韩欧美| 欧美综合一区二区| 国产欧美一区二区精品久导航 | 国产性做久久久久久| 亚洲免费观看高清完整版在线观看熊| 麻豆精品在线看| 色婷婷亚洲一区二区三区| 欧美刺激脚交jootjob| 亚洲精品中文在线| 国产老肥熟一区二区三区| 欧美日本在线一区| 综合久久综合久久| 粉嫩绯色av一区二区在线观看| 欧美日韩国产综合久久| 中文字幕一区二区三中文字幕| 蜜臀av一区二区| 欧美亚男人的天堂| 亚洲免费视频成人| 懂色av一区二区三区蜜臀| 日韩欧美国产1| 丝袜美腿亚洲色图| 欧美性生活久久| 亚洲欧美偷拍另类a∨色屁股| 国产精品18久久久久久vr| 91精品国产色综合久久ai换脸| 亚洲一区二区欧美激情| 91小视频免费观看| 一区视频在线播放| 成人小视频在线| 国产精品无圣光一区二区| 国内久久精品视频| 久久蜜桃av一区二区天堂| 激情综合网最新| 精品国产污污免费网站入口 | 一本色道久久综合狠狠躁的推荐| 国产日产欧美精品一区二区三区| 久久99国产精品久久99| 精品日韩一区二区三区免费视频| 日日摸夜夜添夜夜添精品视频| 精品视频一区三区九区| 亚洲自拍另类综合| 在线观看av不卡| 午夜电影一区二区三区| 91精品国产综合久久国产大片| 午夜在线成人av| 91精品国产高清一区二区三区 | 一区二区三区四区亚洲| 色吊一区二区三区| 亚洲成人动漫精品| 91精品国产色综合久久| 狠狠色伊人亚洲综合成人| 国产色爱av资源综合区| aa级大片欧美| 亚洲国产你懂的| 精品久久久久久久久久久久久久久久久 | 日韩理论片在线| 欧美无乱码久久久免费午夜一区| 亚洲最大的成人av| 欧美一区二区高清| 国产精品69久久久久水密桃| 中文字幕日本乱码精品影院| 色狠狠综合天天综合综合| 日本特黄久久久高潮| 久久精品网站免费观看| 色婷婷久久久综合中文字幕| 日韩激情视频网站| 久久精品视频免费观看| 91热门视频在线观看| 日韩影院精彩在线| 中文一区二区在线观看| 在线一区二区三区做爰视频网站| 日韩二区三区四区| 欧美国产日韩精品免费观看| 91福利精品第一导航| 久久91精品久久久久久秒播| 中文字幕一区二区三区色视频| 欧美日韩小视频| 成人激情视频网站| 久久精品国产免费| 一区二区三区在线看| 精品国产一区久久| 在线观看欧美黄色| 国产黄色精品网站| 奇米色一区二区| 亚洲精选视频免费看| 亚洲精品一区二区三区福利| 在线看国产一区二区| 国产精品亚洲第一区在线暖暖韩国 | 亚洲免费av在线| 久久先锋影音av鲁色资源网| 欧美在线一二三四区| 国产91丝袜在线18| 欧美a一区二区| 亚洲一区在线免费观看| 欧美国产国产综合| 久久久久国产精品人| 日韩精品综合一本久道在线视频| 91麻豆国产精品久久| 国产成人av电影在线观看| 麻豆国产欧美日韩综合精品二区 | 国产 日韩 欧美大片| 日韩黄色免费网站| 五月婷婷欧美视频| 一区二区三区欧美亚洲| 中文字幕一区二区不卡| 久久久久久久综合日本| 精品久久久久久久久久久院品网| 这里只有精品视频在线观看| 色婷婷综合久久久| 91国产精品成人| 色成年激情久久综合| 色老综合老女人久久久| 91视频观看视频| 91玉足脚交白嫩脚丫在线播放| 国产二区国产一区在线观看| 激情五月激情综合网| 久草这里只有精品视频| 免费成人你懂的| 久久99日本精品| 国产精品一区三区| 丁香五精品蜜臀久久久久99网站 | 欧美在线观看一区二区| 99re热视频这里只精品| 色94色欧美sute亚洲线路二| 欧美日韩一区二区在线观看视频 | 欧美精品一区二区在线播放| 精品国产一区二区三区四区四| 精品日韩一区二区三区| 国产亚洲一区二区在线观看| 欧美国产精品v| 亚洲激情自拍视频| 日韩中文字幕麻豆| 久久国产乱子精品免费女| 国模套图日韩精品一区二区| 成人精品视频一区二区三区尤物| 91在线码无精品| 91精品久久久久久久91蜜桃| 日韩欧美第一区| 国产精品欧美一级免费| 亚洲免费观看高清完整版在线 | 久久久www成人免费无遮挡大片| 久久精品欧美一区二区三区不卡 | 久久电影网站中文字幕| 成人爽a毛片一区二区免费| 91在线观看成人| 日韩一区国产二区欧美三区| 国产女同性恋一区二区| 一二三四区精品视频| 激情成人综合网| 欧美性感一类影片在线播放| 精品区一区二区| 亚洲男人电影天堂| 精品一区二区在线观看| 97精品国产露脸对白| 日韩视频中午一区| 亚洲欧美在线另类| 经典三级一区二区| 欧美日韩国产在线播放网站| 国产欧美精品一区二区色综合| 午夜精品福利一区二区三区蜜桃| 成人免费不卡视频| 精品久久久久香蕉网| 一区二区国产盗摄色噜噜| 国产精品一区二区x88av|