- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
icmp_in.c,v
资源名称:icmp.rar [点击查看]
上传用户:lywr2008
上传日期:2022-05-26
资源大小:9k
文件大小:2k
源码类别:
网络
开发平台:
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
- @/* icmp_in.c - icmp_in */
- #include <conf.h>
- #include <kernel.h>
- #include <network.h>
- /*------------------------------------------------------------------------
- * icmp_in - handle ICMP packet coming in from the network
- *------------------------------------------------------------------------
- */
- int icmp_in(pni, pep)
- struct netif *pni; /* not used */
- struct ep *pep;
- {
- struct ip *pip;
- struct icmp *pic;
- int i, len;
- pip = (struct ip *)pep->ep_data;
- pic = (struct icmp *) pip->ip_data;
- #ifdef notdef
- { STATWORD ps;
- kprintf("icmp_in:n");
- pdump(pep);
- }
- #endif
- len = pip->ip_len - IP_HLEN(pip);
- if (cksum(pic, len)) {
- kprintf("icmp_in: BAD CKSUM %X ic_cksum %X len %dn", cksum(pic, len),
- pic->ic_cksum, len);
- IcmpInErrors++;
- freebuf(pep);
- return SYSERR;
- }
- IcmpInMsgs++;
- switch(pic->ic_type) {
- case ICT_ECHORQ:
- IcmpInEchos++;
- return icmp(ICT_ECHORP, 0, pip->ip_src, pep, 0);
- case ICT_MASKRQ:
- IcmpInAddrMasks++;
- if (!gateway) {
- freebuf(pep);
- return OK;
- }
- pic->ic_type = (char) ICT_MASKRP;
- *(IPaddr *)pic->ic_data = netmask(pip->ip_dst);
- break;
- case ICT_MASKRP:
- IcmpInAddrMaskReps++;
- for (i=0; i<Net.nif; ++i)
- if (nif[i].ni_ip == pip->ip_dst)
- break;
- if (i != Net.nif) {
- setmask(i, *(IPaddr *)pic->ic_data);
- send(pic->ic_id, ICT_MASKRP);
- }
- freebuf(pep);
- return OK;
- case ICT_ECHORP:
- IcmpInEchoReps++;
- if (send(pic->ic_id, pep) != OK)
- freebuf(pep);
- return OK;
- case ICT_REDIRECT:
- IcmpInRedirects++;
- icredirect(pep);
- return OK;
- case ICT_DESTUR: IcmpInDestUnreachs++; freebuf(pep); return OK;
- case ICT_SRCQ: IcmpInSrcQuenchs++; freebuf(pep); return OK;
- case ICT_TIMEX: IcmpInTimeExcds++; freebuf(pep); return OK;
- case ICT_PARAMP: IcmpInParmProbs++; freebuf(pep); return OK;
- case ICT_TIMERQ: IcmpInTimestamps++; freebuf(pep); return OK;
- case ICT_TIMERP: IcmpInTimestampReps++; freebuf(pep); return OK;
- default:
- IcmpInErrors++;
- freebuf(pep);
- return OK;
- }
- icsetsrc(pip);
- len = pip->ip_len - IP_HLEN(pip);
- pic->ic_cksum = 0;
- pic->ic_cksum = cksum(pic, len);
- IcmpOutMsgs++;
- ipsend(pip->ip_dst, pep, len, IPT_ICMP, IPP_INCTL, IP_TTL);
- return OK;
- }
- @