| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 6 | kaklik | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> |
||
| 3 | <title>Procyon AVRlib: net/icmp.c Source File</title> |
||
| 4 | <link href="dox.css" rel="stylesheet" type="text/css"> |
||
| 5 | </head><body> |
||
| 6 | <!-- Generated by Doxygen 1.4.2 --> |
||
| 7 | <div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div> |
||
| 8 | <div class="nav"> |
||
| 9 | <a class="el" href="dir_000001.html">net</a></div> |
||
| 10 | <h1>icmp.c</h1><a href="icmp_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file icmp.c \brief ICMP Protocol Library. */</span> |
||
| 11 | 00002 <span class="comment">//*****************************************************************************</span> |
||
| 12 | 00003 <span class="comment">//</span> |
||
| 13 | 00004 <span class="comment">// File Name : 'icmp.c'</span> |
||
| 14 | 00005 <span class="comment">// Title : ICMP (Internet Control Message Protocol) Protocol Library</span> |
||
| 15 | 00006 <span class="comment">// Author : Pascal Stang</span> |
||
| 16 | 00007 <span class="comment">// Created : 9/10/2004</span> |
||
| 17 | 00008 <span class="comment">// Revised : 7/3/2005</span> |
||
| 18 | 00009 <span class="comment">// Version : 0.1</span> |
||
| 19 | 00010 <span class="comment">// Target MCU : Atmel AVR series</span> |
||
| 20 | 00011 <span class="comment">// Editor Tabs : 4</span> |
||
| 21 | 00012 <span class="comment">//</span> |
||
| 22 | 00013 <span class="comment">//*****************************************************************************</span> |
||
| 23 | 00014 |
||
| 24 | 00015 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span> |
||
| 25 | 00016 <span class="preprocessor">#include "<a class="code" href="net_8h.html">net.h</a>"</span> |
||
| 26 | 00017 <span class="preprocessor">#include "<a class="code" href="nic_8h.html">nic.h</a>"</span> |
||
| 27 | 00018 <span class="preprocessor">#include "<a class="code" href="arp_8h.html">arp.h</a>"</span> |
||
| 28 | 00019 <span class="preprocessor">#include "<a class="code" href="icmp_8h.html">icmp.h</a>"</span> |
||
| 29 | 00020 |
||
| 30 | 00021 <span class="preprocessor">#include "<a class="code" href="rprintf_8h.html">rprintf.h</a>"</span> |
||
| 31 | 00022 <span class="preprocessor">#include "<a class="code" href="debug_8h.html">debug.h</a>"</span> |
||
| 32 | 00023 |
||
| 33 | 00024 <span class="comment">//extern void nicSend(unsigned int len, unsigned char* packet);</span> |
||
| 34 | 00025 |
||
| 35 | 00026 <span class="comment">// global variables</span> |
||
| 36 | 00027 |
||
| 37 | 00028 |
||
| 38 | 00029 <span class="comment">// functions</span> |
||
| 39 | <a name="l00030"></a><a class="code" href="group__icmp.html#ga0">00030</a> <span class="keywordtype">void</span> <a class="code" href="group__icmp.html#ga0">icmpInit</a>(<span class="keywordtype">void</span>) |
||
| 40 | 00031 { |
||
| 41 | 00032 } |
||
| 42 | 00033 |
||
| 43 | <a name="l00034"></a><a class="code" href="group__icmp.html#ga1">00034</a> <span class="keywordtype">void</span> <a class="code" href="group__icmp.html#ga1">icmpIpIn</a>(icmpip_hdr* packet) |
||
| 44 | 00035 { |
||
| 45 | 00036 <span class="comment">// check ICMP type</span> |
||
| 46 | 00037 <span class="keywordflow">switch</span>(packet->icmp.type) |
||
| 47 | 00038 { |
||
| 48 | 00039 <span class="keywordflow">case</span> ICMP_TYPE_ECHOREQUEST: |
||
| 49 | 00040 <span class="comment">// echo request</span> |
||
| 50 | 00041 <a class="code" href="group__icmp.html#ga2">icmpEchoRequest</a>(packet); |
||
| 51 | 00042 <span class="keywordflow">break</span>; |
||
| 52 | 00043 <span class="keywordflow">default</span>: |
||
| 53 | 00044 <span class="keywordflow">break</span>; |
||
| 54 | 00045 } |
||
| 55 | 00046 } |
||
| 56 | 00047 |
||
| 57 | <a name="l00048"></a><a class="code" href="group__icmp.html#ga2">00048</a> <span class="keywordtype">void</span> <a class="code" href="group__icmp.html#ga2">icmpEchoRequest</a>(icmpip_hdr* packet) |
||
| 58 | 00049 { |
||
| 59 | 00050 uint32_t tempIp; |
||
| 60 | 00051 |
||
| 61 | 00052 <span class="comment">// change type to reply</span> |
||
| 62 | 00053 packet->icmp.type = ICMP_TYPE_ECHOREPLY; |
||
| 63 | 00054 <span class="comment">// recalculate checksum</span> |
||
| 64 | 00055 packet->icmp.icmpchksum = 0; |
||
| 65 | 00056 packet->icmp.icmpchksum = <a class="code" href="group__net.html#ga4">netChecksum</a>((u08*)&packet->icmp, <a class="code" href="group__net.html#ga2">htons</a>(packet->ip.len)-IP_HEADER_LEN); |
||
| 66 | 00057 <span class="comment">// return to sender</span> |
||
| 67 | 00058 tempIp = packet->ip.destipaddr; |
||
| 68 | 00059 packet->ip.destipaddr = packet->ip.srcipaddr; |
||
| 69 | 00060 packet->ip.srcipaddr = tempIp; |
||
| 70 | 00061 <span class="comment">// add ethernet routing</span> |
||
| 71 | 00062 <a class="code" href="group__arp.html#ga4">arpIpOut</a>((<span class="keyword">struct</span> netEthIpHeader*)(((u08*)packet)-ETH_HEADER_LEN), 0); |
||
| 72 | 00063 |
||
| 73 | 00064 <span class="comment">// debugging</span> |
||
| 74 | 00065 <span class="preprocessor"> #if NET_DEBUG >= 2</span> |
||
| 75 | 00066 <span class="preprocessor"></span> <a class="code" href="group__icmp.html#ga3">icmpPrintHeader</a>(packet); |
||
| 76 | 00067 <span class="comment">//debugPrintHexTable(htons(packet->ip.len), (u08*)packet);</span> |
||
| 77 | 00068 <span class="preprocessor"> #endif</span> |
||
| 78 | 00069 <span class="preprocessor"></span> |
||
| 79 | 00070 <span class="comment">// send it (packet->ip.len+ETH_HEADER_LEN</span> |
||
| 80 | 00071 <a class="code" href="group__nic.html#ga1">nicSend</a>(<a class="code" href="group__net.html#ga2">htons</a>(packet->ip.len)+ETH_HEADER_LEN, (((u08*)packet)-ETH_HEADER_LEN)); |
||
| 81 | 00072 } |
||
| 82 | 00073 |
||
| 83 | 00074 <span class="preprocessor">#ifdef ICMP_DEBUG_PRINT</span> |
||
| 84 | 00075 <span class="preprocessor"></span><span class="keywordtype">void</span> <a class="code" href="group__icmp.html#ga3">icmpPrintHeader</a>(icmpip_hdr* packet) |
||
| 85 | 00076 { |
||
| 86 | 00077 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"ICMP Packet:\r\n"</span>); |
||
| 87 | 00078 <span class="comment">// print source IP address</span> |
||
| 88 | 00079 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"SrcIpAddr: "</span>); <a class="code" href="group__net.html#ga6">netPrintIPAddr</a>(<a class="code" href="group__net.html#ga3">htonl</a>(packet->ip.srcipaddr)); <a class="code" href="group__rprintf.html#ga5">rprintfCRLF</a>(); |
||
| 89 | 00080 <span class="comment">// print dest IP address</span> |
||
| 90 | 00081 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"DstIpAddr: "</span>); <a class="code" href="group__net.html#ga6">netPrintIPAddr</a>(<a class="code" href="group__net.html#ga3">htonl</a>(packet->ip.destipaddr)); <a class="code" href="group__rprintf.html#ga5">rprintfCRLF</a>(); |
||
| 91 | 00082 <span class="comment">// print type</span> |
||
| 92 | 00083 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"Type : "</span>); |
||
| 93 | 00084 <span class="keywordflow">switch</span>(packet->icmp.type) |
||
| 94 | 00085 { |
||
| 95 | 00086 <span class="keywordflow">case</span> ICMP_TYPE_ECHOREQUEST: <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"ECHO REQUEST"</span>); <span class="keywordflow">break</span>; |
||
| 96 | 00087 <span class="keywordflow">case</span> ICMP_TYPE_ECHOREPLY: <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"ECHO REPLY"</span>); <span class="keywordflow">break</span>; |
||
| 97 | 00088 <span class="keywordflow">default</span>: <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"UNKNOWN"</span>); <span class="keywordflow">break</span>; |
||
| 98 | 00089 } |
||
| 99 | 00090 <a class="code" href="group__rprintf.html#ga5">rprintfCRLF</a>(); |
||
| 100 | 00091 <span class="comment">// print code</span> |
||
| 101 | 00092 <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"Code : 0x"</span>); <a class="code" href="group__rprintf.html#ga7">rprintfu08</a>(packet->icmp.icode); <a class="code" href="group__rprintf.html#ga5">rprintfCRLF</a>(); |
||
| 102 | 00093 } |
||
| 103 | 00094 <span class="preprocessor">#endif</span> |
||
| 104 | </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by |
||
| 105 | <a href="http://www.doxygen.org/index.html"> |
||
| 106 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address> |
||
| 107 | </body> |
||
| 108 | </html> |
Powered by WebSVN v2.8.3