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

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

?? tcp.c

?? RTL8019網卡芯片源碼,TCP/IP源碼,包括TCP.C,UDP.C,IP.C
?? C
?? 第 1 頁 / 共 2 頁
字號:
//-----------------------------------------------------------------------------
// Net TCP.C
//
// This module handles TCP segments
// Refer to RFC 793, 896, 1122, 1323, 2018, 2581
//
// A "connection" is a unique combination of 4 items:  His IP address,
// his port number, my IP address, and my port number.
//
// Note that a SYN and a FIN count as a byte of data, but a RST does
// not count. Neither do any of the other flags.
// See "TCP/IP Illustrated, Volume 1" Sect 17.3 for info on flags
//-----------------------------------------------------------------------------
#include <string.h>
#include <stdlib.h>
#include <ctype.h>		// toupper
#include "C8051f.h"
#include "net.h"
#include "cksum.h"
#include "serial.h"
#include "ip.h"
#include "http.h"
#include "tcp.h"


// These structures keep track of connection information
CONNECTION xdata conxn[5];

ULONG idata initial_sequence_nr;
UINT xdata sender_tcpport;
static ULONG xdata sender_ipaddr;
UCHAR idata just_closed; // Keeps track of when a conxn closed

extern ULONG code my_ipaddr;
extern UCHAR idata debug;
extern char xdata text[];

// Options: MSS (4 bytes), NOPS (2 bytes), Selective ACK (2 bytes) 
UCHAR code opt[10] = {
0x02, 0x04, 0x05, 0xB4,
0x01, 0x01,
0x04, 0x02};



//------------------------------------------------------------------------
//  Initialize variables declared in this module
//
//------------------------------------------------------------------------
void init_tcp(void)
{
   memset(conxn, 0, sizeof(conxn));
   just_closed = FALSE;
   initial_sequence_nr = 1;
}



//------------------------------------------------------------------------
// This sends a TCP segments that do not include any data.
// http_send() in the HTTP module is used to send data.
// See "TCP/IP Illustrated, Volume 1" Sect 17.3
//------------------------------------------------------------------------
void tcp_send(UINT flags, UINT hdr_len, UCHAR nr)
{
   ULONG idata sum, dest;
  	UINT idata result;
   UCHAR xdata * outbuf;
   TCP_HEADER xdata * tcp;
   IP_HEADER xdata * ip;
          
   
   // Allocate memory for entire outgoing message including
   // eth & IP headers 
   outbuf = (UCHAR xdata *)malloc(34 + hdr_len);
   if (outbuf == NULL)
   {
      if (debug) serial_send("TCP: Oops, out of memory\r");
      return;
   }

	   
   tcp = (TCP_HEADER xdata *)(outbuf + 34);
   ip = (IP_HEADER xdata *)(outbuf + 14);

   // If no connection, then message is probably a reset
   // message which goes back to the sender
   // Otherwise, use information from the connection.
   if (nr == NO_CONNECTION)
   {
      tcp->source_port = HTTP_PORT;
      tcp->dest_port = sender_tcpport;
      tcp->sequence = 0;
      tcp->ack_number = 0;
      dest = sender_ipaddr;
   }
   else if (nr < 5)
   {
      // This message is to connected port
      tcp->source_port = HTTP_PORT;
      tcp->dest_port = conxn[nr].port;
      tcp->sequence = conxn[nr].my_sequence;
      tcp->ack_number = conxn[nr].his_sequence;
      dest = conxn[nr].ipaddr;
   }
   else
   {
    	if (debug) serial_send("TCP: Oops, sock nr out of range\r");
		free(outbuf);
		return;
	}

   // Total segment length = header length
      
   // Insert header len
   tcp->flags = (hdr_len << 10) | flags;
   tcp->window = 1024;
   tcp->checksum = 0;
   tcp->urgent_ptr = 0;
   
   // Sending SYN with header options
   if (hdr_len == 28)
   {
      memcpy(&tcp->options, opt, 8);
   }   
   
   // Compute checksum including 12 bytes of pseudoheader
	// Must pre-fill 2 items in ip header to do this
	ip->dest_ipaddr = dest;
	ip->source_ipaddr = my_ipaddr;
		
	// Sum source_ipaddr, dest_ipaddr, and entire TCP message 
	sum = (ULONG)cksum(outbuf + 26, 8 + hdr_len);
				
	// Add in the rest of pseudoheader which is
	// protocol id and TCP segment length
	sum += (ULONG)0x0006;
	sum += (ULONG)hdr_len;

	// In case there was a carry, add it back around
	result = (UINT)(sum + (sum >> 16));
	tcp->checksum = ~result;
   
   if (debug) serial_send("TCP: Sending msg to IP layer\r");
	ip_send(outbuf, dest, TCP_TYPE, hdr_len);

   // (Re)start TCP retransmit timer
   conxn[nr].timer = TCP_TIMEOUT;
}




