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

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

?? ip.c

?? 用于以太網開發
?? C
?? 第 1 頁 / 共 2 頁
字號:

/** \file ip.c
 *	\brief OpenTCP IP protocol implementation
 *	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *		\li Vladan Jovanovic (vladan.jovanovic@violasystems.com)
 *	\version 1.0
 *	\date 11.6.2002
 *	\bug
 *	\warning
 *	\todo 
 *		\li Implement stub handler for supporting fragmented datagrams (
 *		may be usefull on MCUs with lots of available RAM)
 *  
 *	OpenTCP IP protocol implementation functions. For declaration,
 *	constants and data structures refer to ip.h.
 */

/*
 *Copyright (c) 2000-2002 Viola Systems Ltd.
 *All rights reserved.
 *
 *Redistribution and use in source and binary forms, with or without 
 *modification, are permitted provided that the following conditions 
 *are met:
 *
 *1. Redistributions of source code must retain the above copyright 
 *notice, this list of conditions and the following disclaimer.
 *
 *2. Redistributions in binary form must reproduce the above copyright 
 *notice, this list of conditions and the following disclaimer in the 
 *documentation and/or other materials provided with the distribution.
 *
 *3. The end-user documentation included with the redistribution, if 
 *any, must include the following acknowledgment:
 *	"This product includes software developed by Viola 
 *	Systems (http://www.violasystems.com/)."
 *
 *Alternately, this acknowledgment may appear in the software itself, 
 *if and wherever such third-party acknowledgments normally appear.
 *
 *4. The names "OpenTCP" and "Viola Systems" must not be used to 
 *endorse or promote products derived from this software without prior 
 *written permission. For written permission, please contact 
 *opentcp@opentcp.org.
 *
 *5. Products derived from this software may not be called "OpenTCP", 
 *nor may "OpenTCP" appear in their name, without prior written 
 *permission of the Viola Systems Ltd.
 *
 *THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 
 *WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
 *IN NO EVENT SHALL VIOLA SYSTEMS LTD. OR ITS CONTRIBUTORS BE LIABLE 
 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 *CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
 *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
 *WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 *OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
 *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *====================================================================
 *
 *OpenTCP is the unified open source TCP/IP stack available on a series 
 *of 8/16-bit microcontrollers, please see <http://www.opentcp.org>.
 *
 *For more information on how to network-enable your devices, or how to 
 *obtain commercial technical support for OpenTCP, please see 
 *<http://www.violasystems.com/>.
 */


#include <debug.h>
#include <datatypes.h>
#include <ethernet.h>
#include <arp.h>
#include <ip.h>
#include <system.h>


/**	\brief Used for storing various information about the incoming IP packet
 *	
 *	Various fields from the IP packet are stored in this structure. These
 *	values are later used from other upper layer protocols (ICMP, UDP, TCP
 *	and possibly others) to extract needed information about the received
 *	packet. See ip_frame definition for struct information.
 */
struct ip_frame received_ip_packet;

/**	\brief Used for storing various information about the outgoing IP packet
 *	
 *	Various fields from the IP packet are stored in this structure. These
 *	values are filled based on the information supplied by the upper 
 * 	layer protocols (ICMP, UDP, TCP and possibly others) and used to form
 *	a correct IP packet (correct filed values, checksum,..). See ip_frame
 *	definition for struct information.
 */
struct ip_frame send_ip_packet;

UINT16 ip_id;	/**< ID field in the next IP packet that will be sent */

/** \brief Process received IP frame
 *	\ingroup periodic_functions
 * 	\author 
 *		\li Jari Lahti
 *	\date 11.06.2002
 *	\param frame pointer to ethernet_frame structure holding information
 *		about the received frame that carries IP datagram.
 *	\return
 *		\li -1 - IP packet not OK
 *		\li >0 - Length of next layer data (IP packet OK)
 *
 *	Process received IP packet by checking necessary header information
 *	and storing it accordingly to received_ip_packet variable. If everything
 *	checks out, return length of the data carried in the IP datagram (for
 *	higher-level protocols), otherwise return -1.
 */
