📄 icmp.lst
字号:
C51 COMPILER V7.06 ICMP 11/26/2004 11:32:46 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE ICMP
OBJECT MODULE PLACED IN .\8052-obj\icmp.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\icmp.c LARGE OPTIMIZE(SIZE) BROWSE INTVECTOR(0X2000) INCDIR(D:\Work\open
-tcp\1-0-2\src\include\) DEFINE(MONITOR,CS8900) DEBUG OBJECTEXTEND CODE SYMBOLS PRINT(.\8052-lst\icmp.lst) PREPRINT(.\805
-2-lst\icmp.i) OBJECT(.\8052-obj\icmp.obj)
stmt level source
1 /*
2 *Copyright (c) 2000-2002 Viola Systems Ltd.
3 *All rights reserved.
4 *
5 *Redistribution and use in source and binary forms, with or without
6 *modification, are permitted provided that the following conditions
7 *are met:
8 *
9 *1. Redistributions of source code must retain the above copyright
10 *notice, this list of conditions and the following disclaimer.
11 *
12 *2. Redistributions in binary form must reproduce the above copyright
13 *notice, this list of conditions and the following disclaimer in the
14 *documentation and/or other materials provided with the distribution.
15 *
16 *3. The end-user documentation included with the redistribution, if
17 *any, must include the following acknowledgment:
18 * "This product includes software developed by Viola
19 * Systems (http://www.violasystems.com/)."
20 *
21 *Alternately, this acknowledgment may appear in the software itself,
22 *if and wherever such third-party acknowledgments normally appear.
23 *
24 *4. The names "OpenTCP" and "Viola Systems" must not be used to
25 *endorse or promote products derived from this software without prior
26 *written permission. For written permission, please contact
27 *opentcp@opentcp.org.
28 *
29 *5. Products derived from this software may not be called "OpenTCP",
30 *nor may "OpenTCP" appear in their name, without prior written
31 *permission of the Viola Systems Ltd.
32 *
33 *THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
34 *WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
35 *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
36 *IN NO EVENT SHALL VIOLA SYSTEMS LTD. OR ITS CONTRIBUTORS BE LIABLE
37 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38 *CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39 *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
40 *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
41 *WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
42 *OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
43 *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 *====================================================================
45 *
46 *OpenTCP is the unified open source TCP/IP stack available on a series
47 *of 8/16-bit microcontrollers, please see <http://www.opentcp.org>.
48 *
49 *For more information on how to network-enable your devices, or how to
50 *obtain commercial technical support for OpenTCP, please see
51 *<http://www.violasystems.com/>.
52 */
53
C51 COMPILER V7.06 ICMP 11/26/2004 11:32:46 PAGE 2
54 /** \file icmp.c
55 * \brief OpenTCP ICMP implementation
56 * \author
57 * \li Jari Lahti (jari.lahti@violasystems.com)
58 * \version 1.0
59 * \date 8.7.2002
60 * \bug
61 * \warning
62 * \todo
63 * \li Add more functionality, not just ICMP Echo request/reply
64 * (possibly Destination unreachable processing)
65 * \li IP address setting option should be runtime or #define
66 * configurable
67 *
68 * OpenTCP ICMP implementation. Functions and other
69 * ICMP-related stuff is declared in inet/tcp_ip.h.
70 */
71
72 #include <inet/debug.h>
*** WARNING C318 IN LINE 72 OF ..\icmp.c: can't open file 'inet/debug.h'
73 #include <inet/datatypes.h>
*** WARNING C318 IN LINE 73 OF ..\icmp.c: can't open file 'inet/datatypes.h'
74 #include <inet/ethernet.h>
*** WARNING C318 IN LINE 74 OF ..\icmp.c: can't open file 'inet/ethernet.h'
75 #include <inet/ip.h>
*** WARNING C318 IN LINE 75 OF ..\icmp.c: can't open file 'inet/ip.h'
76 #include <inet/tcp_ip.h>
*** WARNING C318 IN LINE 76 OF ..\icmp.c: can't open file 'inet/tcp_ip.h'
77 #include <inet/system.h>
*** WARNING C318 IN LINE 77 OF ..\icmp.c: can't open file 'inet/system.h'
78
79 /** \brief Process recieved ICMP datagram
80 * \ingroup periodic_functions
81 * \author
82 * \li Jari Lahti (jari.lahti@violasystems.com)
83 * \date 08.07.2002
84 * \param frame - pointer to received IP frame structure
85 * \param len - length of the received IP datagram (in bytes)
86 * \return
87 * \li -1 - packet not OK (not proper ICMP or not ICMP at all)
88 * \li >=0 - packet OK
89 *
90 * Invoke process_icmp_in whenever IP datagram containing ICMP message
91 * is detected (see main_demo.c for example main loop implementing this).
92 *
93 * This function simply checks correctnes of received ICMP message and
94 * send ICMP replies when requested.
95 *
96 */
97 INT16 process_icmp_in (struct ip_frame* frame, UINT16 len)
*** ERROR C129 IN LINE 97 OF ..\ICMP.C: missing ';' before 'process_icmp_in'
98 {
99 UINT8 type;
100 UINT8 code_;
101 UINT16 checksum;
102 UINT16 i;
103
104
105 /* Is this ICMP? */
106
107 ICMP_DEBUGOUT("Processing ICMP...\n\r");
108
C51 COMPILER V7.06 ICMP 11/26/2004 11:32:46 PAGE 3
109 if( frame->protocol != IP_ICMP ) {
110 ICMP_DEBUGOUT("ERROR: The protocol is not ICMP\n\r");
111 return(-1);
112 }
113
114 /* Calculate checksum for received packet */
115
116 checksum = 0;
117 i = 0;
118
119 NETWORK_RECEIVE_INITIALIZE(frame->buf_index);
120
121 for(i=0; i < len; i++)
122 checksum = ip_checksum(checksum, RECEIVE_NETWORK_B(), (UINT8)i);
123
124 checksum = ~ checksum;
125
126 if(checksum != IP_GOOD_CS) {
127 ICMP_DEBUGOUT("ERROR: ICMP Checksum failed!\n\r");
128 return (-1);
129 }
130
131 ICMP_DEBUGOUT("ICMP Checksum OK\n\r");
132
133 /* Start processing the message */
134
135 NETWORK_RECEIVE_INITIALIZE(frame->buf_index);
136
137 type = RECEIVE_NETWORK_B();
138 code_ = RECEIVE_NETWORK_B();
139
140 /* We have already checked the CS, skip it */
141
142 RECEIVE_NETWORK_B();
143 RECEIVE_NETWORK_B();
144
145 switch(type) {
146 case ICMP_ECHO_REQUEST:
147
148 if(code_ != 0) {
149 ICMP_DEBUGOUT("ERROR:Misformed ICMP ECHO Request\n\r");
150 return(-1);
151 }
152
153 ICMP_DEBUGOUT("ICMP ECHO Request received\n\r");
154
155 /* Is it a packet for setting temporary IP? */
156
157 if(len == (ICMP_ECHOREQ_HLEN + ICMP_TEMPIPSET_DATALEN) )
158 {
159 /* Yep, set temporary IP address */
160
161 ICMP_DEBUGOUT("PING with 102 bytes of data, getting temp. IP\r\n");
162 localmachine.localip = frame->dip;
163
164 }
165
166
167 /* Same IP? */
168
169 if(localmachine.localip != frame->dip)
170 return(-1);
C51 COMPILER V7.06 ICMP 11/26/2004 11:32:46 PAGE 4
171
172 /* Reply it */
173
174 TXBUF[0] = ICMP_ECHO_REPLY;
175 TXBUF[1] = 0;
176 TXBUF[2] = 0;
177 TXBUF[3] = 0;
178
179 /* Copy with truncate if needed */
180
181 if(len > NETWORK_TX_BUFFER_SIZE)
182 len = NETWORK_TX_BUFFER_SIZE;
183
184 /* Calculate Checksum for packet to be sent AND copy it to buffer*/
185
186 checksum = ((UINT16)ICMP_ECHO_REPLY)<<8;
187
188 for(i=4; i<len; i++){
189 checksum = ip_checksum(checksum, TXBUF[i] = RECEIVE_NETWORK_B(), (UINT8)i);
190 }
191
192 checksum = ~ checksum;
193
194 /* Put the checksum on place */
195
196 TXBUF[2] = (UINT8)(checksum>>8);
197 TXBUF[3] = (UINT8)checksum;
198
199 /* Send it */
200
201 process_ip_out(frame->sip, IP_ICMP, 0, 100, &TXBUF[0], len);
202
203 ICMP_DEBUGOUT("ICMP Reply sent\n\r");
204
205 return(0);
206
207
208 break;
209
210 case ICMP_ECHO_REPLY:
211
212 break;
213
214 default: /* Unrecognized ICMP message */
215
216 ICMP_DEBUGOUT("Unrecognized ICMP message\n\r");
217 return(-1);
218 }
219
220 }
221
222
223
224
225
C51 COMPILATION COMPLETE. 6 WARNING(S), 1 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -