home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 3 / hamradioversion3.0examsandprograms1992.iso / misc / 9q920411 / slcompdu.c < prev    next >
C/C++ Source or Header  |  1991-03-08  |  3KB  |  122 lines

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