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

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

?? tcp.c

?? 8051 Web Server project See Makefile for build notes Written for Keil C51 V5.1 compiler, notes:
?? 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一区二区三区免费野_久草精品视频
99久久精品免费观看| 日韩久久久精品| 2024国产精品| 美女视频第一区二区三区免费观看网站 | 日韩av中文字幕一区二区三区| 国产美女一区二区| 精品国产一区二区三区不卡 | 亚洲精品一区二区三区在线观看 | 久久激情五月激情| 欧美一区二区国产| 亚洲第一激情av| 欧美色图激情小说| 亚洲午夜免费视频| 欧美一三区三区四区免费在线看 | 日韩欧美一区二区免费| 亚洲国产一区二区视频| 欧美日韩中文国产| 免费观看日韩电影| 久久久精品tv| 91在线国产观看| 亚洲另类春色国产| 日韩视频在线永久播放| 国产99一区视频免费 | 蜜臀av性久久久久蜜臀aⅴ四虎| 欧美视频三区在线播放| 免费看黄色91| 中文字幕日韩欧美一区二区三区| 丁香婷婷深情五月亚洲| ...av二区三区久久精品| 欧美三级三级三级爽爽爽| 美女任你摸久久| 国产欧美精品区一区二区三区 | 91久久精品一区二区三| 六月丁香婷婷久久| 国产精品国产自产拍在线| 欧美日韩日本视频| 99re成人精品视频| 美女尤物国产一区| 一区二区三区中文字幕| 国产日韩欧美麻豆| 精品国产一区二区在线观看| 91小视频在线| 国产成人精品一区二| 亚洲色图视频网站| 精品国产91乱码一区二区三区 | 欧美日韩国产成人在线免费| 国产成人av电影免费在线观看| 视频一区欧美精品| 亚洲人吸女人奶水| 中文字幕精品一区二区精品绿巨人| 这里只有精品99re| 91.xcao| 91麻豆精品国产自产在线| 色www精品视频在线观看| 成人av中文字幕| 一区二区三区日韩欧美| 7777精品伊人久久久大香线蕉经典版下载| 成人av电影在线观看| 大尺度一区二区| proumb性欧美在线观看| 国产a视频精品免费观看| 国产精品一品二品| 成人国产精品视频| 91伊人久久大香线蕉| 色香蕉成人二区免费| 欧美性一二三区| 日韩三级伦理片妻子的秘密按摩| 欧美一区二区免费| 久久久国产精品麻豆| 中文字幕一区二区三区在线观看| 成人欧美一区二区三区白人| ...中文天堂在线一区| 亚洲午夜羞羞片| 精品在线一区二区三区| www.一区二区| 欧美一区二区精品久久911| 欧美电视剧在线看免费| 国产精品久久久久影院| 婷婷六月综合亚洲| 成人精品鲁一区一区二区| 色综合天天综合狠狠| 欧美日韩美少妇| 欧美韩日一区二区三区四区| 亚洲第一久久影院| 丁香天五香天堂综合| 在线播放91灌醉迷j高跟美女 | 国产成人午夜高潮毛片| 色94色欧美sute亚洲13| 久久人人97超碰com| 午夜影院在线观看欧美| 成人av在线网站| 精品日韩欧美在线| 一区二区三区中文在线观看| 亚洲国产视频直播| 狠狠v欧美v日韩v亚洲ⅴ| 欧美色手机在线观看| 国产精品高潮久久久久无| 国产一区不卡在线| 欧美成人国产一区二区| 天堂精品中文字幕在线| 欧美视频一区二区三区在线观看 | 亚洲超丰满肉感bbw| 99久久99久久精品国产片果冻| 日韩精品一区二区三区中文不卡| 一区二区三区精品| 欧美视频在线一区二区三区| 樱花草国产18久久久久| 欧美日韩在线一区二区| 一片黄亚洲嫩模| 精品1区2区3区| 亚洲不卡在线观看| 欧美日韩视频在线一区二区| 五月开心婷婷久久| 精品国产91洋老外米糕| 国产精品羞羞答答xxdd| 最好看的中文字幕久久| 在线日韩av片| 精品一区二区久久久| 26uuu久久天堂性欧美| jizzjizzjizz欧美| 国产精品污网站| 色狠狠桃花综合| 日韩电影一区二区三区四区| 久久久天堂av| 欧美午夜电影一区| 麻豆国产欧美日韩综合精品二区| 久久久91精品国产一区二区精品| 91丨porny丨国产| 美女脱光内衣内裤视频久久网站 | 91久久线看在观草草青青| 天天综合色天天| 国产精品久久午夜| 韩国精品在线观看| 国产日韩欧美不卡在线| 在线成人av网站| 91小视频免费看| 国产成人精品免费| 免费看日韩精品| 亚洲成av人片www| 亚洲欧美一区二区在线观看| 欧美不卡一区二区三区| 欧美日韩精品欧美日韩精品| 成人综合在线网站| 国内精品久久久久影院色| 石原莉奈在线亚洲三区| 一区二区三区四区av| 亚洲欧美综合网| 国产精品久久久久久久久晋中 | 国产精品视频yy9299一区| 5858s免费视频成人| 欧洲av一区二区嗯嗯嗯啊| 国产成人免费视频一区| 国产伦精品一区二区三区免费迷| 日本系列欧美系列| 午夜伦欧美伦电影理论片| 中文字幕一区二区三区色视频| 欧美经典一区二区| 国产欧美日韩卡一| 国产精品久久久久久户外露出| 欧美高清在线一区| 亚洲欧美日韩在线播放| 一区二区三区色| 首页国产欧美久久| 精品在线免费观看| 成人深夜在线观看| 在线观看免费一区| 3751色影院一区二区三区| www激情久久| 亚洲人成网站影音先锋播放| 亚洲成人黄色影院| 精品午夜久久福利影院| 99久久伊人精品| 欧美日本在线播放| 国产午夜精品久久久久久免费视 | 中文字幕国产精品一区二区| 一区二区三区美女| 国产在线视视频有精品| 色香色香欲天天天影视综合网| 欧美日本一区二区三区四区| 久久久久成人黄色影片| 午夜精品成人在线视频| av电影天堂一区二区在线| 3d成人h动漫网站入口| 中文字幕日本不卡| 国产精品夜夜爽| 欧美老人xxxx18| 日韩一区在线免费观看| 国产成人免费高清| 久久综合色之久久综合| 亚洲大片一区二区三区| 99精品偷自拍| 中文在线资源观看网站视频免费不卡| 日韩av中文字幕一区二区| 91福利在线免费观看| 国产精品嫩草久久久久| 成人性生交大片免费看视频在线| 日韩亚洲欧美高清| 精彩视频一区二区三区| 日韩亚洲欧美综合| 免费欧美在线视频|