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

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

?? arp.c

?? 用于以太網開發
?? C
?? 第 1 頁 / 共 2 頁
字號:
#include <datatypes.h>
#include <debug.h>
#include <ethernet.h>
#include <arp.h>
#include <timers.h>
#include <system.h>
#include <globalvariables.h>

/** \brief ARP cache table holding ARP_TSIZE cache values 
 *
 *	ARP cache table is an array of arp_entry structures holding
 *	all of the necessary information about the state, timeouts and
 *	hardware/IP addresses of individual entries. By modifying the
 *	#ARP_TSIZE, cache size can be changed and thus RAM memory occupied
 *	by the ARP cache significantly reduced or increased. See arp_entry
 *	definition for more information about struct fields.
 */
struct arp_entry	arp_table[ARP_TSIZE]; 

/** \brief ARP timer handle used for measuring timeouts, doing retransmissions,..
 *	
 *	ARP module uses this timer handle to detect that a certain period of
 *	time has expired (defined by the value of #ARP_MANG_TOUT) and that
 *	cache entries should be examined to see what to do with them.
 */
UINT8 arp_timer; 

/** \brief Process and analyze the received ARP packet
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *	
 *	\date 10.07.2002
 *	\param frame Pointer to ethernet_frame structure containing information
 *		about the received frame
 *	\return Return #TRUE if Ethernet frame processed held ARP packet,
 *		otherwise #FALSE.
 *
 *	Invoke process_arp function whenever ARP packet is received 
 *	(see main_demo.c for an example loop). This function will process the
 *	received packet, analyze it'c content briefly and perform on of the
 *	two possible actions:
 *		\li If the received packet is ARP request it will invoke
 *		arp_send_reply in order to send ARP reply back
 *		\li If the received packet is ARP response it will iterate through
 *		the cache table and try to find ARP entry that is beeing resolved
 *		or refreshed
 */
UINT8 process_arp (struct ethernet_frame* frame) 
{
	
	UINT8 temp;		
	
	/* Check if ARP packet*/
	
	if( frame->protocol == ARP_ETHCODE ) 
	{
		/* Yep, ARP */
		
		NETWORK_RECEIVE_INITIALIZE(frame->buf_index);
		
		/* Is it long enough?	*/
		
		if( frame->frame_size < (2*MAXHWALEN + 2*MAXPRALEN + 2 + 6) ) 
		{
			/* Somehow corrupted ARP packet	*/
			ARP_DEBUGOUT("Corrupted ARP packet\n\r");
			return(TRUE);
		}
			 
		
		/* Ignore next 6 bytes: <HW type>, <Protocol type> */
		/* <HW address len> and <Protocol address len> 	   */
		
		for(temp=0; temp<6; temp++)
			RECEIVE_NETWORK_B();
		
		ARP_DEBUGOUT("Incoming ARP..\n\r");
		
		/* Check if request or response */
		
		if( RECEIVE_NETWORK_B() == 0x00) 
		{
		
			temp = RECEIVE_NETWORK_B();	/* get opcode */
		
			if( temp == ARP_REQUEST ) {
				ARP_DEBUGOUT(" ARP REQUEST Received..\n\r");
				arp_send_response();
			} else if( temp == ARP_REPLY ) {
				ARP_DEBUGOUT("ARP Response Received..\n\r");
				arp_get_response();	
			}
			
		/* Wasn't request or response or all done, dump it */
		
		}
		
		/*NETWORK_RECEIVE_END();*/
		return(TRUE);
		
	}
	
	/* Wasn't ARP, don't touch the packet */
	
	return(FALSE);								
}

/** \brief Send response to an ARP request
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *	\date 10.07.2002
 *	\warning
 *		\li This function starts reading data from Ethernet controller
 *		without initializing it for reading it first, so NIC must already
 *		be initialized for reading from correct address (it expects ar$sha
 *		field from ARP packet immediately)
 *
 *	This function is invoked from process_arp() function in order to send
 *	a reply to an ARP request. First, incoming packet is checked to see
 *	if it is intended for us or not. If not, function does not do anything.
 *	Otherwise, ARP reply packet is formed and sent.
 */
