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

网络

开发平台:

Unix_Linux

  1. /* icsetbuf.c - icsetbuf */
  2. #include <conf.h>
  3. #include <kernel.h>
  4. #include <network.h>
  5. /*------------------------------------------------------------------------
  6.  *  icsetbuf -  set up a buffer for an ICMP message
  7.  *------------------------------------------------------------------------
  8.  */
  9. struct ep *
  10. icsetbuf(int type, void *pa1, Bool *pisresp, Bool *piserr)
  11. {
  12. struct ep *pep;
  13. *pisresp = *piserr = FALSE;
  14. switch (type) {
  15. case ICT_REDIRECT:
  16. pep = (struct ep *)getbuf(Net.netpool);
  17. if ((int)pep == SYSERR)
  18. return 0;
  19. memcpy(pep, pa1, MAXNETBUF);
  20. pa1 = (void *)pep;
  21. *piserr = TRUE;
  22. break;
  23. case ICT_DESTUR:
  24. case ICT_SRCQ:
  25. case ICT_TIMEX:
  26. case ICT_PARAMP:
  27. pep = (struct ep *)pa1;
  28. *piserr = TRUE;
  29. break;
  30. case ICT_ECHORP:
  31. case ICT_INFORP:
  32. case ICT_MASKRP:
  33. pep = (struct ep *)pa1;
  34. *pisresp = TRUE;
  35. break;
  36. case ICT_ECHORQ:
  37. case ICT_TIMERQ:
  38. case ICT_INFORQ:
  39. case ICT_MASKRQ:
  40. pep = (struct ep *)getbuf(Net.lrgpool);
  41. if ((int)pep == SYSERR)
  42. return 0;
  43. break;
  44. case ICT_TIMERP: /* Not Implemented */
  45. /* IcmpOutTimestampsReps++; */
  46. IcmpOutErrors--; /* Kludge: we increment above */
  47. freebuf(pa1);
  48. return 0;
  49. default:
  50. kprintf("icsetbuf: unknown ICMP type (%d)n", type);
  51. return 0;
  52. }
  53. if (*piserr)
  54. *pisresp = TRUE;
  55. switch (type) { /* Update MIB Statistics */
  56. case ICT_ECHORP: IcmpOutEchos++; break;
  57. case ICT_ECHORQ: IcmpOutEchoReps++; break;
  58. case ICT_DESTUR: IcmpOutDestUnreachs++; break;
  59. case ICT_SRCQ: IcmpOutSrcQuenchs++; break;
  60. case ICT_REDIRECT: IcmpOutRedirects++; break;
  61. case ICT_TIMEX: IcmpOutTimeExcds++; break;
  62. case ICT_PARAMP: IcmpOutParmProbs++; break;
  63. case ICT_TIMERQ: IcmpOutTimestamps++; break;
  64. case ICT_TIMERP: IcmpOutTimestampReps++; break;
  65. case ICT_MASKRQ: IcmpOutAddrMasks++; break;
  66. case ICT_MASKRP: IcmpOutAddrMaskReps++; break;
  67. }
  68. return pep;
  69. }