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

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

?? dhcpc.c

?? 在freescale 的ne64上開(kāi)發(fā)的源代碼
?? C
?? 第 1 頁(yè) / 共 2 頁(yè)
字號(hào):
/*
 *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/>.
 */

/** \file dhcpc.c
 *	\brief OpenTCP DHCP client implementation
 *	\author
 *		\li Vladan Jovanovic (vladan.jovanovic@violasystems.com)
 *	\version 1.03
 *	\date 23.5.2003
 *	\bug
 *	\warning
 *	\todo
 *		\li	We SHOULD first test (with PING or ARP) assigned IP
 *		address to see if it's in use already.
 *
 *	OpenTCP DHCP client protocol implementation. Features a complete
 * 	DHCP state machine. Function declarations can be found in dhcpc.h
 */

#include"datatypes.h"
#include"debug.h"
#include"system.h"
#include"tcp_ip.h"

#ifdef DHCPC_WANTED

#include"timers.h"
#include"dhcpc.h"

/** \brief Holds DHCP clients' state information
 *
 *	This variable holds DHCP clients' current state information. Possible
 *  states are DHCP_STATE_INIT_REBOOT, DHCP_STATE_REBOOTING,
 *	DHCP_STATE_INIT, DHCP_STATE_SELECTING, DHCP_STATE_REQUESTING,
 *	DHCP_STATE_BOUND, DHCP_STATE_RENEWING, DHCP_STATE_REBINDING.
 */
UINT8 dhcpc_state;

/** \brief DHCP client's timer handle
 *
 *	Hold DHCP clients' timer handle. We'll use only one timer from
 *	timer pool and take care of the rest by ourselves manually
 */
UINT8 dhcpc_timer_handle;

/** \brief DHCP client's UDP socket handle
 *
 *	DHCP client's UDP socket handle
 */
INT8 dhcpc_soc_handle;

/** \brief Holds information if DHCP client is initialized
 *
 *	Holds information if DHCP client is initialized
 */
UINT8	dhcpc_initialized=0;

/** \brief DHCP renew timer
 *
 *	This variable holds renew time (in seconds) after which we'll
 *  start the renewing process. While obtaining the parameters from
 * 	DHCP server (thus before we know of the renew time) this is
 *	used also to time retransmissions.
 */
UINT32 dhcpc_t1;

/** \brief DHCP rebind timer
 *
 *	This variable holds rebind time (in seconds) after which we'll
 *	start the rebinding process. While obtaining the paramters from
 * 	DHCP server (thus before we know of the renew time) this is
 *  also used to time retransmissions as well as timeout detection
 */
UINT32 dhcpc_t2;

/** \brief DHCP server identifier as received from DHCP server
 *
 *	This variable will hold DHCP server identifier (which will actually
 *	be server's IP address).
 */
UINT32 dhcpc_server_identifier;

/** \brief Holds offered IP address or IP address that we're requesting
 *
 *	This variable holds the IP address that DHCP server offered to us
 *	during address request procedure and this is the address that we
 *	will be requesting in all future requests untill DHCP server
 *	disallows us to use it any more.
 */
UINT32 dhcpc_requested_ip;

INT32 dhcpc_eventlistener(INT8 cbhandle, UINT8 event, UINT32 ipaddr, UINT16 port, UINT16 buffindex, UINT16 datalen);
INT8 dhcpc_send_message(UINT8 msg_type);

/** \brief Initializes DHCP client
 * 	\author
 *		\li Vladan Jovanovic (vladan.jovanovic@violasystems.com)
 *	\date 23.05.2003
 *
 *	This function should be called once when system starts to initialize
 *	and start DHCP client. Before this function is invoked,
 *	localmachine.localip MUST be se to either zero (in which case DHCP
 *	client will request any IP address) or a previously assigned IP
 *	address (which doesn't mean DHCP server will allow us to continue
 *	using this address) in which case DHCP client will first try to
 *	obtain that existing IP address.
 */
