tcp.h
net/sys.h
net/mem.h
net/pbuf.h
net/opt.h
net/ipv4/ip.h
net/ipv4/icmp.h
net/err.h
src/sys/include/net/api.h
src/sys/include/net/api_msg.h
src/sys/net/api/tcpip.c
src/sys/net/netif/loopif.c
src/sys/net/netif/tcpdump.c
net/ipv4/ip.h
arch/lib.h
net/netif.h
arch/cpu.h
arch/sys_arch.h
src/sys/include/net/tcp.h
ubixos/types.h
sys/_types.h
net/arch.h
net/ipv4/icmp.h
net/lwipopts.h
net/def.h
net/mem.h
net/ipv4/ip_addr.h
net/err.h
net/opt.h
net/sys.h
net/pbuf.h
net/debug.h
net/ipv4/inet.h
arch/cc.h
src/sys/net/net/udpecho.c
src/sys/net/netif/tcpdump.c
src/sys/net/netif/loopif.c
src/sys/include/net/tcp.h
src/sys/net/net/bot.c
src/sys/net/api/tcpip.c
src/sys/include/net/tcpip.h
src/sys/include/net/api_msg.h
src/sys/net/net/shell.c
src/sys/net/api/api_lib.c
src/sys/net/net/init.c
src/sys/include/net/api.h
src/sys/net/api/sockets.c
src/sys/net/api/api_msg.c
tcp_hdr
tcp_pcb
tcp_pcb_listen
tcp_seg
tcp_ack
pcb
if((pcb)->flags & TF_ACK_DELAY) { \ (pcb)->flags |= TF_ACK_NOW; \ tcp_output(pcb); \ } else { \ (pcb)->flags |= TF_ACK_DELAY; \ }
TCP_ACK
0x10
tcp_ack_now
pcb
(pcb)->flags |= TF_ACK_NOW; \ tcp_output(pcb)
TCP_FAST_INTERVAL
200
TCP_FIN
0x01
TCP_FIN_WAIT_TIMEOUT
20000
TCP_HLEN
20
TCP_MSL
60000
TCP_OOSEQ_TIMEOUT
6
tcp_pcbs_sane
1
TCP_PSH
0x08
TCP_REG
pcbs
npcb
do { \ npcb->next = *pcbs; \ *pcbs = npcb; \ } while(0)
TCP_RMV
pcbs
npcb
do { \ if(*pcbs == npcb) { \ *pcbs = (*pcbs)->next; \ } else for(tcp_tmp_pcb = *pcbs; tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \ if(tcp_tmp_pcb->next != NULL && tcp_tmp_pcb->next == npcb) { \ tcp_tmp_pcb->next = npcb->next; \ break; \ } \ } \ npcb->next = NULL; \ } while(0)
TCP_RST
0x04
TCP_SEQ_GEQ
a
b
((Int32)((a)-(b)) >= 0)
TCP_SEQ_GT
a
b
((Int32)((a)-(b)) > 0)
TCP_SEQ_LEQ
a
b
((Int32)((a)-(b)) <= 0)
TCP_SEQ_LT
a
b
((Int32)((a)-(b)) < 0)
TCP_SLOW_INTERVAL
500
tcp_sndbuf
pcb
((pcb)->snd_buf)
netconn_write
TCP_SYN
0x02
TCP_SYN_RCVD_TIMEOUT
20000
TCP_TCPLEN
seg
((seg)->len + ((TCPH_FLAGS((seg)->tcphdr) & TCP_FIN || \ TCPH_FLAGS((seg)->tcphdr) & TCP_SYN)? 1: 0))
TCP_TMR_INTERVAL
100
tcpip_tcp_timer
tcpip_thread
TCP_URG
0x20
TCPH_FLAGS
hdr
(NTOHS((hdr)->_offset_flags) & 0xff)
TCPH_FLAGS_SET
hdr
flags
(hdr)->_offset_flags = HTONS((TCPH_OFFSET(hdr) << 8) | (flags))
TCPH_OFFSET
hdr
(NTOHS((hdr)->_offset_flags) >> 8)
TCPH_OFFSET_SET
hdr
offset
(hdr)->_offset_flags = HTONS(((offset) << 8) | TCPH_FLAGS(hdr))
TF_ACK_DELAY
0x01
TF_ACK_NOW
0x02
TF_CLOSED
0x10
TF_GOT_FIN
0x20
TF_INFR
0x04
TF_RESET
0x08
tcp_state
CLOSED
0
LISTEN
1
SYN_SENT
2
SYN_RCVD
3
ESTABLISHED
4
FIN_WAIT_1
5
FIN_WAIT_2
6
CLOSE_WAIT
7
CLOSING
8
LAST_ACK
9
TIME_WAIT
10
void void tcp_abort (struct tcp_pcb *pcb) tcp_abort struct tcp_pcb * pcb do_delconn
void void tcp_accept (struct tcp_pcb *pcb, err_t(*accept)(void *arg, struct tcp_pcb *newpcb, err_t err)) tcp_accept struct tcp_pcb * pcb err_t(*)(void *arg, struct tcp_pcb *newpcb, err_t err) accept do_delconn do_listen
void void tcp_arg (struct tcp_pcb *pcb, void *arg) tcp_arg struct tcp_pcb * pcb void * arg do_delconn do_listen setup_tcp
err_t err_t tcp_bind (struct tcp_pcb *pcb, struct ip_addr *ipaddr, uInt16 port) tcp_bind struct tcp_pcb * pcb struct ip_addr * ipaddr uInt16 port do_bind
err_t err_t tcp_close (struct tcp_pcb *pcb) tcp_close struct tcp_pcb * pcb do_close do_delconn
err_t err_t tcp_connect (struct tcp_pcb *pcb, struct ip_addr *ipaddr, uInt16 port, err_t(*connected)(void *arg, struct tcp_pcb *tpcb, err_t err)) tcp_connect struct tcp_pcb * pcb struct ip_addr * ipaddr uInt16 port err_t(*)(void *arg, struct tcp_pcb *tpcb, err_t err) connected do_connect
err_t err_t tcp_enqueue (struct tcp_pcb *pcb, void *dataptr, uInt16 len, uInt8 flags, uInt8 copy, uInt8 *optdata, uInt8 optlen) tcp_enqueue struct tcp_pcb * pcb void * dataptr uInt16 len uInt8 flags uInt8 copy uInt8 * optdata uInt8 optlen
void void tcp_err (struct tcp_pcb *pcb, void(*err)(void *arg, err_t err)) tcp_err struct tcp_pcb * pcb void(*)(void *arg, err_t err) err do_delconn setup_tcp
void void tcp_fasttmr (void) tcp_fasttmr void
void void tcp_init (void) tcp_init void tcpip_thread
void void tcp_input (struct pbuf *p, struct netif *inp) tcp_input struct pbuf * p struct netif * inp
tcp_pcb * struct tcp_pcb* tcp_listen (struct tcp_pcb *pcb) tcp_listen struct tcp_pcb * pcb do_listen
tcp_pcb * struct tcp_pcb* tcp_new (void) tcp_new void do_bind do_connect
uInt32 uInt32 tcp_next_iss (void) tcp_next_iss void
err_t err_t tcp_output (struct tcp_pcb *pcb) tcp_output struct tcp_pcb * pcb do_write
tcp_pcb * struct tcp_pcb* tcp_pcb_copy (struct tcp_pcb *pcb) tcp_pcb_copy struct tcp_pcb * pcb
void void tcp_pcb_purge (struct tcp_pcb *pcb) tcp_pcb_purge struct tcp_pcb * pcb
void void tcp_pcb_remove (struct tcp_pcb **pcblist, struct tcp_pcb *pcb) tcp_pcb_remove struct tcp_pcb ** pcblist struct tcp_pcb * pcb
void void tcp_poll (struct tcp_pcb *pcb, err_t(*poll)(void *arg, struct tcp_pcb *tpcb), uInt8 interval) tcp_poll struct tcp_pcb * pcb err_t(*)(void *arg, struct tcp_pcb *tpcb) poll uInt8 interval do_delconn setup_tcp
void void tcp_recv (struct tcp_pcb *pcb, err_t(*recv)(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)) tcp_recv struct tcp_pcb * pcb err_t(*)(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) recv do_delconn setup_tcp
void void tcp_recved (struct tcp_pcb *pcb, uInt16 len) tcp_recved struct tcp_pcb * pcb uInt16 len do_recv
void void tcp_rexmit_seg (struct tcp_pcb *pcb, struct tcp_seg *seg) tcp_rexmit_seg struct tcp_pcb * pcb struct tcp_seg * seg
void void tcp_rst (uInt32 seqno, uInt32 ackno, struct ip_addr *local_ip, struct ip_addr *remote_ip, uInt16 local_port, uInt16 remote_port) tcp_rst uInt32 seqno uInt32 ackno struct ip_addr * local_ip struct ip_addr * remote_ip uInt16 local_port uInt16 remote_port
tcp_seg * struct tcp_seg* tcp_seg_copy (struct tcp_seg *seg) tcp_seg_copy struct tcp_seg * seg
uInt8 uInt8 tcp_seg_free (struct tcp_seg *seg) tcp_seg_free struct tcp_seg * seg
uInt8 uInt8 tcp_segs_free (struct tcp_seg *seg) tcp_segs_free struct tcp_seg * seg
err_t err_t tcp_send_ctrl (struct tcp_pcb *pcb, uInt8 flags) tcp_send_ctrl struct tcp_pcb * pcb uInt8 flags
void void tcp_sent (struct tcp_pcb *pcb, err_t(*sent)(void *arg, struct tcp_pcb *tpcb, uInt16 len)) tcp_sent struct tcp_pcb * pcb err_t(*)(void *arg, struct tcp_pcb *tpcb, uInt16 len) sent do_delconn setup_tcp
void void tcp_slowtmr (void) tcp_slowtmr void
void void tcp_tmr (void) tcp_tmr void tcpip_tcp_timer
err_t err_t tcp_write (struct tcp_pcb *pcb, const void *dataptr, uInt16 len, uInt8 copy) tcp_write struct tcp_pcb * pcb const void * dataptr uInt16 len uInt8 copy do_write
tcp_hdr struct tcp_hdr PACK_STRUCT_STRUCT PACK_STRUCT_STRUCT
tcp_pcb * struct tcp_pcb* tcp_active_pcbs tcp_active_pcbs
tcp_pcb_listen * struct tcp_pcb_listen* tcp_listen_pcbs tcp_listen_pcbs
uInt32 uInt32 tcp_ticks tcp_ticks
tcp_pcb * struct tcp_pcb* tcp_tmp_pcb tcp_tmp_pcb
tcp_pcb * struct tcp_pcb* tcp_tw_pcbs tcp_tw_pcbs

    /*
    *Copyright(c)2001,SwedishInstituteofComputerScience.
    *Allrightsreserved.
    *
    *Redistributionanduseinsourceandbinaryforms,withorwithout
    *modification,arepermittedprovidedthatthefollowingconditions
    *aremet:
    *1.Redistributionsofsourcecodemustretaintheabovecopyright
    *notice,thislistofconditionsandthefollowingdisclaimer.
    *2.Redistributionsinbinaryformmustreproducetheabovecopyright
    *notice,thislistofconditionsandthefollowingdisclaimerinthe
    *documentationand/orothermaterialsprovidedwiththedistribution.
    *3.NeitherthenameoftheInstitutenorthenamesofitscontributors
    *maybeusedtoendorseorpromoteproductsderivedfromthissoftware
    *withoutspecificpriorwrittenpermission.
    *
    *THISSOFTWAREISPROVIDEDBYTHEINSTITUTEANDCONTRIBUTORS``ASIS''AND
    *ANYEXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THE
    *IMPLIEDWARRANTIESOFMERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSE
    *AREDISCLAIMED.INNOEVENTSHALLTHEINSTITUTEORCONTRIBUTORSBELIABLE
    *FORANYDIRECT,INDIRECT,INCIDENTAL,SPECIAL,EXEMPLARY,ORCONSEQUENTIAL
    *DAMAGES(INCLUDING,BUTNOTLIMITEDTO,PROCUREMENTOFSUBSTITUTEGOODS
    *ORSERVICES;LOSSOFUSE,DATA,ORPROFITS;ORBUSINESSINTERRUPTION)
    *HOWEVERCAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,STRICT
    *LIABILITY,ORTORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAY
    *OUTOFTHEUSEOFTHISSOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITYOF
    *SUCHDAMAGE.
    *
    *ThisfileispartofthelwIPTCP/IPstack.
    *
    *Author:AdamDunkels<adam@sics.se>
    *
    *$Id: tcp_8h.xml 88 2016-01-12 00:11:29Z reddawg $
    */
    #ifndef__LWIP_TCP_H__
    #define__LWIP_TCP_H__

    #include"net/sys.h"
    #include"net/mem.h"

    #include"net/pbuf.h"
    #include"net/opt.h"
    //UBU
    #include"net/ipv4/ip.h"
    //UBU
    #include"net/ipv4/icmp.h"

    #include"net/sys.h"

    #include"net/err.h"

    structtcp_pcb;

    /*FunctionsforinterfacingwithTCP:*/

    /*LowerlayerinterfacetoTCP:*/
    voidtcp_init(void);/*Mustbecalledfirstto
    initializeTCP.*/
    voidtcp_tmr(void);/*Mustbecalledevery
    TCP_TMR_INTERVAL
    ms.(Typically100ms).*/
    /*Applicationprogram'sinterface:*/
    structtcp_pcb*tcp_new(void);

    voidtcp_arg(structtcp_pcb*pcb,void*arg);
    voidtcp_accept(structtcp_pcb*pcb,
    err_t(*accept)(void*arg,structtcp_pcb*newpcb,
    err_terr));
    voidtcp_recv(structtcp_pcb*pcb,
    err_t(*recv)(void*arg,structtcp_pcb*tpcb,
    structpbuf*p,err_terr));
    voidtcp_sent(structtcp_pcb*pcb,
    err_t(*sent)(void*arg,structtcp_pcb*tpcb,
    uInt16len));
    voidtcp_poll(structtcp_pcb*pcb,
    err_t(*poll)(void*arg,structtcp_pcb*tpcb),
    uInt8interval);
    voidtcp_err(structtcp_pcb*pcb,
    void(*err)(void*arg,err_terr));

    #definetcp_sndbuf(pcb)((pcb)->snd_buf)

    voidtcp_recved(structtcp_pcb*pcb,uInt16len);
    err_ttcp_bind(structtcp_pcb*pcb,structip_addr*ipaddr,
    uInt16port);
    err_ttcp_connect(structtcp_pcb*pcb,structip_addr*ipaddr,
    uInt16port,err_t(*connected)(void*arg,
    structtcp_pcb*tpcb,
    err_terr));
    structtcp_pcb*tcp_listen(structtcp_pcb*pcb);
    voidtcp_abort(structtcp_pcb*pcb);
    err_ttcp_close(structtcp_pcb*pcb);
    err_ttcp_write(structtcp_pcb*pcb,constvoid*dataptr,uInt16len,
    uInt8copy);

    /*Itisalsopossibletocallthesetwofunctionsattheright
    intervals(insteadofcallingtcp_tmr()).*/
    voidtcp_slowtmr(void);
    voidtcp_fasttmr(void);

    /*OnlyusedbyIPtopassaTCPsegmenttoTCP:*/
    voidtcp_input(structpbuf*p,structnetif*inp);
    /*UsedwithintheTCPcodeonly:*/
    err_ttcp_output(structtcp_pcb*pcb);

    #defineTCP_SEQ_LT(a,b)((Int32)((a)-(b))<0)
    #defineTCP_SEQ_LEQ(a,b)((Int32)((a)-(b))<=0)
    #defineTCP_SEQ_GT(a,b)((Int32)((a)-(b))>0)
    #defineTCP_SEQ_GEQ(a,b)((Int32)((a)-(b))>=0)

    #defineTCP_FIN0x01
    #defineTCP_SYN0x02
    #defineTCP_RST0x04
    #defineTCP_PSH0x08
    #defineTCP_ACK0x10
    #defineTCP_URG0x20

    /*LengthoftheTCPheader,excludingoptions.*/
    #defineTCP_HLEN20

    #defineTCP_TMR_INTERVAL100/*TheTCPtimerintervalin
    milliseconds.*/

    #defineTCP_FAST_INTERVAL200/*thefinegrainedtimeoutin
    milliseconds*/
    #defineTCP_SLOW_INTERVAL500/*thecoarsegrainedtimeoutin
    milliseconds*/
    #defineTCP_FIN_WAIT_TIMEOUT20000/*milliseconds*/
    #defineTCP_SYN_RCVD_TIMEOUT20000/*milliseconds*/

    #defineTCP_OOSEQ_TIMEOUT6/*xRTO*/

    #defineTCP_MSL60000/*Themaximumsegmentlifetimeinmicroseconds*/

    structtcp_hdr{
    PACK_STRUCT_FIELD(uInt16src);
    PACK_STRUCT_FIELD(uInt16dest);
    PACK_STRUCT_FIELD(uInt32seqno);
    PACK_STRUCT_FIELD(uInt32ackno);
    PACK_STRUCT_FIELD(uInt16_offset_flags);
    PACK_STRUCT_FIELD(uInt16wnd);
    PACK_STRUCT_FIELD(uInt16chksum);
    PACK_STRUCT_FIELD(uInt16urgp);
    }PACK_STRUCT_STRUCT;

    #defineTCPH_OFFSET(hdr)(NTOHS((hdr)->_offset_flags)>>8)
    #defineTCPH_FLAGS(hdr)(NTOHS((hdr)->_offset_flags)&0xff)

    #defineTCPH_OFFSET_SET(hdr,offset)(hdr)->_offset_flags=HTONS(((offset)<<8)|TCPH_FLAGS(hdr))
    #defineTCPH_FLAGS_SET(hdr,flags)(hdr)->_offset_flags=HTONS((TCPH_OFFSET(hdr)<<8)|(flags))

    #defineTCP_TCPLEN(seg)((seg)->len+((TCPH_FLAGS((seg)->tcphdr)&TCP_FIN||\
    TCPH_FLAGS((seg)->tcphdr)&TCP_SYN)?1:0))

    enumtcp_state{
    CLOSED=0,
    LISTEN=1,
    SYN_SENT=2,
    SYN_RCVD=3,
    ESTABLISHED=4,
    FIN_WAIT_1=5,
    FIN_WAIT_2=6,
    CLOSE_WAIT=7,
    CLOSING=8,
    LAST_ACK=9,
    TIME_WAIT=10
    };

    /*theTCPprotocolcontrolblock*/
    structtcp_pcb{
    structtcp_pcb*next;/*forthelinkedlist*/

    enumtcp_statestate;/*TCPstate*/

    void*callback_arg;

    /*Functiontocallwhenalistenerhasbeenconnected.*/
    err_t(*accept)(void*arg,structtcp_pcb*newpcb,err_terr);

    structip_addrlocal_ip;
    uInt16local_port;

    structip_addrremote_ip;
    uInt16remote_port;

    /*receivervarables*/
    uInt32rcv_nxt;/*nextseqnoexpected*/
    uInt16rcv_wnd;/*receiverwindow*/

    /*Timers*/
    uInt16tmr;

    /*Retransmissiontimer.*/
    uInt8rtime;

    uInt16mss;/*maximumsegmentsize*/

    uInt8flags;
    #defineTF_ACK_DELAY0x01/*DelayedACK.*/
    #defineTF_ACK_NOW0x02/*ImmediateACK.*/
    #defineTF_INFR0x04/*Infastrecovery.*/
    #defineTF_RESET0x08/*Connectionwasreset.*/
    #defineTF_CLOSED0x10/*Connectionwassucessfullyclosed.*/
    #defineTF_GOT_FIN0x20/*Connectionwasclosedbytheremoteend.*/

    /*RTTestimationvariables.*/
    uInt16rttest;/*RTTestimatein500msticks*/
    uInt32rtseq;/*sequencenumberbeingtimed*/
    Int32sa,sv;

    uInt16rto;/*retransmissiontime-out*/
    uInt8nrtx;/*numberofretransmissions*/

    /*fastretransmit/recovery*/
    uInt32lastack;/*Highestacknowledgedseqno.*/
    uInt8dupacks;

    /*congestionavoidance/controlvariables*/
    uInt16cwnd;
    uInt16ssthresh;

    /*sendervariables*/
    uInt32snd_nxt,/*nextseqnotobesent*/
    snd_max,/*Highestseqnosent.*/
    snd_wnd,/*senderwindow*/
    snd_wl1,snd_wl2,
    snd_lbb;

    uInt16snd_buf;/*Avaliablebufferspaceforsending.*/
    uInt8snd_queuelen;

    /*Functiontobecalledwhenmoresendbufferspaceisavaliable.*/
    err_t(*sent)(void*arg,structtcp_pcb*pcb,uInt16space);
    uInt16acked;

    /*Functiontobecalledwhen(in-sequence)datahasarrived.*/
    err_t(*recv)(void*arg,structtcp_pcb*pcb,structpbuf*p,err_terr);
    structpbuf*recv_data;

    /*Functiontobecalledwhenaconnectionhasbeensetup.*/
    err_t(*connected)(void*arg,structtcp_pcb*pcb,err_terr);

    /*Functionwhichiscalledperiodically.*/
    err_t(*poll)(void*arg,structtcp_pcb*pcb);

    /*Functiontobecalledwheneverafatalerroroccurs.*/
    void(*errf)(void*arg,err_terr);

    uInt8polltmr,pollinterval;

    /*Theseareorderedbysequencenumber:*/
    structtcp_seg*unsent;/*Unsent(queued)segments.*/
    structtcp_seg*unacked;/*Sentbutunacknowledgedsegments.*/
    #ifTCP_QUEUE_OOSEQ
    structtcp_seg*ooseq;/*Receivedoutofsequencesegments.*/
    #endif/*TCP_QUEUE_OOSEQ*/

    };

    structtcp_pcb_listen{
    structtcp_pcb_listen*next;/*forthelinkedlist*/

    enumtcp_statestate;/*TCPstate*/

    void*callback_arg;

    /*Functiontocallwhenalistenerhasbeenconnected.*/
    void(*accept)(void*arg,structtcp_pcb*newpcb);

    structip_addrlocal_ip;
    uInt16local_port;
    };

    /*ThisstructureisusedtorepressentTCPsegments.*/
    structtcp_seg{
    structtcp_seg*next;/*usedwhenputtingsegementsonaqueue*/
    structpbuf*p;/*buffercontainingdata+TCPheader*/
    void*dataptr;/*pointertotheTCPdatainthepbuf*/
    uInt16len;/*theTCPlengthofthissegment*/
    structtcp_hdr*tcphdr;/*theTCPheader*/
    };

    /*Internalfunctionsandglobalvariables:*/
    structtcp_pcb*tcp_pcb_copy(structtcp_pcb*pcb);
    voidtcp_pcb_purge(structtcp_pcb*pcb);
    voidtcp_pcb_remove(structtcp_pcb**pcblist,structtcp_pcb*pcb);

    uInt8tcp_segs_free(structtcp_seg*seg);
    uInt8tcp_seg_free(structtcp_seg*seg);
    structtcp_seg*tcp_seg_copy(structtcp_seg*seg);

    #definetcp_ack(pcb)if((pcb)->flags&TF_ACK_DELAY){\
    (pcb)->flags|=TF_ACK_NOW;\
    tcp_output(pcb);\
    }else{\
    (pcb)->flags|=TF_ACK_DELAY;\
    }

    #definetcp_ack_now(pcb)(pcb)->flags|=TF_ACK_NOW;\
    tcp_output(pcb)

    err_ttcp_send_ctrl(structtcp_pcb*pcb,uInt8flags);
    err_ttcp_enqueue(structtcp_pcb*pcb,void*dataptr,uInt16len,
    uInt8flags,uInt8copy,
    uInt8*optdata,uInt8optlen);

    voidtcp_rexmit_seg(structtcp_pcb*pcb,structtcp_seg*seg);

    voidtcp_rst(uInt32seqno,uInt32ackno,
    structip_addr*local_ip,structip_addr*remote_ip,
    uInt16local_port,uInt16remote_port);

    uInt32tcp_next_iss(void);

    externuInt32tcp_ticks;

    #ifTCP_DEBUG||TCP_INPUT_DEBUG||TCP_OUTPUT_DEBUG
    voidtcp_debug_print(structtcp_hdr*tcphdr);
    voidtcp_debug_print_flags(uInt8flags);
    voidtcp_debug_print_state(enumtcp_states);
    voidtcp_debug_print_pcbs(void);
    inttcp_pcbs_sane(void);
    #else
    #definetcp_pcbs_sane()1
    #endif/*TCP_DEBUG*/

    /*TheTCPPCBlists.*/
    externstructtcp_pcb_listen*tcp_listen_pcbs;/*ListofallTCPPCBsinLISTENstate.*/
    externstructtcp_pcb*tcp_active_pcbs;/*ListofallTCPPCBsthatareina
    stateinwhichtheyacceptorsend
    data.*/
    externstructtcp_pcb*tcp_tw_pcbs;/*ListofallTCPPCBsinTIME-WAIT.*/

    externstructtcp_pcb*tcp_tmp_pcb;/*Onlyusedfortemporarystorage.*/

    /*Axoimsabouttheabovelists:
    1)EveryTCPPCBthatisnotCLOSEDisinoneofthelists.
    2)APCBisonlyinoneofthelists.
    3)AllPCBsinthetcp_listen_pcbslistisinLISTENstate.
    4)AllPCBsinthetcp_tw_pcbslistisinTIME-WAITstate.
    */

    /*Definetwomacros,TCP_REGandTCP_RMVthatregistersaTCPPCB
    withaPCBlistorremovesaPCBfromalist,respectively.*/
    #ifdefLWIP_DEBUG
    #defineTCP_REG(pcbs,npcb)do{\
    DEBUGF(TCP_DEBUG,("TCP_REG%plocalport%d\n",npcb,npcb->local_port));\
    for(tcp_tmp_pcb=*pcbs;\
    tcp_tmp_pcb!=NULL;\
    tcp_tmp_pcb=tcp_tmp_pcb->next){\
    ASSERT("TCP_REG:alreadyregistered\n",tcp_tmp_pcb!=npcb);\
    }\
    ASSERT("TCP_REG:pcb->state!=CLOSED",npcb->state!=CLOSED);\
    npcb->next=*pcbs;\
    ASSERT("TCP_REG:npcb->next!=npcb",npcb->next!=npcb);\
    *pcbs=npcb;\
    ASSERT("TCP_RMV:tcp_pcbssane",tcp_pcbs_sane());\
    }while(0)
    #defineTCP_RMV(pcbs,npcb)do{\
    ASSERT("TCP_RMV:pcbs!=NULL",*pcbs!=NULL);\
    DEBUGF(TCP_DEBUG,("TCP_RMV:removing%pfrom%p\n",npcb,*pcbs));\
    if(*pcbs==npcb){\
    *pcbs=(*pcbs)->next;\
    }elsefor(tcp_tmp_pcb=*pcbs;tcp_tmp_pcb!=NULL;tcp_tmp_pcb=tcp_tmp_pcb->next){\
    if(tcp_tmp_pcb->next!=NULL&&tcp_tmp_pcb->next==npcb){\
    tcp_tmp_pcb->next=npcb->next;\
    break;\
    }\
    }\
    npcb->next=NULL;\
    ASSERT("TCP_RMV:tcp_pcbssane",tcp_pcbs_sane());\
    DEBUGF(TCP_DEBUG,("TCP_RMV:removed%pfrom%p\n",npcb,*pcbs));\
    }while(0)

    #else/*LWIP_DEBUG*/
    #defineTCP_REG(pcbs,npcb)do{\
    npcb->next=*pcbs;\
    *pcbs=npcb;\
    }while(0)
    #defineTCP_RMV(pcbs,npcb)do{\
    if(*pcbs==npcb){\
    *pcbs=(*pcbs)->next;\
    }elsefor(tcp_tmp_pcb=*pcbs;tcp_tmp_pcb!=NULL;tcp_tmp_pcb=tcp_tmp_pcb->next){\
    if(tcp_tmp_pcb->next!=NULL&&tcp_tmp_pcb->next==npcb){\
    tcp_tmp_pcb->next=npcb->next;\
    break;\
    }\
    }\
    npcb->next=NULL;\
    }while(0)
    #endif/*LWIP_DEBUG*/
    #endif/*__LWIP_TCP_H__*/