if (!icerrok(pep))
{
freebuf(pep);
return OK;
} blkcopy(pic->ic_data, pip, IP_HLEN(pip) + 8);
datalen += IP_HLEN(pip) + 8;
}
icsetsrc(pip);
}
else
pip->ip_src = ip_anyaddr;
pip->ip_dst = dst;
pic->ic_type = (char)type;
pic->ic_code = (char)code;
if (!isresp)
{
if (type == ICT_ECHORQ)
pic->ic_seq = (int)pa1;
else
pic->ic_seq = 0;
pic->ic_id = getpid();
}
datalen += icsetdata(type, pip, pa2);
pic->ic_cksum = 0;
pic->ic_cksum = cksum(pic, datalen);
ipsend(dst, pep, datalen, IPT_ICMP, IPP_INCTL, IP_TTL);
return OK;
}
// icsetdata:根据报文类型填充相应的数据
int icsetdata(type, pip, pa2)
int type;
struct ip *pip;
char *pa2;
{
struct icmp *pic = (struct icmp *)pip->ip_data;
int i, len;
switch (type) {
case ICT_ECHORP:
len = pip->ip_len - IP_HLEN(pip) - IC_HLEN;
if (isodd(len))
pic->ic_data[len] = 0; /* so cksum works */
return len;
case ICT_DESTUR:
case ICT_SRCQ:
case ICT_TIMEX:
pic->ic_mbz = 0; /* must be 0 */
break;
case ICT_REDIRECT:
pic->ic_gw = (IPaddr)pa2;
break;