INT16 process_ip_in (struct ethernet_frame* frame)
{

	UINT8 olen;
	UINT8 i;
	
	/* Check for Protocol								*/
	
	IP_DEBUGOUT("Checking if IP Protocol\n\r");
	
	if( frame->protocol != PROTOCOL_IP )
		return(-1);
		
	IP_DEBUGOUT("It's IP\n\r");
	
	if( frame->frame_size < ETH_HEADER_LEN )
		return(-1);
		
	if( (frame->frame_size - ETH_HEADER_LEN) < IP_HLEN )
		return(-1); 
				
	/* Get IP Header Information						*/
		
	NETWORK_RECEIVE_INITIALIZE(frame->buf_index);
		
	received_ip_packet.vihl = RECEIVE_NETWORK_B();
		
	/* Is it IPv4?	*/
		
	if( (received_ip_packet.vihl & 0xF0) != 0x40 ) {
		IP_DEBUGOUT("ERROR: IP is not version 4!\n\r");
		return(-1);
	}
		
	IP_DEBUGOUT("IP Version 4 OK!\n\r");	
		
	received_ip_packet.tos      = RECEIVE_NETWORK_B();						
	received_ip_packet.tlen     = RECEIVE_NETWORK_W();		
	received_ip_packet.id       = RECEIVE_NETWORK_W();		
	received_ip_packet.frags    = RECEIVE_NETWORK_W();
	received_ip_packet.ttl      = RECEIVE_NETWORK_B();	
	received_ip_packet.protocol = RECEIVE_NETWORK_B();		
	received_ip_packet.checksum = RECEIVE_NETWORK_W();

	received_ip_packet.sip = (((UINT32)RECEIVE_NETWORK_B()) << 24);
	received_ip_packet.sip |= (((UINT32)RECEIVE_NETWORK_B()) << 16);
	received_ip_packet.sip |= (((UINT32)RECEIVE_NETWORK_B()) << 8);
	received_ip_packet.sip |= RECEIVE_NETWORK_B();
		
	received_ip_packet.dip = (((UINT32)RECEIVE_NETWORK_B()) << 24);
	received_ip_packet.dip |= (((UINT32)RECEIVE_NETWORK_B()) << 16);
	received_ip_packet.dip |= (((UINT32)RECEIVE_NETWORK_B()) << 8);
	received_ip_packet.dip |= RECEIVE_NETWORK_B();

	/* Is that packet for us?			*/
	if((received_ip_packet.dip != localmachine.localip )&&
		(received_ip_packet.dip != IP_BROADCAST_ADDRESS)) 
		{

		/* It's not for us. Check still if ICMP with rigth physical	*/
		/* address that migth be used to set temporary IP			*/
		
		IP_DEBUGOUT("IP address does not match!\n\r");
		
		if( received_ip_packet.protocol != IP_ICMP) 
			return(-1);
			
		/* Check physical address			*/
		
		for(i=0; i<PHY_ADR_LEN; i++)
		{
			if(frame->destination[i] != localmachine.localHW[i])
				return(-1);
		}	

	}
	
	
	/* Is there options to copy?		*/
		
	olen = ((received_ip_packet.vihl & 0x0F) << 2) - IP_MIN_HLEN;
	
	/* Somebody bluffing with too long option field?	*/
	
	if(olen > MAX_IP_OPTLEN) {
		IP_DEBUGOUT("ERROR:Size of maximum allowed IP option lengt exceeded!\n\r");
		return(-1);
	}
	
	if( olen > (frame->frame_size - ETH_HEADER_LEN - IP_HLEN) )	{
		IP_DEBUGOUT("ERROR:IP option field too long!\n\r");
		return(-1);
	}
		
	for( i=0; i < olen; i++ ) {
		received_ip_packet.opt[i] = RECEIVE_NETWORK_B();	
		IP_DEBUGOUT("IP Options..\n\r");
	}
	
	if(received_ip_packet.tlen >  (frame->frame_size - ETH_HEADER_LEN) ) {
		IP_DEBUGOUT("ERROR: Total len too long\r\n");
		return(-1);
	}
	
	/* Is the checksum OK?	*/
	
	IP_DEBUGOUT("Validating the IP checksum..\n\r");
	
	if ( ip_check_cs(&received_ip_packet) != TRUE )	{
		IP_DEBUGOUT("IP Checksum Corrupted..\n\r");
		return(-1);
	}	
	
	IP_DEBUGOUT("..Checksum OK!\n\r");	
	
	/* Add the address to ARP cache	*/	
	if( received_ip_packet.sip != IP_BROADCAST_ADDRESS)
		arp_add( received_ip_packet.sip, &frame->source[0], ARP_TEMP_IP);
	
	/* Calculate the start of next layer data	*/	
	received_ip_packet.buf_index = frame->buf_index + IP_HLEN + olen;
	
	/* Is this packet fragmented?						*/
	/* We don't deal with those							*/
	/* TODO: Implement Stub handler for more mem. uP's	*/	
	if( received_ip_packet.frags & (IP_MOREFRAGS | IP_FRAGOFF) ) 
	{
		IP_DEBUGOUT("Fragmented IP packet\r\n");
		return(-1);
	}
	/* checking moved upwards!
	if( received_ip_packet.frags & IP_FRAGOFF )	{
		IP_DEBUGOUT("Fragmented IP packet\r\n");
		return(-1);
	}
	*/
	
	IP_DEBUGOUT("Leaving IP succesfully..\n\r");
	
	return(received_ip_packet.tlen - IP_HLEN - olen);
	
}