void arp_send_response(void)
{
	struct arp_entry *qstruct;
	UINT8 rem_hwadr[MAXHWALEN];
	UINT32 rem_ip;
	UINT32 ltemp;
	INT8 i;
	BYTE j;

	/* Record Sender's HW address		*/
	
	for( i=0; i<MAXHWALEN; i++) 
		rem_hwadr[i] = RECEIVE_NETWORK_B();		
	
	/* Read Sender's IP Address	*/
	
	for( i=0; i<MAXPRALEN; i++) {
		rem_ip <<= 8;
		rem_ip |= RECEIVE_NETWORK_B();
	} 
	
	
	/* Skip Target HW address		*/
	
	RECEIVE_NETWORK_B();
	RECEIVE_NETWORK_B();
	RECEIVE_NETWORK_B();
	RECEIVE_NETWORK_B();
	RECEIVE_NETWORK_B();
	RECEIVE_NETWORK_B();	
	
	/* Is The Packet For Us?	*/
	
	for( i=0; i<MAXPRALEN; i++) {
		ltemp <<= 8;
		ltemp |= RECEIVE_NETWORK_B();
	}
		
	
	if( ltemp != localmachine.localip ) 
		return;								/* No	*/

	ARP_DEBUGOUT("Preparing for ARP Reply\n\r");
	
	/* OK. Now send reply		*/
	
	NETWORK_SEND_INITIALIZE(ARP_BUFFER);
	
	/* Add datalink (Ethernet addresses) information	*/
	
	for( i=0; i<MAXHWALEN; i++)	{
		send_frame.destination[i] = rem_hwadr[i];
		send_frame.source[i] = localmachine.localHW[i];
	}
	
	send_frame.protocol = PROTOCOL_ARP;
	
	NETWORK_ADD_DATALINK(&send_frame);
	
	/* PUT ARP Data	*/
	
	SEND_NETWORK_B( (BYTE)(AR_HARDWARE>>8) );				/* Hardware Type	*/
	SEND_NETWORK_B( (BYTE)AR_HARDWARE );
	SEND_NETWORK_B(0x08);									/* Protocol Type	*/
	SEND_NETWORK_B(0x00);
	SEND_NETWORK_B(MAXHWALEN);								/* HW Adr Len		*/
	SEND_NETWORK_B(MAXPRALEN);								/* Protocol Adr. Len*/
	SEND_NETWORK_B( 0x00 );									/* ARP Opcode		*/	
	SEND_NETWORK_B( 0x02 );					
	SEND_NETWORK_B((UINT8)(localmachine.localHW[0]));		/* Address fields	*/
	SEND_NETWORK_B((UINT8)(localmachine.localHW[1]));
	SEND_NETWORK_B((UINT8)(localmachine.localHW[2]));
	SEND_NETWORK_B((UINT8)(localmachine.localHW[3]));
	SEND_NETWORK_B((UINT8)(localmachine.localHW[4]));
	SEND_NETWORK_B((UINT8)(localmachine.localHW[5]));

	SEND_NETWORK_B((UINT8)(localmachine.localip>>24));
	SEND_NETWORK_B((UINT8)(localmachine.localip>>16));
	SEND_NETWORK_B((UINT8)(localmachine.localip>>8));
	SEND_NETWORK_B((UINT8)(localmachine.localip));
	SEND_NETWORK_B((UINT8)rem_hwadr[0]);
	SEND_NETWORK_B((UINT8)rem_hwadr[1]);
	SEND_NETWORK_B((UINT8)rem_hwadr[2]);
	SEND_NETWORK_B((UINT8)rem_hwadr[3]);
	SEND_NETWORK_B((UINT8)rem_hwadr[4]);
	SEND_NETWORK_B((UINT8)rem_hwadr[5]);						
	SEND_NETWORK_B((UINT8)(rem_ip>>24));
	SEND_NETWORK_B((UINT8)(rem_ip>>16));
	SEND_NETWORK_B((UINT8)(rem_ip>>8));
	SEND_NETWORK_B((UINT8)rem_ip);
	
	NETWORK_COMPLETE_SEND(0x0040);		/* Send the packet	*/
	
	ARP_DEBUGOUT("ARP Reply Sent..\n\r");
	
	/* Add the Sender's info to cache because we can	*/
	
	arp_add(rem_ip, &send_frame.destination[0], ARP_TEMP_IP);
	
	return;
		
}


/** \brief Extract data from the received ARP packet
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *	\date 10.07.2002
 *	\warning
 *		\li This function starts reading data from Ethernet controller
 *		without initializing it for reading it first, so NIC must already
 *		be initialized for reading from correct address (it expects ar$sha
 *		field from ARP packet immediately)
 *
 *	This function is invoked from process_arp() function when ARP reply
 *	packet is detected. Basic checking is performed to see if the packet
 *	is intended for us, and if it is, ARP cache table is checked and 
 *	corresponding entry is refreshed (resolved).
 *
 */
