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

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

?? tcp.c

?? VB從入門到精通學習教程,寫的非常詳細,非常好
?? 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一区二区三区免费野_久草精品视频
久久日韩精品一区二区五区| 久久精品日韩一区二区三区| 国产麻豆精品95视频| 亚洲美女淫视频| 久久精品网站免费观看| 欧美在线视频日韩| 成人黄色av网站在线| 久久99精品久久久久久| 一级精品视频在线观看宜春院| 久久久久9999亚洲精品| 91精品国产一区二区| 欧美写真视频网站| av色综合久久天堂av综合| 久久99精品国产.久久久久久| 亚洲一线二线三线视频| 最近日韩中文字幕| 精品福利二区三区| 欧美一区二区福利在线| 欧美中文字幕一区| 91浏览器打开| 99久久国产综合精品色伊| 国产寡妇亲子伦一区二区| 日本成人在线电影网| 日韩精品色哟哟| 亚洲成在线观看| 亚洲综合激情另类小说区| 色天天综合色天天久久| 亚洲综合成人在线| 1区2区3区欧美| 中文字幕日韩精品一区| 一区在线播放视频| 国产精品高清亚洲| ...xxx性欧美| 中文字幕一区二区日韩精品绯色| 国产欧美一区二区精品婷婷| 久久青草欧美一区二区三区| 久久综合国产精品| 久久久精品日韩欧美| 欧美成人官网二区| 久久蜜桃一区二区| 中文在线一区二区| 国产精品福利一区| 亚洲精品视频一区二区| 亚洲一区二区视频| 日本黄色一区二区| 91黄色激情网站| 欧美日韩国产系列| 欧美一区二区三区婷婷月色 | 亚洲风情在线资源站| 中文字幕一区二区在线播放| 久久久久九九视频| 欧美激情一二三区| 又紧又大又爽精品一区二区| 一区二区三区在线播| 亚洲午夜视频在线观看| 日韩av一区二区三区| 麻豆精品在线播放| 成人污污视频在线观看| 91欧美激情一区二区三区成人| 欧美在线小视频| 日韩欧美你懂的| 欧美国产日韩精品免费观看| ●精品国产综合乱码久久久久| 亚洲一区二区三区小说| 麻豆极品一区二区三区| 国产成人精品网址| 色就色 综合激情| 日韩欧美国产一区二区三区 | 国产精品九色蝌蚪自拍| 亚洲一二三四区| 老司机精品视频在线| 国产成人精品网址| 欧美色图片你懂的| 欧美精品一区二区精品网| 亚洲视频在线观看一区| 亚洲在线视频免费观看| 蜜臀91精品一区二区三区| 国产91丝袜在线播放九色| 欧洲在线/亚洲| 久久免费国产精品| 亚洲观看高清完整版在线观看| 九色porny丨国产精品| 色综合久久久久综合| 欧美va日韩va| 一区二区三区中文免费| 精品中文字幕一区二区| 在线观看日韩电影| 久久综合狠狠综合久久综合88 | 欧美视频一区二区三区| 久久久久久久久久久久久夜| 玉足女爽爽91| 国产精品亚洲一区二区三区妖精| 在线观看网站黄不卡| 欧美高清在线视频| 蜜芽一区二区三区| 91福利精品视频| 中文字幕精品—区二区四季| 亚洲高清视频的网址| www.欧美.com| 精品欧美乱码久久久久久| 午夜视黄欧洲亚洲| 一本色道亚洲精品aⅴ| 国产午夜精品理论片a级大结局| 午夜视频在线观看一区二区三区| 99综合电影在线视频| 久久亚洲私人国产精品va媚药| 午夜不卡av在线| 色欧美乱欧美15图片| 中文av一区二区| 国产精品自拍三区| 精品国产亚洲一区二区三区在线观看| 亚洲国产另类精品专区| 成人动漫视频在线| 欧美韩国日本不卡| 国产麻豆精品一区二区| 欧美成人a在线| 日本在线不卡视频一二三区| 欧美影院一区二区| 中文字幕中文字幕一区二区| 国产不卡高清在线观看视频| 精品国产sm最大网站免费看| 免费人成在线不卡| 欧美一级免费大片| 日韩av一区二| 日韩一卡二卡三卡| 日本视频免费一区| 日韩一区二区三区观看| 免费人成黄页网站在线一区二区| 欧美日本国产一区| 婷婷综合另类小说色区| 欧美剧在线免费观看网站 | 国产成人精品一区二| 久久精品亚洲精品国产欧美 | 国产精品福利av| 高清成人在线观看| 国产精品久久久久久久久晋中| 成人精品免费视频| 亚洲三级在线看| 91在线丨porny丨国产| 中文字幕一区在线观看视频| 99久久精品久久久久久清纯| 亚洲女厕所小便bbb| 欧美自拍偷拍午夜视频| 午夜一区二区三区在线观看| 欧美一区二区三区在线| 韩国v欧美v亚洲v日本v| 中文字幕精品一区二区三区精品| 成人做爰69片免费看网站| 国产精品高潮呻吟| 欧美在线色视频| 奇米四色…亚洲| 国产亚洲成年网址在线观看| 国产成人精品午夜视频免费| 日韩一区在线看| 欧美精品亚洲一区二区在线播放| 麻豆精品新av中文字幕| 国产欧美精品区一区二区三区| 成人av小说网| 亚洲成人av资源| 欧美tickling网站挠脚心| 成人av一区二区三区| 亚洲图片欧美一区| 久久影视一区二区| 91美女片黄在线| 美女脱光内衣内裤视频久久网站 | 午夜精品成人在线| 亚洲精品在线观看网站| av激情亚洲男人天堂| 亚洲一区二区欧美日韩 | 久久影音资源网| 日本乱人伦一区| 国产老女人精品毛片久久| 日韩美女久久久| 国产一区二区中文字幕| 国产精品青草久久| 91国内精品野花午夜精品| 石原莉奈在线亚洲三区| 国产性做久久久久久| 欧美日韩国产首页| 国产91综合网| 日韩成人午夜电影| 亚洲色图自拍偷拍美腿丝袜制服诱惑麻豆| 欧美在线你懂的| 国产成人午夜视频| 亚洲国产毛片aaaaa无费看| 国产日韩欧美精品一区| 欧美日韩精品福利| 成人网在线免费视频| 青椒成人免费视频| 亚洲夂夂婷婷色拍ww47| 国产三级一区二区| 欧美一区国产二区| 一本大道综合伊人精品热热| 九九精品一区二区| 五月激情丁香一区二区三区| 国产精品美女视频| 久久久亚洲综合| 91精品国产欧美一区二区18| 一本大道久久a久久综合婷婷 | 99热在这里有精品免费|