INT8 dhcpc_init(void)
{

	/* If we already have some IP address (stored from some previous
	 * requests, try obtaining it again */
	if((localmachine.localip!=0)&&(localmachine.localip!=0xffffffff)){
		dhcpc_state=DHCP_STATE_INIT_REBOOT;
	}else{
		/* start from beginning */
		dhcpc_state=DHCP_STATE_INIT;
		}

	dhcpc_soc_handle=udp_getsocket(0,dhcpc_eventlistener,UDP_OPT_SEND_CS|UDP_OPT_CHECK_CS);

	if(dhcpc_soc_handle<0){
		DEBUGOUT("DHCP client not able to obtain socket!\r\n");
		return (-1);
	}

	/* open socket for communication immediately */
	(void)udp_open(dhcpc_soc_handle,DHCP_CLIENT_PORT);

	/* get timer handle */
	dhcpc_timer_handle=get_timer();

	/* initialize timer for 1 sec intervals */
	init_timer(dhcpc_timer_handle,TIMERTIC*1);	/* on every second */

	dhcpc_initialized=1;
	DEBUGOUT("DHCP Client initialized\r\n");

	return (0);
}

/** \brief DHCP client main state machine
 * 	\author
 *		\li Vladan Jovanovic (vladan.jovanovic@violasystems.com)
 *	\date 23.05.2003
 *
 *	Call this function periodically from main loop to ensure
 *	proper operation. This function holds the main state machine
 *	of DHCP client that ensures proper operation.
 */
