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

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

?? tcp.c

?? tcpip.rar 是一個51控制8019的程序,我已用于商用.還很穩定,有興趣的可以看一下,對TCP IP UDP ICMP ARP RARP HTTP均可以實現.
?? 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 <reg52.h>
#include <stdio.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) printf("TCP: Oops, out of memory\n");
      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) printf("TCP: Oops, sock nr out of range\n");
		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) printf("TCP: Sending msg to IP layer\n");
	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) printf("TCP: Timeout, sending reset\n");
               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) printf("TCP: Timeout, sending reset\n");
                  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) printf("TCP: Timeout, resending data\n");
                  	http_server(conxn[nr].query, 0, nr, 1);
			            conxn[nr].inactivity = INACTIVITY_TIME;
                  }
						else
						{
						  	if (debug) printf("TCP: Giving up, sending reset\n");
							// 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) printf("TCP: Entered FIN_WAIT_1 state\n");	
         }
      }
   }
}



//------------------------------------------------------------------------
// 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) printf("TCP: Error, bad cksum\n");
		return;
   }

	if (debug) printf("TCP: Msg rcvd with good cksum\n");
   
	// See if message is for http server
	if (tcp->dest_port != HTTP_PORT)	
   {
      if (debug)
      {
         printf("TCP: Error, msg to port\n ");
         memset(text, 0, 10);
         itoa(tcp->dest_port, text, 10);
         printf(text);
		   printf("\n");
      }
      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) printf("TCP: Rcvd msg from existing conxn\n");
         break;
      }       
   }
   

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产91高潮流白浆在线麻豆| 色综合激情久久| 国产精品996| 99视频在线观看一区三区| 成人网在线播放| 91高清视频免费看| 欧美一区二区三区在线| 欧美精品一区男女天堂| 国产欧美va欧美不卡在线| 亚洲人一二三区| 美女一区二区三区在线观看| 国产一区二区网址| 一本久道中文字幕精品亚洲嫩| 欧美在线免费视屏| 日韩一区二区视频在线观看| 国产精品久久久一本精品| 天堂久久一区二区三区| 丰满白嫩尤物一区二区| 欧美性videosxxxxx| 日韩欧美国产成人一区二区| 国产精品久久99| 久久99国产乱子伦精品免费| proumb性欧美在线观看| 欧美成人福利视频| 亚洲电影你懂得| 国产69精品久久久久毛片| 欧美肥妇free| 亚洲自拍偷拍图区| 成人免费看片app下载| 日韩你懂的在线播放| 一区二区三区高清在线| 国产福利不卡视频| 日韩欧美一区在线观看| 欧美国产视频在线| 亚洲欧洲制服丝袜| 欧洲亚洲精品在线| 国产精品人人做人人爽人人添| 黄色资源网久久资源365| 色综合久久天天| 中文字幕av资源一区| 国产精品一区三区| 精品av综合导航| 免费成人在线观看视频| 在线视频一区二区免费| 日韩一区欧美一区| 99免费精品视频| 国产欧美一区二区精品性| 久久99国产精品麻豆| 7799精品视频| 久久精品国产第一区二区三区| 欧美日韩精品综合在线| 午夜av电影一区| 日韩一区二区三区观看| 久久精品噜噜噜成人av农村| 精品国产乱码久久久久久浪潮| 精品一区二区精品| 国产精品国产a| 欧美综合在线视频| 另类小说综合欧美亚洲| 精品福利一区二区三区| 成人小视频免费在线观看| 亚洲色图清纯唯美| 欧美日韩高清一区二区| 激情综合五月天| 中文字幕一区二区三区不卡| 欧美日韩国产经典色站一区二区三区| 亚洲线精品一区二区三区八戒| 日韩欧美中文字幕制服| 成人成人成人在线视频| 日本sm残虐另类| 国产精品夫妻自拍| 91麻豆精品国产91久久久使用方法 | www.66久久| 视频一区欧美日韩| 日本一区二区三区免费乱视频| 欧美又粗又大又爽| 国产精品99久久久久久宅男| 亚洲成人动漫精品| 欧美高清在线视频| 欧美日韩一区二区三区视频| 国产伦精品一区二区三区视频青涩 | 色综合激情久久| 成人国产在线观看| 极品少妇xxxx偷拍精品少妇| 亚洲精品国产精品乱码不99| 久久久久久一二三区| 91精品国产欧美一区二区18| 色八戒一区二区三区| 成人黄色大片在线观看| 国产资源精品在线观看| 午夜精品久久久久久久99水蜜桃 | 日本一区中文字幕| 亚洲一二三四在线| 亚洲精品大片www| 亚洲日本免费电影| 亚洲日本va午夜在线影院| 26uuu久久天堂性欧美| 久久综合色鬼综合色| 欧美电影免费观看高清完整版在线 | 日韩电影免费在线看| 自拍av一区二区三区| 国产精品入口麻豆九色| 国产精品夫妻自拍| 亚洲免费av在线| 亚洲一区二区成人在线观看| 一区二区三区不卡视频在线观看 | 丝瓜av网站精品一区二区 | 在线日韩av片| 欧美日产在线观看| 欧美一区二区精品在线| 日韩欧美视频在线| 亚洲国产经典视频| 日韩美女视频一区二区| 一区二区视频在线看| 亚洲一二三区在线观看| 天天综合网 天天综合色| 激情都市一区二区| 成人精品小蝌蚪| 欧美日本一区二区| 26uuu亚洲| 亚洲一区二区三区在线看| 石原莉奈一区二区三区在线观看| 久久99久久精品| 高清视频一区二区| 欧美精品久久99久久在免费线 | 国模一区二区三区白浆| 成人av影视在线观看| 欧美三级中文字幕| 国产精品素人视频| 日韩中文字幕不卡| 99久久久久久| 2022国产精品视频| 一区二区三区在线视频播放| 国产一区二区三区在线观看精品| 99久久精品99国产精品| 久久亚洲综合色一区二区三区| 欧美精品123区| 久久久久久久久久久久久夜| 亚洲永久免费视频| 色综合视频一区二区三区高清| 欧美一级一级性生活免费录像| 综合中文字幕亚洲| 国产不卡免费视频| 国产欧美一区二区三区沐欲| 婷婷开心激情综合| 91精品91久久久中77777| 中文字幕精品一区二区三区精品| 韩国午夜理伦三级不卡影院| 欧美一区二区三区白人| 亚洲地区一二三色| 欧美日韩一卡二卡三卡| 亚洲一级不卡视频| 欧美日韩精品一区二区三区四区| 亚洲欧洲av另类| 成人app下载| 一区二区三区四区不卡在线 | 成人欧美一区二区三区| av在线不卡网| 中文字幕综合网| 欧美另类videos死尸| 一区av在线播放| 欧美无砖专区一中文字| 亚洲成人激情自拍| 精品国产一区二区三区av性色| 久久er99热精品一区二区| 精品不卡在线视频| 成人激情文学综合网| 亚洲日本韩国一区| 欧美精品v日韩精品v韩国精品v| 午夜精品成人在线视频| 欧美一区二区精美| 国产99久久久国产精品免费看 | 午夜国产不卡在线观看视频| 日韩一区二区三区电影在线观看| 韩国中文字幕2020精品| 中文字幕一区不卡| 欧美日韩在线综合| 久久超碰97中文字幕| 国产精品萝li| 欧美高清视频在线高清观看mv色露露十八 | 午夜精品视频一区| www国产成人| 欧美综合在线视频| 国产一区二区三区免费在线观看| 国产精品国产三级国产普通话99 | 自拍偷拍国产亚洲| 日韩三级精品电影久久久| 色婷婷综合久久久| 国内成人免费视频| 亚洲1区2区3区4区| 亚洲日本va午夜在线电影| 精品捆绑美女sm三区| 欧美日韩综合色| 99在线精品观看| 国产99久久久久久免费看农村| 日本在线观看不卡视频| 亚洲高清免费视频| 亚洲精品少妇30p| 中文字幕亚洲欧美在线不卡| 精品久久久久久久久久久久包黑料|