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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? tcp.c

?? c8051f的tcpip源程序,新一代功能比較齊全的c8051f020單片機(jī)的串行通信c程序,通用的c8051系列tcpip源程序
?? C
?? 第 1 頁 / 共 2 頁
字號(hào):
//-----------------------------------------------------------------------------
// 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

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日韩免费一区二区三区| 最新中文字幕一区二区三区| 91精品国产综合久久精品app| 99精品在线免费| 岛国av在线一区| 成人一区二区三区| 成人午夜激情片| 99re在线视频这里只有精品| 99re8在线精品视频免费播放| 成人深夜福利app| 99久久99久久精品免费观看| 91香蕉视频污在线| 91色在线porny| 欧美主播一区二区三区| 欧美特级限制片免费在线观看| 91一区二区在线观看| 日本道精品一区二区三区 | 911精品国产一区二区在线| 欧洲亚洲国产日韩| 欧美肥妇free| 精品国产乱码91久久久久久网站| 日韩久久免费av| 日本一区二区视频在线观看| 国产精品色在线观看| 亚洲精品欧美综合四区| 亚洲一区在线视频| 日本va欧美va欧美va精品| 六月婷婷色综合| 成人免费视频一区二区| 色狠狠桃花综合| 欧美精品99久久久**| 欧美tickling网站挠脚心| 国产女人aaa级久久久级 | 伊人婷婷欧美激情| 日本视频免费一区| 成人综合婷婷国产精品久久蜜臀| 91麻豆文化传媒在线观看| 欧美日韩美女一区二区| 精品久久久三级丝袜| 国产精品不卡一区二区三区| 亚洲国产精品人人做人人爽| 久久精品国产一区二区三区免费看| 国产一区二区三区视频在线播放| youjizz国产精品| 欧美三级在线播放| 久久久久久久综合狠狠综合| 亚洲天堂2014| 久久 天天综合| 色婷婷久久久久swag精品| 欧美变态凌虐bdsm| 亚洲美女一区二区三区| 久久精品国产第一区二区三区| av激情亚洲男人天堂| 7878成人国产在线观看| 亚洲国产成人自拍| 日本一区中文字幕| 成人美女视频在线看| 911精品国产一区二区在线| 国产精品视频一二三区| 日韩av不卡在线观看| 成人国产精品免费网站| 337p亚洲精品色噜噜噜| 亚洲三级在线播放| 国产一区美女在线| 欧美精品久久久久久久多人混战| 日本一区二区三区国色天香| 日韩国产精品久久| 色婷婷一区二区| 久久精品网站免费观看| 天天综合网 天天综合色| 成人福利视频网站| 欧美大肚乱孕交hd孕妇| 亚洲一区二区在线免费看| 国产成人三级在线观看| 91精品国产综合久久精品麻豆| 亚洲欧美日韩在线不卡| 国产99精品在线观看| 日韩三区在线观看| 亚洲国产成人va在线观看天堂 | 久久综合九色综合欧美98| 亚洲高清中文字幕| 91麻豆产精品久久久久久| 久久久五月婷婷| 日本三级韩国三级欧美三级| 在线观看日韩电影| 亚洲人精品午夜| 国产91高潮流白浆在线麻豆| 日韩三级精品电影久久久| 亚洲午夜激情av| 在线观看国产日韩| 亚洲九九爱视频| 91免费视频大全| 中文字幕亚洲电影| 成人久久久精品乱码一区二区三区 | 国产精品一区二区久久不卡| 欧美一区二区视频观看视频| 亚洲自拍偷拍九九九| 色综合久久综合网97色综合| 1区2区3区欧美| 91免费看片在线观看| 亚洲精品视频在线观看免费| 99精品在线免费| 亚洲女性喷水在线观看一区| 97精品超碰一区二区三区| 国产精品超碰97尤物18| 99久久国产综合精品女不卡| 国产精品久久99| 99久久精品国产一区二区三区| 国产精品久久久久影院色老大| 国产成人在线影院| 国产精品久久久久久久久图文区 | 国产一区三区三区| 2023国产精品自拍| 国产在线乱码一区二区三区| 久久精品欧美一区二区三区不卡| 国产一区二区导航在线播放| 久久老女人爱爱| 成人禁用看黄a在线| 成人免费在线播放视频| 欧美在线你懂得| 日本不卡视频在线观看| 久久亚洲春色中文字幕久久久| 韩国女主播一区二区三区| 国产蜜臀97一区二区三区| 91香蕉视频黄| 天天色天天操综合| 久久久久久久久97黄色工厂| 风间由美一区二区av101| 自拍视频在线观看一区二区| 欧美中文字幕一区二区三区| 日韩精品视频网站| 久久久综合九色合综国产精品| 成人国产在线观看| 亚洲伊人色欲综合网| 日韩免费视频一区二区| 成人国产精品免费网站| 亚洲午夜一区二区| 久久综合资源网| 99视频一区二区| 午夜成人在线视频| 久久久久国产一区二区三区四区| 97精品超碰一区二区三区| 日韩综合一区二区| 亚洲国产精品ⅴa在线观看| 色欧美片视频在线观看| 男人的j进女人的j一区| 国产午夜亚洲精品午夜鲁丝片| 91日韩一区二区三区| 全部av―极品视觉盛宴亚洲| 中文字幕av一区 二区| 欧美日韩亚洲高清一区二区| 韩国精品一区二区| 亚洲午夜精品一区二区三区他趣| 337p日本欧洲亚洲大胆色噜噜| 91欧美一区二区| 久久精品国内一区二区三区| 亚洲欧美一区二区三区极速播放 | 亚洲午夜久久久久久久久久久 | 国产精品免费视频观看| 欧美日韩激情在线| 成人激情黄色小说| 麻豆精品在线视频| 一区二区三区视频在线观看| 欧美videos大乳护士334| 欧美伊人久久久久久午夜久久久久| 国产一区二区福利| 日本va欧美va瓶| 亚洲激情图片qvod| 国产欧美日韩精品一区| 日韩一级在线观看| 欧美伊人久久久久久久久影院| 午夜久久久久久久久| 欧美日韩久久一区二区| 免费成人美女在线观看| 亚洲男同性视频| 国产日韩欧美a| 欧美mv日韩mv| 欧美精品视频www在线观看| 99vv1com这只有精品| 国产成人综合精品三级| 久久精品国产一区二区三区免费看| 亚洲国产精品精华液网站| 136国产福利精品导航| 国产亚洲综合av| 久久众筹精品私拍模特| 欧美一区二区福利视频| 欧美三级电影精品| 91福利国产成人精品照片| 成人激情开心网| 成人一道本在线| 国产91丝袜在线播放| 国产一区三区三区| 国产一区欧美日韩| 国内精品在线播放| 精品一区二区在线观看| 日本成人在线看| 蜜臂av日日欢夜夜爽一区| 日韩av网站免费在线| 午夜伊人狠狠久久| 亚洲线精品一区二区三区八戒|