void dhcpc_run(void){
	UINT8 sec=0;

	if(!dhcpc_initialized)
		return;

	if(!check_timer(dhcpc_timer_handle))
		sec=1;

	switch(dhcpc_state){
		case DHCP_STATE_INIT_REBOOT:
			dhcpc_state=DHCP_STATE_REBOOTING;
			dhcpc_t1=4;	/* next retransmission in 4 secs */
			dhcpc_t2=8;	/* after that after 8 secs retrs */
			dhcpc_requested_ip=localmachine.localip;
			(void)dhcpc_send_message(DHCP_REQUEST);
			break;

		case DHCP_STATE_REBOOTING:
			if(sec)
				dhcpc_t1--;

			if(!dhcpc_t1){
				if(dhcpc_t2>=32){
					/* we need to restart, we don't want to wait more
					 * than 30 secs for retransmissions
					 */
					 dhcpc_state=DHCP_STATE_INIT_REBOOT;
				}else{
					dhcpc_t1=dhcpc_t2;
					dhcpc_t2<<=1;	/* exponential backoff retransmission */
					(void)dhcpc_send_message(DHCP_REQUEST);
				}
			}
			break;
		case DHCP_STATE_INIT:
			/* switch to selecting, send DHCPDISCOVER and initialize
			 * timeout timer
			 */
			DEBUGOUT("DHCP State=INIT; Sending DHCPDISCOVER message; State INIT-->SELECTING\r\n");
			dhcpc_state=DHCP_STATE_SELECTING;
			(void)dhcpc_send_message(DHCP_DISCOVER);
			/* T1 will be timeout timer. T2 will hold next timeout value */
			dhcpc_t1=4;	/* next retransmission after 4 secs */
			dhcpc_t2=8;	/* after 4 secs expire, this will be next timeout */
			break;
		case DHCP_STATE_SELECTING:
			/* one second expired ? */
			if(sec)
				dhcpc_t1--;

			/* timeout expired without receiving DHCPOFFER ? */
			if(!dhcpc_t1){
				DEBUGOUT("DHCP State=SELECTING; ");
				/* yes, retransmit or restart the process */
				if(dhcpc_t2>=32){
					/* we need to restart, we don't want to wait more
					 * than 30 secs for retransmissions
					 */
					 dhcpc_state=DHCP_STATE_INIT;
					 DEBUGOUT("Timeout for retransmissions too big; State SELECTING-->INIT\r\n");
				}else{
					DEBUGOUT("Retransmitting DHCPDISCOVER\r\n");
					dhcpc_t1=dhcpc_t2;
					dhcpc_t2<<=1;	/* exponential backoff retransmission */
					(void)dhcpc_send_message(DHCP_DISCOVER);
				}
			}
			break;
		case DHCP_STATE_REQUESTING:
			/* DHCPREQUEST sent, waiting for proper response. Retransmit
			 * if necessary
			 */
			if(sec)
			 	dhcpc_t1--;

			if(!dhcpc_t1){
				/* timeout occured without receiving DHCPACK */
				DEBUGOUT("DHCP State=REQUESTING; ");
				if(dhcpc_t2>=32){
					/* we need to restart, we don't want to wait more
					 * than 30 secs for retransmissions. Restart whole
					 * process
					 */
					 dhcpc_state=DHCP_STATE_INIT;
					 DEBUGOUT("Timeout for retransmits too big; State REQUESTING-->INIT\r\n");
				}else{
					DEBUGOUT("Retransmitting DHCPREQUEST\r\n");
					dhcpc_t1=dhcpc_t2;
					dhcpc_t2<<=1;	/* exponential backoff retransmission */
					(void)dhcpc_send_message(DHCP_REQUEST);
				}
			}
			break;
		case DHCP_STATE_BOUND:
			/* wait for T1 to expire */
			if(sec){
				dhcpc_t1--;
				dhcpc_t2--;
			}
			if(!dhcpc_t1){
				DEBUGOUT("DHCP State=BOUND; Starting renewing process; State BOUND-->RENEWING\r\n");
				/* T1 expired, start renewing process */
				dhcpc_state=DHCP_STATE_RENEWING;

				(void)dhcpc_send_message(DHCP_REQUEST);

				/* T1 will be used for retransmissions untill we
				 * return to BOUND state or reset to INIT state
				 */
				dhcpc_t1=10;	/* fixed 10sec retransmissions */
			}
			break;
		case DHCP_STATE_RENEWING:
			if(sec){
				dhcpc_t1--;
				dhcpc_t2--;
			}

			if(!dhcpc_t2){
				DEBUGOUT("DHCP State=RENEWING; T2 expired; State RENEWING-->REBINDING\r\n");
				/* oh no, T2 also expired. switch to rebinding state. This
				 * is our last attempt to retain this IP address.
				 */
				dhcpc_state=DHCP_STATE_REBINDING;

				(void)dhcpc_send_message(DHCP_REQUEST);

				/* dhcpc_t1 will be used for timeouts */
				dhcpc_t1=5;	/* 5 second retransmits */

				/* dhcpc_t2 will be used for fixed numer of retries. This
				 * is a bit different than per RFC, but we don't want
				 * another 32-bit timer value for keeping lease time.
				 */
				dhcpc_t2=10;
			}else
				if(!dhcpc_t1){
					DEBUGOUT("DHCP State=RENEWING; Retransmitting DHCPREQUEST\r\n");
					/* retransmit DHCP REQUEST messages */
					(void)dhcpc_send_message(DHCP_REQUEST);
					dhcpc_t1=10;
				}
			break;
		case DHCP_STATE_REBINDING:
			if(sec)
				dhcpc_t1--;

			if(!dhcpc_t1){

				dhcpc_t1=5;	/* 5 second retransmits */

				dhcpc_t2--;	/* retransmit count */

				if(!dhcpc_t2){
					DEBUGOUT("DHCP State=REBINDING; Lease time expired; State REBINDING-->INIT\r\n");
					/* used up retransmission. Assume that lease time
					 * expired by now. Restart the process
					 */
					 dhcpc_state=DHCP_STATE_INIT;
					 localmachine.localip=0;	/* can't use this any more */
				}else{
					DEBUGOUT("DHCP State=REBINDING; Retransmitting DHCPREQUEST\r\n");
					/* still have some time */
					(void)dhcpc_send_message(DHCP_REQUEST);
				}
			}
			break;
		default:
			break;
	}

	if(sec){
		init_timer(dhcpc_timer_handle,TIMERTIC*1);
	}
}

/** \brief Sends DHCP messages
 * 	\author
 *		\li Vladan Jovanovic (vladan.jovanovic@violasystems.com)
 *	\date 23.05.2003
 *	\param msg_type Type of DHCP message to be sent. This implementation
 *		can send only #DHCP_DISCOVER, #DHCP_REQUEST and #DCHP_DECLINE
 *		messages.
 *	\return Returns result of udp_send() function.
 *
 *	This is internal function invoked to send appropriate DHCP message.
 */
