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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? tinytcp.c

?? tiny tcp test program source
?? C
?? 第 1 頁 / 共 2 頁
字號(hào):
/*
 * tinytcp.c - Tiny Implementation of the Transmission Control Protocol
 *
 * Written March 28, 1986 by Geoffrey Cooper, IMAGEN Corporation.
 *
 * This code is a small implementation of the TCP and IP protocols, suitable
 * for burning into ROM.  The implementation is bare-bones and represents
 * two days' coding efforts.  A timer and an ethernet board are assumed.  The
 * implementation is based on busy-waiting, but the tcp_handler procedure
 * could easily be integrated into an interrupt driven scheme.
 *
 * IP routing is accomplished on active opens by broadcasting the tcp SYN
 * packet when ARP mapping fails.  If anyone answers, the ethernet address
 * used is saved for future use.  This also allows IP routing on incoming
 * connections.
 * 
 * The TCP does not implement urgent pointers (easy to add), and discards
 * segments that are received out of order.  It ignores the received window
 * and always offers a fixed window size on input (i.e., it is not flow
 * controlled).
 *
 * Special care is taken to access the ethernet buffers only in word
 * mode.  This is to support boards that only allow word accesses.
 *
 * Copyright (C) 1986, IMAGEN Corporation
 *  "This code may be duplicated in whole or in part provided that [1] there
 *   is no commercial gain involved in the duplication, and [2] that this
 *   copyright notice is preserved on all copies.  Any other duplication
 *   requires written notice of the author (Geoffrey H. Cooper)."
 */

#include "tinytcp.h"

/*
 * Local IP address
 */
in_HwAddress sin_lclINAddr;

/*
 * IP identification numbers
 */
int tcp_id;

tcp_Socket *tcp_allsocs;

/* Timer definitions */
#define tcp_RETRANSMITTIME 1000     /* interval at which retransmitter is called */
#define tcp_LONGTIMEOUT 31000       /* timeout for opens */
#define tcp_TIMEOUT 10000           /* timeout during a connection */

#ifdef DEBUG
/* 
 * Primitive logging facility
 */
#define tcp_LOGPACKETS 1        /* log packet headers */
word tcp_logState;
#endif

/*
 * Initialize the tcp implementation
 */
tcp_Init()
{
    extern eth_HwAddress sed_lclEthAddr;

    /* initialize ethernet interface */
    sed_Init();

    tcp_allsocs = NIL;
#ifdef DEBUG
    tcp_logState = 0;
#endif
    tcp_id = 0;

    /* hack - assume the network number */
    sin_lclINAddr = 0x7d000000 + (*((longword *)&sed_lclEthAddr[1]) & 0xFFFFFF);
}

/*
 * Actively open a TCP connection to a particular destination.
 */
tcp_Open(s, lport, ina, port, datahandler)
    tcp_Socket *s;
    in_HwAddress ina;
    word lport, port;
    procref datahandler;
{
    extern eth_HwAddress sed_ethBcastAddr;

    s->state = tcp_StateSYNSENT;
    s->timeout = tcp_LONGTIMEOUT;
    if ( lport == 0 ) lport = clock_ValueRough();
    s->myport = lport;
    if ( ! sar_MapIn2Eth(ina, &s->hisethaddr[0]) ) {
        printf("tcp_Open of 0x%x: defaulting ethernet address to broadcast\n", ina);
        Move(&sed_ethBcastAddr[0], &s->hisethaddr[0], sizeof(eth_HwAddress));
    }
    s->hisaddr = ina;
    s->hisport = port;
    s->seqnum = 0;
    s->dataSize = 0;
    s->flags = tcp_FlagSYN;
    s->unhappy = true;
    s->dataHandler = datahandler;
    s->next = tcp_allsocs;
    tcp_allsocs = s;
    tcp_Send(s);
}

/*
 * Passive open: listen for a connection on a particular port
 */
