icmpdump.c
上传用户:hepax88
上传日期:2007-01-03
资源大小:1101k
文件大小:2k
源码类别:

TCP/IP协议栈

开发平台:

Visual C++

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