/** \brief Try to send out IP frame
 * 	\author 
 *		\li Jari Lahti
 *	\date 11.06.2002
 *	\param ipadr remote IP address
 *	\param pcol protocol over IP used. Can be one of the
 *		following:
 *		\li #IP_ICMP
 *		\li #IP_UDP
 *		\li #IP_TCP
 *	\param tos type of service required
 *	\param ttl time to live header field of IP packet
 *	\param dat pointer to data buffer
 *	\param len length of data to be sent in IP datagram
 *	\return
 *		\li -1 - general error
 *		\li -2 - ARP cache not ready
 *		\li >0 - number of data bytes sent (packet OK)
 *
 *	Invoke this function to perform all of the necessary preparation in
 *	order to send out an IP packet. These include:
 *		\li Consulting ARP cache for HW address to send the packet to
 *		\li Filling send_ip_packet variable with correct values
 *		\li Calculating checksum for the IP packet
 *		\li Adding datalink header information
 *		\li	Sending IP header and data
 *		\li Instructing NIC to send the data
 */
INT16 process_ip_out (UINT32 ipadr, UINT8 pcol, UINT8 tos, UINT8 ttl, UINT8* dat, UINT16 len)
{
	struct arp_entry *qstruct;
	UINT16 i;
	
	/* Try to get MAC address from ARP cache	*/
	

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本韩国欧美三级| 制服丝袜亚洲色图| 在线亚洲人成电影网站色www| 欧美精品一二三四| 亚洲欧洲三级电影| 久久爱另类一区二区小说| 欧美在线观看视频在线| 午夜精品福利一区二区蜜股av| 久草精品在线观看| 欧美一区二区视频在线观看2020 | 91视频在线观看| 日韩精品一区二区三区四区| 亚洲精品免费播放| 国产福利一区在线| 日韩视频一区二区三区在线播放| 亚洲人成网站在线| av在线播放一区二区三区| 日本一区二区三区视频视频| 另类中文字幕网| 91精品国产免费| 五月婷婷激情综合| 欧美精选一区二区| 五月婷婷色综合| 91精品国产入口在线| 亚洲第一二三四区| 欧美日韩一级视频| 亚洲一区二区av在线| 91免费观看国产| 中文字幕亚洲在| www.99精品| 亚洲免费观看在线观看| 99久久er热在这里只有精品15 | 欧美变态凌虐bdsm| 蜜臀av一区二区在线免费观看| 欧美色图第一页| 香蕉久久一区二区不卡无毒影院| 在线亚洲高清视频| 亚洲国产另类av| 欧美美女激情18p| 免费在线一区观看| 日本伊人精品一区二区三区观看方式 | 日韩福利视频导航| 日韩欧美一区在线| 国产一区二区91| 亚洲国产经典视频| 91美女片黄在线观看91美女| 亚洲免费av在线| 欧美日韩国产一级片| 秋霞av亚洲一区二区三| 欧美电视剧在线观看完整版| 国产大片一区二区| 亚洲欧美日韩人成在线播放| 欧日韩精品视频| 免费观看成人鲁鲁鲁鲁鲁视频| 337p日本欧洲亚洲大胆色噜噜| 国产一本一道久久香蕉| 国产精品你懂的在线| 色香蕉成人二区免费| 三级欧美在线一区| 久久午夜老司机| 色综合久久中文综合久久97 | 国产精品资源站在线| 亚洲品质自拍视频网站| 欧美人与性动xxxx| 国产精品99久久不卡二区| 亚洲欧美偷拍卡通变态| 欧美一二三四区在线| 成人午夜激情片| 日韩制服丝袜av| 国产精品你懂的| 91精品国产综合久久久蜜臀图片| 国产福利91精品一区二区三区| 亚洲夂夂婷婷色拍ww47| 一级日本不卡的影视| 欧美大胆人体bbbb| 91丨九色丨蝌蚪丨老版| 久久er精品视频| 亚洲妇熟xx妇色黄| 国产精品色一区二区三区| 欧美疯狂做受xxxx富婆| 国产不卡视频一区二区三区| 图片区小说区区亚洲影院| 国产欧美一区二区精品久导航| 欧美日本一区二区三区| 高清国产午夜精品久久久久久| 天天综合网天天综合色| 国产精品国产三级国产aⅴ中文| 4438成人网| 色屁屁一区二区| 粉嫩aⅴ一区二区三区四区| 日韩高清一级片| 亚洲一本大道在线| 亚洲特黄一级片| 国产精品成人在线观看| 精品国产麻豆免费人成网站| 欧美日韩精品欧美日韩精品一| 成人国产精品免费观看动漫| 精一区二区三区| 亚洲第一福利视频在线| 亚洲欧美电影院| 国产精品久久久久三级| 国产网站一区二区| 久久婷婷国产综合国色天香| 4hu四虎永久在线影院成人| 精品视频在线免费| 色综合一个色综合亚洲| www.99精品| 精品入口麻豆88视频| 91精品蜜臀在线一区尤物| 欧美三级电影网| 欧美日韩和欧美的一区二区| 色偷偷88欧美精品久久久| 一本一道久久a久久精品综合蜜臀| av动漫一区二区| 色综合久久综合网97色综合 | 亚洲www啪成人一区二区麻豆| 一区二区三区视频在线看| 亚洲欧美日韩一区二区三区在线观看| 欧美国产一区在线| 国产精品卡一卡二| 国产精品成人在线观看| 亚洲视频一区二区免费在线观看 | 日韩 欧美一区二区三区| 日日夜夜精品视频免费| 午夜电影网亚洲视频| 日本不卡高清视频| 精品一区二区免费视频| 激情图区综合网| 国产二区国产一区在线观看 | 国产乱国产乱300精品| 国产成人在线看| 色综合久久久久| 欧美妇女性影城| 精品国产91久久久久久久妲己| 久久久99久久| 亚洲欧美激情在线| 五月天一区二区三区| 久久精品国产一区二区| 黄色资源网久久资源365| 不卡高清视频专区| 一本一道波多野结衣一区二区| 欧美日韩黄视频| 欧美激情自拍偷拍| 亚洲高清不卡在线观看| 另类专区欧美蜜桃臀第一页| 成人av在线看| 欧美日韩不卡视频| 国产亚洲精久久久久久| 亚洲精品第1页| 韩日av一区二区| 色婷婷av一区| 久久久精品黄色| 亚洲第一av色| 国产aⅴ综合色| 欧美精三区欧美精三区| 久久精品一区二区| 亚洲国产一区视频| 国产河南妇女毛片精品久久久| 日本韩国欧美在线| 精品国产91久久久久久久妲己| 亚洲精品视频自拍| 国产精品中文字幕日韩精品| 在线观看成人小视频| 久久精品视频在线看| 午夜久久久影院| 99久久综合狠狠综合久久| 欧美一区二区三级| 亚洲精品精品亚洲| 国产精品一区2区| 91精品国产色综合久久| 亚洲伦在线观看| 懂色一区二区三区免费观看| 69精品人人人人| 亚洲制服丝袜av| 色综合天天综合网国产成人综合天| 欧美一区二区三区四区视频 | 国产一区二区三区香蕉| 制服丝袜日韩国产| 亚洲精品视频观看| 成人激情小说网站| 久久视频一区二区| 蜜臀av一区二区| 91.com视频| 香蕉影视欧美成人| 色94色欧美sute亚洲线路二| 国产精品视频一二三区| 国产一区二区免费在线| 日韩一级二级三级| 日日欢夜夜爽一区| 欧美性做爰猛烈叫床潮| 亚洲欧美偷拍三级| 色诱视频网站一区| 18欧美亚洲精品| 成人av网站在线观看| 中文一区二区在线观看| 国产一区二区久久| 久久精品欧美日韩精品| 国产麻豆日韩欧美久久| 国产亚洲一区二区三区四区 | 蜜桃91丨九色丨蝌蚪91桃色|