smart-green-house/rtt-uart-nb/rt-thread/components/net/uip/doc/html/a00204.html

449 lines
45 KiB
HTML
Raw Normal View History

2023-10-28 18:00:47 +08:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>uIP 1.0: uip/uip_arp.c Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.6 -->
<div class="tabs">
<ul>
<li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="classes.html"><span>Data&nbsp;Structures</span></a></li>
<li id="current"><a href="files.html"><span>Files</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
</ul></div>
<div class="tabs">
<ul>
<li><a href="files.html"><span>File&nbsp;List</span></a></li>
<li><a href="globals.html"><span>Globals</span></a></li>
</ul></div>
<h1>uip/uip_arp.c</h1><a href="a00138.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/**</span>
<a name="l00002"></a>00002 <span class="comment"> * \addtogroup uip</span>
<a name="l00003"></a>00003 <span class="comment"> * @{</span>
<a name="l00004"></a>00004 <span class="comment"> */</span>
<a name="l00005"></a>00005 <span class="comment"></span>
<a name="l00006"></a>00006 <span class="comment">/**</span>
<a name="l00007"></a>00007 <span class="comment"> * \defgroup uiparp uIP Address Resolution Protocol</span>
<a name="l00008"></a>00008 <span class="comment"> * @{</span>
<a name="l00009"></a>00009 <span class="comment"> *</span>
<a name="l00010"></a>00010 <span class="comment"> * The Address Resolution Protocol ARP is used for mapping between IP</span>
<a name="l00011"></a>00011 <span class="comment"> * addresses and link level addresses such as the Ethernet MAC</span>
<a name="l00012"></a>00012 <span class="comment"> * addresses. ARP uses broadcast queries to ask for the link level</span>
<a name="l00013"></a>00013 <span class="comment"> * address of a known IP address and the host which is configured with</span>
<a name="l00014"></a>00014 <span class="comment"> * the IP address for which the query was meant, will respond with its</span>
<a name="l00015"></a>00015 <span class="comment"> * link level address.</span>
<a name="l00016"></a>00016 <span class="comment"> *</span>
<a name="l00017"></a>00017 <span class="comment"> * \note This ARP implementation only supports Ethernet.</span>
<a name="l00018"></a>00018 <span class="comment"> */</span>
<a name="l00019"></a>00019 <span class="comment"></span>
<a name="l00020"></a>00020 <span class="comment">/**</span>
<a name="l00021"></a>00021 <span class="comment"> * \file</span>
<a name="l00022"></a>00022 <span class="comment"> * Implementation of the ARP Address Resolution Protocol.</span>
<a name="l00023"></a>00023 <span class="comment"> * \author Adam Dunkels &lt;adam@dunkels.com&gt;</span>
<a name="l00024"></a>00024 <span class="comment"> *</span>
<a name="l00025"></a>00025 <span class="comment"> */</span>
<a name="l00026"></a>00026
<a name="l00027"></a>00027 <span class="comment">/*</span>
<a name="l00028"></a>00028 <span class="comment"> * Copyright (c) 2001-2003, Adam Dunkels.</span>
<a name="l00029"></a>00029 <span class="comment"> * All rights reserved.</span>
<a name="l00030"></a>00030 <span class="comment"> *</span>
<a name="l00031"></a>00031 <span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
<a name="l00032"></a>00032 <span class="comment"> * modification, are permitted provided that the following conditions</span>
<a name="l00033"></a>00033 <span class="comment"> * are met:</span>
<a name="l00034"></a>00034 <span class="comment"> * 1. Redistributions of source code must retain the above copyright</span>
<a name="l00035"></a>00035 <span class="comment"> * notice, this list of conditions and the following disclaimer.</span>
<a name="l00036"></a>00036 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span>
<a name="l00037"></a>00037 <span class="comment"> * notice, this list of conditions and the following disclaimer in the</span>
<a name="l00038"></a>00038 <span class="comment"> * documentation and/or other materials provided with the distribution.</span>
<a name="l00039"></a>00039 <span class="comment"> * 3. The name of the author may not be used to endorse or promote</span>
<a name="l00040"></a>00040 <span class="comment"> * products derived from this software without specific prior</span>
<a name="l00041"></a>00041 <span class="comment"> * written permission.</span>
<a name="l00042"></a>00042 <span class="comment"> *</span>
<a name="l00043"></a>00043 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS</span>
<a name="l00044"></a>00044 <span class="comment"> * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED</span>
<a name="l00045"></a>00045 <span class="comment"> * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</span>
<a name="l00046"></a>00046 <span class="comment"> * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY</span>
<a name="l00047"></a>00047 <span class="comment"> * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL</span>
<a name="l00048"></a>00048 <span class="comment"> * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE</span>
<a name="l00049"></a>00049 <span class="comment"> * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS</span>
<a name="l00050"></a>00050 <span class="comment"> * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,</span>
<a name="l00051"></a>00051 <span class="comment"> * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING</span>
<a name="l00052"></a>00052 <span class="comment"> * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS</span>
<a name="l00053"></a>00053 <span class="comment"> * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
<a name="l00054"></a>00054 <span class="comment"> *</span>
<a name="l00055"></a>00055 <span class="comment"> * This file is part of the uIP TCP/IP stack.</span>
<a name="l00056"></a>00056 <span class="comment"> *</span>
<a name="l00057"></a>00057 <span class="comment"> * $Id: uip_arp.c,v 1.8 2006/06/02 23:36:21 adam Exp $</span>
<a name="l00058"></a>00058 <span class="comment"> *</span>
<a name="l00059"></a>00059 <span class="comment"> */</span>
<a name="l00060"></a>00060
<a name="l00061"></a>00061
<a name="l00062"></a>00062 <span class="preprocessor">#include "<a class="code" href="a00139.html">uip_arp.h</a>"</span>
<a name="l00063"></a>00063
<a name="l00064"></a>00064 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00065"></a>00065
<a name="l00066"></a>00066 <span class="keyword">struct </span>arp_hdr {
<a name="l00067"></a>00067 <span class="keyword">struct </span><a class="code" href="a00090.html">uip_eth_hdr</a> ethhdr;
<a name="l00068"></a>00068 <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> hwtype;
<a name="l00069"></a>00069 <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> protocol;
<a name="l00070"></a>00070 <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> hwlen;
<a name="l00071"></a>00071 <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> protolen;
<a name="l00072"></a>00072 <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> opcode;
<a name="l00073"></a>00073 <span class="keyword">struct </span><a class="code" href="a00089.html">uip_eth_addr</a> shwaddr;
<a name="l00074"></a>00074 <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> sipaddr[2];
<a name="l00075"></a>00075 <span class="keyword">struct </span><a class="code" href="a00089.html">uip_eth_addr</a> dhwaddr;
<a name="l00076"></a>00076 <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> dipaddr[2];
<a name="l00077"></a>00077 };
<a name="l00078"></a>00078
<a name="l00079"></a>00079 <span class="keyword">struct </span>ethip_hdr {
<a name="l00080"></a>00080 <span class="keyword">struct </span><a class="code" href="a00090.html">uip_eth_hdr</a> ethhdr;
<a name="l00081"></a>00081 <span class="comment">/* IP header. */</span>
<a name="l00082"></a>00082 <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> vhl,
<a name="l00083"></a>00083 tos,
<a name="l00084"></a>00084 len[2],
<a name="l00085"></a>00085 ipid[2],
<a name="l00086"></a>00086 ipoffset[2],
<a name="l00087"></a>00087 ttl,
<a name="l00088"></a>00088 proto;
<a name="l00089"></a>00089 <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> ipchksum;
<a name="l00090"></a>00090 <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> srcipaddr[2],
<a name="l00091"></a>00091 destipaddr[2];
<a name="l00092"></a>00092 };
<a name="l00093"></a>00093
<a name="l00094"></a><a class="code" href="a00152.html#g7a7c46ffaba30477b8c9e3e61bd2e106">00094</a> <span class="preprocessor">#define ARP_REQUEST 1</span>
<a name="l00095"></a><a class="code" href="a00152.html#g06ba7b414e718081998f2814090debf1">00095</a> <span class="preprocessor"></span><span class="preprocessor">#define ARP_REPLY 2</span>
<a name="l00096"></a>00096 <span class="preprocessor"></span>
<a name="l00097"></a><a class="code" href="a00152.html#gbb56b549f7ab4d86e1cc39b8afc70d1e">00097</a> <span class="preprocessor">#define ARP_HWTYPE_ETH 1</span>
<a name="l00098"></a>00098 <span class="preprocessor"></span>
<a name="l00099"></a>00099 <span class="keyword">struct </span>arp_entry {
<a name="l00100"></a>00100 <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> ipaddr[2];
<a name="l00101"></a>00101 <span class="keyword">struct </span><a class="code" href="a00089.html">uip_eth_addr</a> ethaddr;
<a name="l00102"></a>00102 <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> time;
<a name="l00103"></a>00103 };
<a name="l00104"></a>00104
<a name="l00105"></a>00105 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">struct </span><a class="code" href="a00089.html">uip_eth_addr</a> broadcast_ethaddr =
<a name="l00106"></a>00106 {{0xff,0xff,0xff,0xff,0xff,0xff}};
<a name="l00107"></a>00107 <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> broadcast_ipaddr[2] = {0xffff,0xffff};
<a name="l00108"></a>00108
<a name="l00109"></a>00109 <span class="keyword">static</span> <span class="keyword">struct </span>arp_entry arp_table[<a class="code" href="a00153.html#gb1455b27c06532a399cf06d2c1d6d08d">UIP_ARPTAB_SIZE</a>];
<a name="l00110"></a>00110 <span class="keyword">static</span> <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> ipaddr[2];
<a name="l00111"></a>00111 <span class="keyword">static</span> <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> i, c;
<a name="l00112"></a>00112
<a name="l00113"></a>00113 <span class="keyword">static</span> <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> arptime;
<a name="l00114"></a>00114 <span class="keyword">static</span> <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> tmpage;
<a name="l00115"></a>00115
<a name="l00116"></a><a class="code" href="a00152.html#g24f52ac52d6e714cb04a5aa01be3bdd0">00116</a> <span class="preprocessor">#define BUF ((struct arp_hdr *)&amp;uip_buf[0])</span>
<a name="l00117"></a><a class="code" href="a00152.html#g9f2196e2705036869611962425e404bf">00117</a> <span class="preprocessor"></span><span class="preprocessor">#define IPBUF ((struct ethip_hdr *)&amp;uip_buf[0])</span>
<a name="l00118"></a>00118 <span class="preprocessor"></span><span class="comment">/*-----------------------------------------------------------------------------------*/</span><span class="comment"></span>
<a name="l00119"></a>00119 <span class="comment">/**</span>
<a name="l00120"></a>00120 <span class="comment"> * Initialize the ARP module.</span>
<a name="l00121"></a>00121 <span class="comment"> *</span>
<a name="l00122"></a>00122 <span class="comment"> */</span>
<a name="l00123"></a>00123 <span class="comment">/*-----------------------------------------------------------------------------------*/</span>
<a name="l00124"></a>00124 <span class="keywordtype">void</span>
<a name="l00125"></a><a class="code" href="a00152.html#g2d9d28afa353f662b9bb5234fc419f72">00125</a> <a class="code" href="a00152.html#g2d9d28afa353f662b9bb5234fc419f72">uip_arp_init</a>(<span class="keywordtype">void</span>)
<a name="l00126"></a>00126 {
<a name="l00127"></a>00127 <span class="keywordflow">for</span>(i = 0; i &lt; <a class="code" href="a00153.html#gb1455b27c06532a399cf06d2c1d6d08d">UIP_ARPTAB_SIZE</a>; ++i) {
<a name="l00128"></a>00128 memset(arp_table[i].ipaddr, 0, 4);
<a name="l00129"></a>00129 }
<a name="l00130"></a>00130 }
<a name="l00131"></a>00131 <span class="comment">/*-----------------------------------------------------------------------------------*/</span><span class="comment"></span>
<a name="l00132"></a>00132 <span class="comment">/**</span>
<a name="l00133"></a>00133 <span class="comment"> * Periodic ARP processing function.</span>
<a name="l00134"></a>00134 <span class="comment"> *</span>
<a name="l00135"></a>00135 <span class="comment"> * This function performs periodic timer processing in the ARP module</span>
<a name="l00136"></a>00136 <span class="comment"> * and should be called at regular intervals. The recommended interval</span>
<a name="l00137"></a>00137 <span class="comment"> * is 10 seconds between the calls.</span>
<a name="l00138"></a>00138 <span class="comment"> *</span>
<a name="l00139"></a>00139 <span class="comment"> */</span>
<a name="l00140"></a>00140 <span class="comment">/*-----------------------------------------------------------------------------------*/</span>
<a name="l00141"></a>00141 <span class="keywordtype">void</span>
<a name="l00142"></a><a class="code" href="a00152.html#g058a8e6025f67b021862281f1911fcef">00142</a> <a class="code" href="a00152.html#g058a8e6025f67b021862281f1911fcef">uip_arp_timer</a>(<span class="keywordtype">void</span>)
<a name="l00143"></a>00143 {
<a name="l00144"></a>00144 <span class="keyword">struct </span>arp_entry *tabptr;
<a name="l00145"></a>00145
<a name="l00146"></a>00146 ++arptime;
<a name="l00147"></a>00147 <span class="keywordflow">for</span>(i = 0; i &lt; <a class="code" href="a00153.html#gb1455b27c06532a399cf06d2c1d6d08d">UIP_ARPTAB_SIZE</a>; ++i) {
<a name="l00148"></a>00148 tabptr = &amp;arp_table[i];
<a name="l00149"></a>00149 <span class="keywordflow">if</span>((tabptr-&gt;ipaddr[0] | tabptr-&gt;ipaddr[1]) != 0 &amp;&amp;
<a name="l00150"></a>00150 arptime - tabptr-&gt;time &gt;= <a class="code" href="a00153.html#g3090117ef3ff5775b77cb1960e442d07">UIP_ARP_MAXAGE</a>) {
<a name="l00151"></a>00151 memset(tabptr-&gt;ipaddr, 0, 4);
<a name="l00152"></a>00152 }
<a name="l00153"></a>00153 }
<a name="l00154"></a>00154
<a name="l00155"></a>00155 }
<a name="l00156"></a>00156 <span class="comment">/*-----------------------------------------------------------------------------------*/</span>
<a name="l00157"></a>00157 <span class="keyword">static</span> <span class="keywordtype">void</span>
<a name="l00158"></a>00158 uip_arp_update(<a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> *ipaddr, <span class="keyword">struct</span> <a class="code" href="a00089.html">uip_eth_addr</a> *ethaddr)
<a name="l00159"></a>00159 {
<a name="l00160"></a>00160 <span class="keyword">register</span> <span class="keyword">struct </span>arp_entry *tabptr;
<a name="l00161"></a>00161 <span class="comment">/* Walk through the ARP mapping table and try to find an entry to</span>
<a name="l00162"></a>00162 <span class="comment"> update. If none is found, the IP -&gt; MAC address mapping is</span>
<a name="l00163"></a>00163 <span class="comment"> inserted in the ARP table. */</span>
<a name="l00164"></a>00164 <span class="keywordflow">for</span>(i = 0; i &lt; <a class="code" href="a00153.html#gb1455b27c06532a399cf06d2c1d6d08d">UIP_ARPTAB_SIZE</a>; ++i) {
<a name="l00165"></a>00165
<a name="l00166"></a>00166 tabptr = &amp;arp_table[i];
<a name="l00167"></a>00167 <span class="comment">/* Only check those entries that are actually in use. */</span>
<a name="l00168"></a>00168 <span class="keywordflow">if</span>(tabptr-&gt;ipaddr[0] != 0 &amp;&amp;
<a name="l00169"></a>00169 tabptr-&gt;ipaddr[1] != 0) {
<a name="l00170"></a>00170
<a name="l00171"></a>00171 <span class="comment">/* Check if the source IP address of the incoming packet matches</span>
<a name="l00172"></a>00172 <span class="comment"> the IP address in this ARP table entry. */</span>
<a name="l00173"></a>00173 <span class="keywordflow">if</span>(ipaddr[0] == tabptr-&gt;ipaddr[0] &amp;&amp;
<a name="l00174"></a>00174 ipaddr[1] == tabptr-&gt;ipaddr[1]) {
<a name="l00175"></a>00175
<a name="l00176"></a>00176 <span class="comment">/* An old entry found, update this and return. */</span>
<a name="l00177"></a>00177 memcpy(tabptr-&gt;ethaddr.addr, ethaddr-&gt;<a class="code" href="a00089.html#aacd5fa1806e0f0dd0bc96dd36507ad8">addr</a>, 6);
<a name="l00178"></a>00178 tabptr-&gt;time = arptime;
<a name="l00179"></a>00179
<a name="l00180"></a>00180 <span class="keywordflow">return</span>;
<a name="l00181"></a>00181 }
<a name="l00182"></a>00182 }
<a name="l00183"></a>00183 }
<a name="l00184"></a>00184
<a name="l00185"></a>00185 <span class="comment">/* If we get here, no existing ARP table entry was found, so we</span>
<a name="l00186"></a>00186 <span class="comment"> create one. */</span>
<a name="l00187"></a>00187
<a name="l00188"></a>00188 <span class="comment">/* First, we try to find an unused entry in the ARP table. */</span>
<a name="l00189"></a>00189 <span class="keywordflow">for</span>(i = 0; i &lt; <a class="code" href="a00153.html#gb1455b27c06532a399cf06d2c1d6d08d">UIP_ARPTAB_SIZE</a>; ++i) {
<a name="l00190"></a>00190 tabptr = &amp;arp_table[i];
<a name="l00191"></a>00191 <span class="keywordflow">if</span>(tabptr-&gt;ipaddr[0] == 0 &amp;&amp;
<a name="l00192"></a>00192 tabptr-&gt;ipaddr[1] == 0) {
<a name="l00193"></a>00193 <span class="keywordflow">break</span>;
<a name="l00194"></a>00194 }
<a name="l00195"></a>00195 }
<a name="l00196"></a>00196
<a name="l00197"></a>00197 <span class="comment">/* If no unused entry is found, we try to find the oldest entry and</span>
<a name="l00198"></a>00198 <span class="comment"> throw it away. */</span>
<a name="l00199"></a>00199 <span class="keywordflow">if</span>(i == <a class="code" href="a00153.html#gb1455b27c06532a399cf06d2c1d6d08d">UIP_ARPTAB_SIZE</a>) {
<a name="l00200"></a>00200 tmpage = 0;
<a name="l00201"></a>00201 c = 0;
<a name="l00202"></a>00202 <span class="keywordflow">for</span>(i = 0; i &lt; <a class="code" href="a00153.html#gb1455b27c06532a399cf06d2c1d6d08d">UIP_ARPTAB_SIZE</a>; ++i) {
<a name="l00203"></a>00203 tabptr = &amp;arp_table[i];
<a name="l00204"></a>00204 <span class="keywordflow">if</span>(arptime - tabptr-&gt;time &gt; tmpage) {
<a name="l00205"></a>00205 tmpage = arptime - tabptr-&gt;time;
<a name="l00206"></a>00206 c = i;
<a name="l00207"></a>00207 }
<a name="l00208"></a>00208 }
<a name="l00209"></a>00209 i = c;
<a name="l00210"></a>00210 tabptr = &amp;arp_table[i];
<a name="l00211"></a>00211 }
<a name="l00212"></a>00212
<a name="l00213"></a>00213 <span class="comment">/* Now, i is the ARP table entry which we will fill with the new</span>
<a name="l00214"></a>00214 <span class="comment"> information. */</span>
<a name="l00215"></a>00215 memcpy(tabptr-&gt;ipaddr, ipaddr, 4);
<a name="l00216"></a>00216 memcpy(tabptr-&gt;ethaddr.addr, ethaddr-&gt;<a class="code" href="a00089.html#aacd5fa1806e0f0dd0bc96dd36507ad8">addr</a>, 6);
<a name="l00217"></a>00217 tabptr-&gt;time = arptime;
<a name="l00218"></a>00218 }
<a name="l00219"></a>00219 <span class="comment">/*-----------------------------------------------------------------------------------*/</span><span class="comment"></span>
<a name="l00220"></a>00220 <span class="comment">/**</span>
<a name="l00221"></a>00221 <span class="comment"> * ARP processing for incoming IP packets</span>
<a name="l00222"></a>00222 <span class="comment"> *</span>
<a name="l00223"></a>00223 <span class="comment"> * This function should be called by the device driver when an IP</span>
<a name="l00224"></a>00224 <span class="comment"> * packet has been received. The function will check if the address is</span>
<a name="l00225"></a>00225 <span class="comment"> * in the ARP cache, and if so the ARP cache entry will be</span>
<a name="l00226"></a>00226 <span class="comment"> * refreshed. If no ARP cache entry was found, a new one is created.</span>
<a name="l00227"></a>00227 <span class="comment"> *</span>
<a name="l00228"></a>00228 <span class="comment"> * This function expects an IP packet with a prepended Ethernet header</span>
<a name="l00229"></a>00229 <span class="comment"> * in the uip_buf[] buffer, and the length of the packet in the global</span>
<a name="l00230"></a>00230 <span class="comment"> * variable uip_len.</span>
<a name="l00231"></a>00231 <span class="comment"> */</span>
<a name="l00232"></a>00232 <span class="comment">/*-----------------------------------------------------------------------------------*/</span>
<a name="l00233"></a>00233 <span class="preprocessor">#if 0</span>
<a name="l00234"></a>00234 <span class="preprocessor"></span><span class="keywordtype">void</span>
<a name="l00235"></a>00235 <a class="code" href="a00152.html#g737337d6a51e31b236c8233d024138a8">uip_arp_ipin</a>(<span class="keywordtype">void</span>)
<a name="l00236"></a>00236 {
<a name="l00237"></a>00237 <a class="code" href="a00149.html#g12a33f0c09711167bdf3dd7d7cf8c5a1">uip_len</a> -= <span class="keyword">sizeof</span>(<span class="keyword">struct </span><a class="code" href="a00090.html">uip_eth_hdr</a>);
<a name="l00238"></a>00238
<a name="l00239"></a>00239 <span class="comment">/* Only insert/update an entry if the source IP address of the</span>
<a name="l00240"></a>00240 <span class="comment"> incoming IP packet comes from a host on the local network. */</span>
<a name="l00241"></a>00241 <span class="keywordflow">if</span>((<a class="code" href="a00152.html#g9f2196e2705036869611962425e404bf">IPBUF</a>-&gt;srcipaddr[0] &amp; <a class="code" href="a00150.html#g3237be0d9ec457de0177689ee23c0d5c">uip_netmask</a>[0]) !=
<a name="l00242"></a>00242 (<a class="code" href="a00150.html#g7d3673f52f5846b6961d23b150decd54">uip_hostaddr</a>[0] &amp; <a class="code" href="a00150.html#g3237be0d9ec457de0177689ee23c0d5c">uip_netmask</a>[0])) {
<a name="l00243"></a>00243 <span class="keywordflow">return</span>;
<a name="l00244"></a>00244 }
<a name="l00245"></a>00245 <span class="keywordflow">if</span>((<a class="code" href="a00152.html#g9f2196e2705036869611962425e404bf">IPBUF</a>-&gt;srcipaddr[1] &amp; uip_netmask[1]) !=
<a name="l00246"></a>00246 (<a class="code" href="a00150.html#g7d3673f52f5846b6961d23b150decd54">uip_hostaddr</a>[1] &amp; uip_netmask[1])) {
<a name="l00247"></a>00247 <span class="keywordflow">return</span>;
<a name="l00248"></a>00248 }
<a name="l00249"></a>00249 uip_arp_update(<a class="code" href="a00152.html#g9f2196e2705036869611962425e404bf">IPBUF</a>-&gt;srcipaddr, &amp;(<a class="code" href="a00152.html#g9f2196e2705036869611962425e404bf">IPBUF</a>-&gt;ethhdr.src));
<a name="l00250"></a>00250
<a name="l00251"></a>00251 <span class="keywordflow">return</span>;
<a name="l00252"></a>00252 }
<a name="l00253"></a>00253 <span class="preprocessor">#endif </span><span class="comment">/* 0 */</span>
<a name="l00254"></a>00254 <span class="comment">/*-----------------------------------------------------------------------------------*/</span><span class="comment"></span>
<a name="l00255"></a>00255 <span class="comment">/**</span>
<a name="l00256"></a>00256 <span class="comment"> * ARP processing for incoming ARP packets.</span>
<a name="l00257"></a>00257 <span class="comment"> *</span>
<a name="l00258"></a>00258 <span class="comment"> * This function should be called by the device driver when an ARP</span>
<a name="l00259"></a>00259 <span class="comment"> * packet has been received. The function will act differently</span>
<a name="l00260"></a>00260 <span class="comment"> * depending on the ARP packet type: if it is a reply for a request</span>
<a name="l00261"></a>00261 <span class="comment"> * that we previously sent out, the ARP cache will be filled in with</span>
<a name="l00262"></a>00262 <span class="comment"> * the values from the ARP reply. If the incoming ARP packet is an ARP</span>
<a name="l00263"></a>00263 <span class="comment"> * request for our IP address, an ARP reply packet is created and put</span>
<a name="l00264"></a>00264 <span class="comment"> * into the uip_buf[] buffer.</span>
<a name="l00265"></a>00265 <span class="comment"> *</span>
<a name="l00266"></a>00266 <span class="comment"> * When the function returns, the value of the global variable uip_len</span>
<a name="l00267"></a>00267 <span class="comment"> * indicates whether the device driver should send out a packet or</span>
<a name="l00268"></a>00268 <span class="comment"> * not. If uip_len is zero, no packet should be sent. If uip_len is</span>
<a name="l00269"></a>00269 <span class="comment"> * non-zero, it contains the length of the outbound packet that is</span>
<a name="l00270"></a>00270 <span class="comment"> * present in the uip_buf[] buffer.</span>
<a name="l00271"></a>00271 <span class="comment"> *</span>
<a name="l00272"></a>00272 <span class="comment"> * This function expects an ARP packet with a prepended Ethernet</span>
<a name="l00273"></a>00273 <span class="comment"> * header in the uip_buf[] buffer, and the length of the packet in the</span>
<a name="l00274"></a>00274 <span class="comment"> * global variable uip_len.</span>
<a name="l00275"></a>00275 <span class="comment"> */</span>
<a name="l00276"></a>00276 <span class="comment">/*-----------------------------------------------------------------------------------*/</span>
<a name="l00277"></a>00277 <span class="keywordtype">void</span>
<a name="l00278"></a><a class="code" href="a00152.html#g902c4a360134096224bc2655f623aa5f">00278</a> <a class="code" href="a00152.html#g902c4a360134096224bc2655f623aa5f">uip_arp_arpin</a>(<span class="keywordtype">void</span>)
<a name="l00279"></a>00279 {
<a name="l00280"></a>00280
<a name="l00281"></a>00281 <span class="keywordflow">if</span>(<a class="code" href="a00149.html#g12a33f0c09711167bdf3dd7d7cf8c5a1">uip_len</a> &lt; <span class="keyword">sizeof</span>(<span class="keyword">struct</span> arp_hdr)) {
<a name="l00282"></a>00282 <a class="code" href="a00149.html#g12a33f0c09711167bdf3dd7d7cf8c5a1">uip_len</a> = 0;
<a name="l00283"></a>00283 <span class="keywordflow">return</span>;
<a name="l00284"></a>00284 }
<a name="l00285"></a>00285 <a class="code" href="a00149.html#g12a33f0c09711167bdf3dd7d7cf8c5a1">uip_len</a> = 0;
<a name="l00286"></a>00286
<a name="l00287"></a>00287 <span class="keywordflow">switch</span>(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;opcode) {
<a name="l00288"></a>00288 <span class="keywordflow">case</span> <a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>(<a class="code" href="a00152.html#g7a7c46ffaba30477b8c9e3e61bd2e106">ARP_REQUEST</a>):
<a name="l00289"></a>00289 <span class="comment">/* ARP request. If it asked for our address, we send out a</span>
<a name="l00290"></a>00290 <span class="comment"> reply. */</span>
<a name="l00291"></a>00291 <span class="keywordflow">if</span>(<a class="code" href="a00148.html#g210e629f7252e4bc8458cbdf260b3318">uip_ipaddr_cmp</a>(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;dipaddr, <a class="code" href="a00150.html#g7d3673f52f5846b6961d23b150decd54">uip_hostaddr</a>)) {
<a name="l00292"></a>00292 <span class="comment">/* First, we register the one who made the request in our ARP</span>
<a name="l00293"></a>00293 <span class="comment"> table, since it is likely that we will do more communication</span>
<a name="l00294"></a>00294 <span class="comment"> with this host in the future. */</span>
<a name="l00295"></a>00295 uip_arp_update(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;sipaddr, &amp;<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;shwaddr);
<a name="l00296"></a>00296
<a name="l00297"></a>00297 <span class="comment">/* The reply opcode is 2. */</span>
<a name="l00298"></a>00298 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;opcode = <a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>(2);
<a name="l00299"></a>00299
<a name="l00300"></a>00300 memcpy(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;dhwaddr.addr, <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;shwaddr.addr, 6);
<a name="l00301"></a>00301 memcpy(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;shwaddr.addr, <a class="code" href="a00150.html#g499bb98a0b4ae9a98553ede81317606d">uip_ethaddr</a>.<a class="code" href="a00089.html#aacd5fa1806e0f0dd0bc96dd36507ad8">addr</a>, 6);
<a name="l00302"></a>00302 memcpy(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;ethhdr.src.addr, <a class="code" href="a00150.html#g499bb98a0b4ae9a98553ede81317606d">uip_ethaddr</a>.<a class="code" href="a00089.html#aacd5fa1806e0f0dd0bc96dd36507ad8">addr</a>, 6);
<a name="l00303"></a>00303 memcpy(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;ethhdr.dest.addr, <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;dhwaddr.addr, 6);
<a name="l00304"></a>00304
<a name="l00305"></a>00305 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;dipaddr[0] = <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;sipaddr[0];
<a name="l00306"></a>00306 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;dipaddr[1] = <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;sipaddr[1];
<a name="l00307"></a>00307 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;sipaddr[0] = <a class="code" href="a00150.html#g7d3673f52f5846b6961d23b150decd54">uip_hostaddr</a>[0];
<a name="l00308"></a>00308 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;sipaddr[1] = <a class="code" href="a00150.html#g7d3673f52f5846b6961d23b150decd54">uip_hostaddr</a>[1];
<a name="l00309"></a>00309
<a name="l00310"></a>00310 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;ethhdr.type = <a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>(<a class="code" href="a00152.html#g3e1562e8a6de32268e5df92a52152f91">UIP_ETHTYPE_ARP</a>);
<a name="l00311"></a>00311 <a class="code" href="a00149.html#g12a33f0c09711167bdf3dd7d7cf8c5a1">uip_len</a> = <span class="keyword">sizeof</span>(<span class="keyword">struct </span>arp_hdr);
<a name="l00312"></a>00312 }
<a name="l00313"></a>00313 <span class="keywordflow">break</span>;
<a name="l00314"></a>00314 <span class="keywordflow">case</span> <a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>(<a class="code" href="a00152.html#g06ba7b414e718081998f2814090debf1">ARP_REPLY</a>):
<a name="l00315"></a>00315 <span class="comment">/* ARP reply. We insert or update the ARP table if it was meant</span>
<a name="l00316"></a>00316 <span class="comment"> for us. */</span>
<a name="l00317"></a>00317 <span class="keywordflow">if</span>(<a class="code" href="a00148.html#g210e629f7252e4bc8458cbdf260b3318">uip_ipaddr_cmp</a>(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;dipaddr, <a class="code" href="a00150.html#g7d3673f52f5846b6961d23b150decd54">uip_hostaddr</a>)) {
<a name="l00318"></a>00318 uip_arp_update(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;sipaddr, &amp;<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;shwaddr);
<a name="l00319"></a>00319 }
<a name="l00320"></a>00320 <span class="keywordflow">break</span>;
<a name="l00321"></a>00321 }
<a name="l00322"></a>00322
<a name="l00323"></a>00323 <span class="keywordflow">return</span>;
<a name="l00324"></a>00324 }
<a name="l00325"></a>00325 <span class="comment">/*-----------------------------------------------------------------------------------*/</span><span class="comment"></span>
<a name="l00326"></a>00326 <span class="comment">/**</span>
<a name="l00327"></a>00327 <span class="comment"> * Prepend Ethernet header to an outbound IP packet and see if we need</span>
<a name="l00328"></a>00328 <span class="comment"> * to send out an ARP request.</span>
<a name="l00329"></a>00329 <span class="comment"> *</span>
<a name="l00330"></a>00330 <span class="comment"> * This function should be called before sending out an IP packet. The</span>
<a name="l00331"></a>00331 <span class="comment"> * function checks the destination IP address of the IP packet to see</span>
<a name="l00332"></a>00332 <span class="comment"> * what Ethernet MAC address that should be used as a destination MAC</span>
<a name="l00333"></a>00333 <span class="comment"> * address on the Ethernet.</span>
<a name="l00334"></a>00334 <span class="comment"> *</span>
<a name="l00335"></a>00335 <span class="comment"> * If the destination IP address is in the local network (determined</span>
<a name="l00336"></a>00336 <span class="comment"> * by logical ANDing of netmask and our IP address), the function</span>
<a name="l00337"></a>00337 <span class="comment"> * checks the ARP cache to see if an entry for the destination IP</span>
<a name="l00338"></a>00338 <span class="comment"> * address is found. If so, an Ethernet header is prepended and the</span>
<a name="l00339"></a>00339 <span class="comment"> * function returns. If no ARP cache entry is found for the</span>
<a name="l00340"></a>00340 <span class="comment"> * destination IP address, the packet in the uip_buf[] is replaced by</span>
<a name="l00341"></a>00341 <span class="comment"> * an ARP request packet for the IP address. The IP packet is dropped</span>
<a name="l00342"></a>00342 <span class="comment"> * and it is assumed that they higher level protocols (e.g., TCP)</span>
<a name="l00343"></a>00343 <span class="comment"> * eventually will retransmit the dropped packet.</span>
<a name="l00344"></a>00344 <span class="comment"> *</span>
<a name="l00345"></a>00345 <span class="comment"> * If the destination IP address is not on the local network, the IP</span>
<a name="l00346"></a>00346 <span class="comment"> * address of the default router is used instead.</span>
<a name="l00347"></a>00347 <span class="comment"> *</span>
<a name="l00348"></a>00348 <span class="comment"> * When the function returns, a packet is present in the uip_buf[]</span>
<a name="l00349"></a>00349 <span class="comment"> * buffer, and the length of the packet is in the global variable</span>
<a name="l00350"></a>00350 <span class="comment"> * uip_len.</span>
<a name="l00351"></a>00351 <span class="comment"> */</span>
<a name="l00352"></a>00352 <span class="comment">/*-----------------------------------------------------------------------------------*/</span>
<a name="l00353"></a>00353 <span class="keywordtype">void</span>
<a name="l00354"></a><a class="code" href="a00152.html#g54b27e45df15e10a0eb1a3e3a91417d2">00354</a> <a class="code" href="a00152.html#g54b27e45df15e10a0eb1a3e3a91417d2">uip_arp_out</a>(<span class="keywordtype">void</span>)
<a name="l00355"></a>00355 {
<a name="l00356"></a>00356 <span class="keyword">struct </span>arp_entry *tabptr;
<a name="l00357"></a>00357
<a name="l00358"></a>00358 <span class="comment">/* Find the destination IP address in the ARP table and construct</span>
<a name="l00359"></a>00359 <span class="comment"> the Ethernet header. If the destination IP addres isn't on the</span>
<a name="l00360"></a>00360 <span class="comment"> local network, we use the default router's IP address instead.</span>
<a name="l00361"></a>00361 <span class="comment"></span>
<a name="l00362"></a>00362 <span class="comment"> If not ARP table entry is found, we overwrite the original IP</span>
<a name="l00363"></a>00363 <span class="comment"> packet with an ARP request for the IP address. */</span>
<a name="l00364"></a>00364
<a name="l00365"></a>00365 <span class="comment">/* First check if destination is a local broadcast. */</span>
<a name="l00366"></a>00366 <span class="keywordflow">if</span>(<a class="code" href="a00148.html#g210e629f7252e4bc8458cbdf260b3318">uip_ipaddr_cmp</a>(<a class="code" href="a00152.html#g9f2196e2705036869611962425e404bf">IPBUF</a>-&gt;destipaddr, broadcast_ipaddr)) {
<a name="l00367"></a>00367 memcpy(<a class="code" href="a00152.html#g9f2196e2705036869611962425e404bf">IPBUF</a>-&gt;ethhdr.dest.addr, broadcast_ethaddr.<a class="code" href="a00089.html#aacd5fa1806e0f0dd0bc96dd36507ad8">addr</a>, 6);
<a name="l00368"></a>00368 } <span class="keywordflow">else</span> {
<a name="l00369"></a>00369 <span class="comment">/* Check if the destination address is on the local network. */</span>
<a name="l00370"></a>00370 <span class="keywordflow">if</span>(!<a class="code" href="a00148.html#g6b16e0bac41821c1fbe0c267071642f0">uip_ipaddr_maskcmp</a>(<a class="code" href="a00152.html#g9f2196e2705036869611962425e404bf">IPBUF</a>-&gt;destipaddr, <a class="code" href="a00150.html#g7d3673f52f5846b6961d23b150decd54">uip_hostaddr</a>, uip_netmask)) {
<a name="l00371"></a>00371 <span class="comment">/* Destination address was not on the local network, so we need to</span>
<a name="l00372"></a>00372 <span class="comment"> use the default router's IP address instead of the destination</span>
<a name="l00373"></a>00373 <span class="comment"> address when determining the MAC address. */</span>
<a name="l00374"></a>00374 <a class="code" href="a00148.html#g769512993b7b27271909d6daa4748b60">uip_ipaddr_copy</a>(ipaddr, <a class="code" href="a00150.html#g20df5c82f2a15a508c19e505b5d9de2b">uip_draddr</a>);
<a name="l00375"></a>00375 } <span class="keywordflow">else</span> {
<a name="l00376"></a>00376 <span class="comment">/* Else, we use the destination IP address. */</span>
<a name="l00377"></a>00377 <a class="code" href="a00148.html#g769512993b7b27271909d6daa4748b60">uip_ipaddr_copy</a>(ipaddr, <a class="code" href="a00152.html#g9f2196e2705036869611962425e404bf">IPBUF</a>-&gt;destipaddr);
<a name="l00378"></a>00378 }
<a name="l00379"></a>00379
<a name="l00380"></a>00380 <span class="keywordflow">for</span>(i = 0; i &lt; <a class="code" href="a00153.html#gb1455b27c06532a399cf06d2c1d6d08d">UIP_ARPTAB_SIZE</a>; ++i) {
<a name="l00381"></a>00381 tabptr = &amp;arp_table[i];
<a name="l00382"></a>00382 <span class="keywordflow">if</span>(<a class="code" href="a00148.html#g210e629f7252e4bc8458cbdf260b3318">uip_ipaddr_cmp</a>(ipaddr, tabptr-&gt;ipaddr)) {
<a name="l00383"></a>00383 <span class="keywordflow">break</span>;
<a name="l00384"></a>00384 }
<a name="l00385"></a>00385 }
<a name="l00386"></a>00386
<a name="l00387"></a>00387 <span class="keywordflow">if</span>(i == <a class="code" href="a00153.html#gb1455b27c06532a399cf06d2c1d6d08d">UIP_ARPTAB_SIZE</a>) {
<a name="l00388"></a>00388 <span class="comment">/* The destination address was not in our ARP table, so we</span>
<a name="l00389"></a>00389 <span class="comment"> overwrite the IP packet with an ARP request. */</span>
<a name="l00390"></a>00390
<a name="l00391"></a>00391 memset(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;ethhdr.dest.addr, 0xff, 6);
<a name="l00392"></a>00392 memset(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;dhwaddr.addr, 0x00, 6);
<a name="l00393"></a>00393 memcpy(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;ethhdr.src.addr, <a class="code" href="a00150.html#g499bb98a0b4ae9a98553ede81317606d">uip_ethaddr</a>.<a class="code" href="a00089.html#aacd5fa1806e0f0dd0bc96dd36507ad8">addr</a>, 6);
<a name="l00394"></a>00394 memcpy(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;shwaddr.addr, <a class="code" href="a00150.html#g499bb98a0b4ae9a98553ede81317606d">uip_ethaddr</a>.<a class="code" href="a00089.html#aacd5fa1806e0f0dd0bc96dd36507ad8">addr</a>, 6);
<a name="l00395"></a>00395
<a name="l00396"></a>00396 <a class="code" href="a00148.html#g769512993b7b27271909d6daa4748b60">uip_ipaddr_copy</a>(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;dipaddr, ipaddr);
<a name="l00397"></a>00397 <a class="code" href="a00148.html#g769512993b7b27271909d6daa4748b60">uip_ipaddr_copy</a>(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;sipaddr, <a class="code" href="a00150.html#g7d3673f52f5846b6961d23b150decd54">uip_hostaddr</a>);
<a name="l00398"></a>00398 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;opcode = <a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>(<a class="code" href="a00152.html#g7a7c46ffaba30477b8c9e3e61bd2e106">ARP_REQUEST</a>); <span class="comment">/* ARP request. */</span>
<a name="l00399"></a>00399 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;hwtype = <a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>(<a class="code" href="a00152.html#gbb56b549f7ab4d86e1cc39b8afc70d1e">ARP_HWTYPE_ETH</a>);
<a name="l00400"></a>00400 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;protocol = <a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>(<a class="code" href="a00152.html#g03d140db75de3d3cdfbbab1c4fed8d8d">UIP_ETHTYPE_IP</a>);
<a name="l00401"></a>00401 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;hwlen = 6;
<a name="l00402"></a>00402 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;protolen = 4;
<a name="l00403"></a>00403 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;ethhdr.type = <a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>(<a class="code" href="a00152.html#g3e1562e8a6de32268e5df92a52152f91">UIP_ETHTYPE_ARP</a>);
<a name="l00404"></a>00404
<a name="l00405"></a>00405 <a class="code" href="a00150.html#g561b8eda32e059d4e7397f776268cc63">uip_appdata</a> = &amp;<a class="code" href="a00146.html#gb81e78f890dbbee50c533a9734b74fd9">uip_buf</a>[<a class="code" href="a00150.html#gee37386b2ab828787c05227eb109def7">UIP_TCPIP_HLEN</a> + <a class="code" href="a00153.html#ge6f4a2453dbd8bc60e6a82774552366a">UIP_LLH_LEN</a>];
<a name="l00406"></a>00406
<a name="l00407"></a>00407 <a class="code" href="a00149.html#g12a33f0c09711167bdf3dd7d7cf8c5a1">uip_len</a> = <span class="keyword">sizeof</span>(<span class="keyword">struct </span>arp_hdr);
<a name="l00408"></a>00408 <span class="keywordflow">return</span>;
<a name="l00409"></a>00409 }
<a name="l00410"></a>00410
<a name="l00411"></a>00411 <span class="comment">/* Build an ethernet header. */</span>
<a name="l00412"></a>00412 memcpy(<a class="code" href="a00152.html#g9f2196e2705036869611962425e404bf">IPBUF</a>-&gt;ethhdr.dest.addr, tabptr-&gt;ethaddr.addr, 6);
<a name="l00413"></a>00413 }
<a name="l00414"></a>00414 memcpy(<a class="code" href="a00152.html#g9f2196e2705036869611962425e404bf">IPBUF</a>-&gt;ethhdr.src.addr, <a class="code" href="a00150.html#g499bb98a0b4ae9a98553ede81317606d">uip_ethaddr</a>.<a class="code" href="a00089.html#aacd5fa1806e0f0dd0bc96dd36507ad8">addr</a>, 6);
<a name="l00415"></a>00415
<a name="l00416"></a>00416 <a class="code" href="a00152.html#g9f2196e2705036869611962425e404bf">IPBUF</a>-&gt;ethhdr.type = <a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>(<a class="code" href="a00152.html#g03d140db75de3d3cdfbbab1c4fed8d8d">UIP_ETHTYPE_IP</a>);
<a name="l00417"></a>00417
<a name="l00418"></a>00418 <a class="code" href="a00149.html#g12a33f0c09711167bdf3dd7d7cf8c5a1">uip_len</a> += <span class="keyword">sizeof</span>(<span class="keyword">struct </span><a class="code" href="a00090.html">uip_eth_hdr</a>);
<a name="l00419"></a>00419 }
<a name="l00420"></a>00420 <span class="comment">/*-----------------------------------------------------------------------------------*/</span>
<a name="l00421"></a>00421 <span class="comment"></span>
<a name="l00422"></a>00422 <span class="comment">/** @} */</span><span class="comment"></span>
<a name="l00423"></a>00423 <span class="comment">/** @} */</span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Jun 12 10:23:01 2006 for uIP 1.0 by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.6 </small></address>
</body>
</html>