home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR3 / KA9Q212.ZIP / NRDUMP.C < prev    next >
C/C++ Source or Header  |  1993-07-16  |  3KB  |  124 lines

  1. /* NET/ROM header tracing routines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4.  
  5. /****************************************************************************
  6. *    $Id: nrdump.c 1.2 93/07/16 11:48:02 ROOT_DOS Exp $
  7. *    15 Jul 93    1.2        GT    Fix warnings.                                    *
  8. ****************************************************************************/
  9.  
  10. #include <stdio.h>
  11. #include "global.h"
  12. #include "mbuf.h"
  13. #include "netrom.h"
  14. #include "nr4.h"
  15. #include "trace.h"
  16. #include "ip.h"
  17.  
  18. /* Display NET/ROM network and transport headers */
  19. void
  20. netrom_dump(fp,bpp,check)
  21. FILE *fp;
  22. struct mbuf **bpp;
  23. int check;
  24. {
  25.     char src[AXALEN],dest[AXALEN];
  26.     char tmp[AXBUF];
  27.     char thdr[NR4MINHDR];
  28.     register i;
  29.  
  30.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  31.         return;
  32.     /* See if it is a routing broadcast */
  33.     if(uchar(*(*bpp)->data) == NR3NODESIG) {
  34.         (void)PULLCHAR(bpp);        /* Signature */
  35.         pullup(bpp,tmp,ALEN);
  36.         tmp[ALEN] = '\0';
  37.         fprintf(fp,"NET/ROM Routing: %s\n",tmp);
  38.         for(i = 0;i < NRDESTPERPACK;i++) {
  39.             if (pullup(bpp,src,AXALEN) < AXALEN)
  40.                 break;
  41.             fprintf(fp,"        %12s",pax25(tmp,src));
  42.             pullup(bpp,tmp,ALEN);
  43.             tmp[ALEN] = '\0';
  44.             fprintf(fp,"%8s",tmp);
  45.             pullup(bpp,src,AXALEN);
  46.             fprintf(fp,"    %12s",pax25(tmp,src));
  47.             tmp[0] = PULLCHAR(bpp);
  48.             fprintf(fp,"    %3u\n",uchar(tmp[0]));
  49.         }
  50.         return;
  51.     }
  52.     /* Decode network layer */
  53.     pullup(bpp,src,AXALEN);
  54.     fprintf(fp,"NET/ROM: %s",pax25(tmp,src));
  55.  
  56.     pullup(bpp,dest,AXALEN);
  57.     fprintf(fp,"->%s",pax25(tmp,dest));
  58.  
  59.     i = PULLCHAR(bpp);
  60.     fprintf(fp," ttl %d\n",i);
  61.  
  62.     /* Read first five bytes of "transport" header */
  63.     pullup(bpp,thdr,NR4MINHDR);
  64.     switch(thdr[4] & NR4OPCODE){
  65.      case NR4OPPID:    /* network PID extension */
  66.         if (thdr[0] == NRPROTO_IP && thdr[1] == NRPROTO_IP) {
  67.              ip_dump(fp,bpp,check) ;
  68.             return;
  69.         }
  70.          else
  71.              fprintf(fp,"         protocol family %x, proto %x",
  72.              uchar(thdr[0]), uchar(thdr[1])) ;
  73.          break ;
  74.     case NR4OPCONRQ:    /* Connect request */
  75.         fprintf(fp,"         conn rqst: ckt %d/%d",uchar(thdr[0]),uchar(thdr[1]));
  76.         i = PULLCHAR(bpp);
  77.         fprintf(fp," wnd %d",i);
  78.         pullup(bpp,src,AXALEN);
  79.         fprintf(fp," %s",pax25(tmp,src));
  80.         pullup(bpp,dest,AXALEN);
  81.         fprintf(fp,"@%s",pax25(tmp,dest));
  82.         break;
  83.     case NR4OPCONAK:    /* Connect acknowledgement */
  84.         fprintf(fp,"         conn ack: ur ckt %d/%d my ckt %d/%d",
  85.          uchar(thdr[0]), uchar(thdr[1]), uchar(thdr[2]),
  86.          uchar(thdr[3]));
  87.         i = PULLCHAR(bpp);
  88.         fprintf(fp," wnd %d",i);
  89.         break;
  90.     case NR4OPDISRQ:    /* Disconnect request */
  91.         fprintf(fp,"         disc: ckt %d/%d",
  92.          uchar(thdr[0]),uchar(thdr[1]));
  93.         break;
  94.     case NR4OPDISAK:    /* Disconnect acknowledgement */
  95.         fprintf(fp,"         disc ack: ckt %d/%d",
  96.          uchar(thdr[0]),uchar(thdr[1]));
  97.         break;
  98.     case NR4OPINFO:    /* Information (data) */
  99.         fprintf(fp,"         info: ckt %d/%d",
  100.          uchar(thdr[0]),uchar(thdr[1]));
  101.         fprintf(fp," txseq %d rxseq %d",
  102.          uchar(thdr[2]), uchar(thdr[3]));
  103.         break;
  104.     case NR4OPACK:    /* Information acknowledgement */
  105.         fprintf(fp,"         info ack: ckt %d/%d",
  106.          uchar(thdr[0]),uchar(thdr[1]));
  107.         fprintf(fp," txseq %d rxseq %d",
  108.          uchar(thdr[2]), uchar(thdr[3]));
  109.         break;
  110.     default:
  111.          fprintf(fp,"         unknown transport type %d",
  112.          thdr[4] & 0x0f) ;
  113.         break;
  114.     }
  115.     if(thdr[4] & NR4CHOKE)
  116.         fprintf(fp," CHOKE");
  117.     if(thdr[4] & NR4NAK)
  118.         fprintf(fp," NAK");
  119.     if(thdr[4] & NR4MORE)
  120.         fprintf(fp," MORE");
  121.     putc('\n',fp);
  122. }
  123.  
  124.