INT8 dhcpc_send_message(UINT8 msg_type)
{

	UINT16 index;
	UINT8 *buf_ptr;	/* transmit buffer pointer */

	/* first clear transmit buffer to all zeroes */
	for(index=UDP_APP_OFFSET;index<NETWORK_TX_BUFFER_SIZE;index++)
		net_buf[index]=0;

	buf_ptr=net_buf+UDP_APP_OFFSET;

	/* create DHCP message */

	*buf_ptr++=BOOT_REQUEST;
	*buf_ptr++=0x01;		/* htype=ethernet */
	*buf_ptr++=0x06;		/* hlen=6 for ethernet */
	*buf_ptr++=0x00;		/* hops=0 by clients */

	/* xid, use constant value for all requests (allowed by RFC) */
	*buf_ptr++=0xAA;
	*buf_ptr++=0xBB;
	*buf_ptr++=0xCC;
	*buf_ptr++=0xDD;

	/* seconds from boot. Fixed for now */
	*buf_ptr++=0x00;
	*buf_ptr++=0x00;

	/* flags, use broadcast */
	*buf_ptr++=0x80;
	*buf_ptr++=0x00;

	/* ciaddr. Sent only if client is in BOUND, RENEW or REBINDING
	 * state (RFC2131)
	 */
	if((dhcpc_state==DHCP_STATE_BOUND)
		||(dhcpc_state==DHCP_STATE_RENEWING)
		||(dhcpc_state==DHCP_STATE_REBINDING)){
		*buf_ptr++=(UINT8)(localmachine.localip>>24);
		*buf_ptr++=(UINT8)(localmachine.localip>>16);

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品奇米国产一区二区三区| 亚洲一区二区欧美激情| 久久99精品久久久久| 6080国产精品一区二区| 日韩国产成人精品| 久久蜜桃av一区精品变态类天堂| 毛片不卡一区二区| 国产欧美日产一区| 99久久99精品久久久久久| 亚洲一区二区三区三| 欧美卡1卡2卡| 狠狠色狠狠色综合系列| 99精品国产91久久久久久| 久久网这里都是精品| 成人v精品蜜桃久久一区| 亚洲小说春色综合另类电影| 欧美一区二区精品| 91视频国产观看| 蜜臀久久99精品久久久久宅男 | 欧美大片在线观看| 成人性生交大片免费看中文 | 日韩视频免费观看高清完整版| 韩国理伦片一区二区三区在线播放| 99热这里都是精品| 紧缚奴在线一区二区三区| 国产精品全国免费观看高清 | 欧洲精品视频在线观看| 国产精品99久| 亚洲一区中文日韩| 久久噜噜亚洲综合| 91精品黄色片免费大全| 色综合久久久久| 成人禁用看黄a在线| 国产一区二区三区| 久久黄色级2电影| 亚洲精品中文字幕在线观看| 色偷偷一区二区三区| 久久不见久久见免费视频7| 亚洲18女电影在线观看| 亚洲蜜臀av乱码久久精品| 国产亚洲女人久久久久毛片| 2020国产精品| 国产精品久久久久影院色老大| 久久精品视频一区| 国产精品亲子乱子伦xxxx裸| 欧美极品aⅴ影院| 国产精品成人在线观看| 久久久久久电影| 欧美激情一区二区三区不卡| 国产精品久久久久久久岛一牛影视 | 国产精品素人视频| 国产欧美一区二区精品久导航| 91麻豆swag| 欧美一级片在线观看| 精品视频一区三区九区| 中文字幕一区二区三区视频| 狠狠狠色丁香婷婷综合久久五月| 欧美日韩一区中文字幕| 樱花影视一区二区| 91福利视频久久久久| 亚洲精品免费电影| 91污片在线观看| 夜色激情一区二区| 欧美日韩综合在线免费观看| 亚洲高清视频中文字幕| 欧美日韩一区视频| 蜜臀精品久久久久久蜜臀| 大胆亚洲人体视频| 国产欧美一区二区三区沐欲| 日韩一二三区不卡| 久久国产日韩欧美精品| 欧美成人一区二区三区| 久久国产婷婷国产香蕉| 国产日产欧美一区| 成人精品电影在线观看| 一区二区三区美女视频| 欧美色图在线观看| 国产专区欧美精品| 中文字幕在线免费不卡| 欧美日韩精品电影| 国产乱码精品一区二区三| 亚洲欧美在线aaa| 欧美美女视频在线观看| 国产精一区二区三区| 亚洲精品视频自拍| 精品国产免费视频| 欧美在线免费视屏| 国产高清精品在线| 日韩在线一区二区| 中文字幕视频一区二区三区久| 在线观看av一区二区| 国产成人高清在线| 亚洲国产精品人人做人人爽| 色综合咪咪久久| 亚洲伦理在线精品| 蜜桃av噜噜一区| 99re这里只有精品首页| 久久一区二区视频| 欧美人与z0zoxxxx视频| 国产精品美女一区二区在线观看| 五月天激情综合网| 天天综合色天天综合| 免费精品视频最新在线| 狠狠色狠狠色综合| 不卡的电影网站| 91极品视觉盛宴| 日韩欧美中文字幕精品| 欧美日韩久久久久久| voyeur盗摄精品| 国产福利一区在线观看| 天天色天天爱天天射综合| 亚洲黄色小说网站| 中文字幕日韩精品一区| 国产欧美一区二区精品性| 久久久五月婷婷| 久久久国产精品午夜一区ai换脸| 欧美麻豆精品久久久久久| 91官网在线免费观看| 99久久精品费精品国产一区二区| 成人性生交大片免费看在线播放| 久久er99热精品一区二区| 黄色资源网久久资源365| 国产麻豆视频精品| 99久久777色| 欧美性xxxxx极品少妇| 色噜噜久久综合| 色婷婷综合久久| 91精品国产综合久久福利软件 | 欧美一区三区四区| 成人丝袜18视频在线观看| www.欧美.com| 欧美日韩在线播放三区四区| 日韩一区二区三区免费观看| 久久久亚洲高清| 一区二区免费在线播放| 国产综合久久久久久鬼色| av电影在线观看完整版一区二区| 91丨九色porny丨蝌蚪| 日韩女优制服丝袜电影| 国产精品麻豆视频| 精品国产髙清在线看国产毛片| 国产精品毛片久久久久久| 日韩一区欧美二区| 91美女在线看| 国产精品日日摸夜夜摸av| 日韩精品一二区| 欧美裸体bbwbbwbbw| 亚洲精品一二三| 91免费观看视频| 18欧美亚洲精品| 国产黄色成人av| 久久日韩精品一区二区五区| 美腿丝袜在线亚洲一区| 制服.丝袜.亚洲.中文.综合| 亚洲一区在线播放| 在线一区二区观看| 亚洲国产aⅴ天堂久久| 色综合天天在线| 一级做a爱片久久| 欧美日韩视频在线观看一区二区三区 | 亚洲一二三专区| 欧美日韩不卡一区| 婷婷综合五月天| 日韩欧美中文字幕一区| 久久精品国产久精国产爱| 精品国产不卡一区二区三区| 免费成人小视频| 久久精品亚洲精品国产欧美kt∨ | 亚洲国产乱码最新视频 | 欧美成人一区二区三区片免费| 五月婷婷综合网| 2024国产精品| 99久久婷婷国产| 日本aⅴ免费视频一区二区三区| 欧美成人一区二区三区| 成人动漫av在线| 天堂在线亚洲视频| 国产精品视频一二| 欧美丰满美乳xxx高潮www| 国产精品综合网| 亚洲福利视频导航| 中文字幕精品一区| 欧美日韩午夜精品| 风间由美一区二区av101| 偷拍与自拍一区| 亚洲国产成人午夜在线一区| 91麻豆精品国产自产在线| 丰满放荡岳乱妇91ww| 免费av网站大全久久| 亚洲欧洲av一区二区三区久久| 日韩视频在线观看一区二区| 91麻豆国产精品久久| 国产麻豆视频一区| 日韩国产欧美在线观看| 亚洲欧美aⅴ...| 日韩一区中文字幕| 日韩一区二区三区高清免费看看| 亚洲欧美日韩一区| 精品欧美久久久| 精品日韩在线观看|