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

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

?? tcp.c

?? 這是為51單片機編的tcpip協議棧
?? C
?? 第 1 頁 / 共 2 頁
字號:
   // a temporary conection  to it for processing
   if (i == 5)
   {
      if (tcp->flags & FLG_SYN)
      {
         // Find first unused connection (one with IP = 0) 
         for (j=0; j < 5; j++)
         {
            if (conxn[j].ipaddr == 0)
            {
               nr = j;
               // Initialize new connection
               conxn[nr].state = STATE_LISTEN;
               break;
            }
         }
      
         // If all connections are used then drop msg
         if (j == 5) return;
         
         if (debug)
         {
            serial_send("TCP: New connection ");
            memset(text, 0, 10);
            itoa((UINT)nr, text, 10);
            serial_send(text);
			   serial_send("\r");
         }
      }
   }


   // By now we should have a connection number in range of 0-4
   // Do a check to avoid any chance of exceeding size of struct
   if (nr > 4)
   {
      if (debug) serial_send("TCP: Error in assigning conxn number\r");
      return;
   }

   // Eventually put in protection against wrapping sequence
   // numbers, for now make the client start over if his
   // sequence number is close to wrapping
   if (tcp->sequence > 0xFFFFFF00L) 
   {
      if (debug) serial_send("TCP: Rcvd a high sequence number\r");
		conxn[nr].ipaddr = 0;			
		tcp_send(FLG_RST, 20, NO_CONNECTION);
		return;		
   }
           
   // Handle messages whose action is mostly independent of state
   // such as RST, SYN, and segment with no ACK.  That way the
	// state machine below does not need to worry about it.
   if (tcp->flags & FLG_RST)
   {
      // An RST does not depend on state at all.  And it does
      // not count as data so do not send an ACK here.  Close
      // connection
 		if (debug) serial_send("TCP: Rcvd a reset\r");
      conxn[nr].ipaddr = 0;
      return;
   }
	
	else if (tcp->flags & FLG_SYN)
	{
	   // A SYN segment only makes sense if connection is in LISTEN 
	   if ((conxn[nr].state != STATE_LISTEN) &&
          (conxn[nr].state != STATE_CLOSED))
		{
			if (debug) serial_send("TCP: Error, rcvd bogus SYN\r");
			conxn[nr].ipaddr = 0;			
		  	tcp_send(FLG_RST, 20, NO_CONNECTION);
		  	return;		
		}
	}
	
	else if ((tcp->flags & FLG_ACK) == 0)
	{
		// Incoming segments except SYN or RST must have ACK bit set
	 	// See TCP/IP Illustrated, Vol 2, Page 965
      // Drop segment but do not send a reset
		if (debug) serial_send("TCP: Error, rcvd segment has no ACK\r");
		return;
	}
	   
   // Compute length of header including options, and from that
   // compute length of actual data
   header_len =  (tcp->flags & 0xF000) >> 10;
   data_len = len - header_len;


         
   // Handle TCP state machine for this connection
   switch (conxn[nr].state)
   {
      case STATE_CLOSED:
      case STATE_LISTEN:
            
      // If incoming segment contains SYN and no ACK, then handle 
      if ((tcp->flags & FLG_SYN) && ((tcp->flags & FLG_ACK) == 0))
      {
         // Capture his starting sequence number and generate
         // my starting sequence number
         // Fill in connection information
         conxn[nr].ipaddr = ip->source_ipaddr;
         conxn[nr].port = tcp->source_port;
         conxn[nr].state = STATE_LISTEN;
         conxn[nr].his_sequence = 1 + tcp->sequence;
         conxn[nr].his_ack = tcp->ack_number;
         
         // Use system clock for initial sequence number
         EA = 0;
         conxn[nr].my_sequence = initial_sequence_nr;
         initial_sequence_nr += 64000L;
         EA = 1;                  
                  
         // Send header options with the next message
         // Since timestamps are optional and we do not use
         // them, do not have to send them 
         // After sending the SYN ACK the client browser will
         // blast me with 2 messages, an ACK, and a HTTP GET
         tcp_send(FLG_SYN | FLG_ACK, 28, nr);
         
         // My SYN flag increments my sequence number
         // My sequence number is always updated to point to 
         // the next byte to be sent.  So the incoming ack
         // number should equal my sequence number  
         conxn[nr].my_sequence++;
      
         conxn[nr].state = STATE_SYN_RCVD;
         if (debug) serial_send("TCP: Entered SYN RCVD state\r");
      }
		else 
      {
         // Sender is out of sync so send reset
         conxn[nr].ipaddr = 0;
         tcp_send(FLG_RST, 20, NO_CONNECTION);   
      } 
		break;


      case STATE_SYN_RCVD:
      // He may already be sending me data - should process it
		conxn[nr].his_sequence += data_len;
      conxn[nr].his_ack = tcp->ack_number;
            
      if (tcp->flags & FLG_FIN)
		{
		   // His FIN counts as a byte of data
         conxn[nr].his_sequence++;
         tcp_send(FLG_ACK, 20, nr);
         conxn[nr].state = STATE_CLOSE_WAIT;
         if (debug) serial_send("TCP: Entered CLOSE_WAIT state\r");
               
        	// At this point we would normally wait for the	application
         // to close.  For now, send FIN right away.
         tcp_send(FLG_FIN | FLG_ACK, 20, nr);
         conxn[nr].my_sequence++;   // For my FIN
         conxn[nr].state = STATE_LAST_ACK;
         if (debug) serial_send("TCP: Entered LAST ACK state\r");
      }

		// Make sure he is ACKing my SYN
		else if (tcp->ack_number == conxn[nr].my_sequence)
      {
         conxn[nr].state = STATE_ESTABLISHED;
         if (debug) serial_send("TCP: Entered ESTABLISHED state\r");
         // If sender sent data ignore it and he will resend
         // Do not send response because we received no
         // data... wait for client to send something to me 
      }
      break;


      case STATE_ESTABLISHED:
      conxn[nr].his_ack = tcp->ack_number;
           
      if (tcp->flags & FLG_FIN)
		{
		   // His FIN counts as a byte of data
         conxn[nr].his_sequence++;
         tcp_send(FLG_ACK, 20, nr);
         conxn[nr].state = STATE_CLOSE_WAIT;
         if (debug) serial_send("TCP: Entered CLOSE_WAIT state\r");
               
        	// At this point we would normally wait for the	application
         // to close.  For now, send FIN immediately.
         tcp_send(FLG_FIN | FLG_ACK, 20, nr);
         conxn[nr].my_sequence++;   // For my FIN
         conxn[nr].state = STATE_LAST_ACK;
         if (debug) serial_send("TCP: Entered LAST ACK state\r");
      }
		else if (data_len != 0)
      {
			// Received normal TCP segment from sender with data
      	// Send an ACK immediately and pass the data on to
			// the application
			conxn[nr].his_sequence += data_len;
         tcp_send(FLG_ACK, 20, nr); 		// Send ACK
      	  
      	      	      	 									
			// Send pointer to start of TCP payload
			// http_server increments my sequence number when 
         // sending so don't worry about it here
         result = http_server(inbuf, header_len, nr, 0);
								
			// Start timer to close conxn if no activity
			conxn[nr].inactivity = INACTIVITY_TIME;
		}
	   break;


      case STATE_CLOSE_WAIT:
      // With this code, should not get here
      if (debug) serial_send("TCP: Oops! Rcvd unexpected message\r");
      
      break;

      
      case STATE_LAST_ACK:
      conxn[nr].his_ack = tcp->ack_number;
            
      // If he ACK's my FIN then close
      if (tcp->ack_number == conxn[nr].my_sequence)
      {
         conxn[nr].state = STATE_CLOSED;
         conxn[nr].ipaddr = 0;  // Free up struct area
         just_closed = TRUE;
      }
      break;

      
      case STATE_FIN_WAIT_1:
      // He may still be sending me data - should process it
		conxn[nr].his_sequence += data_len;
      conxn[nr].his_ack = tcp->ack_number;
                  
      if (tcp->flags & FLG_FIN)
      {
         // His FIN counts as a byte of data
         conxn[nr].his_sequence++;
         tcp_send(FLG_ACK, 20, nr);
         
         // If he has ACK'd my FIN then we can close connection
         if (tcp->ack_number == conxn[nr].my_sequence)
			{
         	conxn[nr].state = STATE_TIME_WAIT;
         	if (debug) serial_send("TCP: Entered TIME_WAIT state\r");
               
         	conxn[nr].state = STATE_CLOSED;
         	conxn[nr].ipaddr = 0;  // Free up connection
         	just_closed = TRUE;
      	}
			else
			{
				// He has not ACK'd my FIN.  This happens when there is a simultaneous
				// close - I got his FIN but he has not yet ACK'd my FIN
				conxn[nr].state = STATE_CLOSING;
				if (debug) serial_send("TCP: Entered CLOSING state\r");
			}
		}
      else if (tcp->ack_number == conxn[nr].my_sequence)
      {
         // He has ACK'd my FIN but has not sent a FIN yet himself
         conxn[nr].state = STATE_FIN_WAIT_2;
         if (debug) serial_send("TCP: Entered FIN_WAIT_2 state\r");
      }
      break;

      
      case STATE_FIN_WAIT_2:
      // He may still be sending me data - should process it
		conxn[nr].his_sequence += data_len;
      conxn[nr].his_ack = tcp->ack_number;
      
      if (tcp->flags & FLG_FIN)
      {
         conxn[nr].his_sequence++; // For his FIN flag
         tcp_send(FLG_ACK, 20, nr);
         conxn[nr].state = STATE_TIME_WAIT;
         if (debug) serial_send("TCP: Entered TIME_WAIT state\r");
         conxn[nr].state = STATE_CLOSED;
         conxn[nr].ipaddr = 0;  // Free up struct area
         just_closed = TRUE;
      }
      break;
            
            
      case STATE_TIME_WAIT:
      // With this code, should not get here
      if (debug) serial_send("TCP: Oops! In TIME_WAIT state\r");
      break;

      
      case STATE_CLOSING:
      // Simultaneous close has happened. I have received his FIN
      // but he has not yet ACK'd my FIN.  Waiting for ACK.
		// Will not receive data in this state
		conxn[nr].his_ack = tcp->ack_number;
      		
		if (tcp->ack_number == conxn[nr].my_sequence)
      {
		   conxn[nr].state = STATE_TIME_WAIT;
         if (debug) serial_send("TCP: Entered TIME_WAIT state\r");
         
         // Do not send any response to his ACK
         conxn[nr].state = STATE_CLOSED;
         conxn[nr].ipaddr = 0;  // Free up struct area
         just_closed = TRUE;
      }
      break;

      
      default:
      if (debug) serial_send("TCP: Error, no handler\r");
      break;
   }
   
   // This is for debug, to see when conxn closes
   if (just_closed)
   {
      just_closed = FALSE;
      if (debug)
      {
         serial_send("TCP: Closed connection ");
         memset(text, 0, 10);
         itoa((UINT)nr, text, 10);
		   serial_send(text);
		   serial_send("\r");
      }
   }
}



