⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dump_tcbtab.c

📁 一款类linux的操作系统源码
💻 C
字号:
/* *  Roadrunner/pk *    Copyright (C) 1989-2001  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/ether.h>#include <net/tcp.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/intr.h>#include <fs/dump.h>#define TCB_HDR "sport  dst              dport  state"static char *tcb_states[] = {    "CLOSED",    "LISTEN",    "SYN_SENT",    "SYN_RECEIVED",    "ESTABLISHED",    "CLOSE_WAIT",    "FIN_WAIT_1",    "CLOSING",    "LAST_ACK",    "FIN_WAIT_2",    "TIME_WAIT"};static voiddump_packet_queue(char **s, char *name, buf_t b, int reverse_byteorder){    etherhdr_t eh;    iphdr_t ih;    tcphdr_t th;    char s0[32];    tcp_seq seq;    int segcnt = 0;    for (; b != NULL; b = b->next) {	if (segcnt++ == 0) {	    sprintf(*s, "%s:", name);	    *s += strlen(name) + 1;	}	eh = (etherhdr_t) bstart(b);	ih = (iphdr_t) eh->data;	th = (tcphdr_t) (eh->data + IP_HLEN(ih));	if (reverse_byteorder)	    seq = NET2HL(th->seq);	else	    seq = th->seq;	sprintf(s0, " (%u,%u)", seq,		seq + (ih->len - IP_HLEN(ih) - TCP_HLEN(th)) - 1);	sprintf(*s, s0);	*s += strlen(s0);    }    if (segcnt > 0)	sprintf((*s)++, "\n");}voiddump_tcbtab(char *s){    tcb_t tcb;    char s1[32];    int i, j, len, tcbcnt = 0;    for (i = 0; i < TCP_CONNECTIONS; i++)	if (tcbtab[i].state > TCPS_CLOSED) {	    if (tcbcnt++ == 0) {		sprintf(s, "%s\n", TCB_HDR);		s += strlen(TCB_HDR) + 1;	    }	    tcb = &(tcbtab[i]);	    sprintf(s1, "%u", tcb->socket->sport);	    sprintf(s, s1);	    len = strlen(s1);	    s += len;	    for (j = 0; j < 7 - len; j++)		sprintf(s++, " ");	    if (tcb->state == TCPS_LISTEN) {		sprintf(s, "-                -      ");		s += 24;	    } else {		ip2str(tcb->socket->dst, s1);		sprintf(s, s1);		len = strlen(s1);		s += len;		for (j = 0; j < 17 - len; j++)		    sprintf(s++, " ");		sprintf(s1, "%u", tcb->socket->dport);		sprintf(s, s1);		len = strlen(s1);		s += len;		for (j = 0; j < 7 - len; j++)		    sprintf(s++, " ");	    }	    sprintf(s, "%s\n", tcb_states[tcb->state]);	    s += strlen(tcb_states[tcb->state]) + 1;	    dump_packet_queue(&s, "reass", tcb->reass.h, 0);	    dump_packet_queue(&s, "retr ", tcb->retr.h, 1);	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -