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

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

?? tcp.c

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

/*
 * 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.c
 *
 * 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_input.c and tcp_output.c respectively.
 *
 */
/*-----------------------------------------------------------------------------------*/

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

#include "lwip/tcp.h"
//added by dy
#include <string.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. */
struct tcp_pcb_listen *tcp_listen_pcbs;  /* List of all TCP PCBs in LISTEN state. */
struct tcp_pcb *tcp_active_pcbs;  /* List of all TCP PCBs that are in a
				 state in which they accept or send
				 data. */
struct tcp_pcb *tcp_tw_pcbs;      /* List of all TCP PCBs in TIME-WAIT. */

struct tcp_pcb *tcp_tmp_pcb;

#define MIN(x,y) (x) < (y)? (x): (y)

static u8_t tcp_timer;

static u16_t tcp_new_port(void);

/*-----------------------------------------------------------------------------------*/
/*
 * tcp_init():
 *
 * Initializes the TCP layer.
 */
/*-----------------------------------------------------------------------------------*/
void
tcp_init(void)
{
  /* Clear globals. */
  tcp_listen_pcbs = NULL;
  tcp_active_pcbs = NULL;
  tcp_tw_pcbs = NULL;
  tcp_tmp_pcb = NULL;
  
  /* initialize timer */
  tcp_ticks = 0;
  tcp_timer = 0;
  
}
/*-----------------------------------------------------------------------------------*/
/*
 * tcp_tmr():
 *
 * Called periodically to dispatch TCP timers.
 *
 */
/*-----------------------------------------------------------------------------------*/
void
tcp_tmr(void)
{
  ++tcp_timer;
  if(tcp_timer == 10) {
    tcp_timer = 0;
  }
  
  if(tcp_timer & 1) {
    /* Call tcp_fasttmr() every 200 ms, i.e., every other timer
       tcp_tmr() is called. */
    tcp_fasttmr();
  }
  if(tcp_timer == 0 || tcp_timer == 5) {
    /* Call tcp_slowtmr() every 500 ms, i.e., every fifth timer
       tcp_tmr() is called. */
    tcp_slowtmr();
  }
}
/*-----------------------------------------------------------------------------------*/
/*
 * tcp_close():
 *
 * Closes the connection held by the PCB.
 *
 */
/*-----------------------------------------------------------------------------------*/
err_t
tcp_close(struct tcp_pcb *pcb)
{
  err_t err;

#if TCP_DEBUG
  DEBUGF(TCP_DEBUG, ("tcp_close: closing in state "));
  tcp_debug_print_state(pcb->state);
  DEBUGF(TCP_DEBUG, ("\n"));
#endif /* TCP_DEBUG */
  switch(pcb->state) {
  case LISTEN:
    err = ERR_OK;
    tcp_pcb_remove((struct tcp_pcb **)&tcp_listen_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:
    err = tcp_send_ctrl(pcb, TCP_FIN);
    if(err == ERR_OK) {
      pcb->state = FIN_WAIT_1;
    }
    break;
  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;
}
/*-----------------------------------------------------------------------------------*/
/*
 * tcp_abort()
 *
 * 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);
    DEBUGF(TCP_RST_DEBUG, ("tcp_abort: sending RST\n"));
    tcp_rst(seqno, ackno, &local_ip, &remote_ip, local_port, remote_port);
  }
}
/*-----------------------------------------------------------------------------------*/
/*
 * tcp_bind():
 *
 * 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(port == 0) {
    port = tcp_new_port();
  }

  /* Check if the address already is in use. */
  for(cpcb = (struct tcp_pcb *)tcp_listen_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;
      }
    }
  }
  if(!ip_addr_isany(ipaddr)) {
    pcb->local_ip = *ipaddr;
  }
  pcb->local_port = port;
  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)
{
  return ERR_ABRT;
}
#endif /* LWIP_CALLBACK_API */
/*-----------------------------------------------------------------------------------*/
/*
 * tcp_listen():
 *
 * 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;
  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, lpcb);
  return (struct tcp_pcb *)lpcb;
}
/*-----------------------------------------------------------------------------------*/
/*
 * tcp_recved():
 *
 * This function should be called by the application when it has
 * processed the data. The purpose is to advertise a larger window
 * when the data has been processed.
 *
 */
