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

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

?? tcp.c

?? FreeRtos Source code Version 4.04
?? C
?? 第 1 頁 / 共 3 頁
字號:
/**
 * @file
 *
 * Transmission Control Protocol for IP
 *
 * This file contains common functions for the TCP implementation, such as functinos
 * for manipulating the data structures and the TCP timer functions. TCP functions
 * related to input and output is found in tcp_in.c and tcp_out.c respectively.
 *
 */

/*
 * Copyright (c) 2001-2004 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>
 *
 */

#include <string.h>

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

#include "lwip/tcp.h"
#if LWIP_TCP

/* Incremented every coarse grained timer shot
   (typically every 500 ms, determined by TCP_COARSE_TIMEOUT). */
u32_t tcp_ticks;
const u8_t tcp_backoff[13] =
    { 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7};

/* The TCP PCB lists. */

/** List of all TCP PCBs in LISTEN state */
union tcp_listen_pcbs_t tcp_listen_pcbs;
/** List of all TCP PCBs that are in a state in which
 * they accept or send data. */
struct tcp_pcb *tcp_active_pcbs;  
/** List of all TCP PCBs in TIME-WAIT state */
struct tcp_pcb *tcp_tw_pcbs;

struct tcp_pcb *tcp_tmp_pcb;

static u8_t tcp_timer;
static u16_t tcp_new_port(void);

/**
 * Initializes the TCP layer.
 */
void
tcp_init(void)
{
  /* Clear globals. */
  tcp_listen_pcbs.listen_pcbs = NULL;
  tcp_active_pcbs = NULL;
  tcp_tw_pcbs = NULL;
  tcp_tmp_pcb = NULL;
  
  /* initialize timer */
  tcp_ticks = 0;
  tcp_timer = 0;
  
}

/**
 * Called periodically to dispatch TCP timers.
 *
 */
void
tcp_tmr(void)
{
  /* Call tcp_fasttmr() every 250 ms */
  tcp_fasttmr();

  if (++tcp_timer & 1) {
    /* Call tcp_tmr() every 500 ms, i.e., every other timer
       tcp_tmr() is called. */
    tcp_slowtmr();
  }
}

/**
 * Closes the connection held by the PCB.
 *
 */
err_t
tcp_close(struct tcp_pcb *pcb)
{
  err_t err;

#if TCP_DEBUG
  LWIP_DEBUGF(TCP_DEBUG, ("tcp_close: closing in state "));
  tcp_debug_print_state(pcb->state);
  LWIP_DEBUGF(TCP_DEBUG, ("\n"));
#endif /* TCP_DEBUG */
  switch (pcb->state) {
  case CLOSED:
    /* Closing a pcb in the CLOSED state might seem erroneous,
     * however, it is in this state once allocated and as yet unused
     * and the user needs some way to free it should the need arise.
     * Calling tcp_close() with a pcb that has already been closed, (i.e. twice)
     * or for a pcb that has been used and then entered the CLOSED state 
     * is erroneous, but this should never happen as the pcb has in those cases
     * been freed, and so any remaining handles are bogus. */
    err = ERR_OK;
    memp_free(MEMP_TCP_PCB, pcb);
    pcb = NULL;
    break;
  case LISTEN:
    err = ERR_OK;
    tcp_pcb_remove((struct tcp_pcb **)&tcp_listen_pcbs.pcbs, pcb);
    memp_free(MEMP_TCP_PCB_LISTEN, pcb);
    pcb = NULL;
    break;
  case SYN_SENT:
    err = ERR_OK;
    tcp_pcb_remove(&tcp_active_pcbs, pcb);
    memp_free(MEMP_TCP_PCB, pcb);
    pcb = NULL;
    break;
  case SYN_RCVD:
  case ESTABLISHED:
    err = tcp_send_ctrl(pcb, TCP_FIN);
    if (err == ERR_OK) {
      pcb->state = FIN_WAIT_1;
    }
    break;
  case CLOSE_WAIT:
    err = tcp_send_ctrl(pcb, TCP_FIN);
    if (err == ERR_OK) {
      pcb->state = LAST_ACK;
    }
    break;
  default:
    /* Has already been closed, do nothing. */
    err = ERR_OK;
    pcb = NULL;
    break;
  }

  if (pcb != NULL && err == ERR_OK) {
    err = tcp_output(pcb);
  }
  return err;
}