tcp_Listen(s, port, datahandler, timeout)
    tcp_Socket *s;
    word port;
    procref datahandler;
{
    s->state = tcp_StateLISTEN;
    if ( timeout == 0 ) s->timeout = 0x7ffffff; /* forever... */
    else s->timeout = timeout;
    s->myport = port;
    s->hisport = 0;
    s->seqnum = 0;
    s->dataSize = 0;
    s->flags = 0;
    s->unhappy = 0;
    s->dataHandler = datahandler;
    s->next = tcp_allsocs;
    tcp_allsocs = s;
}

/*
 * Send a FIN on a particular port -- only works if it is open
 */
tcp_Close(s)
    tcp_Socket *s;
{
    if ( s->state == tcp_StateESTAB || s->state == tcp_StateSYNREC ) {
        s->flags = tcp_FlagACK | tcp_FlagFIN;
        s->state = tcp_StateFINWT1;
        s->unhappy = true;
    }
}

/*
 * Abort a tcp connection
 */
tcp_Abort(s)
    tcp_Socket *s;
{
    if ( s->state != tcp_StateLISTEN && s->state != tcp_StateCLOSED ) {
        s->flags = tcp_FlagRST | tcp_FlagACK;
        tcp_Send(s);
    }
    s->unhappy = 0;
    s->dataSize = 0;
    s->state = tcp_StateCLOSED;
    s->dataHandler(s, 0, -1);
    tcp_Unthread(s);
}

/*
 * Retransmitter - called periodically to perform tcp retransmissions
 */
tcp_Retransmitter()
{
    tcp_Socket *s;
    BOOL x;

    for ( s = tcp_allsocs; s; s = s->next ) {
        x = false;
        if ( s->dataSize > 0 || s->unhappy ) {
            tcp_Send(s);
            x = true;
        }
        if ( x || s->state != tcp_StateESTAB )
            s->timeout -= tcp_RETRANSMITTIME;
        if ( s->timeout <= 0 ) {
            if ( s->state == tcp_StateTIMEWT ) {
                printf("Closed.    \n");
                s->state = tcp_StateCLOSED;
                s->dataHandler(s, 0, 0);
                tcp_Unthread(s);
            } else {
                printf("Timeout, aborting\n");
                tcp_Abort(s);
            }
        }
    }
}

/*
 * Unthread a socket from the socket list, if it's there 
 */
tcp_Unthread(ds)
    tcp_Socket *ds;
{
    tcp_Socket *s, **sp;

    sp = &tcp_allsocs;
    for (;;) {
        s = *sp;
        if ( s == ds ) {
            *sp = s->next;
            break;
        }
        if ( s == NIL ) break;
        sp = &s->next;
    }
}

/*
 * busy-wait loop for tcp.  Also calls an "application proc"
 */
tcp(application)
    procref application;
{
    in_Header *ip;
    longword timeout, start;
    int x;

    sed_Receive(0);

    timeout = 0;
    while ( tcp_allsocs ) {
        start = clock_ValueRough();
        ip = sed_IsPacket();
        if ( ip == NIL ) {
            if ( clock_ValueRough() > timeout ) {
                tcp_Retransmitter();
                timeout = clock_ValueRough() + tcp_RETRANSMITTIME;
            }

            application();

            continue;
        }

        if ( sed_CheckPacket(ip, 0x806) == 1 ) {
            /* do arp */
            sar_CheckPacket(ip);

        } else if ( sed_CheckPacket(ip, 0x800) == 1 ) {
            /* do IP */
            if ( ip->destination == sin_lclINAddr &&
                 in_GetProtocol(ip) == 6 &&
                 checksum(ip, in_GetHdrlenBytes(ip)) == 0xFFFF ) {
                tcp_Handler(ip);
            }
        }
        /* recycle buffer */
        sed_Receive(ip);

        x = clock_ValueRough() - start;
        timeout -= x;
    }

    return ( 1 );
}

/*
 * Write data to a connection.
 * Returns number of bytes written, == 0 when connection is not in
 * established state.
 */
