home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 3 / hamradioversion3.0examsandprograms1992.iso / packet / n17jsrc / icmpdump.c < prev    next >
C/C++ Source or Header  |  1990-12-11  |  2KB  |  68 lines

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