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

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

?? tinytcp.c

?? TCP/IP協議的工作原理
?? C
?? 第 1 頁 / 共 2 頁
字號:
/*
 * tinytcp.c - Tiny Implementation of the Transmission Control Protocol
 *
 * Written March 28, 1986 by Geoffrey Cooper, IMAGEN Corporation.
 *
 * This code is a small implementation of the TCP and IP protocols, suitable
 * for burning into ROM.  The implementation is bare-bones and represents
 * two days' coding efforts.  A timer and an ethernet board are assumed.  The
 * implementation is based on busy-waiting, but the tcp_handler procedure
 * could easily be integrated into an interrupt driven scheme.
 *
 * IP routing is accomplished on active opens by broadcasting the tcp SYN
 * packet when ARP mapping fails.  If anyone answers, the ethernet address
 * used is saved for future use.  This also allows IP routing on incoming
 * connections.
 * 
 * The TCP does not implement urgent pointers (easy to add), and discards
 * segments that are received out of order.  It ignores the received window
 * and always offers a fixed window size on input (i.e., it is not flow
 * controlled).
 *
 * Special care is taken to access the ethernet buffers only in word
 * mode.  This is to support boards that only allow word accesses.
 *
 * Copyright (C) 1986, IMAGEN Corporation
 *  "This code may be duplicated in whole or in part provided that [1] there
 *   is no commercial gain involved in the duplication, and [2] that this
 *   copyright notice is preserved on all copies.  Any other duplication
 *   requires written notice of the author (Geoffrey H. Cooper)."
 */

#include "tinytcp.h"
#include "include.h"


/*  Local IP address  */
//in_HwAddress sin_lclINAddr;
/* IP identification numbers */

WORD tcp_id;
tcp_Socket *tcp_allsocs;

		extern void putb_ser(byte byte_data);
		
/* Timer definitions */
#define tcp_RETRANSMITTIME 100     /* interval at which retransmitter is called */
#define tcp_LONGTIMEOUT 3100       /* timeout for opens */
#define tcp_TIMEOUT 1000           /* timeout during a connection */

#ifdef DEBUG
/** Primitive logging facility **/
#define tcp_LOGPACKETS 1        /* log packet headers */
WORD tcp_logState;
#endif
void tcp_ProcessData(tcp_Socket *s, tcp_Header *tp, WORD len);
int checksum(WORD *dp, WORD length);
void tcp_Send(tcp_Socket *s);
void tcp_Unthread(tcp_Socket *ds);
void tcp_Handler( in_Header *ip );
void tcp_Flush(tcp_Socket *s);
void tcp_Abort(tcp_Socket *s);
void tcp_Retransmitter(void);
void tcp_Reset( in_Header *ip, tcp_Header *tp );

in_Header *ip_tcp;
DWORD timeout_tcp, start_tcp;
DWORD x_tcp;


//extern WORD i_test;		//	from test_application
//extern BYTE tbuf_test[80];

extern WORD i_hand;

extern BYTE *sed_IsPacket(void);
extern BYTE *sed_FormatPacket( BYTE *destEAddr, WORD ethType );
extern BYTE sed_Send( WORD pkLengthInOctets );
extern sar_MapIn2Eth(DWORD ina, eth_HwAddress *ethap );
extern BYTE sed_Receive( BYTE *buf );
extern BYTE sed_CheckPacket( BYTE *BufLocation, WORD expectedType );
extern void sar_CheckPacket(arp_Header *ap);
extern WORD test_dataHandler( tcp_Socket *s, BYTE *dp, WORD len );
extern WORD test_application( void );
extern void print(BYTE *ch);

/************** Initialize the tcp implementation   ********************************/

void tcp_Init(void)
{
	//extern eth_HwAddress sed_lclEthAddr;

	/* initialize ethernet interface */
	ethernet_init();
	//sed_Init();

	tcp_allsocs = NIL;
	tcp_id = 0;

	/* hack - assume the network number */
//	sin_lclINAddr = LOCAL_IP_ADDR;
	
}