/*-----------------------------------------------------------------------------------*/
void
tcp_recved(struct tcp_pcb *pcb, u16_t len)
{
  pcb->rcv_wnd += len;
  if(pcb->rcv_wnd > TCP_WND) {
    pcb->rcv_wnd = TCP_WND;
  }
  if(!(pcb->flags & TF_ACK_DELAY) &&
     !(pcb->flags & TF_ACK_NOW)) {
    tcp_ack(pcb);
  }
  DEBUGF(TCP_DEBUG, ("tcp_recved: recveived %u bytes, wnd %u (%u).\n",
		     len, pcb->rcv_wnd, TCP_WND - pcb->rcv_wnd));
}
/*-----------------------------------------------------------------------------------*/
/*
 * tcp_new_port():
 *
 * A nastly hack featuring 'goto' statements that allocates a
 * new TCP local port.
 */
/*-----------------------------------------------------------------------------------*/
static u16_t
tcp_new_port(void)
{
  struct tcp_pcb *pcb;
#ifndef TCP_LOCAL_PORT_RANGE_START
#define TCP_LOCAL_PORT_RANGE_START 4096
#define TCP_LOCAL_PORT_RANGE_END   0x7fff
#endif
  static u16_t port = TCP_LOCAL_PORT_RANGE_START;
  
 again:
  if(++port > TCP_LOCAL_PORT_RANGE_END) {
    port = TCP_LOCAL_PORT_RANGE_START;
  }
  
  for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
    if(pcb->local_port == port) {
      goto again;
    }
  }
  for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
    if(pcb->local_port == port) {
      goto again;
    }
  }
  for(pcb = (struct tcp_pcb *)tcp_listen_pcbs; pcb != NULL; pcb = pcb->next) {
    if(pcb->local_port == port) {
      goto again;
    }
  }
  return port;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
