home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 3 / hamradioversion3.0examsandprograms1992.iso / packet / n17jsrc / slhcdump.c < prev    next >
C/C++ Source or Header  |  1991-03-07  |  3KB  |  121 lines

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