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

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

?? tcp_in.c

?? 一個輕量tcpip協議在移植在ucOS2系統上運行
?? C
?? 第 1 頁 / 共 3 頁
字號:
/**
 * @file
 *
 * Transmission Control Protocol, incoming traffic
 */

/*
 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
 * All rights reserved. 
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission. 
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
 * OF SUCH DAMAGE.
 *
 * This file is part of the lwIP TCP/IP stack.
 * 
 * Author: Adam Dunkels <adam@sics.se>
 *
 */

/*-----------------------------------------------------------------------------------*/
/* tcp_input.c
 *
 * The input processing functions of TCP.
 *
 * These functions are generally called in the order (ip_input() ->) tcp_input() ->
 * tcp_process() -> tcp_receive() (-> application).
 *
 */
/*-----------------------------------------------------------------------------------*/


#include "lwip/def.h"
#include "lwip/opt.h"

#include "lwip/netif.h"
#include "lwip/mem.h"
#include "lwip/memp.h"

#include "lwip/inet.h"
#include "lwip/tcp.h"

#include "lwip/stats.h"

#include "arch/perf.h"
#if LWIP_TCP
/* These variables are global to all functions involved in the input
   processing of TCP segments. They are set by the tcp_input()
   function. */
static struct tcp_seg inseg;
static struct tcp_hdr *tcphdr;
static struct ip_hdr *iphdr;
static u32_t seqno, ackno;
static u8_t flags;
static u16_t tcplen;

static u8_t recv_flags;
static struct pbuf *recv_data;

struct tcp_pcb *tcp_input_pcb;

/* Forward declarations. */
static err_t tcp_process(struct tcp_pcb *pcb);
static void tcp_receive(struct tcp_pcb *pcb);
static void tcp_parseopt(struct tcp_pcb *pcb);

static err_t tcp_listen_input(struct tcp_pcb_listen *pcb);
static err_t tcp_timewait_input(struct tcp_pcb *pcb);

/*-----------------------------------------------------------------------------------*/
/* tcp_input:
 *
 * The initial input processing of TCP. It verifies the TCP header, demultiplexes
 * the segment between the PCBs and passes it on to tcp_process(), which implements
 * the TCP finite state machine. This function is called by the IP layer (in
 * ip_input()).
 */
/*-----------------------------------------------------------------------------------*/
void
tcp_input(struct pbuf *p, struct netif *inp)
{
  struct tcp_pcb *pcb, *prev;
  struct tcp_pcb_listen *lpcb;
  u8_t offset;
  err_t err;


  PERF_START;

  
#ifdef TCP_STATS
  ++lwip_stats.tcp.recv;
#endif /* TCP_STATS */

  iphdr = p->payload;
  tcphdr = (struct tcp_hdr *)((u8_t *)p->payload + IPH_HL(iphdr) * 4);
 
  pbuf_header(p, -((s16_t)(IPH_HL(iphdr) * 4)));
  
  /* Don't even process incoming broadcasts/multicasts. */
  if(ip_addr_isbroadcast(&(iphdr->dest), &(inp->netmask)) ||
     ip_addr_ismulticast(&(iphdr->dest))) {
    pbuf_free(p);
    return;
  }

  /* Verify TCP checksum. */
  if(inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src),
			(struct ip_addr *)&(iphdr->dest),
			IP_PROTO_TCP, p->tot_len) != 0) {
    DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packet discarded due to failing checksum 0x%04x\n", inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src),
			(struct ip_addr *)&(iphdr->dest),
			IP_PROTO_TCP, p->tot_len)));
#if TCP_DEBUG
    tcp_debug_print(tcphdr);
#endif /* TCP_DEBUG */
#ifdef TCP_STATS
    ++lwip_stats.tcp.chkerr;
    ++lwip_stats.tcp.drop;
#endif /* TCP_STATS */

    pbuf_free(p);
    return;
  }


  /* Move the payload pointer in the pbuf so that it points to the
     TCP data instead of the TCP header. */
  offset = TCPH_OFFSET(tcphdr) >> 4;
  pbuf_header(p, -(offset * 4));

  /* Convert fields in TCP header to host byte order. */
  tcphdr->src = ntohs(tcphdr->src);
  tcphdr->dest = ntohs(tcphdr->dest);
  seqno = tcphdr->seqno = ntohl(tcphdr->seqno);
  ackno = tcphdr->ackno = ntohl(tcphdr->ackno);
  tcphdr->wnd = ntohs(tcphdr->wnd);

  flags = TCPH_FLAGS(tcphdr) & TCP_FLAGS;
  tcplen = p->tot_len + ((flags & TCP_FIN || flags & TCP_SYN)? 1: 0);
  
  /* Demultiplex an incoming segment. First, we check if it is destined
     for an active connection. */  
  prev = NULL;  
  for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
    LWIP_ASSERT("tcp_input: active pcb->state != CLOSED", pcb->state != CLOSED);
    LWIP_ASSERT("tcp_input: active pcb->state != TIME-WAIT", pcb->state != TIME_WAIT);
    LWIP_ASSERT("tcp_input: active pcb->state != LISTEN", pcb->state != LISTEN);
    if(pcb->remote_port == tcphdr->src &&
       pcb->local_port == tcphdr->dest &&
       ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src)) &&
       ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest))) {
      
      /* Move this PCB to the front of the list so that subsequent
	 lookups will be faster (we exploit locality in TCP segment
	 arrivals). */
      LWIP_ASSERT("tcp_input: pcb->next != pcb (before cache)", pcb->next != pcb);
      if(prev != NULL) {
	prev->next = pcb->next;
	pcb->next = tcp_active_pcbs;
	tcp_active_pcbs = pcb; 
      }
      LWIP_ASSERT("tcp_input: pcb->next != pcb (after cache)", pcb->next != pcb);
      break;
    }
    prev = pcb;
  }

  if (pcb == NULL) {
    /* If it did not go to an active connection, we check the connections
       in the TIME-WAIT state. */

    for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
      LWIP_ASSERT("tcp_input: TIME-WAIT pcb->state == TIME-WAIT", pcb->state == TIME_WAIT);
      if(pcb->remote_port == tcphdr->src &&
	 pcb->local_port == tcphdr->dest &&
	 ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src)) &&
         ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest))) {
	/* We don't really care enough to move this PCB to the front
	   of the list since we are not very likely to receive that
	   many segments for connections in TIME-WAIT. */
	DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packed for TIME_WAITing connection.\n"));
	tcp_timewait_input(pcb);
	pbuf_free(p);
	return;	  
      }
    }  
  
  /* Finally, if we still did not get a match, we check all PCBs that
     are LISTENing for incoming connections. */
    prev = NULL;  
    for(lpcb = tcp_listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
      if((ip_addr_isany(&(lpcb->local_ip)) ||
	  ip_addr_cmp(&(lpcb->local_ip), &(iphdr->dest))) &&
	 lpcb->local_port == tcphdr->dest) {	  
	/* Move this PCB to the front of the list so that subsequent
	   lookups will be faster (we exploit locality in TCP segment
	   arrivals). */
	if(prev != NULL) {
	  ((struct tcp_pcb_listen *)prev)->next = lpcb->next;
          /* our successor is the remainder of the listening list */
	  lpcb->next = tcp_listen_pcbs;
          /* put this listening pcb at the head of the listening list */
	  tcp_listen_pcbs = lpcb; 
	}

	DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packed for LISTENing connection.\n"));
	tcp_listen_input(lpcb);
	pbuf_free(p);
	return;
      }
      prev = (struct tcp_pcb *)lpcb;
    }
  }
  
#if TCP_INPUT_DEBUG
  DEBUGF(TCP_INPUT_DEBUG, ("+-+-+-+-+-+-+-+-+-+-+-+-+-+- tcp_input: flags "));
  tcp_debug_print_flags(TCPH_FLAGS(tcphdr));
  DEBUGF(TCP_INPUT_DEBUG, ("-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n"));