void arp_get_response(void)
{
	struct arp_entry *qstruct;
	UINT8   rem_hwadr[MAXHWALEN];
	UINT32 	rem_ip = 0;
	UINT32 	ltemp  = 0;
	INT8    i;
	UINT8   j;
	
	/* Read Sender's HW address	*/
	
	for( i=0; i<MAXHWALEN; i++) 
		rem_hwadr[i] = RECEIVE_NETWORK_B();
		
	/* Read Sender's IP Address	*/
	
	for( i=0; i<MAXPRALEN; i++) 
	{
		rem_ip <<= 8;
		rem_ip |= RECEIVE_NETWORK_B();
	}
	
	
	/* Skip our HW Address	*/
	
	for(i=0; i<MAXHWALEN; i++)
		RECEIVE_NETWORK_B();
	
	
	/* Is The Packet For Us?	*/
	
	for( i=0; i<MAXPRALEN; i++)	
	{
		ltemp <<= 8;
		ltemp |= RECEIVE_NETWORK_B();
	}
		
	
	if( ltemp != localmachine.localip ) 
		return;								/* No	*/

	ARP_DEBUGOUT("Now entering to process ARP Reply..\n\r");
	
	/* Are we waiting for that reply?	*/
	
	for( i=1; i<ARP_TSIZE; i++ ) 
	{
		qstruct = &arp_table[i];
		
		if( qstruct->state == ARP_FREE )
			continue;
		
		if( qstruct->state == ARP_RESERVED )
			continue;				
		
		if( rem_ip == qstruct->pradr ) 
		{
			/* We are caching that IP, refresh it	*/
			
			ARP_DEBUGOUT("Refreshing ARP cache from Reply..\n\r");
			
			for( j=0; j<MAXHWALEN; j++ )		
				qstruct->hwadr[j] = rem_hwadr[j];
				
			qstruct->ttl = ARP_TIMEOUT;
			qstruct->retries = ARP_MAXRETRY;				/* No need for Retry	*/
			qstruct->state = ARP_RESOLVED;
		
			/* Done	*/
			
			break;
		}	
	
	}

}

/** \brief Send ARP request based on information in an ARP cache table
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *	\date 1.11.2001
 *	\param entry Index of ARP cache entry that is beeing resolved
 * 
 *	Invoked from arp_find() and arp_manage() functions, arp_send_request
 *	creates ARP request packet based on data stored in the ARP cache entry
 *	who's index is given as a parameter.
 */
void arp_send_req (UINT8 entry)
{

	struct arp_entry *qstruct;
	UINT8 i;
	
	qstruct = &arp_table[entry];
	
	NETWORK_SEND_INITIALIZE(ARP_BUFFER);
	
	/* Add datalink (Ethernet addresses) information	*/
	
	for( i=0; i<MAXHWALEN; i++) {
		send_frame.destination[i] = 0xFF;
		send_frame.source[i] = localmachine.localHW[i];
		
	}
	
	
	
	send_frame.protocol = PROTOCOL_ARP;
	
	NETWORK_ADD_DATALINK(&send_frame);
	
	/* PUT ARP Data	*/

	SEND_NETWORK_B( (BYTE) (AR_HARDWARE>>8) );			/* Hardware Type	*/
	SEND_NETWORK_B( (BYTE) AR_HARDWARE );
	SEND_NETWORK_B(0x08);								/* Protocol Type	*/
	SEND_NETWORK_B(0x00);
	SEND_NETWORK_B(MAXHWALEN);							/* HW Adr Len		*/
	SEND_NETWORK_B(MAXPRALEN);							/* Protocol Adr. Len*/
	SEND_NETWORK_B( (BYTE)(ARP_REQUEST>>8));			/* ARP Opcode		*/
	SEND_NETWORK_B( (BYTE) ARP_REQUEST );
	
	SEND_NETWORK_B((UINT8)localmachine.localHW[0]);		
	SEND_NETWORK_B((UINT8)localmachine.localHW[1]);
	SEND_NETWORK_B((UINT8)localmachine.localHW[2]);
	SEND_NETWORK_B((UINT8)localmachine.localHW[3]);
	SEND_NETWORK_B((UINT8)localmachine.localHW[4]);
	SEND_NETWORK_B((UINT8)localmachine.localHW[5]);	
	
	SEND_NETWORK_B((UINT8)(localmachine.localip>>24));
	SEND_NETWORK_B((UINT8)(localmachine.localip>>16));
	SEND_NETWORK_B((UINT8)(localmachine.localip>>8));
	SEND_NETWORK_B((UINT8)localmachine.localip);
	SEND_NETWORK_B((UINT8)0xFF);
	SEND_NETWORK_B((UINT8)0xFF);
	SEND_NETWORK_B((UINT8)0xFF);
	SEND_NETWORK_B((UINT8)0xFF);
	SEND_NETWORK_B((UINT8)0xFF);
	SEND_NETWORK_B((UINT8)0xFF);						
	SEND_NETWORK_B((UINT8)(qstruct->pradr>>24));
	SEND_NETWORK_B((UINT8)(qstruct->pradr>>16));
	SEND_NETWORK_B((UINT8)(qstruct->pradr>>8));
	SEND_NETWORK_B((UINT8)qstruct->pradr);
	
	
	/* Packet assembled now, just send it ... */
	
	NETWORK_COMPLETE_SEND(0x0040);						/* Min packet size	*/
 
 	ARP_DEBUGOUT("ARP Request Sent\n\r");
	
}


