亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
欧美亚洲国产一区二区三区va| 91色视频在线| 日韩福利视频导航| 亚洲v中文字幕| 亚洲综合丁香婷婷六月香| 亚洲精品乱码久久久久| 亚洲女同ⅹxx女同tv| 亚洲免费观看高清完整版在线观看| 中文字幕一区免费在线观看 | 一区二区三区中文在线| 亚洲日本一区二区| 一区在线观看免费| 亚洲精品成人a在线观看| 亚洲一区二区在线免费观看视频 | 成人av资源在线观看| 岛国精品在线观看| www..com久久爱| 色先锋aa成人| 欧美私模裸体表演在线观看| 欧美人与z0zoxxxx视频| 欧美一级夜夜爽| 久久久www成人免费无遮挡大片| 国产天堂亚洲国产碰碰| 国产精品精品国产色婷婷| 亚洲欧美日韩国产综合在线 | 欧美艳星brazzers| 欧美电影在哪看比较好| 精品国产区一区| 中文字幕在线观看一区| 一片黄亚洲嫩模| 蜜桃av一区二区在线观看| 国产精品一区二区三区乱码| 91麻豆swag| 欧美久久久久中文字幕| 日韩欧美国产一二三区| 日本一二三不卡| 亚洲一区二区三区精品在线| 日韩av电影免费观看高清完整版在线观看| 久久精品国产999大香线蕉| 成人av在线播放网址| 欧美日韩情趣电影| 久久精品欧美日韩| 亚洲国产成人va在线观看天堂 | 亚洲欧美日韩电影| 六月丁香婷婷色狠狠久久| 国产精品一区二区视频| 91福利资源站| 日韩午夜在线观看| 国产欧美一区二区精品忘忧草 | 国产成+人+日韩+欧美+亚洲| 99国产精品久| 欧美一区二区视频观看视频| 中文字幕乱码一区二区免费| 亚洲成av人片在www色猫咪| 国产一区二区电影| 精品视频一区二区三区免费| 国产亚洲一区二区三区| 亚洲成a人片在线不卡一二三区| 国产精品一二三四五| 欧美日韩亚洲丝袜制服| 中文字幕一区二区三中文字幕| 日韩精品欧美精品| 97久久超碰精品国产| xf在线a精品一区二区视频网站| 亚洲欧美日韩国产手机在线| 紧缚奴在线一区二区三区| 欧美做爰猛烈大尺度电影无法无天| 久久亚洲一区二区三区四区| 亚洲一区二区三区四区中文字幕| 欧美日韩一级片在线观看| 精品少妇一区二区三区日产乱码 | 一区在线播放视频| 久久不见久久见免费视频1| 色综合久久久久网| 国产欧美视频一区二区三区| 日韩精彩视频在线观看| 色综合网色综合| 久久久久久久久久久久久女国产乱| 午夜精品久久久久久不卡8050| 成人美女视频在线观看| 久久久www免费人成精品| 久久国产三级精品| 91 com成人网| 亚洲自拍偷拍欧美| 色妞www精品视频| 亚洲色欲色欲www在线观看| 国产成人精品综合在线观看| 日韩免费高清av| 日韩经典一区二区| 欧美日韩亚洲综合| 亚洲高清视频中文字幕| 色狠狠综合天天综合综合| 国产精品毛片大码女人| 亚洲人快播电影网| 久久综合色综合88| 日韩不卡一区二区三区 | 日韩欧美国产1| 亚洲成av人影院在线观看网| 欧美在线观看禁18| 亚洲精品写真福利| 色一区在线观看| 一区二区三区成人| 日本高清成人免费播放| 亚洲女同一区二区| 91国产免费看| 一区二区三区 在线观看视频| 欧美在线综合视频| 一二三四社区欧美黄| 欧美日韩一本到| 三级在线观看一区二区| 制服丝袜中文字幕亚洲| 另类小说综合欧美亚洲| 欧美精品一区二区高清在线观看| 精彩视频一区二区三区| 国产日韩欧美不卡在线| 国产综合色在线| 久久久无码精品亚洲日韩按摩| 精品一区免费av| 国产欧美视频在线观看| 91丝袜呻吟高潮美腿白嫩在线观看| 综合久久综合久久| 日本成人中文字幕| 8v天堂国产在线一区二区| 青青草精品视频| 欧美r级在线观看| 成人午夜av在线| 一区二区三区中文字幕在线观看| 欧美视频在线播放| 日韩av一区二区在线影视| 日韩精品一区二区三区四区视频 | 91精品国产福利| 国产乱对白刺激视频不卡| 国产精品剧情在线亚洲| 91国偷自产一区二区使用方法| 天天操天天色综合| 久久久午夜精品理论片中文字幕| 不卡的av电影在线观看| 亚洲一区二区视频在线| 欧美电影免费观看高清完整版| 国产精品99久久久久久有的能看 | 国产精品系列在线播放| 亚洲裸体在线观看| 91精品福利在线一区二区三区 | jvid福利写真一区二区三区| 亚洲小说欧美激情另类| 久久久综合网站| 色婷婷久久99综合精品jk白丝| 三级欧美韩日大片在线看| 一区二区三区久久| 在线观看91av| 国产精品18久久久久久久网站| 亚洲精品中文字幕在线观看| 日韩欧美视频在线| av电影在线观看一区| 免费av网站大全久久| 亚洲欧洲99久久| 精品精品国产高清a毛片牛牛| av一区二区三区四区| 久久精品999| 亚洲乱码中文字幕| 久久久久久久久99精品| 欧美日韩色一区| 菠萝蜜视频在线观看一区| 久久不见久久见免费视频1| 一区二区三区在线不卡| 久久久久久一二三区| 欧美高清视频在线高清观看mv色露露十八| 国产高清成人在线| 日韩av一区二区在线影视| 亚洲手机成人高清视频| 久久久久久久综合色一本| 欧美一区二区三区在线视频| 一本一道综合狠狠老| 国产成人免费9x9x人网站视频| 日本麻豆一区二区三区视频| 一区二区在线观看免费| 国产精品少妇自拍| 精品国产自在久精品国产| 7777精品久久久大香线蕉| 色婷婷激情一区二区三区| 成人av资源网站| 欧美日韩精品一二三区| 国内久久精品视频| 日韩影院免费视频| 中文字幕va一区二区三区| 精品少妇一区二区三区视频免付费| 在线视频一区二区三区| 不卡的电影网站| 另类中文字幕网| 丝袜诱惑亚洲看片| 亚洲va在线va天堂| 亚洲一级二级三级在线免费观看| 国产精品欧美极品| 亚洲国产精品高清| 国产婷婷色一区二区三区在线| 精品少妇一区二区三区视频免付费| 91精品麻豆日日躁夜夜躁| 欧美久久一二区| 欧美日韩精品一区二区天天拍小说 | 亚洲在线免费播放|