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

  1. /* ICMP header tracing
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include <stdio.h>
  5. #include "global.h"
  6. #include "mbuf.h"
  7. #include "internet.h"
  8. #include "netuser.h"
  9. #include "icmp.h"
  10. #include "trace.h"
  11. #include "ip.h"
  12.  
  13. /* Dump an ICMP header */
  14. void
  15. icmp_dump(fp,bpp,source,dest,check)
  16. FILE *fp;
  17. struct mbuf **bpp;
  18. int32 source,dest;
  19. int check;        /* If 0, bypass checksum verify */
  20. {
  21.     struct icmp icmp;
  22.     int16 csum;
  23.  
  24.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  25.         return;
  26.     csum = cksum(NULLHEADER,*bpp,len_p(*bpp));
  27.     
  28.     ntohicmp(&icmp,bpp);
  29.     
  30.     fprintf(fp,"ICMP: type %s",smsg(Icmptypes,ICMP_TYPES,uchar(icmp.type)));
  31.  
  32.     switch(uchar(icmp.type)){
  33.     case ICMP_DEST_UNREACH:
  34.         fprintf(fp," code %s",smsg(Unreach,NUNREACH,uchar(icmp.code)));
  35.         break;
  36.     case ICMP_REDIRECT:
  37.         fprintf(fp," code %s",smsg(Redirect,NREDIRECT,uchar(icmp.code)));
  38.         fprintf(fp," new gateway %s",inet_ntoa(icmp.args.address));
  39.         break;
  40.     case ICMP_TIME_EXCEED:
  41.         fprintf(fp," code %s",smsg(Exceed,NEXCEED,uchar(icmp.code)));
  42.         break;
  43.     case ICMP_PARAM_PROB:
  44.         fprintf(fp," pointer %u",icmp.args.pointer);
  45.         break;
  46.     case ICMP_ECHO:
  47.     case ICMP_ECHO_REPLY:
  48.     case ICMP_INFO_RQST:
  49.     case ICMP_INFO_REPLY:
  50.     case ICMP_TIMESTAMP:
  51.     case ICMP_TIME_REPLY:
  52.         fprintf(fp," id %u seq %u",icmp.args.echo.id,icmp.args.echo.seq);
  53.         break;
  54.     }
  55.     if(check && csum != 0){
  56.         fprintf(fp," CHECKSUM ERROR (%u)",csum);
  57.     }
  58.     putc('\n',fp);
  59.     /* Dump the offending IP header, if any */
  60.     switch(icmp.type){
  61.     case ICMP_DEST_UNREACH:
  62.     case ICMP_TIME_EXCEED:
  63.     case ICMP_PARAM_PROB:
  64.     case ICMP_QUENCH:
  65.     case ICMP_REDIRECT:
  66.         fprintf(fp,"Returned ");
  67.         ip_dump(fp,bpp,0);
  68.     }
  69. }
  70.  
  71.