#endif /* TCP_INPUT_DEBUG */

  
  if(pcb != NULL) {
    /* The incoming segment belongs to a connection. */
#if TCP_INPUT_DEBUG
#if TCP_DEBUG
    tcp_debug_print_state(pcb->state);
#endif /* TCP_DEBUG */
#endif /* TCP_INPUT_DEBUG */
    
    /* Set up a tcp_seg structure. */
    inseg.next = NULL;
    inseg.len = p->tot_len;
    inseg.dataptr = p->payload;
    inseg.p = p;
    inseg.tcphdr = tcphdr;
    
    recv_data = NULL;
    recv_flags = 0;

    tcp_input_pcb = pcb;
    err = tcp_process(pcb);
    tcp_input_pcb = NULL;
    /* A return value of ERR_ABRT means that tcp_abort() was called
       and that the pcb has been freed. If so, we don't do anything. */
    if(err != ERR_ABRT) {
      if(recv_flags & TF_RESET) {
	/* TF_RESET means that the connection was reset by the other
	   end. We then call the error callback to inform the
	   application that the connection is dead before we
	   deallocate the PCB. */
	TCP_EVENT_ERR(pcb->errf, pcb->callback_arg, ERR_RST);
	tcp_pcb_remove(&tcp_active_pcbs, pcb);            
	memp_free(MEMP_TCP_PCB, pcb);
      } else if(recv_flags & TF_CLOSED) {
	/* The connection has been closed and we will deallocate the
	   PCB. */
	tcp_pcb_remove(&tcp_active_pcbs, pcb);
	memp_free(MEMP_TCP_PCB, pcb);
      } else {
	err = ERR_OK;
	/* If the application has registered a "sent" function to be
	   called when new send buffer space is available, we call it
	   now. */
	if(pcb->acked > 0) {
	  TCP_EVENT_SENT(pcb, pcb->acked, err);
	}

	if(recv_data != NULL) {
	  /* Notify application that data has been received. */
	  TCP_EVENT_RECV(pcb, recv_data, ERR_OK, err);
	}
	
	/* If a FIN segment was received, we call the callback
	   function with a NULL buffer to indicate EOF. */
	if(recv_flags & TF_GOT_FIN) {
	  TCP_EVENT_RECV(pcb, NULL, ERR_OK, err);
	}
	/* If there were no errors, we try to send something out. */
	if(err == ERR_OK) {
	  tcp_output(pcb);
	}
      }
    }
    

    /* We deallocate the incoming pbuf. If it was buffered by the
       application, the application should have called pbuf_ref() to
       increase the reference counter in the pbuf. If so, the buffer
       isn't actually deallocated by the call to pbuf_free(), only the
       reference count is decreased. */
    pbuf_free(inseg.p);
#if TCP_INPUT_DEBUG
#if TCP_DEBUG
    tcp_debug_print_state(pcb->state);
#endif /* TCP_DEBUG */
#endif /* TCP_INPUT_DEBUG */
    
  } else {
    /* If no matching PCB was found, send a TCP RST (reset) to the
       sender. */
    DEBUGF(TCP_RST_DEBUG, ("tcp_input: no PCB match found, resetting.\n"));
    if(!(TCPH_FLAGS(tcphdr) & TCP_RST)) {
#ifdef TCP_STATS
      ++lwip_stats.tcp.proterr;
      ++lwip_stats.tcp.drop;
#endif /* TCP_STATS */      
      tcp_rst(ackno, seqno + tcplen,
	      &(iphdr->dest), &(iphdr->src),
	      tcphdr->dest, tcphdr->src);
    }
    pbuf_free(p);
  }

  LWIP_ASSERT("tcp_input: tcp_pcbs_sane()", tcp_pcbs_sane());  
  PERF_STOP("tcp_input");
}
/*-----------------------------------------------------------------------------------*/
/* tcp_listen_input():
 *
 * Called by tcp_input() when a segment arrives for a listening
 * connection.
 */