最近中文字幕一区二区三区| 亚洲欧洲99久久| 欧美综合视频在线观看| 色综合激情久久| 精品少妇一区二区三区| 欧美性色黄大片| 日本韩国一区二区| 欧美在线一二三| 欧美一区二区视频免费观看| 精品国产乱码久久久久久牛牛| 精品国产一区二区三区av性色 | 欧美中文字幕不卡| 97久久精品人人澡人人爽| 在线这里只有精品| 欧美一区二区三区男人的天堂| 日韩欧美中文字幕公布| 久久综合九色综合97婷婷女人| 国产欧美精品国产国产专区| 中文字幕亚洲一区二区va在线| 亚洲免费成人av| 天堂av在线一区| 国产麻豆精品久久一二三| eeuss国产一区二区三区| 一本色道久久综合亚洲aⅴ蜜桃 | 精品一区二区三区免费观看| 国产精品一区二区久久精品爱涩 | 91在线视频播放| 欧美日韩精品福利| 国产三区在线成人av| 亚洲人xxxx| 看电影不卡的网站| 91亚洲精品久久久蜜桃| 欧美高清视频一二三区| 国产欧美日韩在线视频| 亚洲成av人片观看| 国产一区二区日韩精品| 欧美色视频在线观看| 久久久噜噜噜久久人人看| 亚洲自拍偷拍图区| 国产精品一区二区久久不卡| 欧美在线免费观看视频| 国产日韩欧美制服另类| 日韩电影在线观看一区| 91视频观看视频| 日韩精品中文字幕在线不卡尤物 | 日精品一区二区三区| 粉嫩在线一区二区三区视频| 色婷婷综合久色| 国产丝袜在线精品| 国产99久久久久| 在线综合亚洲欧美在线视频| 国产精品私房写真福利视频| 日本中文字幕一区二区视频 | 精品国内片67194| 亚洲综合色区另类av| av成人老司机| 欧美国产日产图区| 国产精品正在播放| 日韩免费视频一区| 午夜激情一区二区| 欧美在线观看视频一区二区三区| 国产精品欧美一区二区三区| 国产一区二区三区在线观看免费视频 | 天天综合色天天| 在线观看视频91| 一区二区三区视频在线看| 成人黄色网址在线观看| 国产日韩欧美电影| 国产麻豆成人精品| 久久久亚洲高清| 久草中文综合在线| 日韩精品影音先锋| 激情深爱一区二区| 精品成人佐山爱一区二区| 久久99久久精品欧美| 日韩一级在线观看| 紧缚奴在线一区二区三区| 4438亚洲最大| 精品无人区卡一卡二卡三乱码免费卡| 欧美一区二区视频免费观看| 日韩影院在线观看| 精品福利一二区| 国产精品99久久久久久久女警| 久久久综合九色合综国产精品| 精品一区二区三区免费观看| 精品国产免费一区二区三区香蕉| 国内一区二区视频| 久久久国产精品不卡| 国产成人在线影院| 亚洲欧美视频在线观看视频| 色婷婷久久综合| 午夜精品久久久| 日韩免费在线观看| av在线综合网| 国产在线精品不卡| 国产精品久久久久永久免费观看| 成人免费av网站| 亚洲午夜久久久久久久久电影院| 91精品免费在线| 国产在线观看一区二区| 亚洲欧美一区二区不卡| 欧美日韩三级视频| 国产一区在线观看麻豆| 亚洲欧美一区二区三区久本道91| 欧美精品亚洲一区二区在线播放| 美女任你摸久久| 亚洲视频小说图片| 欧美一区2区视频在线观看| 懂色av一区二区三区蜜臀| 亚洲久本草在线中文字幕| 91精品国产91久久久久久最新毛片| 国产一区二区在线视频| 亚洲在线视频一区| 欧美国产精品专区| 日韩欧美亚洲国产另类| 99国产精品国产精品毛片| 久久国产欧美日韩精品| 亚洲夂夂婷婷色拍ww47| 国产欧美一区在线| 日韩一区二区免费高清| 91一区二区在线| 国产精品一品二品| 免费在线观看一区| 亚洲综合自拍偷拍| 中文字幕综合网| 国产色产综合色产在线视频| 91精品免费在线| 在线免费精品视频| 91在线精品一区二区| 国产激情91久久精品导航| 美女精品一区二区| 亚洲成人av资源| 一区二区三区在线观看欧美| 国产午夜精品一区二区| 欧美精品一区二区在线播放| 欧美精品久久久久久久多人混战 | 中文字幕亚洲一区二区av在线| 日韩欧美国产综合| 欧美日韩第一区日日骚| 成人av电影在线观看| 国产91清纯白嫩初高中在线观看| 毛片不卡一区二区| 日本 国产 欧美色综合| 日韩精品1区2区3区| 五月激情丁香一区二区三区| 一区二区成人在线| 一区二区三区在线观看欧美| 中文字幕综合网| 亚洲天堂免费看| ...xxx性欧美| 亚洲日本一区二区三区| 亚洲色图.com| 一二三区精品福利视频| 一区二区三区电影在线播| 亚洲一卡二卡三卡四卡无卡久久 | 日韩限制级电影在线观看| 欧美日韩色一区| 69p69国产精品| 精品蜜桃在线看| 欧美成人a∨高清免费观看| 久久这里只精品最新地址| 2023国产精品| 综合久久久久综合| 亚洲一级电影视频| 视频在线观看91| 精品中文av资源站在线观看| 精一区二区三区| fc2成人免费人成在线观看播放| 99久久久国产精品| 欧美日韩另类一区| 日韩欧美专区在线| 国产精品污www在线观看| 成人欧美一区二区三区视频网页| 一区二区三区四区在线| 亚洲电影在线播放| 韩日av一区二区| 91美女福利视频| 日韩精品一区二区三区在线播放 | 天天亚洲美女在线视频| 精品亚洲成av人在线观看| bt7086福利一区国产| 欧美精品免费视频| 中文字幕免费一区| 亚洲成人激情av| 国产大片一区二区| 欧美绝品在线观看成人午夜影视| 欧美精品一区二区三区蜜桃 | 国产.欧美.日韩| 欧美色综合天天久久综合精品| 日韩三级中文字幕| 亚洲蜜臀av乱码久久精品蜜桃| 日日夜夜免费精品视频| 成人黄色小视频| 日韩精品一区二区在线观看| 自拍av一区二区三区| 国产中文字幕精品| 69精品人人人人| 亚洲激情中文1区| 高清在线不卡av| 欧美丰满美乳xxx高潮www|