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

  1. /*
  2.  *  PPPDUMP.C
  3.  *
  4.  *  12-89   -- Katie Stevens (dkstevens@ucdavis.edu)
  5.  *         UC Davis, Computing Services
  6.  *  PPP.08  05-90   [ks] improve tracing reports
  7.  *  PPP.09  05-90   [ks] add UPAP packet reporting
  8.  *  PPP.14  08-90   [ks] change UPAP to PAP for consistency with RFC1172
  9.  *  PPP.15  09-90   [ks] update to KA9Q NOS v900828
  10.  *  Jan 91  [Bill Simpson] small changes to match rewrite of PPP
  11.  *  Aug 91  [Bill Simpson] fixed some buffer loss
  12.  */
  13. #include "global.h"
  14. #ifdef PPP
  15. #include "mbuf.h"
  16. #include "iface.h"
  17. #include "internet.h"
  18. #include "ppp.h"
  19. #include "trace.h"
  20.   
  21. #ifdef TURBOC_SWITCH_BUG
  22. #pragma option -G-
  23. #endif
  24.   
  25. /* dump a PPP packet */
  26. void
  27. ppp_dump(fp,bpp,unused)
  28. FILE *fp;
  29. struct mbuf **bpp;
  30. int unused;
  31. {
  32.     struct ppp_hdr hdr;
  33.     struct mbuf *tbp;
  34.   
  35.     fprintf(fp,"PPP: len %3u\t", len_p(*bpp));
  36.   
  37.     /* HDLC address and control fields may be compressed out */
  38.     if ((byte_t)(*bpp)->data[0] != HDLC_ALL_ADDR) {
  39.         fprintf(fp,"(compressed ALL/UI)\t");
  40.     } else if ((byte_t)(*bpp)->data[1] != HDLC_UI) {
  41.         fprintf(fp,"(missing UI!)\t");
  42.     } else {
  43.         /* skip address/control fields */
  44.         pull16(bpp);
  45.     }
  46.   
  47.     /* Initialize the expected header */
  48.     hdr.addr = HDLC_ALL_ADDR;
  49.     hdr.control = HDLC_UI;
  50.     hdr.protocol = PULLCHAR(bpp);
  51.   
  52.     /* First byte of PPP protocol field may be compressed out */
  53.     if ( hdr.protocol & 0x01 ) {
  54.         fprintf(fp,"compressed ");
  55.     } else {
  56.         hdr.protocol = (hdr.protocol << 8) | PULLCHAR(bpp);
  57.   
  58.         /* Second byte of PPP protocol field must be odd */
  59.         if ( !(hdr.protocol & 0x01) ) {
  60.             fprintf(fp, "(not odd!) " );
  61.         }
  62.     }
  63.   
  64.     fprintf(fp,"protocol: ");
  65.     switch(hdr.protocol){
  66.         case PPP_IP_PROTOCOL:
  67.             fprintf(fp,"IP\n");
  68.             ip_dump(fp,bpp,1);
  69.             break;
  70.         case PPP_IPCP_PROTOCOL:
  71.             fprintf(fp,"IPCP\n");
  72.             break;
  73.         case PPP_LCP_PROTOCOL:
  74.             fprintf(fp,"LCP\n");
  75.             break;
  76.         case PPP_PAP_PROTOCOL:
  77.             fprintf(fp,"PAP\n");
  78.             break;
  79.         case PPP_COMPR_PROTOCOL:
  80.             fprintf(fp,"VJ Compressed TCP/IP\n");
  81.             vjcomp_dump(fp,bpp,0);
  82.             break;
  83.         case PPP_UNCOMP_PROTOCOL:
  84.             fprintf(fp,"VJ Uncompressed TCP/IP\n");
  85.             /* Get our own copy so we can mess with the data */
  86.             if ( (tbp = copy_p(*bpp, len_p(*bpp))) == NULLBUF)
  87.                 return;
  88.   
  89.             fprintf(fp,"\tconnection 0x%02x\n",
  90.             tbp->data[9]);      /* FIX THIS! */
  91.             /* Restore the bytes used with Uncompressed TCP */
  92.             tbp->data[9] = TCP_PTCL;    /* FIX THIS! */
  93.             ip_dump(fp,&tbp,1);
  94.             free_p(tbp);
  95.             break;
  96.         default:
  97.             fprintf(fp,"unknown 0x%04x\n",hdr.protocol);
  98.             break;
  99.     }
  100. }
  101.   
  102. #ifdef TURBOC_SWITCH_BUG
  103. #pragma option -G
  104. #endif
  105.   
  106. #endif /* PPP */
  107.   
  108.