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

  1. /* RIP packet tracing
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  *
  4.  *  Changes Copyright (c) 1993 Jeff White - N0POY, All Rights Reserved.
  5.  *  Permission granted for non-commercial copying and use, provided
  6.  *  this notice is retained.
  7.  *
  8.  * Rehack for RIP-2 (RFC1388) by N0POY 4/1993
  9.  *
  10.  * Beta release 11/10/93 V0.91
  11.  *
  12.  * 2/19/94 release V1.0
  13.  *
  14.  */
  15. #include "global.h"
  16. #ifdef RIP
  17. #include "mbuf.h"
  18. #include "netuser.h"
  19. #include "timer.h"
  20. #include "rip.h"
  21. #include "trace.h"
  22.   
  23. // from trace.c
  24. void fmtline __ARGS((FILE *fp,int16 addr,char *buf,int16 len));
  25.   
  26. void
  27. rip_dump(fp,bpp)
  28. FILE *fp;
  29. struct mbuf **bpp;
  30. {
  31.     struct rip_route entry;
  32.     struct rip_authenticate *ripauth;
  33.     int i;
  34.     int cmd,version;
  35.     int16 len;
  36.     int16 domain;
  37.     char ipaddmask[25];
  38.   
  39.     fprintf(fp,"RIP: ");
  40.     cmd = PULLCHAR(bpp);
  41.     version = PULLCHAR(bpp);
  42.     switch(cmd){
  43.         case RIPCMD_REQUEST:
  44.             fprintf(fp,"REQUEST");
  45.             break;
  46.         case RIPCMD_RESPONSE:
  47.             fprintf(fp,"RESPONSE");
  48.             break;
  49.         default:
  50.             fprintf(fp," cmd %u",cmd);
  51.             break;
  52.     }
  53.   
  54.     domain = pull16(bpp);
  55.   
  56.     len = len_p(*bpp);
  57.     fprintf(fp," vers %u entries %u domain %u:\n",version,len / RIP_ENTRY, domain);
  58.   
  59.     i = 0;
  60.     while(len >= RIP_ENTRY){
  61.         /* Pull an entry off the packet */
  62.         pullentry(&entry,bpp);
  63.         len -= RIP_ENTRY;
  64.   
  65.         if (entry.rip_family == RIP_AF_AUTH) {
  66.             ripauth = (struct rip_authenticate *)&entry;
  67.             fprintf(fp,"RIP: AUTHENTICATION Type %d  Password: %.16s\n",
  68.             ripauth->rip_auth_type,ripauth->rip_auth_str);
  69.             continue;
  70.         }
  71.   
  72.         if(entry.rip_family != RIP_AF_INET) {
  73.             /* Skip non-IP addresses */
  74.             continue;
  75.         }
  76.   
  77.         if (version >= RIP_VERSION_2) {
  78.             sprintf(ipaddmask, "%s/%-4d", inet_ntoa(entry.rip_dest),
  79.             mask2width(entry.rip_dest_mask));
  80.         } else {
  81.             sprintf(ipaddmask, "%s/??", inet_ntoa(entry.rip_dest));
  82.         }
  83.         fprintf(fp,"%-20s%-3u",ipaddmask, entry.rip_metric);
  84.   
  85.         if((++i % 3) == 0){
  86.             putc('\n',fp);
  87.         }
  88.     }
  89.     if((i % 3) != 0)
  90.         putc('\n',fp);
  91. }
  92.   
  93. #endif /* RIP */
  94.   
  95.