home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR3 / KA9Q212.ZIP / ARPDUMP.C < prev    next >
C/C++ Source or Header  |  1993-07-16  |  2KB  |  84 lines

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