/*
 * Actively open a TCP connection to a particular destination.
 */
//void tcp_Open(tcp_Socket *s, WORD lport, in_HwAddress ina, WORD port, procref datahandler)
void tcp_Open(tcp_Socket *s, WORD lport, in_HwAddress ina, WORD port,procref datahandler) 
{
	//extern eth_HwAddress sed_ethBcastAddr;

	s->state = tcp_StateSYNSENT;
	s->timeout = tcp_LONGTIMEOUT;
	if ( lport == 0 ) lport = clock_ValueRough();
	s->myport = lport;
	if ( ! sar_MapIn2Eth(ina, &s->hisethaddr[0]) ) {
#ifdef DEBUG
		print(" : defaulting ethernet address to broadcast\r\n\r");
#endif
		Move(&sed_ethBcastAddr[0], &s->hisethaddr[0], sizeof(eth_HwAddress));
	}
	s->hisaddr = ina;
	s->hisport = port;
	s->seqnum = 0;
	s->dataSize = 0;
	s->flags = tcp_FlagSYN;
	s->unhappy = true;
	s->dataHandler = datahandler;
	s->next = tcp_allsocs;
	tcp_allsocs = s;
	tcp_Send(s);
}

/*
 * Passive open: listen for a connection on a particular port
 */
//void tcp_Listen(tcp_Socket *s, WORD port, procref datahandler, DWORD timeout)
void tcp_Listen(tcp_Socket *s, WORD port, DWORD timeout)
{
	s->state = tcp_StateLISTEN;
	if ( timeout == 0 ) s->timeout = 0x7ffffff; /* forever... */
	else s->timeout = timeout;
	s->myport = port;
	s->hisport = 0;
	s->seqnum = 0;
	s->dataSize = 0;
	s->flags = 0;
	s->unhappy = 0;
	//s->dataHandler = datahandler;
//	s->dataHandler = (void *)test_dataHandler( (tcp_Socket *)s, (BYTE *)0, (WORD)0);
	
	s->next = tcp_allsocs;
	tcp_allsocs = s;
}

/*
 * Send a FIN on a particular port -- only works if it is open
 */
void tcp_Close(tcp_Socket *s)
{
	if ( s->state == tcp_StateESTAB || s->state == tcp_StateSYNREC ) {
		s->flags = tcp_FlagACK | tcp_FlagFIN;
		s->state = tcp_StateFINWT1;
		s->unhappy = true;
		tcp_Send(s);
	}
}

/*
 * Abort a tcp connection
 */

void tcp_Abort(tcp_Socket *s)
{
	if ( s->state != tcp_StateLISTEN && s->state != tcp_StateCLOSED ) {
		s->flags = tcp_FlagRST | tcp_FlagACK;
		tcp_Send(s);
	}
	s->unhappy = 0;
	s->dataSize = 0;
	s->state = tcp_StateCLOSED;
//	s->dataHandler((tcp_Socket*)s,(BYTE *)0, (WORD *)-1); 
	DATAHANDLER( (tcp_Socket *)s,(BYTE *)0, (WORD *)0 ) ;

//	s->dataHandler(0,0,0); 
	tcp_Unthread(s);
}

/*
 * Retransmitter - called periodically to perform tcp retransmissions
 */
void tcp_Retransmitter(void)
{
	tcp_Socket *s;
	BOOL x;

	for ( s = tcp_allsocs; s; s = s->next ) {
		x = false;
		if ( s->dataSize > 0 || s->unhappy ) {	/* if we didn't received ack( dataSize > 0 ) or unhappy, then re-xmit it */
			tcp_Send(s);
			x = true;
		}
		if ( x || s->state != tcp_StateESTAB )
			s->timeout -= tcp_RETRANSMITTIME;
		if ( s->timeout <= 0 ) {
			if ( s->state == tcp_StateTIMEWT ) {
#ifdef DEBUG
				print("Closed.    \r\n");
#endif
				s->state = tcp_StateCLOSED;
//				s->dataHandler((tcp_Socket *)s,(BYTE *)0, (WORD *)0);
				DATAHANDLER((tcp_Socket *)s,(BYTE *)0, 0);
				tcp_Unthread(s);
			} else {
#ifdef DEBUG
				print(" : Timeout, aborting\r\n");
#endif
				tcp_Abort(s);
			}
		}
	}
}

