home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 024 / psi110g.zip / ICMPDUMP.C < prev    next >
C/C++ Source or Header  |  1994-04-17  |  3KB  |  90 lines

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