/*-----------------------------------------------------------------------------------*/
static err_t
tcp_listen_input(struct tcp_pcb_listen *pcb)
{
  struct tcp_pcb *npcb;
  u32_t optdata;
    
  /* In the LISTEN state, we check for incoming SYN segments,
     creates a new PCB, and responds with a SYN|ACK. */
  if(flags & TCP_ACK) {
    /* For incoming segments with the ACK flag set, respond with a
       RST. */
    DEBUGF(TCP_RST_DEBUG, ("tcp_listen_input: ACK in LISTEN, sending reset\n"));
    tcp_rst(ackno + 1, seqno + tcplen,
	    &(iphdr->dest), &(iphdr->src),
	    tcphdr->dest, tcphdr->src);
  } else if(flags & TCP_SYN) {
    DEBUGF(DEMO_DEBUG, ("TCP connection request %d -> %d.\n", tcphdr->src, tcphdr->dest));
    npcb = tcp_alloc(pcb->prio);
    /* If a new PCB could not be created (probably due to lack of memory),
       we don't do anything, but rely on the sender will retransmit the
       SYN at a time when we have more memory available. */
    if(npcb == NULL) {
      DEBUGF(TCP_DEBUG, ("tcp_listen_input: could not allocate PCB\n"));
#ifdef TCP_STATS
      ++lwip_stats.tcp.memerr;
#endif /* TCP_STATS */
      return ERR_MEM;
    }
    /* Set up the new PCB. */
    ip_addr_set(&(npcb->local_ip), &(iphdr->dest));
    npcb->local_port = pcb->local_port;
    ip_addr_set(&(npcb->remote_ip), &(iphdr->src));
    npcb->remote_port = tcphdr->src;
    npcb->state = SYN_RCVD;
    npcb->rcv_nxt = seqno + 1;
    npcb->snd_wnd = tcphdr->wnd;
    npcb->ssthresh = npcb->snd_wnd;
    npcb->snd_wl1 = seqno;
    npcb->callback_arg = pcb->callback_arg;
#if LWIP_CALLBACK_API
    npcb->accept = pcb->accept;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
中文字幕国产精品一区二区| 国产精品狼人久久影院观看方式| 亚洲精品成人悠悠色影视| 99久久精品免费看| 亚洲欧美欧美一区二区三区| 欧洲在线/亚洲| 亚洲成人www| 日韩精品一区二区三区四区视频| 韩国女主播成人在线观看| 国产午夜一区二区三区| 成人不卡免费av| 亚洲精品伦理在线| 91 com成人网| 国产大陆a不卡| 亚洲丝袜制服诱惑| 欧美色视频一区| 九九久久精品视频| 亚洲视频资源在线| 欧美剧情片在线观看| 精品一区二区三区在线视频| 国产精品天美传媒| 欧美在线免费播放| 国产在线不卡视频| 国模无码大尺度一区二区三区| 精品成人一区二区三区| 成人av午夜电影| 日韩 欧美一区二区三区| 国产欧美一区二区三区网站| 欧美亚洲国产怡红院影院| 久久99这里只有精品| 成人欧美一区二区三区视频网页 | 日韩一区二区三区三四区视频在线观看| 久久国产综合精品| 专区另类欧美日韩| 日韩欧美中文一区| 一本久久a久久免费精品不卡| 日本美女一区二区三区| 国产精品理论在线观看| 欧美一区二区三区视频免费| 91小视频免费观看| 国产在线日韩欧美| 爽好久久久欧美精品| 国产精品久久久久三级| 欧美精品一区男女天堂| 欧美色网站导航| 成人av电影在线| 国产综合久久久久久久久久久久| 亚洲一二三四区| 国产精品免费久久久久| 欧美精品一区二区三区视频| 欧美日韩精品电影| 色综合天天综合给合国产| 国产毛片精品视频| 蜜桃视频免费观看一区| 亚瑟在线精品视频| 亚洲色图欧美在线| 国产亚洲女人久久久久毛片| 欧美大肚乱孕交hd孕妇| 欧美日韩亚洲丝袜制服| 99国产精品国产精品毛片| 国产精品综合av一区二区国产馆| 日本一区中文字幕| 亚洲成在人线在线播放| 亚洲欧美区自拍先锋| 中文字幕在线播放不卡一区| 久久精品亚洲一区二区三区浴池| 欧美一区二区三区成人| 91精品国产综合久久久久| 欧美色精品在线视频| 91成人看片片| 91日韩在线专区| 色偷偷一区二区三区| 色屁屁一区二区| 日本韩国视频一区二区| 91伊人久久大香线蕉| 久久综合狠狠综合久久激情| 欧美日韩高清一区二区不卡 | 欧美三电影在线| 欧美丝袜自拍制服另类| 欧美艳星brazzers| 欧美日韩的一区二区| 91麻豆精品国产91久久久使用方法| 精品1区2区3区| 91精品国产综合久久精品性色| 欧美疯狂做受xxxx富婆| 制服视频三区第一页精品| 日韩女优av电影| 久久美女高清视频| 国产精品麻豆99久久久久久| 亚洲欧洲制服丝袜| 午夜欧美电影在线观看| 免费亚洲电影在线| 国产成人亚洲综合a∨婷婷 | 日韩一区二区在线观看视频| 欧美精品一区二区在线播放| 国产日韩综合av| 日韩一区有码在线| 五月婷婷色综合| 国产麻豆视频精品| 91影视在线播放| 欧美一区二区视频免费观看| 久久久九九九九| 亚洲综合色自拍一区| 理论电影国产精品| 国产不卡高清在线观看视频| 99re视频这里只有精品| 欧美二区乱c少妇| 久久理论电影网| 亚洲黄色小视频| 麻豆91在线看| 91在线视频在线| 91精品国产综合久久久久久久久久 | 午夜精品成人在线视频| 国产真实乱偷精品视频免| 91在线一区二区| 精品久久久久久无| 亚洲女子a中天字幕| 美女视频网站久久| 91女神在线视频| 日韩女优av电影在线观看| 椎名由奈av一区二区三区| 蜜臀a∨国产成人精品| 99精品在线观看视频| 欧美一级欧美三级| 亚洲天堂2014| 狠狠色丁香九九婷婷综合五月| 91一区二区三区在线观看| 欧美一卡2卡3卡4卡| 亚洲图片你懂的| 国产真实精品久久二三区| 在线观看国产91| 日本一区二区三区在线观看| 午夜精品视频在线观看| av电影一区二区| 欧美精品一区男女天堂| 亚洲444eee在线观看| eeuss鲁片一区二区三区在线看| 91精品国产综合久久国产大片| 中文字幕一区av| 国产麻豆精品久久一二三| 欧美高清hd18日本| 亚洲综合一区二区精品导航| 岛国一区二区三区| 亚洲国产cao| 99v久久综合狠狠综合久久| 精品久久国产97色综合| 视频在线观看一区二区三区| 一本大道av一区二区在线播放| 久久蜜桃一区二区| 激情久久久久久久久久久久久久久久| 欧美日韩精品三区| 亚洲国产cao| 在线中文字幕一区| 亚洲欧美另类久久久精品| 懂色一区二区三区免费观看| 精品福利av导航| 极品少妇xxxx偷拍精品少妇| 在线播放一区二区三区| 亚洲午夜久久久久久久久电影网 | 亚洲激情图片一区| 9i在线看片成人免费| 国产欧美精品一区aⅴ影院| 精品一区二区三区视频| 欧美一卡二卡在线观看| 日本亚洲三级在线| 91精品国产入口| 免费成人结看片| 精品国偷自产国产一区| 激情成人综合网| 国产亚洲精品精华液| 国产成人精品1024| 国产精品美女久久久久aⅴ| 波多野结衣亚洲| 亚洲欧美怡红院| 日本久久电影网| 香蕉久久一区二区不卡无毒影院| 欧美日韩国产首页| 日韩电影在线免费看| 日韩三级在线免费观看| 久久国产精品99久久久久久老狼| 精品剧情在线观看| 国产成人免费视频一区| 国产精品久久午夜夜伦鲁鲁| 99久久精品费精品国产一区二区| 亚洲私人影院在线观看| 在线亚洲精品福利网址导航| 天天影视涩香欲综合网| 日韩欧美激情四射| 国产成a人无v码亚洲福利| 亚洲欧美另类综合偷拍| 欧美理论在线播放| 韩国女主播一区| 一区二区中文字幕在线| 欧美日韩电影在线| 国产福利精品一区| 亚洲乱码中文字幕| 日韩精品一区二区在线| 成人a区在线观看| 午夜激情一区二区三区| 久久精品日韩一区二区三区|