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

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

?? tcp.c

?? 80c51 TCP/IP協議棧
?? 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一区二区三区免费野_久草精品视频
一区二区三区蜜桃| 成人一区二区视频| 欧美一级爆毛片| 国产成人精品影院| 亚洲精品国产精华液| 欧美日韩第一区日日骚| 麻豆久久久久久| 亚洲成人在线观看视频| 高清不卡在线观看| 国产精品嫩草影院com| 在线免费视频一区二区| 免费高清在线一区| 1000部国产精品成人观看| 7777精品伊人久久久大香线蕉完整版 | 国产a级毛片一区| 亚洲一区二区三区视频在线| 国产日韩精品一区二区三区在线| 9久草视频在线视频精品| 美国十次了思思久久精品导航| 久久精品水蜜桃av综合天堂| 91精品国模一区二区三区| av不卡免费电影| 国产一区在线不卡| 蜜桃av一区二区在线观看| 亚洲色图20p| 亚洲乱码日产精品bd| 国产欧美日韩不卡免费| 95精品视频在线| 99在线精品一区二区三区| 欧洲视频一区二区| 国产欧美日韩另类一区| 91免费在线视频观看| 欧美情侣在线播放| 色噜噜狠狠色综合欧洲selulu| 国产又黄又大久久| 奇米精品一区二区三区在线观看 | 欧美丝袜丝交足nylons图片| voyeur盗摄精品| av一区二区三区| 国产一区二区在线看| 国产一区二区三区四区在线观看| 久久爱www久久做| 成人黄色在线网站| 色悠悠亚洲一区二区| 日本乱人伦aⅴ精品| 欧美图区在线视频| 91麻豆精品久久久久蜜臀| 日韩小视频在线观看专区| 中文字幕高清不卡| 天天色综合成人网| 国产一二三精品| 欧美亚洲另类激情小说| 欧美理论在线播放| 欧美国产乱子伦| 日韩精品视频网| 99久久久久免费精品国产| 欧美日韩一区在线观看| 亚洲精品在线网站| 一区二区在线电影| 国产美女主播视频一区| 日本电影欧美片| 精品国产乱码久久久久久久久| 亚洲男人电影天堂| 99久久777色| 欧美经典三级视频一区二区三区| 丝袜诱惑制服诱惑色一区在线观看| 精品一区二区在线看| 777xxx欧美| 青青草精品视频| 日韩一二三四区| 麻豆精品蜜桃视频网站| 在线电影院国产精品| 亚洲成人精品一区二区| 99在线视频精品| 亚洲欧洲99久久| 色天天综合色天天久久| 欧美极品xxx| 色婷婷一区二区三区四区| 亚洲黄色免费电影| 欧美视频一区二区三区在线观看 | 国产91清纯白嫩初高中在线观看| 日韩午夜在线播放| 久久精品国产第一区二区三区| 91精品国产高清一区二区三区蜜臀| 午夜精品久久久久久久久| 色成人在线视频| 国产精品私人影院| 欧美性色欧美a在线播放| 亚洲影院在线观看| 欧美日韩视频不卡| 蜜臀va亚洲va欧美va天堂| 精品国产乱码久久久久久久| 国产精品资源站在线| 欧美日韩国产天堂| 午夜日韩在线观看| 日本一区中文字幕| 国产精品人妖ts系列视频 | 亚洲影视资源网| 日韩免费观看2025年上映的电影| 国产主播一区二区三区| 亚洲精品高清在线观看| 精品国产一二三区| 在线区一区二视频| 9色porny自拍视频一区二区| 九色porny丨国产精品| 亚洲综合在线免费观看| 国产亚洲欧洲997久久综合| 欧美三级韩国三级日本一级| 懂色av噜噜一区二区三区av| 日本v片在线高清不卡在线观看| 国产午夜一区二区三区| 欧美成人一区二区三区片免费| 91国偷自产一区二区三区观看 | 一区二区三区欧美日韩| 久久久久久电影| 成人免费视频视频在线观看免费| 美女尤物国产一区| 久久精品国产99国产| 免费欧美日韩国产三级电影| 日韩电影在线观看电影| 中文一区在线播放| 欧美刺激午夜性久久久久久久| 欧美一区二区播放| 欧美一区二区在线观看| 日韩你懂的在线观看| 精品国产乱码久久久久久浪潮 | 国产亚洲精品7777| 欧美精品一区二区三区在线 | 国产精品18久久久| 日韩电影免费在线| www.成人网.com| 日本道精品一区二区三区| 成人av在线播放网站| 在线观看欧美黄色| 欧美探花视频资源| 欧美成人综合网站| 国产精品国产三级国产aⅴ无密码 国产精品国产三级国产aⅴ原创 | 亚洲国产高清不卡| 在线日韩一区二区| 日本黄色一区二区| 国产精品久久久久永久免费观看 | 粉嫩一区二区三区性色av| 亚洲丝袜另类动漫二区| 91精品国产综合久久香蕉麻豆| 日本亚洲免费观看| 一区二区三区四区高清精品免费观看| 日韩欧美一区二区免费| 欧美无乱码久久久免费午夜一区| 国产精品资源在线观看| 青青草精品视频| 亚洲成人av在线电影| 久久精品夜色噜噜亚洲a∨| 7777精品伊人久久久大香线蕉最新版 | 久久久精品欧美丰满| 精品国产免费久久| 69久久夜色精品国产69蝌蚪网| 成人av资源站| 91免费国产在线观看| 99riav久久精品riav| 欧美人妇做爰xxxⅹ性高电影 | 视频一区视频二区中文| 精品亚洲免费视频| 91在线免费看| 欧美欧美欧美欧美首页| 91精品国产麻豆| 国产欧美一区二区三区网站 | 国产精品资源网| 99国产精品国产精品毛片| 91精品国产高清一区二区三区蜜臀| 国产亚洲一区二区三区在线观看 | 免费在线视频一区| www.亚洲色图.com| 欧美一区二区视频在线观看2020| 国产午夜精品一区二区三区嫩草 | 日本一区二区三级电影在线观看| 亚洲情趣在线观看| 极品美女销魂一区二区三区| 成人精品视频网站| 精品国产sm最大网站免费看| 亚洲韩国一区二区三区| 成人av电影在线观看| 国产清纯美女被跳蛋高潮一区二区久久w | 欧美成人精品1314www| 一区二区三区在线观看网站| 五月激情丁香一区二区三区| 色视频成人在线观看免| 国产日韩欧美一区二区三区乱码| 免费国产亚洲视频| 欧美日韩一区二区三区在线看| 亚洲人成影院在线观看| 成人av综合一区| 亚洲人吸女人奶水| 欧美又粗又大又爽| 亚洲精品国产无天堂网2021| 欧美伊人久久久久久久久影院| 亚洲品质自拍视频网站| 91在线观看高清| 亚洲乱码中文字幕| 欧美电影影音先锋| 蜜臀久久99精品久久久久宅男|