/*
 * Unthread a socket from the socket list, if it's there 
 */
void tcp_Unthread(tcp_Socket *ds)
{
	tcp_Socket *s, **sp;

	sp = &tcp_allsocs;
	for (;;) {
		s = *sp;
		if ( s == ds ) {
			*sp = s->next;
			break;
		}
		if ( s == NIL ) break;
		sp = &s->next;
	}
}

/*
 * busy-wait loop for tcp.  Also calls an "application proc"
 */
//void tcp(procref application)
void tcp(void) reentrant
{
	unsigned char i ;
	char *ptr ;
	
	//in_Header *ip;
	//DWORD timeout, start;
	//DWORD x;

	sed_Receive(0);

	timeout_tcp = clock_ValueRough() + tcp_RETRANSMITTIME;
	while ( tcp_allsocs ) {
		start_tcp = clock_ValueRough();
		ip_tcp = (in_Header *)sed_IsPacket();

		/* Modified by junku 
		 * Retransmitter is on this 
		 */
		if ( ip_tcp == NIL ) {
			if ( clock_ValueRough() > timeout_tcp ) {
				tcp_Retransmitter();
				timeout_tcp = clock_ValueRough() + tcp_RETRANSMITTIME;
			}

			//application();
			//print("before test_application\n\r");
			test_application();
			//print("after test_application\n\r");
			continue;
		}
		
		if ( sed_CheckPacket(ip_tcp, 0x806) == 1 ) {
			/* do arp */
			print("arp packet") ;
			for ( i=0,ptr=(char *)ip_tcp ; i<sizeof( arp_Header ); i++) {
				putb_ser( *ptr++ ) ;
			}
			print("\r\n") ;
			sar_CheckPacket(ip_tcp);
		} else if ( sed_CheckPacket(ip_tcp, 0x800) == 1 ) {
			/* do IP */
			print("ip packet : ") ;
			for ( i=0,ptr=(char *)ip_tcp ; i<sizeof( in_Header ); i++) {
				putb_ser( *ptr++ ) ;
				print("#");
			}
			print("\r\n") ;
			if ( ip_tcp->destination == sin_lclINAddr && in_GetProtocol(ip_tcp) == 6 
				&& checksum((WORD *)ip_tcp, in_GetHdrlenBytes(ip_tcp)) == 0xFFFF )
			{
					print("it's our ip\r\n") ;
					tcp_Handler(ip_tcp);
			} 
		}
	        /* recycle buffer */
        	sed_Receive(ip_tcp);

        	x_tcp = clock_ValueRough() - start_tcp;
        	timeout_tcp -= x_tcp;
        }
	return;
}

/*
 * Write data to a connection.
 * Returns number of bytes written, == 0 when connection is not in
 * established state.
 */
//void tcp_Write( tcp_Socket *s, BYTE *dp, WORD len )
WORD tcp_Write( tcp_Socket *s, BYTE *dp, WORD len )
{
	WORD x;

	if ( s->state != tcp_StateESTAB ) len = 0;
	if ( len > (x = tcp_MaxData - s->dataSize) ) len = x;
	if ( len > 0 ) {
		Move(dp, &s->datas[s->dataSize], len);
		s->dataSize += len;
		tcp_Flush(s);
	}

	return ( len );
}

/*
 * Send pending data
 */
void tcp_Flush(tcp_Socket *s)
{
    if ( s->dataSize > 0 ) {
        s->flags |= tcp_FlagPUSH;
        tcp_Send(s);
    }
}

