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

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

?? tcp.c

?? 通過單片機控制RTL8019實現TCP/IP
?? 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一区二区三区免费野_久草精品视频
欧美综合天天夜夜久久| 欧美自拍偷拍一区| 国产精品污www在线观看| 蜜桃一区二区三区四区| 色婷婷久久99综合精品jk白丝 | 国产午夜亚洲精品不卡| 日韩电影在线看| 欧美一级片在线| 男人的天堂亚洲一区| 中文字幕一区二区日韩精品绯色| 中文成人综合网| 无吗不卡中文字幕| 91女人视频在线观看| 精品国产欧美一区二区| 日韩和欧美一区二区三区| 91在线精品一区二区| 国产欧美中文在线| 国产在线精品一区在线观看麻豆| 欧美日韩电影在线播放| 依依成人精品视频| 91丨国产丨九色丨pron| 国产精品美女久久久久久| 国产一区二区久久| xfplay精品久久| 国产一区二区精品在线观看| 日韩欧美黄色影院| 蜜臀av一区二区在线观看| 9191国产精品| 五月天亚洲婷婷| 7777精品伊人久久久大香线蕉 | 国产精品一品二品| 精品国产a毛片| 国产自产视频一区二区三区| 日韩精品一区国产麻豆| 日韩国产精品大片| 日韩一本二本av| 激情欧美一区二区三区在线观看| 欧美一区二区性放荡片| 麻豆国产精品一区二区三区| 日韩亚洲欧美中文三级| 狠狠色丁香久久婷婷综| 久久久久久久久久久黄色| 国产99久久久国产精品免费看| 久久久综合激的五月天| av一区二区三区四区| 亚洲乱码中文字幕| 欧美日韩精品免费观看视频| 日本中文字幕一区| 亚洲色图视频网| 亚洲一级二级三级在线免费观看| 日韩av电影免费观看高清完整版在线观看| 人人狠狠综合久久亚洲| 欧美日韩一区二区三区免费看| 亚洲国产电影在线观看| www.欧美.com| 亚洲最大成人综合| 欧美写真视频网站| 99久久精品国产一区二区三区| 在线观看视频91| 欧美日韩一本到| 国产精品久久三区| 国产激情91久久精品导航| 国产精品久久久久久久久免费丝袜| 精品在线免费视频| 久久电影网电视剧免费观看| 久久综合久久综合久久综合| 色诱亚洲精品久久久久久| 热久久免费视频| 欧美国产一区二区在线观看| 日韩精品中文字幕在线一区| 色视频成人在线观看免| 日韩和的一区二区| 欧美国产日韩a欧美在线观看| 91麻豆成人久久精品二区三区| 午夜精品久久久久影视| 亚洲国产高清在线| 欧美一区二区三区男人的天堂| 国产精品一二三| 中文字幕欧美一区| 日韩美女视频在线| 在线一区二区视频| 国产99久久久国产精品潘金网站| 午夜免费久久看| 中文字幕一区视频| 久久久亚洲午夜电影| 欧美日韩一区二区三区高清| 高清不卡一区二区| 七七婷婷婷婷精品国产| 中文字幕一区二区三区四区不卡| 日韩欧美中文字幕制服| 色欧美乱欧美15图片| 国产凹凸在线观看一区二区| 亚洲电影第三页| 综合婷婷亚洲小说| 国产女人aaa级久久久级| 51精品视频一区二区三区| 91丨porny丨户外露出| 国产aⅴ综合色| 激情五月播播久久久精品| 亚洲va在线va天堂| 亚洲欧洲一区二区在线播放| 国产午夜精品一区二区| 2024国产精品| 欧美电影免费观看高清完整版在线观看 | 亚洲图片欧美视频| 亚洲情趣在线观看| 亚洲欧美综合网| 国产欧美综合在线观看第十页| 精品免费一区二区三区| 欧美大片在线观看一区二区| 555夜色666亚洲国产免| 欧美狂野另类xxxxoooo| 欧美放荡的少妇| 欧美日韩高清在线播放| 欧美日韩日本视频| 欧美裸体一区二区三区| 5月丁香婷婷综合| 91麻豆精品国产91久久久久久 | 8x8x8国产精品| 欧美精品在线一区二区三区| 欧美高清dvd| 日韩视频在线永久播放| 精品剧情在线观看| 久久久久成人黄色影片| 国产精品蜜臀av| 亚洲少妇最新在线视频| 亚洲一区在线观看免费| 亚洲综合色丁香婷婷六月图片| 亚洲一区视频在线观看视频| 丝袜亚洲另类欧美| 欧洲精品视频在线观看| 7777精品伊人久久久大香线蕉超级流畅| 91捆绑美女网站| 欧美三区在线视频| 日韩欧美电影一二三| 国产亚洲午夜高清国产拍精品| 欧美激情在线观看视频免费| 亚洲欧美日韩中文字幕一区二区三区| 亚洲欧美aⅴ...| 首页国产欧美久久| 国产在线视频一区二区| 99视频精品全部免费在线| 一本高清dvd不卡在线观看| 欧美在线视频你懂得| 欧美成人高清电影在线| 国产精品人妖ts系列视频| 亚洲欧美一区二区久久| 日本欧美一区二区在线观看| 国产在线视频一区二区| 日本久久一区二区三区| 91精品一区二区三区在线观看| 欧美精品一卡二卡| 日本一区二区三区国色天香| 亚洲激情在线激情| 国产主播一区二区| 91原创在线视频| 欧美成人一区二区| 亚洲人成7777| 久久99国内精品| 色视频成人在线观看免| 久久久久成人黄色影片| 亚洲福利一区二区三区| 国产xxx精品视频大全| 欧美精品一卡两卡| 亚洲色图在线视频| 国产一区二区调教| 制服丝袜国产精品| 亚洲精品成人精品456| 韩国av一区二区三区四区| 欧美日韩另类一区| 国产精品乱码妇女bbbb| 免费不卡在线视频| 在线区一区二视频| 国产目拍亚洲精品99久久精品| 午夜精品久久久久久久| 99久久免费国产| 久久伊人中文字幕| 免费人成在线不卡| 欧美日韩高清在线播放| 亚洲欧美激情一区二区| 国产91精品欧美| 久久丝袜美腿综合| 美美哒免费高清在线观看视频一区二区| 色婷婷av一区二区三区大白胸| 国产精品日日摸夜夜摸av| 国产精品伊人色| 亚洲精品一区二区三区福利| 五月婷婷久久综合| 欧美日韩国产高清一区| 亚洲另类色综合网站| a亚洲天堂av| 国产精品麻豆一区二区| 高清日韩电视剧大全免费| 久久精品亚洲精品国产欧美| 国模无码大尺度一区二区三区| 91精品国产综合久久婷婷香蕉| 亚洲卡通欧美制服中文| 色婷婷综合久久久久中文一区二区| 国产精品久久久久久久久久免费看| 国产乱码精品一品二品|