/** \brief Allocate ARP entry in ARP cache table
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *	\date 1.11.2001
 *	\param type Type of ARP cache entry beeing allocated. Can be one of the
 *		following:
 *		\li #ARP_FIXED_IP
 *		\li #ARP_TEMP_IP 
 *	\return >=0 - pointer to allocated ARP entry (actaully index in the 
 *		ARP cache table)
 * 
 *	Allocate arp entry for given type. Chooses the unused entry if 
 *	one exists. Otherwice deletes entries in round-robin fashion.
 */
INT8 arp_alloc (UINT8 type)
{
	struct arp_entry *qstruct;
	INT8 i;
	static BYTE aenext = 1;		/* Cache Manager	*/
	INT16 found;
	
	/* try to find free entry */
	found=-1;

	for( i=0; i<ARP_TSIZE; i++ ) {
	
		if( arp_table[i].state == ARP_FREE ) {
			found=i;
			break;
		}
	}
	
	if(found != (-1) ) {
		qstruct = &arp_table[found];
		qstruct->state = ARP_RESERVED;
		qstruct->type = type;	
		return( (UINT8)found );
	}


	/* if no success, try ro find first temporary entry	*/
	/* on round-robin fashion							*/
	

	for( i=0; i<ARP_TSIZE; i++ ) {	
		if( arp_table[aenext].type == ARP_TEMP_IP) {
			found = aenext;			
			break;
		}
			
		/* Move to next entry */
	
		aenext = (aenext + 1);
		if( aenext >= ARP_TSIZE )
			aenext = 1;
			
	}
	
	
	/* Was there free or temporary entries?	*/
	
	if( found == (-1) )
		return(-1);
		

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久综合av免费| 麻豆传媒一区二区三区| 午夜视频一区在线观看| 国产老妇另类xxxxx| 欧美日韩国产在线播放网站| 国产日韩欧美精品电影三级在线| 丝袜亚洲精品中文字幕一区| 暴力调教一区二区三区| 久久午夜羞羞影院免费观看| 男人的天堂亚洲一区| 91蝌蚪porny| 国产精品美女久久久久久 | 欧美xxxxxxxx| 亚洲sss视频在线视频| 99精品国产91久久久久久| 久久久一区二区| 精品一区二区三区不卡| 欧美日韩你懂得| 亚洲宅男天堂在线观看无病毒| 丁香一区二区三区| 日本一区二区在线不卡| 国产98色在线|日韩| 久久综合久久综合久久综合| 日韩精品电影在线| 欧美日韩视频不卡| 亚洲一区在线观看视频| 色呦呦一区二区三区| 国产精品电影一区二区| 成人久久18免费网站麻豆| 精品久久国产老人久久综合| 另类欧美日韩国产在线| 精品剧情在线观看| 激情综合色播五月| 欧美精品一区二区三区在线播放| 日本成人在线电影网| 欧美一区二区三区日韩视频| 日本中文字幕一区二区有限公司| 777久久久精品| 精品影视av免费| 久久久久国产一区二区三区四区| 国产精品66部| 亚洲欧洲精品成人久久奇米网| 91丨porny丨中文| 亚洲永久精品国产| 欧美丰满一区二区免费视频| 毛片av中文字幕一区二区| 欧美v日韩v国产v| 国产91在线看| 亚洲国产一区二区三区| 欧美一区二视频| 精品一区二区三区在线播放| 国产午夜精品久久久久久免费视 | 日韩影院在线观看| 日韩欧美色电影| 国产高清在线观看免费不卡| 国产精品大尺度| 欧美色老头old∨ideo| 蜜臀av性久久久久av蜜臀妖精| 久久久亚洲精品石原莉奈| heyzo一本久久综合| 亚洲va在线va天堂| 久久美女艺术照精彩视频福利播放| 99国产精品国产精品久久| 日韩黄色一级片| 中文字幕 久热精品 视频在线| 欧美色视频在线观看| 国产麻豆日韩欧美久久| 一区二区三区日韩欧美精品 | 国产人久久人人人人爽| 在线日韩av片| 国产成人精品aa毛片| 亚洲成av人片| 最近日韩中文字幕| 精品三级在线看| 日本韩国一区二区三区| 国产一区二区精品久久91| 亚洲一区日韩精品中文字幕| 久久嫩草精品久久久精品一| 在线观看国产91| 国产91富婆露脸刺激对白| 日韩国产精品久久久久久亚洲| 国产精品久久久久久久午夜片| 日韩一卡二卡三卡| 一本色道综合亚洲| 成人教育av在线| 久久99精品久久久久| 午夜不卡在线视频| 一区二区三区中文字幕电影| 欧美韩国一区二区| 精品久久久久久久一区二区蜜臀| 欧美日本一道本| 91在线观看视频| 成人黄色一级视频| 国产伦理精品不卡| 黄页视频在线91| 七七婷婷婷婷精品国产| 日韩在线卡一卡二| 亚洲在线视频免费观看| 国产精品久久久爽爽爽麻豆色哟哟 | 国产盗摄视频一区二区三区| 日韩不卡一区二区| 亚洲香肠在线观看| 一级日本不卡的影视| 亚洲视频免费在线观看| 国产精品免费久久| 国产日本一区二区| 国产女人aaa级久久久级| 国产欧美一区二区精品婷婷| 久久这里都是精品| 欧美精品一区二区三区在线播放| 日韩精品一区二区三区视频 | 欧美无砖砖区免费| 91视频91自| 91蜜桃免费观看视频| av中文字幕亚洲| 色吊一区二区三区| 欧美午夜一区二区三区| 欧美精选午夜久久久乱码6080| 欧美性受xxxx| 欧美电影一区二区三区| 91精品国产一区二区三区蜜臀 | 国产精品人妖ts系列视频| 国产清纯美女被跳蛋高潮一区二区久久w | 国产91精品免费| 国产成人av电影在线观看| 成人黄色在线网站| 91免费视频网| 欧美一区二区三区在线观看视频| 3751色影院一区二区三区| 欧美电影免费观看高清完整版在线| 欧美一区二区不卡视频| 26uuu久久综合| 国产女人aaa级久久久级| 亚洲激情成人在线| 亚洲成国产人片在线观看| 麻豆精品一区二区三区| 成人影视亚洲图片在线| 在线观看一区二区精品视频| 日韩亚洲欧美在线| 中文字幕乱码亚洲精品一区| 亚洲精品视频免费观看| 喷水一区二区三区| 成人av在线播放网站| 欧美日韩国产综合一区二区| 精品国产一区a| 亚洲视频在线观看三级| 天堂久久一区二区三区| 国产寡妇亲子伦一区二区| 欧美在线高清视频| 精品国精品国产| 亚洲日本护士毛茸茸| 久色婷婷小香蕉久久| av电影一区二区| 欧美精品v国产精品v日韩精品| 国产无人区一区二区三区| 亚洲美腿欧美偷拍| 免费成人在线网站| 色综合天天性综合| 欧美www视频| 国产精品一区二区视频| 欧美怡红院视频| 久久久久久久久久久久电影| 亚洲一二三四在线| 大白屁股一区二区视频| 日韩视频国产视频| 国产一区二区三区在线观看免费 | 欧美va天堂va视频va在线| 亚洲免费观看高清完整版在线观看| 久久不见久久见中文字幕免费| 91久久精品一区二区三区| 国产日本欧洲亚洲| 久久精品国产99久久6| 欧美日韩另类一区| 国产精品国产自产拍在线| 国产露脸91国语对白| 日韩精品中文字幕一区| 亚洲成人精品影院| 在线观看日韩av先锋影音电影院| 国产欧美日本一区视频| 精品一区二区久久| 日韩三级精品电影久久久 | 欧美日韩国产一级二级| 中文字幕一区二区三| 夫妻av一区二区| 久久久综合网站| 精品一区二区综合| 制服丝袜av成人在线看| 午夜久久电影网| 欧美视频一区二区三区在线观看| 国产精品精品国产色婷婷| 国产福利电影一区二区三区| 精品国产三级a在线观看| 日本不卡一区二区| 91精品国产综合久久婷婷香蕉| 亚洲一区视频在线| 欧美日韩国产免费| 日韩制服丝袜av| 日韩一区二区麻豆国产| 精品综合久久久久久8888| 精品国产乱码久久久久久闺蜜|