/*
 * Handler for incoming packets.
 */
void tcp_Handler( in_Header *ip )
{
	tcp_Header *tp;
	tcp_PseudoHeader ph;
	WORD len;
	BYTE *dp;
	WORD x, diff;
	tcp_Socket *s;
	WORD flags;

	len = in_GetHdrlenBytes(ip);
	tp = (tcp_Header *)((BYTE *)ip + len);
	len = ip->length - len;

	/* demux to active sockets */
	for ( s = tcp_allsocs; s; s = s->next )
		if ( s->hisport != 0 &&
		tp->dstPort == s->myport &&
		tp->srcPort == s->hisport &&
		ip->source == s->hisaddr ) break;
	if ( s == NIL ) {
		/* demux to passive sockets */
		for ( s = tcp_allsocs; s; s = s->next )
		if ( s->hisport == 0 && tp->dstPort == s->myport ) break;
	}
	if ( s == NIL ) {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日韩国产高清一区二区| 国产在线播放一区| 成人综合日日夜夜| 亚洲精品一区二区三区99| 日本亚洲免费观看| 久久免费国产精品| 国产成人福利片| 国产欧美日产一区| 91免费视频观看| 亚洲成人综合网站| 日韩视频一区二区三区在线播放 | 26uuu久久天堂性欧美| 国产高清不卡二三区| 国产精品乱人伦| 日本电影欧美片| 免费看黄色91| 久久精品亚洲一区二区三区浴池| 从欧美一区二区三区| 亚洲精品国产一区二区精华液| 欧洲亚洲精品在线| 国内外成人在线| 亚洲欧美综合在线精品| 欧美日韩一区二区三区在线| 九九**精品视频免费播放| 国产精品麻豆99久久久久久| 欧美主播一区二区三区| 奇米在线7777在线精品| 国产欧美一区二区三区鸳鸯浴| 一本到三区不卡视频| 美腿丝袜亚洲一区| 成人欧美一区二区三区1314| 91麻豆精品国产无毒不卡在线观看| 久久99精品国产麻豆婷婷| 亚洲天堂中文字幕| 欧美精品一二三区| 成人精品电影在线观看| 午夜欧美2019年伦理| 国产精品沙发午睡系列990531| 色欧美乱欧美15图片| 毛片av中文字幕一区二区| 国产精品入口麻豆九色| 欧美一区二区免费视频| 91农村精品一区二区在线| 久久精品国产99| 亚洲一区视频在线观看视频| 久久亚洲综合色| 欧美性受极品xxxx喷水| 国产成人精品免费网站| 日韩av电影天堂| 亚洲乱码国产乱码精品精的特点| 日韩一区国产二区欧美三区| 91精品福利视频| 成人综合在线网站| 精品午夜久久福利影院| 视频在线观看91| 亚洲欧美日韩小说| 久久久久国产精品麻豆ai换脸| 欧美三级资源在线| eeuss鲁片一区二区三区在线观看 eeuss鲁片一区二区三区在线看 | 亚洲大片在线观看| 国产精品天干天干在观线| 91精品国产色综合久久不卡蜜臀 | 亚洲美女电影在线| 中文子幕无线码一区tr| 精品久久人人做人人爽| 欧美视频一区二| 91麻豆自制传媒国产之光| 成人动漫一区二区三区| 精品一区二区日韩| 久久精品噜噜噜成人av农村| 日本亚洲一区二区| 天天影视色香欲综合网老头| 亚洲一区二区三区四区在线免费观看 | 强制捆绑调教一区二区| 亚洲高清视频的网址| 一区二区三区影院| 亚洲综合图片区| 亚洲乱码精品一二三四区日韩在线| 国产精品传媒入口麻豆| 日本一区二区免费在线| 国产精品麻豆网站| 成人欧美一区二区三区小说| 中文字幕一区不卡| 亚洲精品五月天| 一区二区三区四区不卡在线 | 亚洲国产一区视频| 一区二区三区四区亚洲| 亚洲午夜三级在线| 日韩精品久久久久久| 免费xxxx性欧美18vr| 久久99热国产| 国内成+人亚洲+欧美+综合在线| 国内精品免费在线观看| 国产成人在线看| aaa亚洲精品| 欧美亚男人的天堂| 91精品国产色综合久久ai换脸| 欧美一级高清片| 精品国产第一区二区三区观看体验 | 日韩视频免费直播| 欧美xxx久久| 久久久av毛片精品| 国产精品大尺度| 日韩中文字幕亚洲一区二区va在线| 日韩电影免费在线观看网站| 精品一区二区在线播放| 成人精品国产一区二区4080| 91久久国产综合久久| 欧美一区二区三区在线观看| 久久蜜桃av一区二区天堂| 国产精品理伦片| 香蕉av福利精品导航| 免费不卡在线观看| 成人av电影免费在线播放| 欧美日韩成人综合在线一区二区| 日韩三级免费观看| 国产精品久线在线观看| 亚洲高清免费一级二级三级| 国产老妇另类xxxxx| 91国偷自产一区二区三区成为亚洲经典 | 亚洲成人一区二区在线观看| 狠狠色综合日日| 一本色道久久综合精品竹菊| 欧美日韩高清在线| 欧美国产成人精品| 亚洲国产一二三| 粉嫩一区二区三区性色av| 欧美中文字幕一区二区三区亚洲| 精品国产百合女同互慰| 一区二区三区小说| 国产成人av在线影院| 欧美日韩一区成人| 中文字幕在线不卡国产视频| 日韩avvvv在线播放| 99久久伊人久久99| 日韩久久精品一区| 亚洲成在线观看| av一区二区三区黑人| 精品久久久久久久久久久久久久久 | 欧美日韩免费在线视频| 久久―日本道色综合久久| 亚洲国产一区在线观看| 成人精品鲁一区一区二区| 337p亚洲精品色噜噜狠狠| 亚洲色图在线播放| 国产福利视频一区二区三区| 欧美一区永久视频免费观看| 亚洲欧美韩国综合色| 成人免费高清视频| 精品国产一区久久| 天使萌一区二区三区免费观看| 色呦呦国产精品| 国产精品美女久久福利网站| 国产在线精品视频| 精品日韩99亚洲| 日韩av电影免费观看高清完整版 | 麻豆精品新av中文字幕| 欧美三级欧美一级| 一区二区三区视频在线看| 97成人超碰视| 国产精品亲子乱子伦xxxx裸| 国产剧情在线观看一区二区| 欧美一区二区三区在线看| 日日夜夜免费精品视频| 欧美久久婷婷综合色| 亚洲国产一区视频| 欧美日韩国产bt| 午夜视频在线观看一区| 欧美日韩欧美一区二区| 亚洲成人激情自拍| 欧美日韩视频在线第一区| 亚洲综合成人网| 欧美综合欧美视频| 亚洲成人精品在线观看| 欧美人伦禁忌dvd放荡欲情| 亚洲一区二区精品视频| 欧美日韩一本到| 婷婷丁香激情综合| 日韩小视频在线观看专区| 免费av成人在线| 欧美精品一区二区在线观看| 国产精品中文字幕一区二区三区| 欧美精品一区视频| 高清视频一区二区| 亚洲品质自拍视频| 欧美系列一区二区| 免费在线观看一区二区三区| 日韩欧美一区二区久久婷婷| 黄一区二区三区| 中文字幕中文字幕一区二区| 成人国产亚洲欧美成人综合网| 亚洲精品成人精品456| 欧美专区亚洲专区| 免费在线成人网| 中文字幕精品—区二区四季| 91视频在线观看免费| 亚洲v日本v欧美v久久精品| 精品91自产拍在线观看一区| 成人网在线播放| 亚洲不卡在线观看|