home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include "global.h"
- #include "mbuf.h"
- #include "netuser.h"
- #include "internet.h"
- #include "timer.h"
- #include "tcp.h"
- #include "trace.h"
- #include "misc.h"
-
- /* TCP segment header flags */
- char *tcpflags[] = {
- "FIN", /* 0x01 */
- "SYN", /* 0x02 */
- "RST", /* 0x04 */
- "PSH", /* 0x08 */
- "ACK", /* 0x10 */
- "URG" /* 0x20 */
- };
-
- /* Dump a TCP segment header. Assumed to be in network byte order */
- void tcp_dump(struct mbuf **bpp, int32 source, int32 dest, int check)
- {
- int i;
- struct tcp seg;
- struct pseudo_header ph;
- int16 csum;
-
- if(bpp == NULLBUFP || *bpp == NULLBUF)
- return;
-
- /* Verify checksum */
- ph.source = source;
- ph.dest = dest;
- ph.protocol = TCP_PTCL;
- ph.length = len_mbuf(*bpp);
- csum = cksum(&ph,*bpp,ph.length);
-
- ntohtcp(&seg,bpp);
-
- twprintf("TCP: %u->%u Seq x%lx",seg.source,seg.dest,seg.seq);
- if(seg.flags & ACK)
- twprintf(" Ack x%lx",seg.ack);
- for(i=0;i<6;i++){
- if(seg.flags & 1 << i){
- twprintf(" %s",tcpflags[i]);
- }
- }
- twprintf(" Wnd %u",seg.wnd);
- if(seg.flags & URG)
- twprintf(" UP x%x",seg.up);
- /* Print options, if any */
- if(seg.mss != 0)
- twprintf(" MSS %u",seg.mss);
- if(check && csum != 0)
- twprintf(" CHECKSUM ERROR (%u)",i);
- twprintf("\n");
- }
-
-