home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / internet / tcpipsrc / ARP / c / ARPDUMP < prev   
Text File  |  1994-06-24  |  2KB  |  58 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "timer.h"
  5. #include "netuser.h"
  6. #include "arp.h"
  7. #include "misc.h"
  8.  
  9. void arp_dump(struct mbuf **bpp)
  10. {
  11.         struct arp arp;
  12.         struct arp_type *at;
  13.         int is_ip = 0;
  14.  
  15.         if(bpp == NULLBUFP || *bpp == NULLBUF)
  16.                 return;
  17.         twprintf("ARP: len %d",len_mbuf(*bpp));
  18.         if(ntoharp(&arp,bpp) == -1){
  19.                 twprintf(" bad packet\n");
  20.                 return;
  21.         }
  22.         /* Print hardware type in Ascii if known, numerically if not */
  23.         if(arp.hardware < NHWTYPES){
  24.                 at = &arp_type[arp.hardware];
  25.                 twprintf(" hwtype %s",arptypes[arp.hardware]);
  26.         } else {
  27.                 at = NULLATYPE;
  28.                 twprintf(" hwtype %u",arp.hardware);
  29.         }
  30.         /* Print hardware length only if unknown type, or if it doesn't match
  31.          * the length in the known types table
  32.          */
  33.         if(at == NULLATYPE || arp.hwalen != at->hwalen)
  34.                 twprintf(" hwlen %u",arp.hwalen);
  35.  
  36.         /* Check for most common case -- upper level protocol is IP */
  37.         if(at != NULLATYPE && arp.protocol == at->iptype){
  38.                 twprintf(" prot IP");
  39.                 is_ip = 1;
  40.         } else {
  41.                 twprintf(" prot 0x%x prlen %u",arp.protocol,arp.pralen);
  42.         }
  43.         switch(arp.opcode){
  44.         case ARP_REQUEST:
  45.                 twprintf(" op REQUEST");
  46.                 break;
  47.         case ARP_REPLY:
  48.                 twprintf(" op REPLY");
  49.                 break;
  50.         default:
  51.                 twprintf(" op %u",arp.opcode);
  52.                 break;
  53.         }
  54.         if(is_ip)
  55.                 twprintf(" target %s",inet_ntoa(arp.tprotaddr));
  56.         twprintf("\n");
  57. }
  58.