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

  1. /* NET/ROM header tracing routines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include "global.h"
  5. #ifdef NETROM
  6. #include "mbuf.h"
  7. #include "netrom.h"
  8. #include "nr4.h"
  9. #include "trace.h"
  10.   
  11. /* Display NET/ROM network and transport headers */
  12. void
  13. netrom_dump(fp,bpp,check)
  14. FILE *fp;
  15. struct mbuf **bpp;
  16. int check;
  17. {
  18.     char src[AXALEN],dest[AXALEN];
  19.     char tmp[AXBUF];
  20.     char thdr[NR4MINHDR];
  21.     register i;
  22.   
  23.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  24.         return;
  25.     /* See if it is a routing broadcast */
  26.     if(uchar(*(*bpp)->data) == NR3NODESIG) {
  27.         (void)PULLCHAR(bpp);        /* Signature */
  28.         pullup(bpp,tmp,ALEN);
  29.         tmp[ALEN] = '\0';
  30.         fprintf(fp,"NET/ROM Routing: %s\n",tmp);
  31.         for(i = 0;i < NRDESTPERPACK;i++) {
  32.             if (pullup(bpp,src,AXALEN) < AXALEN)
  33.                 break;
  34.             fprintf(fp,"        %12s",pax25(tmp,src));
  35.             pullup(bpp,tmp,ALEN);
  36.             tmp[ALEN] = '\0';
  37.             fprintf(fp,"%8s",tmp);
  38.             pullup(bpp,src,AXALEN);
  39.             fprintf(fp,"    %12s",pax25(tmp,src));
  40.             tmp[0] = PULLCHAR(bpp);
  41.             fprintf(fp,"    %3u\n",uchar(tmp[0]));
  42.         }
  43.         return;
  44.     }
  45.     /* See if it is a routing poll - WG7J */
  46.     if(uchar(*(*bpp)->data) == NR3POLLSIG) {
  47.         (void)PULLCHAR(bpp);        /* Signature */
  48.         pullup(bpp,tmp,ALEN);
  49.         tmp[ALEN] = '\0';
  50.         fprintf(fp,"NET/ROM Poll: %s\n",tmp);
  51.         return;
  52.     }
  53.     /* Decode network layer */
  54.     pullup(bpp,src,AXALEN);
  55. #ifdef MONITOR
  56.     if (Trace_compact_header)
  57.         fprintf(fp, "NET/ROM %s", pax25(tmp, src));
  58.     else
  59. #endif
  60.         fprintf(fp,"NET/ROM: %s",pax25(tmp,src));
  61.   
  62.     pullup(bpp,dest,AXALEN);
  63.     fprintf(fp,"->%s",pax25(tmp,dest));
  64.   
  65.     i = PULLCHAR(bpp);
  66. #ifdef MONITOR
  67.     if (!Trace_compact_header)
  68. #endif
  69.         fprintf(fp," ttl %d\n",i);
  70.   
  71.     /* Read first five bytes of "transport" header */
  72.     pullup(bpp,thdr,NR4MINHDR);
  73.     switch(thdr[4] & NR4OPCODE){
  74.         case NR4OPPID:  /* network PID extension */
  75.             if (thdr[0] == NRPROTO_IP && thdr[1] == NRPROTO_IP) {
  76. #ifdef MONITOR
  77.                 if (Trace_compact_header)
  78.                     fprintf(fp, " [IP]:\n");
  79. #endif
  80.                 ip_dump(fp,bpp,check) ;
  81.                 return;
  82.             }
  83.             else
  84. #ifdef MONITOR
  85.                 if (Trace_compact_header)
  86.                     fprintf(fp, " [%x/%x]:\n",uchar(thdr[0]), uchar(thdr[1]));
  87.                 else
  88. #endif
  89.                     fprintf(fp,"         protocol family %x, proto %x",
  90.                     uchar(thdr[0]), uchar(thdr[1])) ;
  91.             break ;
  92.         case NR4OPCONRQ:    /* Connect request */
  93. #ifdef MONITOR
  94.             if (Trace_compact_header)
  95.                 fprintf(fp, " conn req %d/%d", uchar(thdr[0]), uchar(thdr[1]));
  96.             else
  97. #endif
  98.                 fprintf(fp,"         conn rqst: ckt %d/%d",uchar(thdr[0]),uchar(thdr[1]));
  99.             i = PULLCHAR(bpp);
  100. #ifdef MONITOR
  101.             if (!Trace_compact_header)
  102. #endif
  103.                 fprintf(fp," wnd %d",i);
  104.             pullup(bpp,src,AXALEN);
  105.             fprintf(fp," %s",pax25(tmp,src));
  106.             pullup(bpp,dest,AXALEN);
  107.             fprintf(fp,"@%s",pax25(tmp,dest));
  108.             break;
  109.         case NR4OPCONAK:    /* Connect acknowledgement */
  110. #ifdef MONITOR
  111.             if (Trace_compact_header)
  112.                 fprintf(fp, " conn ack %d/%d->%d/%d",
  113.                 uchar(thdr[0]), uchar(thdr[1]),
  114.                 uchar(thdr[2]), uchar(thdr[3]));
  115.             else
  116. #endif
  117.                 fprintf(fp,"         conn ack: ur ckt %d/%d my ckt %d/%d",
  118.                 uchar(thdr[0]), uchar(thdr[1]), uchar(thdr[2]),
  119.                 uchar(thdr[3]));
  120.             i = PULLCHAR(bpp);
  121. #ifdef MONITOR
  122.             if (!Trace_compact_header)
  123. #endif
  124.                 fprintf(fp," wnd %d",i);
  125.             break;
  126.         case NR4OPDISRQ:    /* Disconnect request */
  127. #ifdef MONITOR
  128.             if (Trace_compact_header)
  129.                 fprintf(fp, " disc %d/%d",uchar(thdr[0]), uchar(thdr[1]));
  130.             else
  131. #endif
  132.                 fprintf(fp,"         disc: ckt %d/%d",
  133.                 uchar(thdr[0]),uchar(thdr[1]));
  134.             break;
  135.         case NR4OPDISAK:    /* Disconnect acknowledgement */
  136. #ifdef MONITOR
  137.             if (Trace_compact_header)
  138.                 fprintf(fp, " disc ack %d/%d", uchar(thdr[0]),uchar(thdr[1]));
  139.             else
  140. #endif
  141.                 fprintf(fp,"         disc ack: ckt %d/%d",
  142.                 uchar(thdr[0]),uchar(thdr[1]));
  143.             break;
  144.         case NR4OPINFO: /* Information (data) */
  145. #ifdef MONITOR
  146.             if (Trace_compact_header)
  147.                 fprintf(fp, " %d/%d", uchar(thdr[0]),uchar(thdr[1]));
  148.             else
  149.             {
  150. #endif
  151.                 fprintf(fp,"         info: ckt %d/%d",
  152.                 uchar(thdr[0]),uchar(thdr[1]));
  153.                 fprintf(fp," txseq %d rxseq %d",
  154.                 uchar(thdr[2]), uchar(thdr[3]));
  155. #ifdef MONITOR
  156.             }
  157. #endif
  158.             break;
  159.         case NR4OPACK:  /* Information acknowledgement */
  160. #ifdef MONITOR
  161.             if (Trace_compact_header)
  162.                 fprintf(fp, " ack %d/%d",uchar(thdr[0]), uchar(thdr[1]));
  163.             else
  164.             {
  165. #endif
  166.                 fprintf(fp,"         info ack: ckt %d/%d",
  167.                 uchar(thdr[0]),uchar(thdr[1]));
  168.                 fprintf(fp," txseq %d rxseq %d",
  169.                 uchar(thdr[2]), uchar(thdr[3]));
  170. #ifdef MONITOR
  171.             }
  172. #endif
  173.             break;
  174.         default:
  175.             fprintf(fp,"         unknown transport type %d",
  176.             thdr[4] & 0x0f) ;
  177.             break;
  178.     }
  179.     if(thdr[4] & NR4CHOKE)
  180.         fprintf(fp," CHOKE");
  181.     if(thdr[4] & NR4NAK)
  182.         fprintf(fp," NAK");
  183.     if(thdr[4] & NR4MORE)
  184.         fprintf(fp," MORE");
  185.     fprintf(fp,"\n");
  186. }
  187.   
  188. #endif /* NETROM */
  189.   
  190.