home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 024 / psi110g.zip / SLHCDUMP.C < prev    next >
C/C++ Source or Header  |  1994-04-17  |  3KB  |  120 lines

  1. #include "global.h"
  2. #include "mbuf.h"
  3. #include "internet.h"
  4. #include "ip.h"
  5. #include "slhc.h"
  6. #include "trace.h"
  7.   
  8. static int16 decodeint __ARGS((struct mbuf **bpp));
  9.   
  10. static int16
  11. decodeint(bpp)
  12. struct mbuf **bpp;
  13. {
  14.     char tmpbuf[2];
  15.   
  16.     pullup(bpp,tmpbuf,1);
  17.     if (tmpbuf[0] == 0)
  18.         pullup(bpp,tmpbuf,2);
  19.     else {
  20.         tmpbuf[1] = tmpbuf[0];
  21.         tmpbuf[0] = 0;
  22.     }
  23.     return(get16(tmpbuf));
  24. }
  25.   
  26. void
  27. vjcomp_dump(fp,bpp,unused)
  28. FILE *fp;
  29. struct mbuf **bpp;
  30. int unused;
  31. {
  32.     char changes;
  33.     char tmpbuf[2];
  34.   
  35.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  36.         return;
  37.   
  38.     /* Dump compressed TCP/IP header */
  39.     changes = pullchar(bpp);
  40.     fprintf(fp,"\tchanges: 0x%02x",uchar(changes));
  41.     if (changes & NEW_C) {
  42.         pullup(bpp,tmpbuf,1);
  43.         fprintf(fp,"   connection: 0x%02x",uchar(tmpbuf[0]));
  44.     }
  45.     pullup(bpp,tmpbuf,2);
  46.     fprintf(fp,"   TCP checksum: 0x%04x",get16(tmpbuf));
  47.   
  48.     if (changes & TCP_PUSH_BIT)
  49.         fprintf(fp,"   PUSH");
  50.     fprintf(fp,"\n");
  51.   
  52.     switch (changes & SPECIALS_MASK) {
  53.         case SPECIAL_I:
  54.             fprintf(fp,"\tdelta ACK and delta SEQ implied by length of data\n");
  55.             break;
  56.   
  57.         case SPECIAL_D:
  58.             fprintf(fp,"\tdelta SEQ implied by length of data\n");
  59.             break;
  60.   
  61.         default:
  62.             if (changes & NEW_U) {
  63.                 fprintf(fp,"\tUrgent pointer: 0x%02x",decodeint(bpp));
  64.             }
  65.             if (changes & NEW_W)
  66.                 fprintf(fp,"\tdelta WINDOW: 0x%02x",decodeint(bpp));
  67.             if (changes & NEW_A)
  68.                 fprintf(fp,"\tdelta ACK: 0x%02x",decodeint(bpp));
  69.             if (changes & NEW_S)
  70.                 fprintf(fp,"\tdelta SEQ: 0x%02x",decodeint(bpp));
  71.             break;
  72.     };
  73.     if (changes & NEW_I) {
  74.         fprintf(fp,"\tdelta ID: 0x%02x\n",decodeint(bpp));
  75.     } else {
  76.         fprintf(fp,"\tincrement ID\n");
  77.     }
  78. }
  79.   
  80.   
  81. /* dump serial line IP packet; may have Van Jacobson TCP header compression */
  82. void
  83. sl_dump(fp,bpp,unused)
  84. FILE *fp;
  85. struct mbuf **bpp;
  86. int unused;
  87. {
  88.     struct mbuf *bp, *tbp;
  89.     unsigned char c;
  90.     int len;
  91.   
  92.     bp = *bpp;
  93.     c = bp->data[0];
  94.     if (c & SL_TYPE_COMPRESSED_TCP) {
  95.         fprintf(fp,"serial line VJ Compressed TCP: len %3u\n",
  96.         len_p(*bpp));
  97.         vjcomp_dump(fp,bpp,0);
  98.     } else if ( c >= SL_TYPE_UNCOMPRESSED_TCP ) {
  99.         fprintf(fp,"serial line VJ Uncompressed TCP: len %3u\n",
  100.         len = len_p(bp));
  101.         /* Get our own copy so we can mess with the data */
  102.         if ( (tbp = copy_p(bp, len)) == NULLBUF )
  103.             return;
  104.   
  105.         fprintf(fp,"\tconnection ID = %d\n",
  106.         uchar(tbp->data[9]));   /* FIX THIS! */
  107.         /* Restore the bytes used with Uncompressed TCP */
  108.         tbp->data[0] &= 0x4f;       /* FIX THIS! */
  109.         tbp->data[9] = TCP_PTCL;    /* FIX THIS! */
  110.         /* Dump contents as a regular IP packet */
  111.         ip_dump(fp,&tbp,1);
  112.         free_p(tbp);
  113.     } else {
  114.         fprintf(fp,"serial line IP: len: %3u\n",len_p(*bpp));
  115.         ip_dump(fp,bpp,1);
  116.     }
  117. }
  118.   
  119.   
  120.