| 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/arp.h 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>arp.h</h1><a href="arp_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file arp.h \brief ARP Protocol Library. */</span> |
||
| 11 | 00002 <span class="comment">//*****************************************************************************</span> |
||
| 12 | 00003 <span class="comment">//</span> |
||
| 13 | 00004 <span class="comment">// File Name : 'arp.h'</span> |
||
| 14 | 00005 <span class="comment">// Title : ARP Protocol Library</span> |
||
| 15 | 00006 <span class="comment">// Author : Pascal Stang</span> |
||
| 16 | 00007 <span class="comment">// Created : 9/7/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><span class="comment"></span> |
||
| 22 | 00013 <span class="comment">/// \ingroup network</span> |
||
| 23 | 00014 <span class="comment">/// \defgroup arp ARP Protocol Library (arp.c)</span> |
||
| 24 | 00015 <span class="comment">/// \code #include "net/arp.h" \endcode</span> |
||
| 25 | 00016 <span class="comment">/// \par Description</span> |
||
| 26 | 00017 <span class="comment">/// To send anything over ethernet (or most any other physical network)</span> |
||
| 27 | 00018 <span class="comment">/// a packet must be addressed to a physical network node address, often</span> |
||
| 28 | 00019 <span class="comment">/// called a MAC/hardware/ethernet address. This MAC address identifies</span> |
||
| 29 | 00020 <span class="comment">/// a specific interface (like the ethernet card in your computer) on the</span> |
||
| 30 | 00021 <span class="comment">/// network.</span> |
||
| 31 | 00022 <span class="comment">/// ARP (Address Resolution Protocol) assists in mapping IP addresses to </span> |
||
| 32 | 00023 <span class="comment">/// the MAC addresses required to actually get data to its destination.</span> |
||
| 33 | 00024 <span class="comment">/// In other words, an IP address is not enough to send information over</span> |
||
| 34 | 00025 <span class="comment">/// ethernet. You need the MAC address of the network interface/card that</span> |
||
| 35 | 00026 <span class="comment">/// "owns" that IP address. ARP maintains a table mapping IP addresses to</span> |
||
| 36 | 00027 <span class="comment">/// MAC addresses. This table can be filled by both listening to</span> |
||
| 37 | 00028 <span class="comment">/// traffic on the network, as well as making specific ARP requests if</span> |
||
| 38 | 00029 <span class="comment">/// an IP<->MAC mapping is not in the table.</span> |
||
| 39 | 00030 <span class="comment">/// </span> |
||
| 40 | 00031 <span class="comment">/// \note This code is currently below version 1.0, and therefore is considered</span> |
||
| 41 | 00032 <span class="comment">/// to be lacking in some functionality or documentation, or may not be fully</span> |
||
| 42 | 00033 <span class="comment">/// tested. Nonetheless, you can expect most functions to work.</span> |
||
| 43 | 00034 <span class="comment">///</span> |
||
| 44 | 00035 <span class="comment"></span><span class="comment">// This code is distributed under the GNU Public License</span> |
||
| 45 | 00036 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span> |
||
| 46 | 00037 <span class="comment">//*****************************************************************************</span><span class="comment"></span> |
||
| 47 | 00038 <span class="comment">//@{</span> |
||
| 48 | 00039 <span class="comment"></span> |
||
| 49 | 00040 <span class="preprocessor">#ifndef ARP_H</span> |
||
| 50 | 00041 <span class="preprocessor"></span><span class="preprocessor">#define ARP_H</span> |
||
| 51 | 00042 <span class="preprocessor"></span> |
||
| 52 | 00043 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span> |
||
| 53 | 00044 <span class="preprocessor">#include "<a class="code" href="net_8h.html">net.h</a>"</span> |
||
| 54 | 00045 |
||
| 55 | 00046 <span class="preprocessor">#ifndef ARP_TABLE_SIZE</span> |
||
| 56 | 00047 <span class="preprocessor"></span><span class="preprocessor">#define ARP_TABLE_SIZE 8</span> |
||
| 57 | 00048 <span class="preprocessor"></span><span class="preprocessor">#endif</span> |
||
| 58 | 00049 <span class="preprocessor"></span> |
||
| 59 | 00050 <span class="preprocessor">#ifndef ARP_CACHE_TIME_TO_LIVE</span> |
||
| 60 | 00051 <span class="preprocessor"></span><span class="preprocessor">#define ARP_CACHE_TIME_TO_LIVE 100</span> |
||
| 61 | 00052 <span class="preprocessor"></span><span class="preprocessor">#endif</span> |
||
| 62 | 00053 <span class="preprocessor"></span> |
||
| 63 | 00054 <span class="comment">//#define ARP_DEBUG_PRINT</span> |
||
| 64 | 00055 |
||
| 65 | 00056 <span class="comment"></span> |
||
| 66 | 00057 <span class="comment">/*! Initialize ARP system.</span> |
||
| 67 | 00058 <span class="comment"> Clears ARP table and prepares it for use. This is typically done</span> |
||
| 68 | 00059 <span class="comment"> once at program initialization. */</span> |
||
| 69 | 00060 <span class="keywordtype">void</span> <a class="code" href="group__arp.html#ga0">arpInit</a>(<span class="keywordtype">void</span>); |
||
| 70 | 00061 <span class="comment"></span> |
||
| 71 | 00062 <span class="comment">/*! Set IP and Ethernet hardware/MAC address.</span> |
||
| 72 | 00063 <span class="comment"> This must be done before valid replies can be generated for ARP</span> |
||
| 73 | 00064 <span class="comment"> requests. Typically done once at program initialization. */</span> |
||
| 74 | 00065 <span class="keywordtype">void</span> <a class="code" href="group__arp.html#ga1">arpSetAddress</a>(<span class="keyword">struct</span> netEthAddr* myeth, uint32_t myip); |
||
| 75 | 00066 <span class="comment"></span> |
||
| 76 | 00067 <span class="comment">/*! Processes incoming ARP packets.</span> |
||
| 77 | 00068 <span class="comment"> This function is to be called when an ARP type packet has arrived</span> |
||
| 78 | 00069 <span class="comment"> over the network. If the packet type is an ARP request for us,</span> |
||
| 79 | 00070 <span class="comment"> an ARP reply will be generated and sent. */</span> |
||
| 80 | 00071 <span class="keywordtype">void</span> <a class="code" href="group__arp.html#ga2">arpArpIn</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len, <span class="keyword">struct</span> netEthArpHeader* packet); |
||
| 81 | 00072 <span class="comment"></span> |
||
| 82 | 00073 <span class="comment">/*! Process incoming IP packets to harvest IP<->MAC relationships.</span> |
||
| 83 | 00074 <span class="comment"> This function should be called when IP packets are received over the</span> |
||
| 84 | 00075 <span class="comment"> network. It does nothing more than harvest the IP<->MAC address</span> |
||
| 85 | 00076 <span class="comment"> relationships from the ethernet and IP header of the packet. The</span> |
||
| 86 | 00077 <span class="comment"> packet is not changed nor processed. Nothing is sent on the network.</span> |
||
| 87 | 00078 <span class="comment"> Use of this command is not required, but it is a good way to</span> |
||
| 88 | 00079 <span class="comment"> automatically fill the ARP table with information about nodes that are</span> |
||
| 89 | 00080 <span class="comment"> active on the network.</span> |
||
| 90 | 00081 <span class="comment"> </span> |
||
| 91 | 00082 <span class="comment"> \warning On very busy or heavily populated netorks, this can quickly</span> |
||
| 92 | 00083 <span class="comment"> fill the ARP table with unnecessary entries, and/or cause some CPU load.</span> |
||
| 93 | 00084 <span class="comment">*/</span> |
||
| 94 | 00085 <span class="keywordtype">void</span> <a class="code" href="group__arp.html#ga3">arpIpIn</a>(<span class="keyword">struct</span> netEthIpHeader* packet); |
||
| 95 | 00086 <span class="comment"></span> |
||
| 96 | 00087 <span class="comment">/*! Process outgoing IP packet to fill in ethernet header information.</span> |
||
| 97 | 00088 <span class="comment"> To be sent on a network, an IP packet must have the correct ethernet</span> |
||
| 98 | 00089 <span class="comment"> header information appended to the front. This function will fill</span> |
||
| 99 | 00090 <span class="comment"> in this information.</span> |
||
| 100 | 00091 <span class="comment"> </span> |
||
| 101 | 00092 <span class="comment"> A physical destination IP address argument is needed to support</span> |
||
| 102 | 00093 <span class="comment"> sending to a gateway (i.e. when a packet is destined for a node that</span> |
||
| 103 | 00094 <span class="comment"> is not on this network, IP addressing is as usual, but we phyiscally</span> |
||
| 104 | 00095 <span class="comment"> send the packet to the gateway's ethernet address/interface).</span> |
||
| 105 | 00096 <span class="comment"> </span> |
||
| 106 | 00097 <span class="comment"> \warning Technically, if an IP<->MAC address mapping is not in the</span> |
||
| 107 | 00098 <span class="comment"> ARP table, then the IP packet should be held while an ARP request is</span> |
||
| 108 | 00099 <span class="comment"> made, and the reply received. However, in single-threaded ram-limited</span> |
||
| 109 | 00100 <span class="comment"> embedded systems, such a holdup is unacceptable. This function instead</span> |
||
| 110 | 00101 <span class="comment"> sends the packet as an ethernet broadcast if a mapping cannot be found.</span> |
||
| 111 | 00102 <span class="comment"></span> |
||
| 112 | 00103 <span class="comment"> \todo Send the packet broadcast AND send an ARP request, if a mapping</span> |
||
| 113 | 00104 <span class="comment"> is not found.</span> |
||
| 114 | 00105 <span class="comment">*/</span> |
||
| 115 | 00106 <span class="keywordtype">void</span> <a class="code" href="group__arp.html#ga4">arpIpOut</a>(<span class="keyword">struct</span> netEthIpHeader* packet, uint32_t phyDstIp); |
||
| 116 | 00107 <span class="comment"></span> |
||
| 117 | 00108 <span class="comment">/*! Periodic ARP cache maintenance.</span> |
||
| 118 | 00109 <span class="comment"> This function is to be called once per second and will slowly </span> |
||
| 119 | 00110 <span class="comment"> expire old ARP cache entries. */</span> |
||
| 120 | 00111 <span class="keywordtype">void</span> <a class="code" href="group__arp.html#ga5">arpTimer</a>(<span class="keywordtype">void</span>); |
||
| 121 | 00112 |
||
| 122 | 00113 <span class="comment"></span> |
||
| 123 | 00114 <span class="comment">/*! Check if this IP address is present in the ARP cache. Internal function.</span> |
||
| 124 | 00115 <span class="comment"> If IP address is found, function returns index of entry. If not found,</span> |
||
| 125 | 00116 <span class="comment"> returns -1. */</span> |
||
| 126 | 00117 <span class="keywordtype">int</span> <a class="code" href="group__arp.html#ga6">arpMatchIp</a>(uint32_t ipaddr); |
||
| 127 | 00118 <span class="comment"></span> |
||
| 128 | 00119 <span class="comment">//! Print diagnotic information about ARP packet.</span> |
||
| 129 | 00120 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__arp.html#ga7">arpPrintHeader</a>(<span class="keyword">struct</span> netArpHeader* packet);<span class="comment"></span> |
||
| 130 | 00121 <span class="comment">//! Print diagnotic information about ARP cache.</span> |
||
| 131 | 00122 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__arp.html#ga8">arpPrintTable</a>(<span class="keywordtype">void</span>); |
||
| 132 | 00123 |
||
| 133 | 00124 <span class="preprocessor">#endif</span> |
||
| 134 | 00125 <span class="preprocessor"></span><span class="comment">//@}</span> |
||
| 135 | </span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by |
||
| 136 | <a href="http://www.doxygen.org/index.html"> |
||
| 137 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address> |
||
| 138 | </body> |
||
| 139 | </html> |
Powered by WebSVN v2.8.3