亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
日本高清不卡aⅴ免费网站| 国产欧美日韩综合精品一区二区| 日韩精品一区二区三区中文不卡 | 国内精品不卡在线| 99re这里都是精品| 精品精品国产高清a毛片牛牛 | 欧美国产日韩a欧美在线观看| 亚洲一区二区三区激情| 福利一区二区在线| 日韩精品一区二区在线| 丝袜诱惑亚洲看片| 色综合久久久久网| 久久日韩粉嫩一区二区三区| 免费一区二区视频| 欧美精品在线视频| 亚洲一区二区视频在线观看| 色综合天天综合网天天狠天天 | 成人av电影在线网| 久久久久久久久免费| 日本成人在线看| 91精品国产色综合久久| 午夜在线电影亚洲一区| 91小视频免费观看| 国产精品国产馆在线真实露脸| 精品夜夜嗨av一区二区三区| 7777精品伊人久久久大香线蕉| 一区二区三区国产豹纹内裤在线| 99这里都是精品| 国产精品福利影院| www.亚洲色图| 综合色中文字幕| 色噜噜狠狠一区二区三区果冻| 最新日韩在线视频| 99综合影院在线| 亚洲一级二级在线| 在线不卡中文字幕播放| 偷拍一区二区三区四区| 日韩一区二区三| 狂野欧美性猛交blacked| 精品久久国产老人久久综合| 美女网站色91| 国产亚洲综合性久久久影院| 国产91精品久久久久久久网曝门| 国产精品美女www爽爽爽| av不卡在线观看| 午夜视频在线观看一区二区| 91精品国产高清一区二区三区| 久久精品999| 国产人久久人人人人爽| 97久久精品人人做人人爽| 亚洲男同性视频| 7777精品伊人久久久大香线蕉超级流畅| 秋霞电影网一区二区| 精品免费视频一区二区| 成人免费看片app下载| 玉米视频成人免费看| 欧美精品在线一区二区| 国产激情视频一区二区在线观看| 中文一区二区在线观看| 欧美天堂亚洲电影院在线播放| 日本成人在线网站| 国产精品久久久久影院色老大| 欧美在线free| 国产一区二区精品在线观看| 日韩伦理电影网| 日韩欧美在线123| 99久久精品国产麻豆演员表| 亚洲成在人线免费| 国产亚洲欧美日韩在线一区| 在线精品视频一区二区三四| 激情小说欧美图片| 又紧又大又爽精品一区二区| 日韩欧美一级二级三级久久久| 成人国产精品免费观看动漫| 青青草一区二区三区| 国产精品久久久久9999吃药| 91精品国产综合久久福利| 成人午夜视频福利| 美日韩一区二区三区| 综合久久久久久久| 精品av综合导航| 欧美日韩免费观看一区二区三区| 国产成人亚洲综合色影视| 午夜精品aaa| 亚洲男女一区二区三区| 亚洲精品一区在线观看| 欧美美女直播网站| 91丨porny丨国产| 国产精品99久久久久久有的能看 | 亚洲美女视频在线观看| 2023国产精华国产精品| 91精品国产综合久久精品app| av色综合久久天堂av综合| 国产一区二区三区四区在线观看| 视频精品一区二区| 一个色妞综合视频在线观看| 国产欧美一区二区三区在线看蜜臀 | 中文字幕一区二区三区精华液 | 欧美一区二区国产| 欧美色手机在线观看| av在线这里只有精品| 国产精品一区一区| 国产在线不卡一卡二卡三卡四卡| 五月天激情综合| 亚洲午夜免费福利视频| 夜色激情一区二区| 一级日本不卡的影视| 夜夜精品浪潮av一区二区三区| 中文字幕一区二区三区av| 欧美激情在线一区二区| 国产婷婷一区二区| 欧美经典三级视频一区二区三区| 久久综合丝袜日本网| 久久久久久97三级| 国产无人区一区二区三区| 国产免费成人在线视频| 国产日韩成人精品| 欧美国产精品专区| 国产精品美女久久福利网站| 中文字幕一区二区三区在线播放 | 久久美女艺术照精彩视频福利播放| 日韩一级完整毛片| 精品久久久久久亚洲综合网| 久久久久国产成人精品亚洲午夜| 欧美精品一区二区三区蜜桃| 久久人人超碰精品| 国产女主播一区| 中文字幕日韩av资源站| 亚洲视频一二三区| 洋洋av久久久久久久一区| 日韩综合小视频| 久久不见久久见免费视频7 | 精油按摩中文字幕久久| 国产一区二区三区四区五区美女| 国产精品一级片在线观看| av毛片久久久久**hd| 欧美日韩一区三区四区| 精品国产成人系列| 中文欧美字幕免费| 亚洲伊人伊色伊影伊综合网| 日韩电影在线看| 成人精品小蝌蚪| 欧美日韩中文国产| 亚洲精品在线一区二区| 综合久久国产九一剧情麻豆| 亚洲国产精品久久久男人的天堂 | 日韩av一区二区在线影视| 麻豆精品视频在线观看免费| 成人小视频免费观看| 欧美午夜寂寞影院| 国产视频不卡一区| 午夜精品一区二区三区电影天堂 | 欧美人成免费网站| 337p日本欧洲亚洲大胆精品| 国产精品亲子伦对白| 午夜影院在线观看欧美| 成人中文字幕在线| 在线播放亚洲一区| 中文字幕一区二区三区蜜月 | 成人动漫视频在线| 欧美一区二区在线观看| 亚洲欧洲av一区二区三区久久| 亚洲成人av电影在线| 成人中文字幕合集| 日韩欧美色电影| 亚洲综合小说图片| 国产91色综合久久免费分享| 日韩三级中文字幕| 亚洲美女偷拍久久| 成人免费视频免费观看| 日韩丝袜美女视频| 亚洲国产一区二区三区 | 欧美一级高清片| 亚洲色图视频网| 国产成人免费视频一区| 555夜色666亚洲国产免| 亚洲激情一二三区| 国产91露脸合集magnet| 精品国产乱码久久久久久1区2区 | 亚洲黄网站在线观看| 成人高清免费在线播放| 精品日韩一区二区| 男人的天堂亚洲一区| 欧美日韩国产精品成人| 一区二区三区av电影 | 97se狠狠狠综合亚洲狠狠| 日韩欧美国产一区在线观看| 午夜久久久久久久久久一区二区| 99久久国产综合色|国产精品| 久久综合九色综合欧美就去吻 | 亚洲女同一区二区| 成人一区二区三区视频| 久久天天做天天爱综合色| 久久精品久久久精品美女| 欧美日韩国产片| 亚洲一区二区三区四区五区中文| 91女厕偷拍女厕偷拍高清| 中文字幕在线观看不卡视频| 高清成人在线观看| 亚洲国产成人一区二区三区|