case ICT_PARAMP: pic->ic_ptr = (char) pa2; for (i=0; i<IC_PADLEN; ++i) pic->ic_pad[i] = 0; break; case ICT_MASKRP: blkcopy(pic->ic_data, &pa2, IP_ALEN); break; case ICT_ECHORQ: if ((int)pa2 > ECHOMAX(pip)) pa2 = (char *)ECHOMAX(pip); for (i=0; i<(int)pa2; ++i) pic->ic_data[i] = i; return (int)pa2; case ICT_MASKRQ: blkcopy(pic->ic_data, &ip_anyaddr, IP_ALEN); return IP_ALEN; }
return 0; }
而下面的代码则显示了计算机在收到ICMP redirect报文后的行为:
// icredirect:处理接收到的ICMP redirect报文,刷新路由缓存 int icredirect(pep) struct ep *pep; { struct route *prt; struct ip *pip, *pip2; struct icmp *pic; IPaddr mask;
pip = (struct ip*)pep->ep_data; pic = (struct icmp*)pip->ip_data; pip2 = (struct ip*)pic->ic_data;
if (pic->ic_code == ICC_HOSTRD) mask = ip_maskall; else netmask(mask, pip2->ip_dst); prt = rtget(pip2->ip_dst, RTF_LOCAL);
if (prt == 0) { freebuf(pep); return OK; }
if (pip->ip_src == prt->rt_gw) { rtdel(pip2->ip_dst, mask); rtadd(pip2->ip_dst, mask, pic->ic_gw, prt->rt_metric, prt->rt_ifnum,IC_RDTTL); }
rtfree(prt); freebuf(pep); return OK; }
University of North Carolina完整的ICMP代码下载地址为:http://www.cs.unc.edu/~dewan/242/s00/xinu-pentium/icmp/
(参考链接: http://dev.yesky.com/158/2667658.shtml)
共3页: 上一页 [1] [2] 3 下一页
|