//------------------------------------------------------------------------
// This runs every 0.5 seconds.  If the other end has not ACK'd
// everyting we have sent, it re-sends it.  To save RAM space, we 
// regenerate a segment rather than keeping a bunch of segments 
// hanging around eating up RAM.  A connection should not be in an
// opening or closing state when this timer expires, so we simply
// send a reset.
//
//	If a connection is in the ESTABLISHED state when the timer expires
// then we have just sent a web page so re-send the page
//------------------------------------------------------------------------
void tcp_retransmit(void)
{
   static UCHAR idata retries = 0;
   UCHAR idata nr;

   // Scan through all active connections 
   for (nr = 0; nr < 5; nr++)
   {
      if ((conxn[nr].ipaddr != 0) && (conxn[nr].timer))
      {
         // Decrement the timer and see if it hit 0
         conxn[nr].timer--;
         if (conxn[nr].timer == 0)
         {
            // Socket just timed out. If we are not in ESTABLISHED state
            // something is amiss so send reset and close connection
            if (conxn[nr].state != STATE_ESTABLISHED)
            {
               // Send reset and close connection
               if (debug) serial_send("TCP: Timeout, sending reset\r");
               tcp_send(FLG_RST, 20, nr);
               conxn[nr].ipaddr = 0;
               return;
            }
            else
            {
               // Socket is in ESTABLISHED state. First make sure his
               // ack number is not bogus.
               if (conxn[nr].his_ack > conxn[nr].my_sequence)
               {
                  // Send reset and close connection
                  if (debug) serial_send("TCP: Timeout, sending reset\r");
                  tcp_send(FLG_RST, 20, nr);
                  conxn[nr].ipaddr = 0;
                  return;
               }
               
               // We always increment our sequence number immediately
					// after sending, so the ack number from the other end
					// should be equal to our sequence number.  If it is less,
					// it means he lost some of our data.
               if (conxn[nr].his_ack < conxn[nr].my_sequence)
					{
                  retries++;
						if (retries <= 2)
						{
                   	// The only thing we send is a web page, and it looks
                  	// like other end did not get it, so resend
                  	// but do not increase my sequence number
                  	if (debug) serial_send("TCP: Timeout, resending data\r");
                  	http_server(conxn[nr].query, 0, nr, 1);
			            conxn[nr].inactivity = INACTIVITY_TIME;
                  }
						else
						{
						  	if (debug) serial_send("TCP: Giving up, sending reset\r");
							// Send reset and close connection
               		tcp_send(FLG_RST, 20, nr);
               		conxn[nr].ipaddr = 0;
               	}
               }
            }
         }
      }
   }
}




//------------------------------------------------------------------------
// This runs every 0.5 seconds.  If the connection has had no activity
// it initiates closing the connection.
//
//------------------------------------------------------------------------
void tcp_inactivity(void)
{
   UCHAR idata nr;
   
   // Look for active connections in the established state
   for (nr = 0; nr < 5; nr++)
   {
      if ((conxn[nr].ipaddr != 0) && 
          (conxn[nr].state == STATE_ESTABLISHED) &&
          (conxn[nr].inactivity))
      {
         // Decrement the timer and see if it hit 0
         conxn[nr].inactivity--;
         if (conxn[nr].inactivity == 0)
         {
            // Inactivity timer has just timed out.
            // Initiate close of connection
            tcp_send((FLG_ACK | FLG_FIN), 20, nr);
            conxn[nr].my_sequence++;    // For my FIN
            conxn[nr].state = STATE_FIN_WAIT_1;
            if (debug) serial_send("TCP: Entered FIN_WAIT_1 state\r");	
         }
      }
   }
}



