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

  1. /* ARP packet tracing routines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include "global.h"
  5. #include "mbuf.h"
  6. #include "arp.h"
  7. #include "netuser.h"
  8. #include "trace.h"
  9.   
  10. void
  11. arp_dump(fp,bpp)
  12. FILE *fp;
  13. struct mbuf **bpp;
  14. {
  15.     struct arp arp;
  16.     struct arp_type *at;
  17.     int is_ip = 0;
  18.     char tmp[25];
  19.   
  20.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  21.         return;
  22. #ifdef MONITOR
  23.     if (Trace_compact_header)
  24.     {
  25.       /* it's different enough that we just do it here */
  26.       /* except for the setup, that is... */
  27.         if (ntoharp(&arp,bpp) == -1)
  28.         {
  29.             fprintf(fp, "bad packet\n");
  30.             return;
  31.         }
  32.         if (arp.hardware < NHWTYPES)
  33.             at = &Arp_type[arp.hardware];
  34.         else
  35.             at = NULLATYPE;
  36.         if (at != NULLATYPE && arp.protocol == at->iptype)
  37.             is_ip = 1;
  38.         switch (arp.opcode)
  39.         {
  40.             case ARP_REQUEST:
  41.             case REVARP_REQUEST:
  42.                 fprintf(fp, "REQ");
  43.                 break;
  44.             case ARP_REPLY:
  45.             case REVARP_REPLY:
  46.                 fprintf(fp, "REP");
  47.                 break;
  48.             default:
  49.                 fprintf(fp, "%u", arp.opcode);
  50.                 break;
  51.         }
  52.         if (is_ip)
  53.             fprintf(fp, " %s@", inet_ntoa(arp.sprotaddr));
  54.         if (at)
  55.             fprintf(fp, "%s->", at->format(tmp, arp.shwaddr));
  56.         if (is_ip)
  57.             fprintf(fp, "%s@", inet_ntoa(arp.tprotaddr));
  58.         if (at)
  59.             fprintf(fp, "%s", at->format(tmp, arp.thwaddr));
  60.         fprintf(fp, "\n");
  61.         return;
  62.     }
  63. #endif
  64.   
  65.     fprintf(fp,"ARP: len %d",len_p(*bpp));
  66.     if(ntoharp(&arp,bpp) == -1){
  67.         fprintf(fp," bad packet\n");
  68.         return;
  69.     }
  70.     if(arp.hardware < NHWTYPES)
  71.         at = &Arp_type[arp.hardware];
  72.     else
  73.         at = NULLATYPE;
  74.   
  75.     /* Print hardware type in Ascii if known, numerically if not */
  76.     fprintf(fp," hwtype %s",smsg(Arptypes,NHWTYPES,arp.hardware));
  77.   
  78.     /* Print hardware length only if unknown type, or if it doesn't match
  79.      * the length in the known types table
  80.      */
  81.     if(at == NULLATYPE || arp.hwalen != at->hwalen)
  82.         fprintf(fp," hwlen %u",arp.hwalen);
  83.   
  84.     /* Check for most common case -- upper level protocol is IP */
  85.     if(at != NULLATYPE && arp.protocol == at->iptype){
  86.         fprintf(fp," prot IP");
  87.         is_ip = 1;
  88.     } else {
  89.         fprintf(fp," prot 0x%x prlen %u",arp.protocol,arp.pralen);
  90.     }
  91.     switch(arp.opcode){
  92.         case ARP_REQUEST:
  93.             fprintf(fp," op REQUEST");
  94.             break;
  95.         case ARP_REPLY:
  96.             fprintf(fp," op REPLY");
  97.             break;
  98.         case REVARP_REQUEST:
  99.             fprintf(fp," op REVERSE REQUEST");
  100.             break;
  101.         case REVARP_REPLY:
  102.             fprintf(fp," op REVERSE REPLY");
  103.             break;
  104.         default:
  105.             fprintf(fp," op %u",arp.opcode);
  106.             break;
  107.     }
  108.     fprintf(fp,"\n");
  109.     fprintf(fp,"sender");
  110.     if(is_ip)
  111.         fprintf(fp," IPaddr %s",inet_ntoa(arp.sprotaddr));
  112.     fprintf(fp," hwaddr %s\n",at->format(tmp,arp.shwaddr));
  113.   
  114.     fprintf(fp,"target");
  115.     if(is_ip)
  116.         fprintf(fp," IPaddr %s",inet_ntoa(arp.tprotaddr));
  117.     fprintf(fp," hwaddr %s\n",at->format(tmp,arp.thwaddr));
  118. }
  119.