?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91精品国产福利| 91精品国模一区二区三区| 久久精品亚洲一区二区三区浴池 | 中文字幕国产一区二区| 99久久99久久综合| 在线视频一区二区免费| 中文字幕不卡的av| 久久精品国产久精国产| 欧美日韩中文字幕一区二区| 专区另类欧美日韩| 国产成人精品亚洲日本在线桃色| 日韩一区二区三区av| 亚洲线精品一区二区三区八戒| 国产91高潮流白浆在线麻豆| 精品久久久久香蕉网| 喷白浆一区二区| 欧美日韩精品欧美日韩精品| 亚洲人成人一区二区在线观看| 国产激情视频一区二区三区欧美| 亚洲国产精品激情在线观看| 日韩av网站在线观看| 欧美在线看片a免费观看| 国产精品日韩精品欧美在线| 国产精一区二区三区| 日韩欧美国产三级电影视频| 日韩电影在线观看网站| 欧美日韩精品欧美日韩精品| 亚洲成a人在线观看| 欧美性大战久久久久久久 | 欧美一级搡bbbb搡bbbb| 奇米影视一区二区三区| 欧美日韩mp4| 日产国产高清一区二区三区| 欧美巨大另类极品videosbest | 亚洲成a人片综合在线| 欧美老女人在线| 日日夜夜精品免费视频| 欧美精品久久99久久在免费线| 亚洲国产乱码最新视频 | va亚洲va日韩不卡在线观看| 中文字幕五月欧美| 色哟哟一区二区三区| 亚洲国产三级在线| 欧美理论电影在线| 久久69国产一区二区蜜臀| 久久亚洲二区三区| 丁香啪啪综合成人亚洲小说| 中文字幕在线免费不卡| 精品视频全国免费看| 麻豆91免费观看| 久久久噜噜噜久久中文字幕色伊伊 | 精品国产一区二区精华| 国产一区 二区| 自拍偷拍国产精品| 欧美日韩精品专区| 国产一区二区三区在线观看免费视频 | 亚洲欧美精品午睡沙发| 欧美日韩成人在线一区| 国产在线看一区| 亚洲日本中文字幕区| 欧美人牲a欧美精品| 国产一区999| 亚洲一区二区美女| 精品国产第一区二区三区观看体验| 国产精品资源网| 一区二区三区在线观看欧美| 91精品国产免费久久综合| 风间由美中文字幕在线看视频国产欧美| 国产精品进线69影院| 欧美在线一二三| 国产一区二区三区在线观看免费| 国产婷婷色一区二区三区 | 粉嫩嫩av羞羞动漫久久久| 亚洲制服欧美中文字幕中文字幕| 日韩久久精品一区| 91搞黄在线观看| 国产一区二区不卡在线| 亚洲国产欧美日韩另类综合| 国产人成亚洲第一网站在线播放| 欧美欧美午夜aⅴ在线观看| aaa欧美日韩| 久久av中文字幕片| 亚洲午夜久久久| 中文字幕电影一区| 精品乱人伦一区二区三区| 色诱亚洲精品久久久久久| 国产中文一区二区三区| 午夜精品久久一牛影视| 亚洲欧洲国产日本综合| 国产日韩成人精品| 精品国产制服丝袜高跟| 91精品国产综合久久香蕉麻豆| 一本久道久久综合中文字幕 | 国产精品拍天天在线| 日韩欧美国产电影| 精品视频色一区| 色www精品视频在线观看| 成人av在线播放网站| 国产一区二区不卡| 韩国女主播成人在线| 蜜桃精品视频在线观看| 日韩精品视频网| 亚洲va在线va天堂| 亚洲精选一二三| 亚洲欧洲日本在线| 亚洲区小说区图片区qvod| 国产精品久久久久四虎| 日本一区二区三级电影在线观看| 久久综合99re88久久爱| 日韩欧美专区在线| 精品久久久久香蕉网| 精品国产乱码久久久久久浪潮| 宅男噜噜噜66一区二区66| 欧美军同video69gay| 91麻豆精品国产91久久久更新时间| 欧美日韩精品三区| 日韩一区和二区| 精品免费一区二区三区| 久久婷婷久久一区二区三区| 久久色在线观看| 国产欧美va欧美不卡在线| 国产精品免费视频一区| 亚洲美女视频在线观看| 亚洲高清视频中文字幕| 人人精品人人爱| 国内精品国产成人国产三级粉色| 国内外精品视频| 成人高清免费观看| 日本道在线观看一区二区| 欧美二区乱c少妇| 日韩精品一区二区三区四区 | 偷窥少妇高潮呻吟av久久免费| 日本视频中文字幕一区二区三区| 麻豆国产精品官网| 国产成人午夜精品影院观看视频 | 国产成人aaa| 99久久综合狠狠综合久久| 欧美自拍偷拍午夜视频| 欧美一区二区三区男人的天堂| 久久精品一区二区三区四区| 国产精品二三区| 天天做天天摸天天爽国产一区| 精品一区二区av| caoporen国产精品视频| 欧美熟乱第一页| 久久视频一区二区| 亚洲精品久久久蜜桃| 蜜桃一区二区三区在线观看| 成人av午夜电影| 欧美二区在线观看| 日本一区二区高清| 日韩电影在线看| 99久久精品国产网站| 日韩欧美电影在线| 亚洲欧美日韩久久| 极品少妇xxxx精品少妇| 色婷婷综合久色| 欧美精品一区二区三区蜜臀| 一区二区三区在线观看视频| 九色|91porny| 欧美日韩综合不卡| ●精品国产综合乱码久久久久| 蜜桃精品视频在线| 欧美亚洲动漫另类| 国产精品久久久久久福利一牛影视 | 丁香另类激情小说| 日韩欧美一级片| 一区二区三区**美女毛片| 国产精品一区二区久久精品爱涩| 在线成人免费视频| 一区二区三区高清不卡| 国产不卡高清在线观看视频| 欧美一区二区在线视频| 日韩一区日韩二区| 国产一区二区视频在线播放| 欧美一区二区三区婷婷月色| 一区二区视频在线看| 国产99久久久国产精品潘金| 日韩欧美国产一区二区三区| 午夜精品一区二区三区三上悠亚| 91亚洲精品久久久蜜桃网站 | 久久亚洲欧美国产精品乐播| 首页亚洲欧美制服丝腿| 色综合夜色一区| 中文字幕中文字幕在线一区 | 成人免费视频网站在线观看| 久久综合九色综合97婷婷女人 | 亚洲精品欧美综合四区| 成人国产精品免费观看| 国产性做久久久久久| 九色综合狠狠综合久久| 日韩美女天天操| 麻豆精品新av中文字幕| 日韩三区在线观看| 美女精品一区二区| 精品国精品国产尤物美女| 久久99精品国产麻豆婷婷洗澡| 日韩一区二区三区四区| 免费在线欧美视频| 精品久久一区二区|