/**
 * Aborts a connection by sending a RST to the remote host and deletes
 * the local protocol control block. This is done when a connection is
 * killed because of shortage of memory.
 *
 */
void
tcp_abort(struct tcp_pcb *pcb)
{
  u32_t seqno, ackno;
  u16_t remote_port, local_port;
  struct ip_addr remote_ip, local_ip;
#if LWIP_CALLBACK_API  
  void (* errf)(void *arg, err_t err);
#endif /* LWIP_CALLBACK_API */
  void *errf_arg;

  
  /* Figure out on which TCP PCB list we are, and remove us. If we
     are in an active state, call the receive function associated with
     the PCB with a NULL argument, and send an RST to the remote end. */
  if (pcb->state == TIME_WAIT) {
    tcp_pcb_remove(&tcp_tw_pcbs, pcb);
    memp_free(MEMP_TCP_PCB, pcb);
  } else {
    seqno = pcb->snd_nxt;
    ackno = pcb->rcv_nxt;
    ip_addr_set(&local_ip, &(pcb->local_ip));
    ip_addr_set(&remote_ip, &(pcb->remote_ip));
    local_port = pcb->local_port;
    remote_port = pcb->remote_port;
#if LWIP_CALLBACK_API
    errf = pcb->errf;
#endif /* LWIP_CALLBACK_API */
    errf_arg = pcb->callback_arg;
    tcp_pcb_remove(&tcp_active_pcbs, pcb);
    if (pcb->unacked != NULL) {
      tcp_segs_free(pcb->unacked);
    }
    if (pcb->unsent != NULL) {
      tcp_segs_free(pcb->unsent);
    }
#if TCP_QUEUE_OOSEQ    
    if (pcb->ooseq != NULL) {
      tcp_segs_free(pcb->ooseq);
    }
#endif /* TCP_QUEUE_OOSEQ */
    memp_free(MEMP_TCP_PCB, pcb);
    TCP_EVENT_ERR(errf, errf_arg, ERR_ABRT);
    LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_abort: sending RST\n"));
    tcp_rst(seqno, ackno, &local_ip, &remote_ip, local_port, remote_port);
  }
}

/**
 * Binds the connection to a local portnumber and IP address. If the
 * IP address is not given (i.e., ipaddr == NULL), the IP address of
 * the outgoing network interface is used instead.
 *
 */

