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

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

?? tcp.c

?? 一個8位單片機的TCPIP處理程序
?? 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一区二区三区免费野_久草精品视频
亚洲人成网站在线| 亚洲精品在线免费观看视频| 国产校园另类小说区| 日韩av午夜在线观看| 欧美性一级生活| 亚洲欧美另类久久久精品| 成人黄色免费短视频| 2023国产精品视频| 狠狠色狠狠色综合| 精品播放一区二区| 国产一区二区不卡在线| 美女视频黄免费的久久| 日韩欧美一二三四区| 紧缚奴在线一区二区三区| 久久综合久久综合久久| 国产一区在线观看视频| 久久久久久久久久久电影| 国产不卡视频一区| 国产精品成人一区二区三区夜夜夜| 懂色av一区二区三区蜜臀| 国产精品成人免费| 在线观看区一区二| 美腿丝袜在线亚洲一区| 久久嫩草精品久久久精品| 99久久精品免费精品国产| 亚洲少妇屁股交4| 欧美日韩日本视频| 精品一区二区精品| 亚洲欧美怡红院| 欧美影片第一页| 精油按摩中文字幕久久| 成人av在线网| 丝袜美腿亚洲一区二区图片| 日本一区二区视频在线| 欧美图片一区二区三区| 激情综合色综合久久综合| 亚洲欧美视频在线观看视频| 精品久久久网站| 91在线丨porny丨国产| 日本女人一区二区三区| 亚洲欧洲一区二区三区| 欧美xxxxx裸体时装秀| 在线观看亚洲专区| 成人一二三区视频| 琪琪一区二区三区| 亚洲一区精品在线| 最新久久zyz资源站| 久久久精品2019中文字幕之3| 欧美日韩亚洲综合在线| 色婷婷综合视频在线观看| 国产成人综合在线播放| 久久av老司机精品网站导航| 亚洲成a天堂v人片| 一区二区三区在线免费| 亚洲图片另类小说| 九一久久久久久| 免费看欧美美女黄的网站| 亚洲午夜久久久久中文字幕久| 亚洲国产精品成人综合色在线婷婷| 日韩欧美一区在线观看| 6080国产精品一区二区| 欧美精品aⅴ在线视频| 欧美日韩久久久| 欧美精品乱码久久久久久按摩| 91黄色小视频| 欧美日韩国产系列| 欧美日韩aaaaa| 欧美男生操女生| 欧美一区二区视频在线观看2022 | 亚洲欧美一区二区三区孕妇| 国产亚洲成aⅴ人片在线观看| 欧美一级精品大片| 精品国产污网站| 欧美mv日韩mv国产网站| 久久久久久免费| 国产欧美日韩精品在线| 中文字幕一区二区三区蜜月 | 午夜精品免费在线| 久久99精品久久久久久动态图| 精品影院一区二区久久久| 岛国一区二区三区| 色八戒一区二区三区| 3d动漫精品啪啪1区2区免费| 欧美一区二区三区成人| 久久精品人人做| 亚洲素人一区二区| 亚洲成人av资源| 国产麻豆欧美日韩一区| 91麻豆免费视频| 日韩欧美一区中文| 欧美国产欧美亚州国产日韩mv天天看完整| 中文字幕欧美日韩一区| 亚洲一区在线观看免费观看电影高清| 日本成人在线一区| 成人午夜精品一区二区三区| 欧美色倩网站大全免费| 国产欧美一区二区精品仙草咪| 亚洲国产精品久久艾草纯爱| 国产成人精品网址| 在线不卡中文字幕| 亚洲三级电影全部在线观看高清| 美女性感视频久久| 欧美在线小视频| 中文字幕av资源一区| 久久99国产精品麻豆| 欧美婷婷六月丁香综合色| 国产精品久久久久久久久快鸭| 免费亚洲电影在线| 精品视频一区三区九区| 国产精品久久久久aaaa| 麻豆精品在线播放| 欧美三级日韩三级| 一区二区三区免费| jizzjizzjizz欧美| 国产亚洲欧美中文| 国产精品123| 久久久久国产精品麻豆| 激情五月播播久久久精品| 日韩午夜在线影院| 秋霞午夜鲁丝一区二区老狼| 欧美性xxxxx极品少妇| 一区二区三区中文在线观看| 色哟哟精品一区| 亚洲一区二区三区三| 欧亚一区二区三区| 午夜国产精品影院在线观看| 欧美群妇大交群中文字幕| 亚洲成人高清在线| 91精品国产综合久久久蜜臀图片| 亚洲成人久久影院| 一级做a爱片久久| 欧美三级中文字幕在线观看| 亚洲福中文字幕伊人影院| 欧美日韩成人在线| 久久er99热精品一区二区| 久久久.com| 日本丶国产丶欧美色综合| 三级成人在线视频| 久久网站最新地址| 成人av电影在线观看| 天天色综合天天| 欧美精品一区二区在线播放| 成人av资源网站| 亚洲va国产天堂va久久en| 精品国产免费一区二区三区四区| 国产精品一区二区久久不卡 | 亚洲欧洲日产国产综合网| 91极品美女在线| 激情综合网天天干| 亚洲一区欧美一区| 精品国产污网站| 在线精品亚洲一区二区不卡| 奇米综合一区二区三区精品视频| 久久九九全国免费| 欧美午夜电影网| www.视频一区| 久草这里只有精品视频| 亚洲夂夂婷婷色拍ww47| 久久先锋影音av鲁色资源| 在线日韩国产精品| 粉嫩av一区二区三区粉嫩| 午夜电影网亚洲视频| 亚洲免费观看高清在线观看| 91精品国产综合久久久久| 色激情天天射综合网| 岛国一区二区在线观看| 麻豆成人免费电影| 亚洲国产cao| 亚洲日穴在线视频| 国产精品福利一区二区三区| 日韩欧美高清在线| 欧美二区三区的天堂| 一本久道久久综合中文字幕| 成人午夜免费电影| 老鸭窝一区二区久久精品| 亚洲超碰精品一区二区| 日本一区二区成人在线| 国产欧美日韩不卡| 日韩欧美国产三级电影视频| 日韩欧美中文一区| 日韩欧美一级片| 日韩精品在线一区二区| 欧美sm极限捆绑bd| 欧美一区二区视频免费观看| 欧美日韩不卡在线| 欧美日韩日日夜夜| 91精品国产综合久久精品图片| 欧美另类久久久品| 在线电影院国产精品| 91精品午夜视频| 欧美精品一区男女天堂| 91精品国产91久久久久久最新毛片| 欧美少妇xxx| 欧美岛国在线观看| 国产精品久久久久影院| 亚洲人成网站精品片在线观看 | 波多野结衣在线一区| 99国产精品视频免费观看| 欧美性色欧美a在线播放| 日韩欧美在线一区二区三区|