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

网络

开发平台:

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. @/* icredirect.c - icredirect */
  19. #include <conf.h>
  20. #include <kernel.h>
  21. #include <network.h>
  22. struct route *rtget();
  23. /*------------------------------------------------------------------------
  24.  *  icredirect -  handle an incoming ICMP redirect
  25.  *------------------------------------------------------------------------
  26.  */
  27. int icredirect(pep)
  28. struct ep *pep;
  29. {
  30. struct route *prt;
  31. struct ip *pip, *pip2;
  32. struct icmp *pic;
  33. IPaddr mask;
  34. pip = (struct ip *)pep->ep_data;
  35. pic = (struct icmp *)pip->ip_data;
  36. pip2 = (struct ip *)pic->ic_data;
  37. if (pic->ic_code == ICC_HOSTRD)
  38. mask = ip_maskall;
  39. else
  40. mask = netmask(pip2->ip_dst);
  41. prt = rtget(pip2->ip_dst, RTF_LOCAL);
  42. if (prt == 0) {
  43. freebuf(pep);
  44. return OK;
  45. }
  46. if (pip->ip_src == prt->rt_gw) {
  47. rtdel(pip2->ip_dst, mask);
  48. rtadd(pip2->ip_dst, mask, pic->ic_gw, prt->rt_metric,
  49. prt->rt_ifnum, IC_RDTTL);
  50. }
  51. rtfree(prt);
  52. freebuf(pep);
  53. return OK;
  54. }
  55. @