📄 tcp.c
字号:
/* * Roadrunner/pk * Copyright (C) 1989-2002 Cornfed Systems, Inc. * * The Roadrunner/pk operating system is free software; you can * redistribute and/or modify it under the terms of the GNU General * Public License, version 2, as published by the Free Software * Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * More information about the Roadrunner/pk operating system of * which this file is a part is available on the World-Wide Web * at: http://www.cornfed.com. * */#include <net/tcp.h>#include <stdlib.h>#include <string.h>#include <sys/time.h>#include <sys/timer.h>struct tcb tcbtab[TCP_CONNECTIONS];voidtcp_init(){ bzero(tcbtab, TCP_CONNECTIONS * sizeof(struct tcb));}voidtcp_close(tcb_t tcb){ socket_clear(tcb->socket); tcb_clear(tcb);}tcb_ttcb_alloc(int state){ tcb_t tcb; int i; for (i = 0; i < TCP_CONNECTIONS; i++) { tcb = &(tcbtab[i]); if (tcb->state == TCPS_CLOSED) { tcb->state = state; return tcb; } } return NULL;}voidtcb_clear(tcb_t tcb){ bzero(tcb, sizeof(struct tcb));}tcb_ttcb_find(ipaddr src, u_short sport, ipaddr dst, u_short dport, int match_wildcards){ socket_t socket; tcb_t match = NULL, tcb; int i, wildcards, wildcard_matches = 3; for (i = 0; i < TCP_CONNECTIONS; i++) { tcb = &(tcbtab[i]); socket = tcb->socket; if (socket == NULL) continue; if (dport != socket->sport) continue; wildcards = 0; if (dst == IP_ADDR_ANY) { if (socket->src != IP_ADDR_ANY) wildcards++; } else { if (socket->src == IP_ADDR_ANY) wildcards++; else if (dst != socket->src) continue; } if (src == IP_ADDR_ANY) { if (socket->dst != IP_ADDR_ANY) wildcards++; } else { if (socket->dst == IP_ADDR_ANY) wildcards++; else if (src != socket->dst || sport != socket->dport) continue; } if (wildcards > 0 && match_wildcards == 0) continue; if (wildcards < wildcard_matches) { match = tcb; wildcard_matches = wildcards; if (wildcard_matches == 0) break; } } return match;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -