Pseudo-codes from RFC 1644


Passive OPEN =>
{
    Create new TCB;
}

Active OPEN =>
{
    <Create new TCB>
    CCrecv = 0;
    CCsend = CCgen;
    if(CCgen == 0xffffffff) then Set CCgen = 1;
    else Set CCgen = CCgen + 1.
        <Send initial {SYN} segment (see below)>
}

Send initial {SYN} segment =>
{
    if(cache.CCsent[fh] == 0 OR CCsend < cache.CCsent[fh] ) then
    {
        Include CC.NEW(CCsend) option in segment;
        Set cache.CCsent[fh] = 0;
    }
    else
    {
        Include CC(CCsend) option in segment;
        Set cache.CCsent[fh] = CCsend;
    }
}

Send {SYN,ACK} segment =>
{
    if(CCrecv != 0) then
        Include CC(CCsend), CC.ECHO(CCrecv) options in segment.
}

Receive {SYN} segment in LISTEN, SYN-SENT, or SYN-SENT* state =>
{
    if state == LISTEN then
    {
        CCrecv = 0;
        CCsend = CCgen;
        if(CCgen == 0xffffffff) then Set CCgen = 1;
        else Set CCgen = CCgen + 1;
    }
    if(Segment contains CC option  OR
        Segment contains CC.NEW option) then
    Set CCrecv = SEG.CC.
    if(Segment contains CC option  AND
        cache.CC[fh] != 0  AND
       SEG.CC > cache.CC[fh] ) then
    {  /* TAO Test OK */
        Set cache.CC[fh] = CCrecv;
        <Mark connection half-synchronized>
        <Process data and/or FIN and return>
    }
    if(Segment does not contain CC option)  then
        Set cache.CC[fh] = 0;
    <Do normal TCP processing and return>.
}

Receive {SYN,ACK} segment =>
{
    if(Segment contains CC.ECHO option  AND
        SEG.CC != CCsend) then
    <Send a reset and discard segment>.
    if(Segment contains CC option) then
    {
        Set CCrecv = SEG.CC.
        if(cache.CC[fh] is undefined) then
            Set cache.CC[fh] = CCrecv.
    }
}

Send non-SYN segment =>
{
    if(CCrecv != 0  OR
        (cache.CCsent[fh] != 0  AND
       state is SYN-SENT or SYN-SENT*)) then
    Include CC(CCsend) option in segment.
}

Receive non-SYN segment in SYN-RECEIVED state =>
{
    if(Segment contains CC option  AND  RST bit is off)
    {
        if(SEG.CC != CCrecv)  then
            <Segment is unacceptable;
        drop it and send an
        ACK segment, as in normal TCP processing>.
        if(cache.CC[fh] is undefined)  then
            Set cache.CC[fh] = CCrecv.
    }
}

Receive non-SYN segment in (state >= ESTABLISHED) =>
{
    if(Segment contains CC option  AND  RST bit is off)
    {
        if(SEG.CC != CCrecv)  then
            <Segment is unacceptable;
        drop it and send an
        ACK segment, as in normal TCP processing>.
    }
}