<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Ubixos: tcp.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.3 -->
<h1>tcp.h</h1><div class="fragment"><pre>00001 <span class="comment">/*</span>
00002 <span class="comment"> * Copyright (c) 2001, Swedish Institute of Computer Science.</span>
00003 <span class="comment"> * All rights reserved. </span>
00004 <span class="comment"> *</span>
00005 <span class="comment"> * Redistribution and use in source and binary forms, with or without </span>
00006 <span class="comment"> * modification, are permitted provided that the following conditions </span>
00007 <span class="comment"> * are met: </span>
00008 <span class="comment"> * 1. Redistributions of source code must retain the above copyright </span>
00009 <span class="comment"> * notice, this list of conditions and the following disclaimer. </span>
00010 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright </span>
00011 <span class="comment"> * notice, this list of conditions and the following disclaimer in the </span>
00012 <span class="comment"> * documentation and/or other materials provided with the distribution. </span>
00013 <span class="comment"> * 3. Neither the name of the Institute nor the names of its contributors </span>
00014 <span class="comment"> * may be used to endorse or promote products derived from this software </span>
00015 <span class="comment"> * without specific prior written permission. </span>
00016 <span class="comment"> *</span>
00017 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND </span>
00018 <span class="comment"> * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE </span>
00019 <span class="comment"> * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE </span>
00020 <span class="comment"> * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE </span>
00021 <span class="comment"> * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL </span>
00022 <span class="comment"> * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS </span>
00023 <span class="comment"> * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) </span>
00024 <span class="comment"> * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT </span>
00025 <span class="comment"> * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY </span>
00026 <span class="comment"> * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF </span>
00027 <span class="comment"> * SUCH DAMAGE. </span>
00028 <span class="comment"> *</span>
00029 <span class="comment"> * This file is part of the lwIP TCP/IP stack.</span>
00030 <span class="comment"> * </span>
00031 <span class="comment"> * Author: Adam Dunkels <adam@sics.se></span>
00032 <span class="comment"> *</span>
00033 <span class="comment"> * $Id$</span>
00034 <span class="comment"> */</span>
00035 <span class="preprocessor">#ifndef __LWIP_TCP_H__</span>
00036 <span class="preprocessor"></span><span class="preprocessor">#define __LWIP_TCP_H__</span>
00037 <span class="preprocessor"></span>
00038 <span class="preprocessor">#include "net/sys.h"</span>
00039 <span class="preprocessor">#include "net/mem.h"</span>
00040
00041 <span class="preprocessor">#include "net/pbuf.h"</span>
00042 <span class="preprocessor">#include "net/opt.h"</span>
00043 <span class="comment">//UBU</span>
00044 <span class="preprocessor">#include "net/ipv4/ip.h"</span>
00045 <span class="comment">//UBU</span>
00046 <span class="preprocessor">#include "net/ipv4/icmp.h"</span>
00047
00048 <span class="preprocessor">#include "net/sys.h"</span>
00049
00050 <span class="preprocessor">#include "net/err.h"</span>
00051
00052 <span class="keyword">struct </span>tcp_pcb;
00053
00054 <span class="comment">/* Functions for interfacing with TCP: */</span>
00055
00056 <span class="comment">/* Lower layer interface to TCP: */</span>
00057 <span class="keywordtype">void</span> tcp_init (<span class="keywordtype">void</span>); <span class="comment">/* Must be called first to</span>
00058 <span class="comment"> initialize TCP. */</span>
00059 <span class="keywordtype">void</span> tcp_tmr (<span class="keywordtype">void</span>); <span class="comment">/* Must be called every</span>
00060 <span class="comment"> TCP_TMR_INTERVAL</span>
00061 <span class="comment"> ms. (Typically 100 ms). */</span>
00062 <span class="comment">/* Application program's interface: */</span>
00063 <span class="keyword">struct </span>tcp_pcb * tcp_new (<span class="keywordtype">void</span>);
00064
00065 <span class="keywordtype">void</span> tcp_arg (<span class="keyword">struct</span> tcp_pcb *pcb, <span class="keywordtype">void</span> *arg);
00066 <span class="keywordtype">void</span> tcp_accept (<span class="keyword">struct</span> tcp_pcb *pcb,
00067 err_t (* accept)(<span class="keywordtype">void</span> *arg, <span class="keyword">struct</span> tcp_pcb *newpcb,
00068 err_t err));
00069 <span class="keywordtype">void</span> tcp_recv (<span class="keyword">struct</span> tcp_pcb *pcb,
00070 err_t (* recv)(<span class="keywordtype">void</span> *arg, <span class="keyword">struct</span> tcp_pcb *tpcb,
00071 <span class="keyword">struct</span> pbuf *p, err_t err));
00072 <span class="keywordtype">void</span> tcp_sent (<span class="keyword">struct</span> tcp_pcb *pcb,
00073 err_t (* sent)(<span class="keywordtype">void</span> *arg, <span class="keyword">struct</span> tcp_pcb *tpcb,
00074 uInt16 len));
00075 <span class="keywordtype">void</span> tcp_poll (<span class="keyword">struct</span> tcp_pcb *pcb,
00076 err_t (* poll)(<span class="keywordtype">void</span> *arg, <span class="keyword">struct</span> tcp_pcb *tpcb),
00077 uInt8 interval);
00078 <span class="keywordtype">void</span> tcp_err (<span class="keyword">struct</span> tcp_pcb *pcb,
00079 <span class="keywordtype">void</span> (* err)(<span class="keywordtype">void</span> *arg, err_t err));
00080
00081 <span class="preprocessor">#define tcp_sndbuf(pcb) ((pcb)->snd_buf)</span>
00082 <span class="preprocessor"></span>
00083 <span class="keywordtype">void</span> tcp_recved (<span class="keyword">struct</span> tcp_pcb *pcb, uInt16 len);
00084 err_t tcp_bind (<span class="keyword">struct</span> tcp_pcb *pcb, <span class="keyword">struct</span> ip_addr *ipaddr,
00085 uInt16 port);
00086 err_t tcp_connect (<span class="keyword">struct</span> tcp_pcb *pcb, <span class="keyword">struct</span> ip_addr *ipaddr,
00087 uInt16 port, err_t (* connected)(<span class="keywordtype">void</span> *arg,
00088 <span class="keyword">struct</span> tcp_pcb *tpcb,
00089 err_t err));
00090 <span class="keyword">struct </span>tcp_pcb * tcp_listen (<span class="keyword">struct</span> tcp_pcb *pcb);
00091 <span class="keywordtype">void</span> tcp_abort (<span class="keyword">struct</span> tcp_pcb *pcb);
00092 err_t tcp_close (<span class="keyword">struct</span> tcp_pcb *pcb);
00093 err_t tcp_write (<span class="keyword">struct</span> tcp_pcb *pcb, <span class="keyword">const</span> <span class="keywordtype">void</span> *dataptr, uInt16 len,
00094 uInt8 copy);
00095
00096 <span class="comment">/* It is also possible to call these two functions at the right</span>
00097 <span class="comment"> intervals (instead of calling tcp_tmr()). */</span>
00098 <span class="keywordtype">void</span> tcp_slowtmr (<span class="keywordtype">void</span>);
00099 <span class="keywordtype">void</span> tcp_fasttmr (<span class="keywordtype">void</span>);
00100
00101
00102 <span class="comment">/* Only used by IP to pass a TCP segment to TCP: */</span>
00103 <span class="keywordtype">void</span> tcp_input (<span class="keyword">struct</span> pbuf *p, <span class="keyword">struct</span> netif *inp);
00104 <span class="comment">/* Used within the TCP code only: */</span>
00105 err_t tcp_output (<span class="keyword">struct</span> tcp_pcb *pcb);
00106
00107
00108
00109
00110 <span class="preprocessor">#define TCP_SEQ_LT(a,b) ((Int32)((a)-(b)) < 0)</span>
00111 <span class="preprocessor"></span><span class="preprocessor">#define TCP_SEQ_LEQ(a,b) ((Int32)((a)-(b)) <= 0)</span>
00112 <span class="preprocessor"></span><span class="preprocessor">#define TCP_SEQ_GT(a,b) ((Int32)((a)-(b)) > 0)</span>
00113 <span class="preprocessor"></span><span class="preprocessor">#define TCP_SEQ_GEQ(a,b) ((Int32)((a)-(b)) >= 0)</span>
00114 <span class="preprocessor"></span>
00115 <span class="preprocessor">#define TCP_FIN 0x01</span>
00116 <span class="preprocessor"></span><span class="preprocessor">#define TCP_SYN 0x02</span>
00117 <span class="preprocessor"></span><span class="preprocessor">#define TCP_RST 0x04</span>
00118 <span class="preprocessor"></span><span class="preprocessor">#define TCP_PSH 0x08</span>
00119 <span class="preprocessor"></span><span class="preprocessor">#define TCP_ACK 0x10</span>
00120 <span class="preprocessor"></span><span class="preprocessor">#define TCP_URG 0x20</span>
00121 <span class="preprocessor"></span>
00122 <span class="comment">/* Length of the TCP header, excluding options. */</span>
00123 <span class="preprocessor">#define TCP_HLEN 20</span>
00124 <span class="preprocessor"></span>
00125 <span class="preprocessor">#define TCP_TMR_INTERVAL 100 </span><span class="comment">/* The TCP timer interval in</span>
00126 <span class="comment"> milliseconds. */</span>
00127
00128 <span class="preprocessor">#define TCP_FAST_INTERVAL 200 </span><span class="comment">/* the fine grained timeout in</span>
00129 <span class="comment"> milliseconds */</span>
00130 <span class="preprocessor">#define TCP_SLOW_INTERVAL 500 </span><span class="comment">/* the coarse grained timeout in</span>
00131 <span class="comment"> milliseconds */</span>
00132 <span class="preprocessor">#define TCP_FIN_WAIT_TIMEOUT 20000 </span><span class="comment">/* milliseconds */</span>
00133 <span class="preprocessor">#define TCP_SYN_RCVD_TIMEOUT 20000 </span><span class="comment">/* milliseconds */</span>
00134
00135 <span class="preprocessor">#define TCP_OOSEQ_TIMEOUT 6 </span><span class="comment">/* x RTO */</span>
00136
00137 <span class="preprocessor">#define TCP_MSL 60000 </span><span class="comment">/* The maximum segment lifetime in microseconds */</span>
00138
00139 <span class="keyword">struct </span>tcp_hdr {
00140 PACK_STRUCT_FIELD(uInt16 src);
00141 PACK_STRUCT_FIELD(uInt16 dest);
00142 PACK_STRUCT_FIELD(uInt32 seqno);
00143 PACK_STRUCT_FIELD(uInt32 ackno);
00144 PACK_STRUCT_FIELD(uInt16 _offset_flags);
00145 PACK_STRUCT_FIELD(uInt16 wnd);
00146 PACK_STRUCT_FIELD(uInt16 chksum);
00147 PACK_STRUCT_FIELD(uInt16 urgp);
00148 } PACK_STRUCT_STRUCT;
00149
00150 <span class="preprocessor">#define TCPH_OFFSET(hdr) (NTOHS((hdr)->_offset_flags) >> 8)</span>
00151 <span class="preprocessor"></span><span class="preprocessor">#define TCPH_FLAGS(hdr) (NTOHS((hdr)->_offset_flags) & 0xff)</span>
00152 <span class="preprocessor"></span>
00153 <span class="preprocessor">#define TCPH_OFFSET_SET(hdr, offset) (hdr)->_offset_flags = HTONS(((offset) << 8) | TCPH_FLAGS(hdr))</span>
00154 <span class="preprocessor"></span><span class="preprocessor">#define TCPH_FLAGS_SET(hdr, flags) (hdr)->_offset_flags = HTONS((TCPH_OFFSET(hdr) << 8) | (flags))</span>
00155 <span class="preprocessor"></span>
00156 <span class="preprocessor">#define TCP_TCPLEN(seg) ((seg)->len + ((TCPH_FLAGS((seg)->tcphdr) & TCP_FIN || \</span>
00157 <span class="preprocessor"> TCPH_FLAGS((seg)->tcphdr) & TCP_SYN)? 1: 0))</span>
00158 <span class="preprocessor"></span>
00159 <span class="keyword">enum</span> tcp_state {
00160 CLOSED = 0,
00161 LISTEN = 1,
00162 SYN_SENT = 2,
00163 SYN_RCVD = 3,
00164 ESTABLISHED = 4,
00165 FIN_WAIT_1 = 5,
00166 FIN_WAIT_2 = 6,
00167 CLOSE_WAIT = 7,
00168 CLOSING = 8,
00169 LAST_ACK = 9,
00170 TIME_WAIT = 10
00171 };
00172
00173
00174 <span class="comment">/* the TCP protocol control block */</span>
00175 <span class="keyword">struct </span>tcp_pcb {
00176 <span class="keyword">struct </span>tcp_pcb *next; <span class="comment">/* for the linked list */</span>
00177
00178 <span class="keyword">enum</span> tcp_state state; <span class="comment">/* TCP state */</span>
00179
00180 <span class="keywordtype">void</span> *callback_arg;
00181
00182 <span class="comment">/* Function to call when a listener has been connected. */</span>
00183 err_t (* accept)(<span class="keywordtype">void</span> *arg, <span class="keyword">struct </span>tcp_pcb *newpcb, err_t err);
00184
00185 <span class="keyword">struct </span>ip_addr local_ip;
00186 uInt16 local_port;
00187
00188 <span class="keyword">struct </span>ip_addr remote_ip;
00189 uInt16 remote_port;
00190
00191 <span class="comment">/* receiver varables */</span>
00192 uInt32 rcv_nxt; <span class="comment">/* next seqno expected */</span>
00193 uInt16 rcv_wnd; <span class="comment">/* receiver window */</span>
00194
00195 <span class="comment">/* Timers */</span>
00196 uInt16 tmr;
00197
00198 <span class="comment">/* Retransmission timer. */</span>
00199 uInt8 rtime;
00200
00201 uInt16 mss; <span class="comment">/* maximum segment size */</span>
00202
00203 uInt8 flags;
00204 <span class="preprocessor">#define TF_ACK_DELAY 0x01 </span><span class="comment">/* Delayed ACK. */</span>
00205 <span class="preprocessor">#define TF_ACK_NOW 0x02 </span><span class="comment">/* Immediate ACK. */</span>
00206 <span class="preprocessor">#define TF_INFR 0x04 </span><span class="comment">/* In fast recovery. */</span>
00207 <span class="preprocessor">#define TF_RESET 0x08 </span><span class="comment">/* Connection was reset. */</span>
00208 <span class="preprocessor">#define TF_CLOSED 0x10 </span><span class="comment">/* Connection was sucessfully closed. */</span>
00209 <span class="preprocessor">#define TF_GOT_FIN 0x20 </span><span class="comment">/* Connection was closed by the remote end. */</span>
00210
00211 <span class="comment">/* RTT estimation variables. */</span>
00212 uInt16 rttest; <span class="comment">/* RTT estimate in 500ms ticks */</span>
00213 uInt32 rtseq; <span class="comment">/* sequence number being timed */</span>
00214 Int32 sa, sv;
00215
00216 uInt16 rto; <span class="comment">/* retransmission time-out */</span>
00217 uInt8 nrtx; <span class="comment">/* number of retransmissions */</span>
00218
00219 <span class="comment">/* fast retransmit/recovery */</span>
00220 uInt32 lastack; <span class="comment">/* Highest acknowledged seqno. */</span>
00221 uInt8 dupacks;
00222
00223 <span class="comment">/* congestion avoidance/control variables */</span>
00224 uInt16 cwnd;
00225 uInt16 ssthresh;
00226
00227 <span class="comment">/* sender variables */</span>
00228 uInt32 snd_nxt, <span class="comment">/* next seqno to be sent */</span>
00229 snd_max, <span class="comment">/* Highest seqno sent. */</span>
00230 snd_wnd, <span class="comment">/* sender window */</span>
00231 snd_wl1, snd_wl2,
00232 snd_lbb;
00233
00234 uInt16 snd_buf; <span class="comment">/* Avaliable buffer space for sending. */</span>
00235 uInt8 snd_queuelen;
00236
00237 <span class="comment">/* Function to be called when more send buffer space is avaliable. */</span>
00238 err_t (* sent)(<span class="keywordtype">void</span> *arg, <span class="keyword">struct </span>tcp_pcb *pcb, uInt16 space);
00239 uInt16 acked;
00240
00241 <span class="comment">/* Function to be called when (in-sequence) data has arrived. */</span>
00242 err_t (* recv)(<span class="keywordtype">void</span> *arg, <span class="keyword">struct </span>tcp_pcb *pcb, <span class="keyword">struct </span>pbuf *p, err_t err);
00243 <span class="keyword">struct </span>pbuf *recv_data;
00244
00245 <span class="comment">/* Function to be called when a connection has been set up. */</span>
00246 err_t (* connected)(<span class="keywordtype">void</span> *arg, <span class="keyword">struct </span>tcp_pcb *pcb, err_t err);
00247
00248 <span class="comment">/* Function which is called periodically. */</span>
00249 err_t (* poll)(<span class="keywordtype">void</span> *arg, <span class="keyword">struct </span>tcp_pcb *pcb);
00250
00251 <span class="comment">/* Function to be called whenever a fatal error occurs. */</span>
00252 void (* errf)(<span class="keywordtype">void</span> *arg, err_t err);
00253
00254 uInt8 polltmr, pollinterval;
00255
00256 <span class="comment">/* These are ordered by sequence number: */</span>
00257 <span class="keyword">struct </span>tcp_seg *unsent; <span class="comment">/* Unsent (queued) segments. */</span>
00258 <span class="keyword">struct </span>tcp_seg *unacked; <span class="comment">/* Sent but unacknowledged segments. */</span>
00259 <span class="preprocessor">#if TCP_QUEUE_OOSEQ </span>
00260 <span class="preprocessor"></span> <span class="keyword">struct </span>tcp_seg *ooseq; <span class="comment">/* Received out of sequence segments. */</span>
00261 <span class="preprocessor">#endif </span><span class="comment">/* TCP_QUEUE_OOSEQ */</span>
00262
00263 };
00264
00265 <span class="keyword">struct </span>tcp_pcb_listen {
00266 <span class="keyword">struct </span>tcp_pcb_listen *next; <span class="comment">/* for the linked list */</span>
00267
00268 <span class="keyword">enum</span> tcp_state state; <span class="comment">/* TCP state */</span>
00269
00270 <span class="keywordtype">void</span> *callback_arg;
00271
00272 <span class="comment">/* Function to call when a listener has been connected. */</span>
00273 void (* accept)(<span class="keywordtype">void</span> *arg, <span class="keyword">struct </span>tcp_pcb *newpcb);
00274
00275 <span class="keyword">struct </span>ip_addr local_ip;
00276 uInt16 local_port;
00277 };
00278
00279 <span class="comment">/* This structure is used to repressent TCP segments. */</span>
00280 <span class="keyword">struct </span>tcp_seg {
00281 <span class="keyword">struct </span>tcp_seg *next; <span class="comment">/* used when putting segements on a queue */</span>
00282 <span class="keyword">struct </span>pbuf *p; <span class="comment">/* buffer containing data + TCP header */</span>
00283 <span class="keywordtype">void</span> *dataptr; <span class="comment">/* pointer to the TCP data in the pbuf */</span>
00284 uInt16 len; <span class="comment">/* the TCP length of this segment */</span>
00285 <span class="keyword">struct </span>tcp_hdr *tcphdr; <span class="comment">/* the TCP header */</span>
00286 };
00287
00288 <span class="comment">/* Internal functions and global variables: */</span>
00289 <span class="keyword">struct </span>tcp_pcb *tcp_pcb_copy(<span class="keyword">struct</span> tcp_pcb *pcb);
00290 <span class="keywordtype">void</span> tcp_pcb_purge(<span class="keyword">struct</span> tcp_pcb *pcb);
00291 <span class="keywordtype">void</span> tcp_pcb_remove(<span class="keyword">struct</span> tcp_pcb **pcblist, <span class="keyword">struct</span> tcp_pcb *pcb);
00292
00293 uInt8 tcp_segs_free(<span class="keyword">struct</span> tcp_seg *seg);
00294 uInt8 tcp_seg_free(<span class="keyword">struct</span> tcp_seg *seg);
00295 <span class="keyword">struct </span>tcp_seg *tcp_seg_copy(<span class="keyword">struct</span> tcp_seg *seg);
00296
00297 <span class="preprocessor">#define tcp_ack(pcb) if((pcb)->flags & TF_ACK_DELAY) { \</span>
00298 <span class="preprocessor"> (pcb)->flags |= TF_ACK_NOW; \</span>
00299 <span class="preprocessor"> tcp_output(pcb); \</span>
00300 <span class="preprocessor"> } else { \</span>
00301 <span class="preprocessor"> (pcb)->flags |= TF_ACK_DELAY; \</span>
00302 <span class="preprocessor"> }</span>
00303 <span class="preprocessor"></span>
00304 <span class="preprocessor">#define tcp_ack_now(pcb) (pcb)->flags |= TF_ACK_NOW; \</span>
00305 <span class="preprocessor"> tcp_output(pcb)</span>
00306 <span class="preprocessor"></span>
00307 err_t tcp_send_ctrl(<span class="keyword">struct</span> tcp_pcb *pcb, uInt8 flags);
00308 err_t tcp_enqueue(<span class="keyword">struct</span> tcp_pcb *pcb, <span class="keywordtype">void</span> *dataptr, uInt16 len,
00309 uInt8 flags, uInt8 copy,
00310 uInt8 *optdata, uInt8 optlen);
00311
00312 <span class="keywordtype">void</span> tcp_rexmit_seg(<span class="keyword">struct</span> tcp_pcb *pcb, <span class="keyword">struct</span> tcp_seg *seg);
00313
00314 <span class="keywordtype">void</span> tcp_rst(uInt32 seqno, uInt32 ackno,
00315 <span class="keyword">struct</span> ip_addr *local_ip, <span class="keyword">struct</span> ip_addr *remote_ip,
00316 uInt16 local_port, uInt16 remote_port);
00317
00318 uInt32 tcp_next_iss(<span class="keywordtype">void</span>);
00319
00320 <span class="keyword">extern</span> uInt32 tcp_ticks;
00321
00322 <span class="preprocessor">#if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG</span>
00323 <span class="preprocessor"></span><span class="keywordtype">void</span> tcp_debug_print(<span class="keyword">struct</span> tcp_hdr *tcphdr);
00324 <span class="keywordtype">void</span> tcp_debug_print_flags(uInt8 flags);
00325 <span class="keywordtype">void</span> tcp_debug_print_state(<span class="keyword">enum</span> tcp_state s);
00326 <span class="keywordtype">void</span> tcp_debug_print_pcbs(<span class="keywordtype">void</span>);
00327 <span class="keywordtype">int</span> tcp_pcbs_sane(<span class="keywordtype">void</span>);
00328 <span class="preprocessor">#else</span>
00329 <span class="preprocessor"></span><span class="preprocessor">#define tcp_pcbs_sane() 1</span>
00330 <span class="preprocessor"></span><span class="preprocessor">#endif </span><span class="comment">/* TCP_DEBUG */</span>
00331
00332
00333 <span class="comment">/* The TCP PCB lists. */</span>
00334 <span class="keyword">extern</span> <span class="keyword">struct </span>tcp_pcb_listen *tcp_listen_pcbs; <span class="comment">/* List of all TCP PCBs in LISTEN state. */</span>
00335 <span class="keyword">extern</span> <span class="keyword">struct </span>tcp_pcb *tcp_active_pcbs; <span class="comment">/* List of all TCP PCBs that are in a</span>
00336 <span class="comment"> state in which they accept or send</span>
00337 <span class="comment"> data. */</span>
00338 <span class="keyword">extern</span> <span class="keyword">struct </span>tcp_pcb *tcp_tw_pcbs; <span class="comment">/* List of all TCP PCBs in TIME-WAIT. */</span>
00339
00340 <span class="keyword">extern</span> <span class="keyword">struct </span>tcp_pcb *tcp_tmp_pcb; <span class="comment">/* Only used for temporary storage. */</span>
00341
00342 <span class="comment">/* Axoims about the above lists: </span>
00343 <span class="comment"> 1) Every TCP PCB that is not CLOSED is in one of the lists.</span>
00344 <span class="comment"> 2) A PCB is only in one of the lists.</span>
00345 <span class="comment"> 3) All PCBs in the tcp_listen_pcbs list is in LISTEN state.</span>
00346 <span class="comment"> 4) All PCBs in the tcp_tw_pcbs list is in TIME-WAIT state.</span>
00347 <span class="comment">*/</span>
00348
00349 <span class="comment">/* Define two macros, TCP_REG and TCP_RMV that registers a TCP PCB</span>
00350 <span class="comment"> with a PCB list or removes a PCB from a list, respectively. */</span>
00351 <span class="preprocessor">#ifdef LWIP_DEBUG</span>
00352 <span class="preprocessor"></span><span class="preprocessor">#define TCP_REG(pcbs, npcb) do {\</span>
00353 <span class="preprocessor"> DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", npcb, npcb->local_port)); \</span>
00354 <span class="preprocessor"> for(tcp_tmp_pcb = *pcbs; \</span>
00355 <span class="preprocessor"> tcp_tmp_pcb != NULL; \</span>
00356 <span class="preprocessor"> tcp_tmp_pcb = tcp_tmp_pcb->next) { \</span>
00357 <span class="preprocessor"> ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != npcb); \</span>
00358 <span class="preprocessor"> } \</span>
00359 <span class="preprocessor"> ASSERT("TCP_REG: pcb->state != CLOSED", npcb->state != CLOSED); \</span>
00360 <span class="preprocessor"> npcb->next = *pcbs; \</span>
00361 <span class="preprocessor"> ASSERT("TCP_REG: npcb->next != npcb", npcb->next != npcb); \</span>
00362 <span class="preprocessor"> *pcbs = npcb; \</span>
00363 <span class="preprocessor"> ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \</span>
00364 <span class="preprocessor"> } while(0)</span>
00365 <span class="preprocessor"></span><span class="preprocessor">#define TCP_RMV(pcbs, npcb) do { \</span>
00366 <span class="preprocessor"> ASSERT("TCP_RMV: pcbs != NULL", *pcbs != NULL); \</span>
00367 <span class="preprocessor"> DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", npcb, *pcbs)); \</span>
00368 <span class="preprocessor"> if(*pcbs == npcb) { \</span>
00369 <span class="preprocessor"> *pcbs = (*pcbs)->next; \</span>
00370 <span class="preprocessor"> } else for(tcp_tmp_pcb = *pcbs; tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \</span>
00371 <span class="preprocessor"> if(tcp_tmp_pcb->next != NULL && tcp_tmp_pcb->next == npcb) { \</span>
00372 <span class="preprocessor"> tcp_tmp_pcb->next = npcb->next; \</span>
00373 <span class="preprocessor"> break; \</span>
00374 <span class="preprocessor"> } \</span>
00375 <span class="preprocessor"> } \</span>
00376 <span class="preprocessor"> npcb->next = NULL; \</span>
00377 <span class="preprocessor"> ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \</span>
00378 <span class="preprocessor"> DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", npcb, *pcbs)); \</span>
00379 <span class="preprocessor"> } while(0)</span>
00380 <span class="preprocessor"></span>
00381 <span class="preprocessor">#else </span><span class="comment">/* LWIP_DEBUG */</span>
00382 <span class="preprocessor">#define TCP_REG(pcbs, npcb) do { \</span>
00383 <span class="preprocessor"> npcb->next = *pcbs; \</span>
00384 <span class="preprocessor"> *pcbs = npcb; \</span>
00385 <span class="preprocessor"> } while(0)</span>
00386 <span class="preprocessor"></span><span class="preprocessor">#define TCP_RMV(pcbs, npcb) do { \</span>
00387 <span class="preprocessor"> if(*pcbs == npcb) { \</span>
00388 <span class="preprocessor"> *pcbs = (*pcbs)->next; \</span>
00389 <span class="preprocessor"> } else for(tcp_tmp_pcb = *pcbs; tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \</span>
00390 <span class="preprocessor"> if(tcp_tmp_pcb->next != NULL && tcp_tmp_pcb->next == npcb) { \</span>
00391 <span class="preprocessor"> tcp_tmp_pcb->next = npcb->next; \</span>
00392 <span class="preprocessor"> break; \</span>
00393 <span class="preprocessor"> } \</span>
00394 <span class="preprocessor"> } \</span>
00395 <span class="preprocessor"> npcb->next = NULL; \</span>
00396 <span class="preprocessor"> } while(0)</span>
00397 <span class="preprocessor"></span><span class="preprocessor">#endif </span><span class="comment">/* LWIP_DEBUG */</span>
00398 <span class="preprocessor">#endif </span><span class="comment">/* __LWIP_TCP_H__ */</span>
00399
00400
00401
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Wed Apr 28 17:49:41 2004 for Ubixos by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 >
</a>1.3.3 </small></address>
</body>
</html>