home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / network / src_1218.zip / ARPDUMP.C < prev    next >
C/C++ Source or Header  |  1991-03-04  |  2KB  |  77 lines

  1. /* ARP packet tracing routines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include <stdio.h>
  5. #include "global.h"
  6. #include "mbuf.h"
  7. #include "arp.h"
  8. #include "netuser.h"
  9. #include "trace.h"
  10.  
  11. void
  12. arp_dump(fp,bpp)
  13. FILE *fp;
  14. struct mbuf **bpp;
  15. {
  16.     struct arp arp;
  17.     struct arp_type *at;
  18.     int is_ip = 0;
  19.     char tmp[25];
  20.  
  21.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  22.         return;
  23.     fprintf(fp,"ARP: len %d",len_p(*bpp));
  24.     if(ntoharp(&arp,bpp) == -1){
  25.         fprintf(fp," bad packet\n");
  26.         return;
  27.     }
  28.     if(arp.hardware < NHWTYPES)
  29.         at = &Arp_type[arp.hardware];
  30.     else
  31.         at = NULLATYPE;
  32.  
  33.     /* Print hardware type in Ascii if known, numerically if not */
  34.     fprintf(fp," hwtype %s",smsg(Arptypes,NHWTYPES,arp.hardware));
  35.  
  36.     /* Print hardware length only if unknown type, or if it doesn't match
  37.      * the length in the known types table
  38.      */
  39.     if(at == NULLATYPE || arp.hwalen != at->hwalen)
  40.         fprintf(fp," hwlen %u",arp.hwalen);
  41.  
  42.     /* Check for most common case -- upper level protocol is IP */
  43.     if(at != NULLATYPE && arp.protocol == at->iptype){
  44.         fprintf(fp," prot IP");
  45.         is_ip = 1;
  46.     } else {
  47.         fprintf(fp," prot 0x%x prlen %u",arp.protocol,arp.pralen);
  48.     }
  49.     switch(arp.opcode){
  50.     case ARP_REQUEST:
  51.         fprintf(fp," op REQUEST");
  52.         break;
  53.     case ARP_REPLY:
  54.         fprintf(fp," op REPLY");
  55.         break;
  56.     case REVARP_REQUEST:
  57.         fprintf(fp," op REVERSE REQUEST");
  58.         break;
  59.     case REVARP_REPLY:
  60.         fprintf(fp," op REVERSE REPLY");
  61.         break;
  62.     default:
  63.         fprintf(fp," op %u",arp.opcode);
  64.         break;
  65.     }
  66.     fprintf(fp,"\n");
  67.     fprintf(fp,"sender");
  68.     if(is_ip)
  69.         fprintf(fp," IPaddr %s",inet_ntoa(arp.sprotaddr));
  70.     fprintf(fp," hwaddr %s\n",at->format(tmp,arp.shwaddr));
  71.  
  72.     fprintf(fp,"target");
  73.     if(is_ip)
  74.         fprintf(fp," IPaddr %s",inet_ntoa(arp.tprotaddr));
  75.     fprintf(fp," hwaddr %s\n",at->format(tmp,arp.thwaddr));
  76. }
  77.