home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / network / src_1218.zip / RIPDUMP.C < prev    next >
C/C++ Source or Header  |  1991-01-27  |  1KB  |  59 lines

  1. /* RIP packet tracing
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include "global.h"
  5. #include "mbuf.h"
  6. #include "netuser.h"
  7. #include "timer.h"
  8. #include "rip.h"
  9. #include "trace.h"
  10.  
  11. void
  12. rip_dump(fp,bpp)
  13. FILE *fp;
  14. struct mbuf **bpp;
  15. {
  16.     struct rip_route entry;
  17.     int i;
  18.     int cmd,version;
  19.     int16 len;
  20.     
  21.     fprintf(fp,"RIP: ");
  22.     cmd = PULLCHAR(bpp);
  23.     version = PULLCHAR(bpp);
  24.     switch(cmd){
  25.     case RIPCMD_REQUEST:
  26.         fprintf(fp,"REQUEST");
  27.         break;
  28.     case RIPCMD_RESPONSE:
  29.         fprintf(fp,"RESPONSE");
  30.         break;
  31.     default:
  32.         fprintf(fp," cmd %u",cmd);
  33.         break;
  34.     }
  35.  
  36.     pull16(bpp);    /* remove one word of padding */
  37.  
  38.     len = len_p(*bpp);
  39.     fprintf(fp," vers %u entries %u:\n",version,len / RIPROUTE);
  40.  
  41.     i = 0;
  42.     while(len >= RIPROUTE){
  43.         /* Pull an entry off the packet */
  44.         pullentry(&entry,bpp);
  45.         len -= RIPROUTE;
  46.  
  47.         if(entry.addr_fam != RIP_IPFAM) {
  48.             /* Skip non-IP addresses */
  49.             continue;
  50.         }
  51.         fprintf(fp,"%-16s%-3u ",inet_ntoa(entry.target),entry.metric);
  52.         if((++i % 3) == 0){
  53.             putc('\n',fp);
  54.         }
  55.     }
  56.     if((i % 3) != 0)
  57.         putc('\n',fp);
  58. }
  59.