err_t
tcp_bind(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
{
  struct tcp_pcb *cpcb;
#if SO_REUSE
  int reuse_port_all_set = 1;
#endif /* SO_REUSE */

  if (port == 0) {
    port = tcp_new_port();
  }
#if SO_REUSE == 0
  /* Check if the address already is in use. */
  for(cpcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs;
      cpcb != NULL; cpcb = cpcb->next) {
    if (cpcb->local_port == port) {
      if (ip_addr_isany(&(cpcb->local_ip)) ||
        ip_addr_isany(ipaddr) ||
        ip_addr_cmp(&(cpcb->local_ip), ipaddr)) {
          return ERR_USE;
      }
    }
  }
  for(cpcb = tcp_active_pcbs;
      cpcb != NULL; cpcb = cpcb->next) {
    if (cpcb->local_port == port) {
      if (ip_addr_isany(&(cpcb->local_ip)) ||
   ip_addr_isany(ipaddr) ||
   ip_addr_cmp(&(cpcb->local_ip), ipaddr)) {
  return ERR_USE;
      }
    }
  }
#else /* SO_REUSE */
  /* Search through list of PCB's in LISTEN state. 
     
  If there is a PCB bound to specified port and IP_ADDR_ANY another PCB can be bound to the interface IP
  or to the loopback address on the same port if SOF_REUSEADDR is set. Any combination of PCB's bound to 
  the same local port, but to one address out of {IP_ADDR_ANY, 127.0.0.1, interface IP} at a time is valid.
  But no two PCB's bound to same local port and same local address is valid.
  
  If SOF_REUSEPORT is set several PCB's can be bound to same local port and same local address also. But then 
  all PCB's must have the SOF_REUSEPORT option set.
  
  When the two options aren't set and specified port is already bound, ERR_USE is returned saying that 
  address is already in use. */
  for(cpcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; cpcb != NULL; cpcb = cpcb->next) {
    if(cpcb->local_port == port) {
      if(ip_addr_cmp(&(cpcb->local_ip), ipaddr)) {
        if(pcb->so_options & SOF_REUSEPORT) {
          LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: in listening PCB's: SO_REUSEPORT set and same address.\n"));
          reuse_port_all_set = (reuse_port_all_set && (cpcb->so_options & SOF_REUSEPORT));
        }
        else {
          LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: in listening PCB's: SO_REUSEPORT not set and same address.\n"));
          return ERR_USE;
        }
      }
      else if((ip_addr_isany(ipaddr) && !ip_addr_isany(&(cpcb->local_ip))) ||
              (!ip_addr_isany(ipaddr) && ip_addr_isany(&(cpcb->local_ip)))) {
        if(!(pcb->so_options & SOF_REUSEADDR) && !(pcb->so_options & SOF_REUSEPORT)) {
          LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: in listening PCB's SO_REUSEPORT or SO_REUSEADDR not set and not the same address.\n"));
          return ERR_USE;
        }      
        else {
          LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: in listening PCB's SO_REUSEPORT or SO_REUSEADDR set and not the same address.\n"));
        }     
      }
    }
  }

  /* Search through list of PCB's in a state in which they can accept or send data. Same decription as for 
     PCB's in state LISTEN applies to this PCB's regarding the options SOF_REUSEADDR and SOF_REUSEPORT. */
  for(cpcb = tcp_active_pcbs; cpcb != NULL; cpcb = cpcb->next) {
    if(cpcb->local_port == port) {
      if(ip_addr_cmp(&(cpcb->local_ip), ipaddr)) {
        if(pcb->so_options & SOF_REUSEPORT) {
          LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: in active PCB's SO_REUSEPORT set and same address.\n"));
          reuse_port_all_set = (reuse_port_all_set && (cpcb->so_options & SOF_REUSEPORT));
        }
        else {
          LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: in active PCB's SO_REUSEPORT not set and same address.\n"));
          return ERR_USE;
        }
      }
      else if((ip_addr_isany(ipaddr) && !ip_addr_isany(&(cpcb->local_ip))) ||
              (!ip_addr_isany(ipaddr) && ip_addr_isany(&(cpcb->local_ip)))) {
        if(!(pcb->so_options & SOF_REUSEADDR) && !(pcb->so_options & SOF_REUSEPORT)) {
          LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: in active PCB's SO_REUSEPORT or SO_REUSEADDR not set and not the same address.\n"));
          return ERR_USE;
        }   
        else {
          LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: in active PCB's SO_REUSEPORT or SO_REUSEADDR set and not the same address.\n"));
        }        
      }
    }
  }

  /* Search through list of PCB's in TIME_WAIT state. If SO_REUSEADDR is set a bound combination [IP, port} 
     can be rebound. The same applies when SOF_REUSEPORT is set. 
     
     If SOF_REUSEPORT is set several PCB's can be bound to same local port and same local address also. But then 
     all PCB's must have the SOF_REUSEPORT option set.
     
     When the two options aren't set and specified port is already bound, ERR_USE is returned saying that 
     address is already in use. */
  for(cpcb = tcp_tw_pcbs; cpcb != NULL; cpcb = cpcb->next) {
    if(cpcb->local_port == port) {
      if(ip_addr_cmp(&(cpcb->local_ip), ipaddr)) {
        if(!(pcb->so_options & SOF_REUSEADDR) && !(pcb->so_options & SOF_REUSEPORT)) {
          LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: in TIME_WAIT PCB's SO_REUSEPORT or SO_REUSEADDR not set and same address.\n"));
          return ERR_USE;
        }
        else if(pcb->so_options & SOF_REUSEPORT) {
          LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: in TIME_WAIT PCB's SO_REUSEPORT set and same address.\n"));
          reuse_port_all_set = (reuse_port_all_set && (cpcb->so_options & SOF_REUSEPORT));
        }
      }
    }
  }

  /* If SOF_REUSEPORT isn't set in all PCB's bound to specified port and local address specified then 
     {IP, port} can't be reused. */
  if(!reuse_port_all_set) {
    LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: not all sockets have SO_REUSEPORT set.\n"));
    return ERR_USE;
  }
#endif /* SO_REUSE */

  if (!ip_addr_isany(ipaddr)) {
    pcb->local_ip = *ipaddr;
  }
  pcb->local_port = port;
  LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: bind to port %u\n", port));
  return ERR_OK;
}
#if LWIP_CALLBACK_API
static err_t
tcp_accept_null(void *arg, struct tcp_pcb *pcb, err_t err)
{
  (void)arg;
  (void)pcb;
  (void)err;

  return ERR_ABRT;
}
#endif /* LWIP_CALLBACK_API */

/**
 * Set the state of the connection to be LISTEN, which means that it
 * is able to accept incoming connections. The protocol control block
 * is reallocated in order to consume less memory. Setting the
 * connection to LISTEN is an irreversible process.
 *
 */
struct tcp_pcb *
tcp_listen(struct tcp_pcb *pcb)
{
  struct tcp_pcb_listen *lpcb;

  /* already listening? */
  if (pcb->state == LISTEN) {
    return pcb;
  }
  lpcb = memp_malloc(MEMP_TCP_PCB_LISTEN);
  if (lpcb == NULL) {
    return NULL;
  }
  lpcb->callback_arg = pcb->callback_arg;
  lpcb->local_port = pcb->local_port;
  lpcb->state = LISTEN;
  lpcb->so_options = pcb->so_options;
  lpcb->so_options |= SOF_ACCEPTCONN;
  lpcb->ttl = pcb->ttl;
  lpcb->tos = pcb->tos;
  ip_addr_set(&lpcb->local_ip, &pcb->local_ip);
  memp_free(MEMP_TCP_PCB, pcb);
#if LWIP_CALLBACK_API
  lpcb->accept = tcp_accept_null;
#endif /* LWIP_CALLBACK_API */
  TCP_REG(&tcp_listen_pcbs.listen_pcbs, lpcb);
  return (struct tcp_pcb *)lpcb;
}

/**
 * This function should be called by the application when it has
 * processed the data. The purpose is to advertise a larger window

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品一区二区三区蜜桃| 久久99国产精品久久99| www国产成人| 欧美va亚洲va在线观看蝴蝶网| 美女视频黄 久久| 日韩av一二三| 免费看日韩a级影片| 日韩电影一区二区三区| 免费观看日韩电影| 精品综合久久久久久8888| 久久精品国产久精国产爱| 久久成人18免费观看| 国产原创一区二区三区| 国产成人8x视频一区二区| 国产成人av影院| 99riav久久精品riav| 色综合色狠狠天天综合色| 91黄视频在线| 日韩欧美一区中文| 久久久久久**毛片大全| 国产精品久久久久久久久免费樱桃 | 精品国产自在久精品国产| 欧美日韩国产综合一区二区 | 97久久久精品综合88久久| 一本大道久久a久久综合| 欧美军同video69gay| 久久麻豆一区二区| 成人欧美一区二区三区视频网页 | 亚洲色图视频网| 日韩影院精彩在线| 国产经典欧美精品| 91福利在线看| 欧美电影免费观看高清完整版| 国产精品视频免费看| 亚洲电影中文字幕在线观看| 精品亚洲aⅴ乱码一区二区三区| 国产成人精品三级| 欧美在线免费观看亚洲| 日韩欧美国产1| 日韩理论片一区二区| 欧美aaa在线| 成年人网站91| 日韩精品自拍偷拍| 一个色妞综合视频在线观看| 国模套图日韩精品一区二区| 91网页版在线| 久久天天做天天爱综合色| 一区二区三区不卡视频| 国产精品一二二区| 欧美一级欧美一级在线播放| 成人欧美一区二区三区白人| 精品无码三级在线观看视频| 色嗨嗨av一区二区三区| 国产无一区二区| 卡一卡二国产精品| 欧美三级中文字幕在线观看| 国产精品色哟哟| 国产资源精品在线观看| 91精品国产综合久久久蜜臀粉嫩 | 蜜桃av噜噜一区二区三区小说| 91麻豆视频网站| 中文字幕av一区 二区| 精品一区二区在线看| 日本福利一区二区| 亚洲视频资源在线| 国产69精品久久99不卡| 91麻豆精品国产91久久久使用方法 | 国产a精品视频| 欧美精品一区二区三区蜜臀 | 综合久久一区二区三区| 国产成人亚洲综合a∨婷婷图片| 精品美女一区二区三区| 久久99久国产精品黄毛片色诱| 欧美日本乱大交xxxxx| 亚洲成人av一区二区三区| 欧美熟乱第一页| 亚洲va欧美va国产va天堂影院| 色婷婷久久一区二区三区麻豆| 亚洲免费毛片网站| 欧洲一区二区三区在线| 亚洲一区二区五区| 欧美午夜影院一区| 天天操天天干天天综合网| 欧美日韩高清不卡| 欧美a级理论片| 久久久电影一区二区三区| 丁香网亚洲国际| 中文字幕中文字幕在线一区| 色综合久久久久| 亚洲成人7777| 日韩欧美你懂的| 国产99久久久国产精品潘金| 国产精品人妖ts系列视频| av在线不卡电影| 亚洲最色的网站| 日韩精品在线一区| 不卡av免费在线观看| 亚洲一区在线电影| 欧美变态口味重另类| 粉嫩在线一区二区三区视频| 亚洲日本在线a| 在线综合+亚洲+欧美中文字幕| 韩国毛片一区二区三区| 中文字幕在线观看一区二区| 欧美三级视频在线播放| 国产精品自拍网站| 亚洲一区在线观看免费| 精品99一区二区三区| 色综合激情久久| 久久99精品久久久久久国产越南| 国产农村妇女精品| 欧美精品123区| 丁香六月综合激情| 丝袜美腿亚洲色图| 国产精品灌醉下药二区| 777午夜精品视频在线播放| 成人爽a毛片一区二区免费| 亚洲韩国精品一区| 国产精品久久免费看| 欧美一区二区三区的| 91色.com| 成人一区二区视频| 日韩制服丝袜av| 亚洲综合色噜噜狠狠| 国产欧美中文在线| 日韩美女在线视频 | 麻豆成人免费电影| 一区二区三区欧美激情| 国产色综合一区| 日韩天堂在线观看| 在线免费观看日韩欧美| av影院午夜一区| 国产精品自拍三区| 狠狠色丁香久久婷婷综合_中| 亚洲尤物在线视频观看| 中文字幕亚洲电影| 国产女同性恋一区二区| 337p日本欧洲亚洲大胆色噜噜| 欧美日韩国产不卡| 色菇凉天天综合网| 色哟哟精品一区| 不卡在线观看av| 成人激情图片网| 国产v日产∨综合v精品视频| 久久99久久精品| 国产综合色产在线精品| 久久不见久久见中文字幕免费| 热久久免费视频| 奇米777欧美一区二区| 日本最新不卡在线| 日韩精品一区第一页| 日本成人在线视频网站| 麻豆成人在线观看| 激情文学综合丁香| 国产成人精品免费在线| 丁香啪啪综合成人亚洲小说 | 国产乱理伦片在线观看夜一区| 蜜乳av一区二区| 九色综合国产一区二区三区| 狠狠色狠狠色合久久伊人| 国产精品66部| 成人激情校园春色| 欧美主播一区二区三区美女| 欧美午夜在线一二页| 91精品国产日韩91久久久久久| 91精品国产黑色紧身裤美女| 欧美一二三在线| 国产婷婷色一区二区三区| 中文字幕日本乱码精品影院| 怡红院av一区二区三区| 丝袜国产日韩另类美女| 国产一区二区影院| 99这里只有久久精品视频| 色老汉一区二区三区| 欧美一区二区久久| 国产人成亚洲第一网站在线播放 | 青青草原综合久久大伊人精品优势 | 亚洲同性同志一二三专区| 亚洲自拍与偷拍| 久久精品国产精品亚洲综合| 成人精品高清在线| 欧美精品丝袜中出| 久久免费偷拍视频| 亚洲综合自拍偷拍| 久久国产剧场电影| 97精品视频在线观看自产线路二| 欧美人妇做爰xxxⅹ性高电影| 欧美不卡视频一区| 亚洲欧美日韩一区二区三区在线观看| 偷窥少妇高潮呻吟av久久免费| 国产一区二三区好的| 欧美特级限制片免费在线观看| 欧美精品一区二区三区视频| 亚洲欧美一区二区三区国产精品| 日韩高清不卡一区二区三区| 成人免费毛片app| 日韩欧美自拍偷拍| 一卡二卡三卡日韩欧美| 成人午夜视频在线| 欧美一二三区精品|