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

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

?? tcp.c

?? 基于GPRS網絡的遠程監控系統
?? 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一区二区三区免费野_久草精品视频
日本乱人伦一区| 国产成人夜色高潮福利影视| 国产欧美一区二区三区鸳鸯浴| 欧美一级视频精品观看| 精品视频在线免费看| 一本色道亚洲精品aⅴ| 色综合一区二区三区| 色综合久久久久网| 在线欧美日韩精品| 在线观看日韩国产| 欧美日韩一区中文字幕| 欧美日韩国产123区| 欧美妇女性影城| 日韩免费在线观看| 精品国产免费久久| 国产亚洲欧美色| 亚洲欧美影音先锋| 一区二区三区在线观看欧美| 亚洲一区二区视频| 日韩国产欧美在线视频| 欧美一级理论片| 26uuu精品一区二区| 中文字幕欧美三区| 亚洲蜜臀av乱码久久精品| 夜夜嗨av一区二区三区中文字幕| 亚洲成人久久影院| 韩国午夜理伦三级不卡影院| 大尺度一区二区| 色94色欧美sute亚洲13| 欧美精品1区2区| 精品久久久久久久久久久久久久久久久| 精品久久久久香蕉网| 国产精品初高中害羞小美女文| 一区二区三区四区视频精品免费 | 精品久久久久久久久久久久包黑料 | 日韩欧美中文字幕公布| 2020日本不卡一区二区视频| 国产精品日日摸夜夜摸av| 亚洲国产视频直播| 精品在线播放免费| 99精品视频在线观看| 5566中文字幕一区二区电影| 丁香一区二区三区| 国产麻豆91精品| 成人av网站免费| 欧美麻豆精品久久久久久| 久久综合九色综合97婷婷 | 亚洲电影在线免费观看| 久久99深爱久久99精品| 99精品久久只有精品| 欧美一区三区二区| 国产精品色噜噜| 欧美aaa在线| 99久久99久久精品免费看蜜桃| 337p亚洲精品色噜噜狠狠| 中文字幕 久热精品 视频在线| 亚洲电影视频在线| 岛国一区二区三区| 欧美美女视频在线观看| 国产精品久久久久一区二区三区 | 99国产精品久久久| 欧美一区二视频| 国产精品成人在线观看| 精品无人码麻豆乱码1区2区| 欧洲av在线精品| 国产精品素人视频| 美国三级日本三级久久99| 91丨porny丨国产| 精品成人免费观看| 午夜久久久久久久久| av激情成人网| 国产日韩三级在线| 麻豆中文一区二区| 精品婷婷伊人一区三区三| 国产精品欧美一区二区三区| 精品夜夜嗨av一区二区三区| 欧美色图天堂网| 亚洲天堂免费在线观看视频| 国产精品影视天天线| 欧美日韩小视频| 亚洲精品中文字幕乱码三区| 国产不卡免费视频| 精品毛片乱码1区2区3区| 日韩电影在线一区| 欧美视频在线一区| 一区二区三区四区亚洲| 99久久99久久精品免费观看| 国产精品无圣光一区二区| 国产一区在线视频| 欧美va日韩va| 欧美疯狂做受xxxx富婆| 亚洲一区二区偷拍精品| 欧洲一区在线观看| 亚洲免费视频成人| 91色视频在线| 亚洲激情自拍偷拍| 日本丶国产丶欧美色综合| 中文字幕一区二区三中文字幕| 国产精品一二三| 久久免费偷拍视频| 国产又黄又大久久| 国产午夜精品福利| 白白色 亚洲乱淫| 国产精品美女久久久久久久久| 欧美三级视频在线观看| 亚洲国产精品尤物yw在线观看| 中文字幕欧美日韩一区| 国产激情精品久久久第一区二区 | 国产乱人伦偷精品视频不卡| 日韩一区二区不卡| 美国十次综合导航| 精品国产乱码久久久久久久久 | 日韩欧美视频一区| 美美哒免费高清在线观看视频一区二区 | 久久精品国产精品亚洲精品| 51精品国自产在线| 麻豆成人91精品二区三区| 精品久久久久久久久久久久久久久 | 99久久婷婷国产| 国产精品短视频| 一本到不卡免费一区二区| 玉米视频成人免费看| 欧美视频在线一区| 久久国产精品无码网站| 精品久久国产老人久久综合| 国产精品香蕉一区二区三区| 亚洲国产成人在线| 日本高清免费不卡视频| 亚洲国产精品精华液网站| 欧美一区日本一区韩国一区| 国产麻豆精品视频| 中文字幕日韩欧美一区二区三区| www.在线欧美| 亚洲一区二区三区在线| 欧美mv日韩mv国产| 成人av影院在线| 午夜亚洲国产au精品一区二区| 91精品国产91久久久久久最新毛片 | 成人av在线播放网站| 亚洲一区二区三区四区在线免费观看| 欧美福利视频导航| 国产精品伊人色| 亚洲大片在线观看| 2023国产精华国产精品| 色婷婷综合视频在线观看| 青青草91视频| 中文幕一区二区三区久久蜜桃| 91福利精品第一导航| 美国毛片一区二区三区| 亚洲欧美中日韩| 51午夜精品国产| 91在线播放网址| 日韩电影免费一区| 国产精品天美传媒| 欧美一级高清片| 99热在这里有精品免费| 免费精品视频在线| 国产精品久久久久久久久久久免费看 | 国产精品一线二线三线精华| 亚洲欧美另类图片小说| 欧美电影免费观看高清完整版在 | 亚洲视频1区2区| 日韩午夜在线影院| 一本一道久久a久久精品| 久久 天天综合| 一区二区三区日韩精品| 久久综合给合久久狠狠狠97色69| 国产精品18久久久久| 99re8在线精品视频免费播放| 日韩一区二区三区视频| 国产精品婷婷午夜在线观看| 国产精品91一区二区| 一区二区三区中文字幕电影 | 国产精品久久久久久久久免费樱桃 | 色av成人天堂桃色av| 国产一区二区三区精品欧美日韩一区二区三区 | 亚洲国产美国国产综合一区二区 | 成人综合婷婷国产精品久久蜜臀 | 亚洲国产欧美在线| 国产精品成人网| 艳妇臀荡乳欲伦亚洲一区| 日韩色视频在线观看| 国产激情一区二区三区桃花岛亚洲| 天堂va蜜桃一区二区三区漫画版| 国产精品久久久久久户外露出 | 国产精品丝袜在线| 亚洲精品在线电影| 欧美久久久久久蜜桃| 色婷婷av久久久久久久| 91偷拍与自偷拍精品| 大陆成人av片| 丰满放荡岳乱妇91ww| 欧美大白屁股肥臀xxxxxx| 欧美日韩免费高清一区色橹橹| 成人免费视频视频| 国产精品综合久久| 美脚の诱脚舐め脚责91| 蜜臀av国产精品久久久久| 天天色综合成人网| 亚洲国产一区二区a毛片|