home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / internet / tcpip / src205 / TCPIP_Src / TCP / c / TCPDUMP < prev    next >
Encoding:
Text File  |  1994-06-24  |  1.5 KB  |  60 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "netuser.h"
  5. #include "internet.h"
  6. #include "timer.h"
  7. #include "tcp.h"
  8. #include "trace.h"
  9. #include "misc.h"
  10.  
  11. /* TCP segment header flags */
  12. char *tcpflags[] = {
  13.         "FIN",  /* 0x01 */
  14.         "SYN",  /* 0x02 */
  15.         "RST",  /* 0x04 */
  16.         "PSH",  /* 0x08 */
  17.         "ACK",  /* 0x10 */
  18.         "URG"   /* 0x20 */
  19. };
  20.  
  21. /* Dump a TCP segment header. Assumed to be in network byte order */
  22. void tcp_dump(struct mbuf **bpp, int32 source, int32 dest, int check)
  23. {
  24.         int i;
  25.         struct tcp seg;
  26.         struct pseudo_header ph;
  27.         int16 csum;
  28.  
  29.         if(bpp == NULLBUFP || *bpp == NULLBUF)
  30.                 return;
  31.  
  32.         /* Verify checksum */
  33.         ph.source = source;
  34.         ph.dest = dest;
  35.         ph.protocol = TCP_PTCL;
  36.         ph.length = len_mbuf(*bpp);
  37.         csum = cksum(&ph,*bpp,ph.length);
  38.  
  39.         ntohtcp(&seg,bpp);
  40.  
  41.         twprintf("TCP: %u->%u Seq x%lx",seg.source,seg.dest,seg.seq);
  42.         if(seg.flags & ACK)
  43.                 twprintf(" Ack x%lx",seg.ack);
  44.         for(i=0;i<6;i++){
  45.                 if(seg.flags & 1 << i){
  46.                         twprintf(" %s",tcpflags[i]);
  47.                 }
  48.         }
  49.         twprintf(" Wnd %u",seg.wnd);
  50.         if(seg.flags & URG)
  51.                 twprintf(" UP x%x",seg.up);
  52.         /* Print options, if any */
  53.         if(seg.mss != 0)
  54.                 twprintf(" MSS %u",seg.mss);
  55.         if(check && csum != 0)
  56.                 twprintf(" CHECKSUM ERROR (%u)",i);
  57.         twprintf("\n");
  58. }
  59.  
  60.