📄 tcp_debug.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/ether.h>#include <net/tcp.h>#include <stdio.h>#include <stdlib.h>#if _DEBUG_TCPchar *tcb_states[] = { "CLOSED", "LISTEN", "SYN_SENT", "SYN_RECEIVED", "ESTABLISHED", "CLOSE_WAIT", "FIN_WAIT_1", "CLOSING", "LAST_ACK", "FIN_WAIT_2", "TIME_WAIT"};voidtcp_dump_segment(char *func, tcphdr_t th){ kprintf("%s: sport %u dport %u seq %u ack %u win %u", func, th->sport, th->dport, th->seq, th->ack, th->win); if (th->flags & TF_FIN) kprintf(" FIN"); if (th->flags & TF_SYN) kprintf(" SYN"); if (th->flags & TF_RST) kprintf(" RST"); if (th->flags & TF_PSH) kprintf(" PSH"); if (th->flags & TF_ACK) kprintf(" ACK"); if (th->flags & TF_URG) kprintf(" URG"); kprintf("\n");}static voidtcp_dump_reass(char *s, buf_t b){ etherhdr_t eh; iphdr_t ih; tcphdr_t th; int segcnt = 0; for (; b != NULL; b = b->next) { if (segcnt++ == 0) kprintf("%s:", s); eh = (etherhdr_t) bstart(b); ih = (iphdr_t) eh->data; th = (tcphdr_t) (eh->data + IP_HLEN(ih)); kprintf(" [%u,%u]", th->seq, th->seq + (ih->len - IP_HLEN(ih) - TCP_HLEN(th)) - 1); } if (segcnt > 0) kprintf("\n");}#endif#if _DEBUG_RETRvoidtcp_dump_retr(char *s, buf_t b){ etherhdr_t eh; iphdr_t ih; tcphdr_t th; int datalen, segcnt = 0; for (; b != NULL; b = b->next) { if (segcnt++ == 0) kprintf("%s:", s); eh = (etherhdr_t) bstart(b); ih = (iphdr_t) eh->data; th = (tcphdr_t) (eh->data + IP_HLEN(ih)); datalen = NET2HS(ih->len) - IP_HLEN(ih) - TCP_HLEN(th); kprintf(" <"); if (th->flags & TF_SYN) kprintf("SYN,"); if (th->flags & TF_FIN) kprintf("FIN,"); kprintf("%u,", NET2HL(th->seq)); if (datalen > 0) kprintf("%u>", NET2HL(th->seq) + datalen - 1); else kprintf("->"); } if (segcnt > 0) kprintf("\n");}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -