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

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

?? tcp.c

?? C51的tcpip源程序 包含了TCP,IP,ARP,ICMP等協議的接口
?? 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第一页| 亚洲国产一区二区三区| 欧美一区二区三区啪啪| 国产成人av自拍| 洋洋成人永久网站入口| 日韩欧美国产午夜精品| 国产一区在线看| 亚洲图片激情小说| 91精品欧美久久久久久动漫| 韩国欧美一区二区| 亚洲同性同志一二三专区| 91麻豆精品国产91久久久使用方法| 国产麻豆91精品| 一区二区视频在线| 精品国产一区二区三区不卡| 一本大道综合伊人精品热热| 麻豆精品视频在线观看视频| 国产精品久久久久久户外露出 | 亚洲综合另类小说| 日韩欧美一二三| 97se亚洲国产综合自在线观| 日韩专区在线视频| 中文字幕亚洲成人| 日韩限制级电影在线观看| 岛国精品在线观看| 欧美aaaaa成人免费观看视频| 国产精品黄色在线观看| 欧美大度的电影原声| 一本一本大道香蕉久在线精品 | 精品在线你懂的| 亚洲自拍偷拍九九九| 久久久久久亚洲综合影院红桃 | 蜜桃视频一区二区三区| 亚洲人123区| 国产夜色精品一区二区av| 欧美另类久久久品| 一本久道中文字幕精品亚洲嫩| 久久97超碰色| 丝袜美腿亚洲色图| 一级做a爱片久久| 日韩美女视频一区| 日本一区二区免费在线| 欧美xfplay| 日韩一区二区三区免费观看 | 欧美少妇性性性| 91浏览器入口在线观看| 从欧美一区二区三区| 国产自产高清不卡| 日本欧美在线看| 日韩制服丝袜av| 亚洲成人在线网站| 亚洲一区视频在线| 夜夜亚洲天天久久| 亚洲乱码日产精品bd| 中文字幕免费在线观看视频一区| 精品国产91九色蝌蚪| 日韩精品在线一区| 日韩亚洲欧美一区二区三区| 欧美精品久久天天躁| 99re免费视频精品全部| 高清国产一区二区三区| 国产一区二区三区综合| 激情深爱一区二区| 激情成人综合网| 国产精品99久久久久久有的能看| 精品一区二区久久| 国产精品一区二区三区网站| 国产成人综合在线播放| 国产**成人网毛片九色 | 一区二区久久久久久| 亚洲一区二区成人在线观看| 香蕉影视欧美成人| 爽好久久久欧美精品| 老司机午夜精品| 国产91高潮流白浆在线麻豆| 丁香一区二区三区| 一本色道综合亚洲| 91精品欧美一区二区三区综合在 | 国产精品成人免费在线| 1区2区3区精品视频| 一区二区三区.www| 午夜免费欧美电影| 久久99精品久久久久久久久久久久| 欧美aⅴ一区二区三区视频| 韩国毛片一区二区三区| 久久精品国产精品亚洲红杏| 国产成人鲁色资源国产91色综| 国产传媒久久文化传媒| 国产一区二区三区电影在线观看| 国产精品91xxx| 国产.欧美.日韩| 91国产成人在线| 欧美mv和日韩mv国产网站| 久久精品一区八戒影视| 亚洲另类一区二区| 日本亚洲最大的色成网站www| 国产成人免费视频精品含羞草妖精| 91在线观看成人| 6080yy午夜一二三区久久| 日本一区二区成人| 国产日韩欧美麻豆| 亚洲永久精品国产| 狠狠色综合播放一区二区| 99国产欧美久久久精品| 欧美日韩激情在线| 日韩一区二区三区观看| 亚洲国产成人午夜在线一区| 亚洲激情在线激情| 麻豆专区一区二区三区四区五区| 国产精品亚洲а∨天堂免在线| 99久久精品免费看| 欧美体内she精视频| 国产日韩欧美在线一区| 看电影不卡的网站| 91.com视频| 天天色天天操综合| 91亚洲永久精品| 欧美日韩高清在线| 中文字幕不卡的av| 日韩国产一区二| 97se狠狠狠综合亚洲狠狠| 日韩免费电影一区| 亚洲韩国一区二区三区| 懂色av一区二区三区蜜臀| 欧美一卡2卡3卡4卡| 国产精品不卡一区二区三区| 毛片不卡一区二区| 色94色欧美sute亚洲线路一ni| 久久久亚洲国产美女国产盗摄| 日韩黄色小视频| 91国产视频在线观看| 中文字幕日韩一区| 精东粉嫩av免费一区二区三区| 在线观看精品一区| 亚洲欧美在线观看| 粉嫩一区二区三区在线看| 精品欧美一区二区在线观看| 亚洲国产精品久久久久婷婷884| 国产成人精品亚洲午夜麻豆| 欧美日韩一级黄| 一二三区精品视频| 日韩欧美国产一区二区三区| 92精品国产成人观看免费| 欧美美女激情18p| 亚洲激情在线激情| 色视频成人在线观看免| 亚洲欧美自拍偷拍| 9人人澡人人爽人人精品| 国产精品色哟哟网站| 国产河南妇女毛片精品久久久 | 欧美高清精品3d| 亚洲一区二区三区中文字幕在线| 99久久精品国产网站| 亚洲欧洲精品天堂一级| 99这里都是精品| 亚洲欧美中日韩| 日本丰满少妇一区二区三区| 亚洲精品国产第一综合99久久| 一本在线高清不卡dvd| 亚洲精品视频在线| 在线观看成人免费视频| 亚洲一区在线看| 欧美精品久久99| 蜜桃av一区二区| 久久这里只有精品6| 国产成人精品亚洲日本在线桃色| 久久九九影视网| 国产成a人亚洲精| 国产欧美日韩不卡免费| 国产一区不卡视频| 欧美本精品男人aⅴ天堂| 久久国内精品自在自线400部| 日韩免费观看2025年上映的电影| 国模无码大尺度一区二区三区 | 国产精品美女久久久久久2018| 风间由美一区二区三区在线观看| 亚洲精品在线三区| 成人蜜臀av电影| 亚洲成人www| 欧美日韩中文一区| 日本高清不卡aⅴ免费网站| 99久久久久免费精品国产| 成人夜色视频网站在线观看| 日韩不卡在线观看日韩不卡视频| 91精品黄色片免费大全| 国产精品123区| 亚洲精品久久久蜜桃| 777午夜精品免费视频|