icmp_in.c,v
上传用户:lywr2008
上传日期:2022-05-26
资源大小:9k
文件大小:2k
源码类别:

网络

开发平台:

Unix_Linux

  1. head 1.1;
  2. access;
  3. symbols;
  4. locks
  5. dls:1.1; strict;
  6. comment @ * @;
  7. 1.1
  8. date 97.09.21.19.26.41; author dls; state Dist;
  9. branches;
  10. next ;
  11. desc
  12. @@
  13. 1.1
  14. log
  15. @pre-3e code
  16. @
  17. text
  18. @/* icmp_in.c - icmp_in */
  19. #include <conf.h>
  20. #include <kernel.h>
  21. #include <network.h>
  22. /*------------------------------------------------------------------------
  23.  *  icmp_in  -  handle ICMP packet coming in from the network
  24.  *------------------------------------------------------------------------
  25.  */
  26. int icmp_in(pni, pep)
  27. struct netif *pni; /* not used */
  28. struct ep *pep;
  29. {
  30. struct ip *pip;
  31. struct icmp *pic;
  32. int i, len;
  33. pip = (struct ip *)pep->ep_data;
  34. pic = (struct icmp *) pip->ip_data;
  35. #ifdef notdef
  36. { STATWORD ps;
  37. kprintf("icmp_in:n");
  38. pdump(pep);
  39. }
  40. #endif
  41. len = pip->ip_len - IP_HLEN(pip);
  42. if (cksum(pic, len)) {
  43. kprintf("icmp_in: BAD CKSUM %X ic_cksum %X len %dn", cksum(pic, len),
  44. pic->ic_cksum, len);
  45. IcmpInErrors++;
  46. freebuf(pep);
  47. return SYSERR;
  48. }
  49. IcmpInMsgs++;
  50. switch(pic->ic_type) {
  51. case ICT_ECHORQ:
  52. IcmpInEchos++;
  53. return icmp(ICT_ECHORP, 0, pip->ip_src, pep, 0);
  54. case ICT_MASKRQ:
  55. IcmpInAddrMasks++;
  56. if (!gateway) {
  57. freebuf(pep);
  58. return OK;
  59. }
  60. pic->ic_type = (char) ICT_MASKRP;
  61. *(IPaddr *)pic->ic_data = netmask(pip->ip_dst);
  62. break;
  63. case ICT_MASKRP:
  64. IcmpInAddrMaskReps++;
  65. for (i=0; i<Net.nif; ++i)
  66. if (nif[i].ni_ip == pip->ip_dst)
  67. break;
  68. if (i != Net.nif) {
  69. setmask(i, *(IPaddr *)pic->ic_data);
  70. send(pic->ic_id, ICT_MASKRP);
  71. }
  72. freebuf(pep);
  73. return OK;
  74. case ICT_ECHORP:
  75. IcmpInEchoReps++;
  76. if (send(pic->ic_id, pep) != OK)
  77. freebuf(pep);
  78. return OK;
  79. case ICT_REDIRECT:
  80. IcmpInRedirects++;
  81. icredirect(pep);
  82. return OK;
  83. case ICT_DESTUR: IcmpInDestUnreachs++; freebuf(pep); return OK;
  84. case ICT_SRCQ:  IcmpInSrcQuenchs++; freebuf(pep); return OK;
  85. case ICT_TIMEX:  IcmpInTimeExcds++; freebuf(pep); return OK;
  86. case ICT_PARAMP: IcmpInParmProbs++; freebuf(pep); return OK;
  87. case ICT_TIMERQ: IcmpInTimestamps++; freebuf(pep); return OK;
  88. case ICT_TIMERP: IcmpInTimestampReps++; freebuf(pep); return OK;
  89. default:
  90. IcmpInErrors++;
  91. freebuf(pep);
  92. return OK;
  93. }
  94. icsetsrc(pip);
  95. len = pip->ip_len - IP_HLEN(pip);
  96. pic->ic_cksum = 0;
  97. pic->ic_cksum = cksum(pic, len);
  98. IcmpOutMsgs++;
  99. ipsend(pip->ip_dst, pep, len, IPT_ICMP, IPP_INCTL, IP_TTL);
  100. return OK;
  101. }
  102. @