tcp_Write(s, dp, len)
    tcp_Socket *s;
    byte *dp;
    int len;
{
    int x;

    if ( s->state != tcp_StateESTAB ) len = 0;
    if ( len > (x = tcp_MaxData - s->dataSize) ) len = x;
    if ( len > 0 ) {
        Move(dp, &s->data[s->dataSize], len);
        s->dataSize += len;
        tcp_Flush(s);
    }

    return ( len );
}

/*
 * Send pending data
 */
tcp_Flush(s)
    tcp_Socket *s;
{
    if ( s->dataSize > 0 ) {
        s->flags |= tcp_FlagPUSH;
        tcp_Send(s);
    }
}

/*
 * Handler for incoming packets.
 */
tcp_Handler(ip)
    in_Header *ip;
{
    tcp_Header *tp;
    tcp_PseudoHeader ph;
    int len;
    byte *dp;
    int x, diff;
    tcp_Socket *s;
    word flags;

    len = in_GetHdrlenBytes(ip);
    tp = (tcp_Header *)((byte *)ip + len);
    len = ip->length - len;

    /* demux to active sockets */
    for ( s = tcp_allsocs; s; s = s->next )
        if ( s->hisport != 0 &&
             tp->dstPort == s->myport &&
             tp->srcPort == s->hisport &&
             ip->source == s->hisaddr ) break;
    if ( s == NIL ) {
        /* demux to passive sockets */
        for ( s = tcp_allsocs; s; s = s->next )
            if ( s->hisport == 0 && tp->dstPort == s->myport ) break;
    }
    if ( s == NIL ) {

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产日韩欧美综合在线| 狠狠色狠狠色综合日日91app| 国产色一区二区| www久久精品| 精品少妇一区二区三区视频免付费 | www.色精品| 成人动漫中文字幕| 99热国产精品| 色又黄又爽网站www久久| 99国产麻豆精品| 色欲综合视频天天天| 在线视频一区二区三| 欧美色图12p| 欧美精品一二三四| 日韩欧美在线影院| 欧美精品一区男女天堂| 久久伊人蜜桃av一区二区| 国产日韩欧美制服另类| 国产精品国产三级国产| 亚洲日本丝袜连裤袜办公室| 亚洲免费观看视频| 亚洲午夜国产一区99re久久| 五月天视频一区| 久久成人精品无人区| 国产精品综合在线视频| 成人午夜激情在线| 一本大道久久精品懂色aⅴ| 欧美中文字幕一区二区三区 | 欧美一区二区视频网站| 日韩欧美不卡一区| 国产午夜亚洲精品午夜鲁丝片| 国产精品日韩成人| 亚洲一区二区三区四区在线免费观看| 午夜电影久久久| 国产综合色在线| 99精品视频中文字幕| 在线观看视频91| 麻豆一区二区三| 国产精品1区二区.| 日本久久电影网| 91精品国产一区二区三区| 久久久美女毛片| 亚洲精品日产精品乱码不卡| 日韩和欧美一区二区| 国产一区999| 在线观看91精品国产入口| 日韩欧美视频一区| 日韩一区中文字幕| 免费成人结看片| 99视频有精品| 日韩精品中午字幕| 一区二区三区欧美激情| 伦理电影国产精品| 色婷婷精品大视频在线蜜桃视频 | 亚洲欧美日韩国产中文在线| 日韩精品久久理论片| 成人免费高清视频| 欧美一级久久久| 亚洲女人****多毛耸耸8| 麻豆免费看一区二区三区| 不卡欧美aaaaa| 日韩精品一区二区三区三区免费| 1024成人网| 国产精品一区二区免费不卡| 欧美视频在线观看一区| 日本一区免费视频| 免费成人性网站| 欧美亚洲国产怡红院影院| 国产网站一区二区| 日韩av一级片| 欧美在线综合视频| 国产精品视频一二三| 免费成人av在线| 欧美日韩日日摸| 自拍偷拍亚洲综合| 粉嫩绯色av一区二区在线观看| 3d动漫精品啪啪| 亚洲最色的网站| 成人动漫视频在线| 国产欧美日本一区二区三区| 日本麻豆一区二区三区视频| 91福利区一区二区三区| 亚洲欧美怡红院| 国产成人精品免费网站| 欧美xxxxxxxxx| 日韩不卡一区二区| 欧美日韩精品欧美日韩精品| 亚洲免费成人av| 不卡一卡二卡三乱码免费网站| 久久久亚洲精华液精华液精华液| 麻豆精品新av中文字幕| 在线成人小视频| 午夜精品久久久久久久99水蜜桃| 一本到一区二区三区| 亚洲欧美综合色| av爱爱亚洲一区| 国产精品久久久久久久第一福利 | www.色精品| 国产精品少妇自拍| 福利一区在线观看| 国产欧美日韩麻豆91| 国产成人精品在线看| 久久视频一区二区| 狠狠色丁香九九婷婷综合五月 | 亚洲一区二区视频在线| 成人激情免费网站| 国产精品免费av| www.色综合.com| 亚洲三级在线免费观看| 欧美专区日韩专区| 午夜国产不卡在线观看视频| 欧美色图12p| 日韩精品成人一区二区在线| 欧美一二三区在线观看| 麻豆国产精品一区二区三区| 欧美一二三四在线| 国产一区二区女| 国产精品日日摸夜夜摸av| 99re视频精品| 亚洲二区在线视频| 欧美一级欧美一级在线播放| 裸体在线国模精品偷拍| 中文字幕欧美一区| 色吊一区二区三区| 日韩精品久久理论片| 欧美tickling网站挠脚心| 高潮精品一区videoshd| 亚洲精品欧美二区三区中文字幕| 欧美三级日韩三级| 麻豆精品久久精品色综合| 久久亚洲一区二区三区四区| 成人av午夜影院| 亚洲r级在线视频| 欧美v国产在线一区二区三区| 国产乱码精品一区二区三| 中文字幕中文乱码欧美一区二区| 91福利在线观看| 美女性感视频久久| 国产精品视频麻豆| 欧美日韩午夜影院| 精品午夜久久福利影院| 国产精品每日更新在线播放网址| 日本久久电影网| 狠狠色综合日日| 一区二区三区在线免费| 欧美一区二区黄色| 99视频在线精品| 美女在线视频一区| 中文字幕一区视频| 欧美一区二区三区免费在线看| 国产乱人伦偷精品视频不卡| 亚洲女厕所小便bbb| 精品对白一区国产伦| 色综合天天综合给合国产| 青娱乐精品在线视频| 中文字幕亚洲在| 日韩三级免费观看| 色综合天天综合网国产成人综合天| 日韩av成人高清| 国产精品久久久久aaaa樱花| 91精品在线免费| 99久久婷婷国产| 美女在线观看视频一区二区| 亚洲欧美国产三级| 久久免费美女视频| 欧美日韩日日骚| 99精品视频中文字幕| 国产一区在线视频| 日日噜噜夜夜狠狠视频欧美人| 国产精品久久毛片| 337p日本欧洲亚洲大胆色噜噜| 欧亚洲嫩模精品一区三区| 成人小视频在线观看| 老司机午夜精品| 亚洲午夜久久久久久久久久久| 国产日产精品1区| 日韩久久久精品| 欧美日韩小视频| 99国产精品99久久久久久| 国产在线精品不卡| 日韩电影免费在线观看网站| 亚洲精品一二三| 中文字幕一区免费在线观看 | 亚洲高清三级视频| 中文字幕永久在线不卡| 国产午夜精品一区二区三区四区 | 国产精品不卡一区二区三区| 日韩精品中文字幕在线一区| 欧美体内she精高潮| av在线一区二区三区| 国产精品夜夜爽| 精品一区在线看| 美女精品一区二区| 日韩精品亚洲专区| 一二三四社区欧美黄| 成人免费小视频| 国产精品不卡一区二区三区| 国产嫩草影院久久久久| 国产亚洲精品福利| 久久久久久97三级|