//------------------------------------------------------------------------
// This handles incoming TCP messages and manages the TCP state machine
// Note - both the SYN and FIN flags consume a sequence number.
// See "TCP/IP Illustrated, Volume 1" Sect 18.6 for info on TCP states
// See "TCP/IP Illustrated, Volume 1" Sect 17.3 for info on flags
//------------------------------------------------------------------------
void tcp_rcve(UCHAR xdata * inbuf, UINT len)
{
   UCHAR idata i, j, nr;
   UINT idata result, header_len, data_len;
   TCP_HEADER xdata * tcp;
   IP_HEADER xdata * ip;
   ULONG idata sum;
   
   // IP header is always 20 bytes so message starts at index 34      
   tcp = (TCP_HEADER xdata *)(inbuf + 34);
   ip = (IP_HEADER xdata *)(inbuf + 14);
				   
	// Compute TCP checksum including 12 byte pseudoheader
	// Sum source_ipaddr, dest_ipaddr, and entire TCP message 
	sum = (ULONG)cksum(inbuf + 26, 8 + len);
		
	// Add in the rest of pseudoheader which is
	// protocol id and TCP segment length
	sum += (ULONG)0x0006;     
	sum += (ULONG)len;

	// In case there was a carry, add it back around
	result = (UINT)(sum + (sum >> 16));
		
	if (result != 0xFFFF)
	{
		if (debug) serial_send("TCP: Error, bad cksum\r");
		return;
   }

	if (debug) serial_send("TCP: Msg rcvd with good cksum\r");
   
	// See if message is for http server
	if (tcp->dest_port != HTTP_PORT)	
   {
      if (debug)
      {
         serial_send("TCP: Error, msg to port ");
         memset(text, 0, 10);
         itoa(tcp->dest_port, text, 10);
         serial_send(text);
		   serial_send("\r");
      }
      tcp_send(FLG_RST, 20, NO_CONNECTION);
      return;
   }
   
   // Capture sender's IP address and port number
   sender_ipaddr = ip->source_ipaddr;
   sender_tcpport = tcp->source_port;
   
   // See if the TCP segment is from someone we are already
   // connected to. 
   for (i=0; i < 5; i++)
   {
      if ((ip->source_ipaddr == conxn[i].ipaddr) &&
         (tcp->source_port == conxn[i].port))
      {   
         nr = i;
         if (debug) serial_send("TCP: Rcvd msg from existing conxn\r");
         break;
      }       
   }
   
   // If i = 5, we are not connected. If it is a SYN then assign

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲精选视频在线| 日本vs亚洲vs韩国一区三区二区| 国产人成一区二区三区影院| 日韩欧美一二区| 久久综合给合久久狠狠狠97色69| 日韩欧美专区在线| 欧美高清在线一区二区| 亚洲免费色视频| 免费日韩伦理电影| 高清av一区二区| 欧美色精品在线视频| 日韩午夜三级在线| 国产亚洲一区字幕| 一区二区三区欧美在线观看| 日韩av一区二区在线影视| 丁香婷婷综合色啪| 成人伦理片在线| 欧美高清视频一二三区| 国产网站一区二区| 亚洲第一精品在线| 国产精品18久久久| 5566中文字幕一区二区电影| 久久久久久久久久久黄色| 亚洲激情自拍偷拍| 国产白丝网站精品污在线入口| 在线观看精品一区| 久久久不卡影院| 日本美女一区二区三区| 在线免费视频一区二区| 337p日本欧洲亚洲大胆色噜噜| 午夜欧美大尺度福利影院在线看| 国产91综合一区在线观看| 欧美一区二区视频在线观看2020 | 国产精品资源在线看| 欧美性淫爽ww久久久久无| 国产精品毛片大码女人| 国产一区二区三区久久悠悠色av| 在线观看av一区| 亚洲精品写真福利| 成人午夜大片免费观看| 久久一夜天堂av一区二区三区 | 一区2区3区在线看| 成人夜色视频网站在线观看| 精品日韩在线一区| 日韩成人免费看| 在线不卡的av| 日本视频免费一区| 日本一区二区免费在线| 免费看黄色91| 亚洲欧洲三级电影| 在线不卡欧美精品一区二区三区| 2014亚洲片线观看视频免费| 蜜臀久久99精品久久久画质超高清 | 日本韩国欧美一区二区三区| 亚洲欧美偷拍另类a∨色屁股| 不卡欧美aaaaa| 亚洲欧美日韩国产综合在线| 欧洲亚洲国产日韩| 日韩黄色免费电影| 欧美一区二区三区啪啪| 韩国欧美国产一区| 国产精品乱码一区二三区小蝌蚪| 成人18精品视频| 亚洲人快播电影网| 制服丝袜激情欧洲亚洲| 久久超碰97人人做人人爱| 国产精品女同一区二区三区| 91女人视频在线观看| 首页国产欧美日韩丝袜| 国产性色一区二区| 欧美色中文字幕| 国产九色sp调教91| 亚洲国产精品视频| 国产亚洲精久久久久久| 欧美日韩在线亚洲一区蜜芽| 久久99精品久久久久久国产越南| 国产精品免费视频一区| 制服视频三区第一页精品| eeuss鲁片一区二区三区| 日韩精品1区2区3区| 国产精品色婷婷| 精品奇米国产一区二区三区| 91亚洲国产成人精品一区二区三| 精品亚洲免费视频| 午夜精品久久久久久久久久| 亚洲欧洲日韩综合一区二区| 精品国产免费人成电影在线观看四季| 91麻豆免费观看| 成人av在线资源| 国产一区亚洲一区| 另类综合日韩欧美亚洲| 亚洲777理论| 亚洲国产日韩在线一区模特| 中文字幕免费不卡| 久久久一区二区| xf在线a精品一区二区视频网站| 欧美最猛性xxxxx直播| 色欧美片视频在线观看 | 一道本成人在线| 日本韩国一区二区| 日本高清不卡视频| 一本一道综合狠狠老| 99久久99久久精品免费看蜜桃| 国产成人av电影在线观看| 国产一区二区三区视频在线播放| 蜜臀av性久久久久蜜臀aⅴ流畅 | 在线观看成人小视频| 99久久国产综合精品麻豆| 成人激情av网| 99精品偷自拍| 欧美无砖专区一中文字| 欧美肥妇bbw| 欧美成人精品二区三区99精品| 精品久久久久久最新网址| 日韩一区二区三区高清免费看看| 成人一区二区视频| 天天av天天翘天天综合网| 最新中文字幕一区二区三区| 亚洲欧洲www| 五月天婷婷综合| 黑人巨大精品欧美一区| av在线免费不卡| 日韩一级二级三级精品视频| 久久九九久精品国产免费直播| 国产亚洲午夜高清国产拍精品 | 伊人色综合久久天天人手人婷| 亚洲一区在线观看视频| 精品一区二区三区免费视频| av不卡在线播放| 91麻豆精品国产91久久久更新时间 | 日韩一级黄色片| 亚洲欧洲精品一区二区精品久久久| 亚洲国产色一区| 成人高清免费在线播放| 日韩一区二区中文字幕| 亚洲欧洲日韩av| 盗摄精品av一区二区三区| 欧美一三区三区四区免费在线看| 国产色91在线| 精品影视av免费| 欧美精选午夜久久久乱码6080| 欧美激情综合网| 久久不见久久见免费视频1| 色狠狠综合天天综合综合| 国产日韩欧美精品在线| 久久福利资源站| 在线播放亚洲一区| 午夜精品久久久久久| 一本一本大道香蕉久在线精品 | 成人中文字幕在线| 精品对白一区国产伦| 青青草97国产精品免费观看无弹窗版| 色综合天天综合狠狠| 亚洲四区在线观看| a4yy欧美一区二区三区| 国产精品的网站| 99久久国产综合精品麻豆| 亚洲欧美区自拍先锋| 91网址在线看| 一区二区三区波多野结衣在线观看| 成人精品鲁一区一区二区| 国产精品卡一卡二卡三| av成人免费在线观看| 亚洲精品日韩一| 欧美三级一区二区| 丝袜美腿一区二区三区| 欧美亚洲丝袜传媒另类| 亚洲成a人片综合在线| 欧美日本一道本在线视频| 亚洲第一在线综合网站| 欧美美女一区二区三区| 天天色天天爱天天射综合| 91视频xxxx| 亚洲午夜免费视频| 日韩一区二区三区四区| 伦理电影国产精品| 久久午夜国产精品| 色综合视频一区二区三区高清| 亚洲欧美日韩中文字幕一区二区三区| 91亚洲男人天堂| 国产精品国产三级国产普通话三级| 91丨九色丨黑人外教| 午夜日韩在线电影| 国产亚洲欧美一区在线观看| 欧美中文字幕不卡| 美女久久久精品| 亚洲视频在线一区观看| 精品国产污网站| 91美女在线视频| 国产自产2019最新不卡| 一区二区三区免费在线观看| 欧美一级爆毛片| 一区二区在线免费| 在线免费亚洲电影| 国产精品一级片| 亚洲一区二区精品3399| 国产欧美综合色| 777精品伊人久久久久大香线蕉| 国产综合色精品一区二区三区| 欧美一区二区福利视频|