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

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

?? tcp.c

?? c8051f020源代碼39個 使用Silicon Labs IDE 調試器
?? C
?? 第 1 頁 / 共 2 頁
字號:
//-----------------------------------------------------------------------------
// Copyright (c) 2002 Jim Brady
// Do not use commercially without author's permission
// Last revised August 2002
// 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;
      }       
   }

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
一区二区三区在线免费视频| 国产主播一区二区三区| 99久久久国产精品| 久久se精品一区精品二区| 亚洲综合色自拍一区| 国产精品久久久久久久久搜平片| 9191成人精品久久| 欧美在线视频日韩| 91最新地址在线播放| 精品国产亚洲在线| 日韩欧美国产精品| 日韩一区二区电影在线| 欧美精品一区在线观看| 亚洲成av人片在线观看无码| 夜夜嗨av一区二区三区中文字幕 | 一级特黄大欧美久久久| 国产·精品毛片| 国产福利一区在线观看| 国产福利一区二区三区视频| 日韩欧美成人激情| 免费成人深夜小野草| 久久国产三级精品| 在线综合+亚洲+欧美中文字幕| 一区二区三区四区在线免费观看| 成人av网站免费| 色欧美88888久久久久久影院| 91老师片黄在线观看| 欧美亚洲高清一区| xnxx国产精品| 亚洲精选免费视频| 麻豆精品视频在线观看| 波多野结衣欧美| 欧美日韩极品在线观看一区| 精品国产91乱码一区二区三区 | 久久亚洲一区二区三区四区| 蜜桃视频在线观看一区| 日韩一区二区三区电影在线观看| 日本中文一区二区三区| 成人v精品蜜桃久久一区| 国产亚洲综合色| 亚洲色图色小说| 丝袜美腿亚洲色图| av日韩在线网站| 亚洲一区二区在线播放相泽| 欧美日韩一区二区三区在线| 国产欧美一区二区精品久导航| 亚洲激情图片一区| 欧美日韩精品一区二区在线播放 | 国产精品资源在线看| 色综合婷婷久久| 精品国产一区二区三区久久久蜜月| 麻豆精品在线视频| 欧美—级在线免费片| 天天影视涩香欲综合网| 91在线观看美女| 亚洲午夜久久久久中文字幕久| 国产白丝精品91爽爽久久| 国产精品激情偷乱一区二区∴| 不卡影院免费观看| 天天爽夜夜爽夜夜爽精品视频| 日韩美女在线视频| 成人精品鲁一区一区二区| 日韩视频一区二区在线观看| 国产成人亚洲综合a∨婷婷| 亚洲久本草在线中文字幕| 555www色欧美视频| 国产盗摄一区二区| 亚洲一区二区三区免费视频| 久久久久久久久伊人| 国模少妇一区二区三区| 亚洲丝袜自拍清纯另类| 欧美剧情片在线观看| 亚洲制服丝袜av| 欧美成人在线直播| 久久精品国产精品亚洲精品| 中文在线免费一区三区高中清不卡| 欧美综合在线视频| 国产盗摄一区二区| 日本三级韩国三级欧美三级| 亚洲欧洲日韩综合一区二区| 成人午夜视频在线观看| 男女激情视频一区| 亚洲女女做受ⅹxx高潮| 在线观看不卡一区| 国产成人免费高清| 秋霞午夜av一区二区三区| 国产精品美女www爽爽爽| av激情成人网| 九一九一国产精品| 26uuu国产一区二区三区| 91黄视频在线观看| 天涯成人国产亚洲精品一区av| 中文字幕在线一区免费| 精品国产露脸精彩对白| 欧美精品电影在线播放| 在线免费观看日韩欧美| aaa亚洲精品| 国产成人啪免费观看软件| 韩国v欧美v日本v亚洲v| 免费看黄色91| 欧美a级理论片| 免费在线看成人av| 日韩成人av影视| 日韩制服丝袜先锋影音| 亚洲精品视频在线| 亚洲免费av在线| 亚洲精品ww久久久久久p站| 国产精品丝袜黑色高跟| 国产精品女同互慰在线看| 久久精品视频在线看| 2020国产精品久久精品美国| 日韩免费一区二区三区在线播放| 91精品国产综合久久精品图片| 欧美色大人视频| 欧美高清你懂得| 欧美一级xxx| 精品人伦一区二区色婷婷| 欧美一级夜夜爽| av在线不卡网| 色乱码一区二区三区88| 欧洲av在线精品| 欧美精品久久一区| 欧美xxxxx裸体时装秀| 欧美精品一区二区三区高清aⅴ| 精品人在线二区三区| 国产欧美日韩一区二区三区在线观看| 国产午夜一区二区三区| 国产精品久久久久久久久免费桃花| 国产精品国产三级国产aⅴ无密码| 国产精品入口麻豆原神| 亚洲欧美激情在线| 亚洲国产精品一区二区www| 性做久久久久久久免费看| 美国十次综合导航| 国产不卡在线一区| 日本乱人伦一区| 欧美一激情一区二区三区| 久久久精品影视| 亚洲精品视频在线| 麻豆精品国产91久久久久久| 成人精品视频一区二区三区| 欧美在线视频你懂得| 91精品国产一区二区| 国产精品天天看| 图片区小说区国产精品视频| 狠狠色狠狠色综合系列| 色综合网色综合| 26uuu精品一区二区三区四区在线 26uuu精品一区二区在线观看 | 午夜精品一区二区三区电影天堂 | 热久久久久久久| 国产精品18久久久久久久久| 91福利在线看| 国产亚洲精品aa午夜观看| 樱花草国产18久久久久| 久久精品国产秦先生| 色偷偷一区二区三区| 2021国产精品久久精品| 亚洲第一二三四区| 国产成人av网站| 日韩欧美色电影| 一卡二卡欧美日韩| 粉嫩欧美一区二区三区高清影视 | 欧美裸体一区二区三区| 国产精品污网站| 毛片基地黄久久久久久天堂| 91麻豆国产香蕉久久精品| 久久蜜桃一区二区| 三级久久三级久久久| 白白色亚洲国产精品| 欧美草草影院在线视频| 性久久久久久久久久久久| av不卡免费在线观看| 国产亚洲制服色| 日韩国产精品久久| 欧美优质美女网站| 国产亚洲欧美激情| 精品一区二区三区在线视频| 欧美人动与zoxxxx乱| 亚洲欧美视频一区| 99久久精品免费看国产免费软件| 精品国产一区二区亚洲人成毛片| 亚洲va韩国va欧美va| 99久久免费精品高清特色大片| 久久免费视频一区| 国产老肥熟一区二区三区| 欧美一二三区在线| 伦理电影国产精品| 欧美电视剧在线观看完整版| 欧美aa在线视频| 日韩欧美国产精品一区| 免费在线观看成人| 日韩精品一区二区三区四区| 秋霞电影一区二区| 色综合天天综合网天天狠天天| 亚洲午夜激情网站| 91老师国产黑色丝袜在线| 国产精品久久免费看| 粉嫩av一区二区三区在线播放| 国产欧美综合在线观看第十页| 国产精品一区二区在线看|