icsetdata.c,v
资源名称:icmp.rar [点击查看]
上传用户:lywr2008
上传日期:2022-05-26
资源大小:9k
文件大小:1k
源码类别:
网络
开发平台:
Unix_Linux
- head 1.1;
- access;
- symbols;
- locks
- dls:1.1; strict;
- comment @ * @;
- 1.1
- date 97.09.21.19.26.41; author dls; state Dist;
- branches;
- next ;
- desc
- @@
- 1.1
- log
- @pre-3e code
- @
- text
- @/* icsetdata.c - icsetdata */
- #include <conf.h>
- #include <kernel.h>
- #include <network.h>
- /* ECHOMAX must be an even number */
- #define ECHOMAX(pip) (MAXLRGBUF-IC_HLEN-IP_HLEN(pip)-EP_HLEN-EP_CRC)
- /*------------------------------------------------------------------------
- * icsetdata - set the data section. Return value is data length
- *------------------------------------------------------------------------
- */
- int icsetdata(type, pip, pa2)
- int type;
- struct ip *pip;
- void *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;
- 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 ((unsigned)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;
- }
- @