1<!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>uIP 1.0: uip/uip_arp.c Source File</title> 4<link href="doxygen.css" rel="stylesheet" type="text/css"> 5<link href="tabs.css" rel="stylesheet" type="text/css"> 6</head><body> 7<!-- Generated by Doxygen 1.4.6 --> 8<div class="tabs"> 9 <ul> 10 <li><a href="main.html"><span>Main Page</span></a></li> 11 <li><a href="modules.html"><span>Modules</span></a></li> 12 <li><a href="classes.html"><span>Data Structures</span></a></li> 13 <li id="current"><a href="files.html"><span>Files</span></a></li> 14 <li><a href="examples.html"><span>Examples</span></a></li> 15 </ul></div> 16<div class="tabs"> 17 <ul> 18 <li><a href="files.html"><span>File List</span></a></li> 19 <li><a href="globals.html"><span>Globals</span></a></li> 20 </ul></div> 21<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> 22<a name="l00002"></a>00002 <span class="comment"> * \addtogroup uip</span> 23<a name="l00003"></a>00003 <span class="comment"> * @{</span> 24<a name="l00004"></a>00004 <span class="comment"> */</span> 25<a name="l00005"></a>00005 <span class="comment"></span> 26<a name="l00006"></a>00006 <span class="comment">/**</span> 27<a name="l00007"></a>00007 <span class="comment"> * \defgroup uiparp uIP Address Resolution Protocol</span> 28<a name="l00008"></a>00008 <span class="comment"> * @{</span> 29<a name="l00009"></a>00009 <span class="comment"> *</span> 30<a name="l00010"></a>00010 <span class="comment"> * The Address Resolution Protocol ARP is used for mapping between IP</span> 31<a name="l00011"></a>00011 <span class="comment"> * addresses and link level addresses such as the Ethernet MAC</span> 32<a name="l00012"></a>00012 <span class="comment"> * addresses. ARP uses broadcast queries to ask for the link level</span> 33<a name="l00013"></a>00013 <span class="comment"> * address of a known IP address and the host which is configured with</span> 34<a name="l00014"></a>00014 <span class="comment"> * the IP address for which the query was meant, will respond with its</span> 35<a name="l00015"></a>00015 <span class="comment"> * link level address.</span> 36<a name="l00016"></a>00016 <span class="comment"> *</span> 37<a name="l00017"></a>00017 <span class="comment"> * \note This ARP implementation only supports Ethernet.</span> 38<a name="l00018"></a>00018 <span class="comment"> */</span> 39<a name="l00019"></a>00019 <span class="comment"></span> 40<a name="l00020"></a>00020 <span class="comment">/**</span> 41<a name="l00021"></a>00021 <span class="comment"> * \file</span> 42<a name="l00022"></a>00022 <span class="comment"> * Implementation of the ARP Address Resolution Protocol.</span> 43<a name="l00023"></a>00023 <span class="comment"> * \author Adam Dunkels <[email protected]></span> 44<a name="l00024"></a>00024 <span class="comment"> *</span> 45<a name="l00025"></a>00025 <span class="comment"> */</span> 46<a name="l00026"></a>00026 47<a name="l00027"></a>00027 <span class="comment">/*</span> 48<a name="l00028"></a>00028 <span class="comment"> * Copyright (c) 2001-2003, Adam Dunkels.</span> 49<a name="l00029"></a>00029 <span class="comment"> * All rights reserved.</span> 50<a name="l00030"></a>00030 <span class="comment"> *</span> 51<a name="l00031"></a>00031 <span class="comment"> * Redistribution and use in source and binary forms, with or without</span> 52<a name="l00032"></a>00032 <span class="comment"> * modification, are permitted provided that the following conditions</span> 53<a name="l00033"></a>00033 <span class="comment"> * are met:</span> 54<a name="l00034"></a>00034 <span class="comment"> * 1. Redistributions of source code must retain the above copyright</span> 55<a name="l00035"></a>00035 <span class="comment"> * notice, this list of conditions and the following disclaimer.</span> 56<a name="l00036"></a>00036 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span> 57<a name="l00037"></a>00037 <span class="comment"> * notice, this list of conditions and the following disclaimer in the</span> 58<a name="l00038"></a>00038 <span class="comment"> * documentation and/or other materials provided with the distribution.</span> 59<a name="l00039"></a>00039 <span class="comment"> * 3. The name of the author may not be used to endorse or promote</span> 60<a name="l00040"></a>00040 <span class="comment"> * products derived from this software without specific prior</span> 61<a name="l00041"></a>00041 <span class="comment"> * written permission.</span> 62<a name="l00042"></a>00042 <span class="comment"> *</span> 63<a name="l00043"></a>00043 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS</span> 64<a name="l00044"></a>00044 <span class="comment"> * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED</span> 65<a name="l00045"></a>00045 <span class="comment"> * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</span> 66<a name="l00046"></a>00046 <span class="comment"> * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY</span> 67<a name="l00047"></a>00047 <span class="comment"> * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL</span> 68<a name="l00048"></a>00048 <span class="comment"> * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE</span> 69<a name="l00049"></a>00049 <span class="comment"> * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS</span> 70<a name="l00050"></a>00050 <span class="comment"> * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,</span> 71<a name="l00051"></a>00051 <span class="comment"> * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING</span> 72<a name="l00052"></a>00052 <span class="comment"> * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS</span> 73<a name="l00053"></a>00053 <span class="comment"> * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span> 74<a name="l00054"></a>00054 <span class="comment"> *</span> 75<a name="l00055"></a>00055 <span class="comment"> * This file is part of the uIP TCP/IP stack.</span> 76<a name="l00056"></a>00056 <span class="comment"> *</span> 77<a name="l00057"></a>00057 <span class="comment"> * $Id: uip_arp.c,v 1.8 2006/06/02 23:36:21 adam Exp $</span> 78<a name="l00058"></a>00058 <span class="comment"> *</span> 79<a name="l00059"></a>00059 <span class="comment"> */</span> 80<a name="l00060"></a>00060 81<a name="l00061"></a>00061 82<a name="l00062"></a>00062 <span class="preprocessor">#include "<a class="code" href="a00139.html">uip_arp.h</a>"</span> 83<a name="l00063"></a>00063 84<a name="l00064"></a>00064 <span class="preprocessor">#include <string.h></span> 85<a name="l00065"></a>00065 86<a name="l00066"></a>00066 <span class="keyword">struct </span>arp_hdr { 87<a name="l00067"></a>00067 <span class="keyword">struct </span><a class="code" href="a00090.html">uip_eth_hdr</a> ethhdr; 88<a name="l00068"></a>00068 <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> hwtype; 89<a name="l00069"></a>00069 <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> protocol; 90<a name="l00070"></a>00070 <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> hwlen; 91<a name="l00071"></a>00071 <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> protolen; 92<a name="l00072"></a>00072 <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> opcode; 93<a name="l00073"></a>00073 <span class="keyword">struct </span><a class="code" href="a00089.html">uip_eth_addr</a> shwaddr; 94<a name="l00074"></a>00074 <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> sipaddr[2]; 95<a name="l00075"></a>00075 <span class="keyword">struct </span><a class="code" href="a00089.html">uip_eth_addr</a> dhwaddr; 96<a name="l00076"></a>00076 <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> dipaddr[2]; 97<a name="l00077"></a>00077 }; 98<a name="l00078"></a>00078 99<a name="l00079"></a>00079 <span class="keyword">struct </span>ethip_hdr { 100<a name="l00080"></a>00080 <span class="keyword">struct </span><a class="code" href="a00090.html">uip_eth_hdr</a> ethhdr; 101<a name="l00081"></a>00081 <span class="comment">/* IP header. */</span> 102<a name="l00082"></a>00082 <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> vhl, 103<a name="l00083"></a>00083 tos, 104<a name="l00084"></a>00084 len[2], 105<a name="l00085"></a>00085 ipid[2], 106<a name="l00086"></a>00086 ipoffset[2], 107<a name="l00087"></a>00087 ttl, 108<a name="l00088"></a>00088 proto; 109<a name="l00089"></a>00089 <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> ipchksum; 110<a name="l00090"></a>00090 <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> srcipaddr[2], 111<a name="l00091"></a>00091 destipaddr[2]; 112<a name="l00092"></a>00092 }; 113<a name="l00093"></a>00093 114<a name="l00094"></a><a class="code" href="a00152.html#g7a7c46ffaba30477b8c9e3e61bd2e106">00094</a> <span class="preprocessor">#define ARP_REQUEST 1</span> 115<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> 116<a name="l00096"></a>00096 <span class="preprocessor"></span> 117<a name="l00097"></a><a class="code" href="a00152.html#gbb56b549f7ab4d86e1cc39b8afc70d1e">00097</a> <span class="preprocessor">#define ARP_HWTYPE_ETH 1</span> 118<a name="l00098"></a>00098 <span class="preprocessor"></span> 119<a name="l00099"></a>00099 <span class="keyword">struct </span>arp_entry { 120<a name="l00100"></a>00100 <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> ipaddr[2]; 121<a name="l00101"></a>00101 <span class="keyword">struct </span><a class="code" href="a00089.html">uip_eth_addr</a> ethaddr; 122<a name="l00102"></a>00102 <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> time; 123<a name="l00103"></a>00103 }; 124<a name="l00104"></a>00104 125<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 = 126<a name="l00106"></a>00106 {{0xff,0xff,0xff,0xff,0xff,0xff}}; 127<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}; 128<a name="l00108"></a>00108 129<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>]; 130<a name="l00110"></a>00110 <span class="keyword">static</span> <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> ipaddr[2]; 131<a name="l00111"></a>00111 <span class="keyword">static</span> <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> i, c; 132<a name="l00112"></a>00112 133<a name="l00113"></a>00113 <span class="keyword">static</span> <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> arptime; 134<a name="l00114"></a>00114 <span class="keyword">static</span> <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> tmpage; 135<a name="l00115"></a>00115 136<a name="l00116"></a><a class="code" href="a00152.html#g24f52ac52d6e714cb04a5aa01be3bdd0">00116</a> <span class="preprocessor">#define BUF ((struct arp_hdr *)&uip_buf[0])</span> 137<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 *)&uip_buf[0])</span> 138<a name="l00118"></a>00118 <span class="preprocessor"></span><span class="comment">/*-----------------------------------------------------------------------------------*/</span><span class="comment"></span> 139<a name="l00119"></a>00119 <span class="comment">/**</span> 140<a name="l00120"></a>00120 <span class="comment"> * Initialize the ARP module.</span> 141<a name="l00121"></a>00121 <span class="comment"> *</span> 142<a name="l00122"></a>00122 <span class="comment"> */</span> 143<a name="l00123"></a>00123 <span class="comment">/*-----------------------------------------------------------------------------------*/</span> 144<a name="l00124"></a>00124 <span class="keywordtype">void</span> 145<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>) 146<a name="l00126"></a>00126 { 147<a name="l00127"></a>00127 <span class="keywordflow">for</span>(i = 0; i < <a class="code" href="a00153.html#gb1455b27c06532a399cf06d2c1d6d08d">UIP_ARPTAB_SIZE</a>; ++i) { 148<a name="l00128"></a>00128 memset(arp_table[i].ipaddr, 0, 4); 149<a name="l00129"></a>00129 } 150<a name="l00130"></a>00130 } 151<a name="l00131"></a>00131 <span class="comment">/*-----------------------------------------------------------------------------------*/</span><span class="comment"></span> 152<a name="l00132"></a>00132 <span class="comment">/**</span> 153<a name="l00133"></a>00133 <span class="comment"> * Periodic ARP processing function.</span> 154<a name="l00134"></a>00134 <span class="comment"> *</span> 155<a name="l00135"></a>00135 <span class="comment"> * This function performs periodic timer processing in the ARP module</span> 156<a name="l00136"></a>00136 <span class="comment"> * and should be called at regular intervals. The recommended interval</span> 157<a name="l00137"></a>00137 <span class="comment"> * is 10 seconds between the calls.</span> 158<a name="l00138"></a>00138 <span class="comment"> *</span> 159<a name="l00139"></a>00139 <span class="comment"> */</span> 160<a name="l00140"></a>00140 <span class="comment">/*-----------------------------------------------------------------------------------*/</span> 161<a name="l00141"></a>00141 <span class="keywordtype">void</span> 162<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>) 163<a name="l00143"></a>00143 { 164<a name="l00144"></a>00144 <span class="keyword">struct </span>arp_entry *tabptr; 165<a name="l00145"></a>00145 166<a name="l00146"></a>00146 ++arptime; 167<a name="l00147"></a>00147 <span class="keywordflow">for</span>(i = 0; i < <a class="code" href="a00153.html#gb1455b27c06532a399cf06d2c1d6d08d">UIP_ARPTAB_SIZE</a>; ++i) { 168<a name="l00148"></a>00148 tabptr = &arp_table[i]; 169<a name="l00149"></a>00149 <span class="keywordflow">if</span>((tabptr->ipaddr[0] | tabptr->ipaddr[1]) != 0 && 170<a name="l00150"></a>00150 arptime - tabptr->time >= <a class="code" href="a00153.html#g3090117ef3ff5775b77cb1960e442d07">UIP_ARP_MAXAGE</a>) { 171<a name="l00151"></a>00151 memset(tabptr->ipaddr, 0, 4); 172<a name="l00152"></a>00152 } 173<a name="l00153"></a>00153 } 174<a name="l00154"></a>00154 175<a name="l00155"></a>00155 } 176<a name="l00156"></a>00156 <span class="comment">/*-----------------------------------------------------------------------------------*/</span> 177<a name="l00157"></a>00157 <span class="keyword">static</span> <span class="keywordtype">void</span> 178<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) 179<a name="l00159"></a>00159 { 180<a name="l00160"></a>00160 <span class="keyword">register</span> <span class="keyword">struct </span>arp_entry *tabptr; 181<a name="l00161"></a>00161 <span class="comment">/* Walk through the ARP mapping table and try to find an entry to</span> 182<a name="l00162"></a>00162 <span class="comment"> update. If none is found, the IP -> MAC address mapping is</span> 183<a name="l00163"></a>00163 <span class="comment"> inserted in the ARP table. */</span> 184<a name="l00164"></a>00164 <span class="keywordflow">for</span>(i = 0; i < <a class="code" href="a00153.html#gb1455b27c06532a399cf06d2c1d6d08d">UIP_ARPTAB_SIZE</a>; ++i) { 185<a name="l00165"></a>00165 186<a name="l00166"></a>00166 tabptr = &arp_table[i]; 187<a name="l00167"></a>00167 <span class="comment">/* Only check those entries that are actually in use. */</span> 188<a name="l00168"></a>00168 <span class="keywordflow">if</span>(tabptr->ipaddr[0] != 0 && 189<a name="l00169"></a>00169 tabptr->ipaddr[1] != 0) { 190<a name="l00170"></a>00170 191<a name="l00171"></a>00171 <span class="comment">/* Check if the source IP address of the incoming packet matches</span> 192<a name="l00172"></a>00172 <span class="comment"> the IP address in this ARP table entry. */</span> 193<a name="l00173"></a>00173 <span class="keywordflow">if</span>(ipaddr[0] == tabptr->ipaddr[0] && 194<a name="l00174"></a>00174 ipaddr[1] == tabptr->ipaddr[1]) { 195<a name="l00175"></a>00175 196<a name="l00176"></a>00176 <span class="comment">/* An old entry found, update this and return. */</span> 197<a name="l00177"></a>00177 memcpy(tabptr->ethaddr.addr, ethaddr-><a class="code" href="a00089.html#aacd5fa1806e0f0dd0bc96dd36507ad8">addr</a>, 6); 198<a name="l00178"></a>00178 tabptr->time = arptime; 199<a name="l00179"></a>00179 200<a name="l00180"></a>00180 <span class="keywordflow">return</span>; 201<a name="l00181"></a>00181 } 202<a name="l00182"></a>00182 } 203<a name="l00183"></a>00183 } 204<a name="l00184"></a>00184 205<a name="l00185"></a>00185 <span class="comment">/* If we get here, no existing ARP table entry was found, so we</span> 206<a name="l00186"></a>00186 <span class="comment"> create one. */</span> 207<a name="l00187"></a>00187 208<a name="l00188"></a>00188 <span class="comment">/* First, we try to find an unused entry in the ARP table. */</span> 209<a name="l00189"></a>00189 <span class="keywordflow">for</span>(i = 0; i < <a class="code" href="a00153.html#gb1455b27c06532a399cf06d2c1d6d08d">UIP_ARPTAB_SIZE</a>; ++i) { 210<a name="l00190"></a>00190 tabptr = &arp_table[i]; 211<a name="l00191"></a>00191 <span class="keywordflow">if</span>(tabptr->ipaddr[0] == 0 && 212<a name="l00192"></a>00192 tabptr->ipaddr[1] == 0) { 213<a name="l00193"></a>00193 <span class="keywordflow">break</span>; 214<a name="l00194"></a>00194 } 215<a name="l00195"></a>00195 } 216<a name="l00196"></a>00196 217<a name="l00197"></a>00197 <span class="comment">/* If no unused entry is found, we try to find the oldest entry and</span> 218<a name="l00198"></a>00198 <span class="comment"> throw it away. */</span> 219<a name="l00199"></a>00199 <span class="keywordflow">if</span>(i == <a class="code" href="a00153.html#gb1455b27c06532a399cf06d2c1d6d08d">UIP_ARPTAB_SIZE</a>) { 220<a name="l00200"></a>00200 tmpage = 0; 221<a name="l00201"></a>00201 c = 0; 222<a name="l00202"></a>00202 <span class="keywordflow">for</span>(i = 0; i < <a class="code" href="a00153.html#gb1455b27c06532a399cf06d2c1d6d08d">UIP_ARPTAB_SIZE</a>; ++i) { 223<a name="l00203"></a>00203 tabptr = &arp_table[i]; 224<a name="l00204"></a>00204 <span class="keywordflow">if</span>(arptime - tabptr->time > tmpage) { 225<a name="l00205"></a>00205 tmpage = arptime - tabptr->time; 226<a name="l00206"></a>00206 c = i; 227<a name="l00207"></a>00207 } 228<a name="l00208"></a>00208 } 229<a name="l00209"></a>00209 i = c; 230<a name="l00210"></a>00210 tabptr = &arp_table[i]; 231<a name="l00211"></a>00211 } 232<a name="l00212"></a>00212 233<a name="l00213"></a>00213 <span class="comment">/* Now, i is the ARP table entry which we will fill with the new</span> 234<a name="l00214"></a>00214 <span class="comment"> information. */</span> 235<a name="l00215"></a>00215 memcpy(tabptr->ipaddr, ipaddr, 4); 236<a name="l00216"></a>00216 memcpy(tabptr->ethaddr.addr, ethaddr-><a class="code" href="a00089.html#aacd5fa1806e0f0dd0bc96dd36507ad8">addr</a>, 6); 237<a name="l00217"></a>00217 tabptr->time = arptime; 238<a name="l00218"></a>00218 } 239<a name="l00219"></a>00219 <span class="comment">/*-----------------------------------------------------------------------------------*/</span><span class="comment"></span> 240<a name="l00220"></a>00220 <span class="comment">/**</span> 241<a name="l00221"></a>00221 <span class="comment"> * ARP processing for incoming IP packets</span> 242<a name="l00222"></a>00222 <span class="comment"> *</span> 243<a name="l00223"></a>00223 <span class="comment"> * This function should be called by the device driver when an IP</span> 244<a name="l00224"></a>00224 <span class="comment"> * packet has been received. The function will check if the address is</span> 245<a name="l00225"></a>00225 <span class="comment"> * in the ARP cache, and if so the ARP cache entry will be</span> 246<a name="l00226"></a>00226 <span class="comment"> * refreshed. If no ARP cache entry was found, a new one is created.</span> 247<a name="l00227"></a>00227 <span class="comment"> *</span> 248<a name="l00228"></a>00228 <span class="comment"> * This function expects an IP packet with a prepended Ethernet header</span> 249<a name="l00229"></a>00229 <span class="comment"> * in the uip_buf[] buffer, and the length of the packet in the global</span> 250<a name="l00230"></a>00230 <span class="comment"> * variable uip_len.</span> 251<a name="l00231"></a>00231 <span class="comment"> */</span> 252<a name="l00232"></a>00232 <span class="comment">/*-----------------------------------------------------------------------------------*/</span> 253<a name="l00233"></a>00233 <span class="preprocessor">#if 0</span> 254<a name="l00234"></a>00234 <span class="preprocessor"></span><span class="keywordtype">void</span> 255<a name="l00235"></a>00235 <a class="code" href="a00152.html#g737337d6a51e31b236c8233d024138a8">uip_arp_ipin</a>(<span class="keywordtype">void</span>) 256<a name="l00236"></a>00236 { 257<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>); 258<a name="l00238"></a>00238 259<a name="l00239"></a>00239 <span class="comment">/* Only insert/update an entry if the source IP address of the</span> 260<a name="l00240"></a>00240 <span class="comment"> incoming IP packet comes from a host on the local network. */</span> 261<a name="l00241"></a>00241 <span class="keywordflow">if</span>((<a class="code" href="a00152.html#g9f2196e2705036869611962425e404bf">IPBUF</a>->srcipaddr[0] & <a class="code" href="a00150.html#g3237be0d9ec457de0177689ee23c0d5c">uip_netmask</a>[0]) != 262<a name="l00242"></a>00242 (<a class="code" href="a00150.html#g7d3673f52f5846b6961d23b150decd54">uip_hostaddr</a>[0] & <a class="code" href="a00150.html#g3237be0d9ec457de0177689ee23c0d5c">uip_netmask</a>[0])) { 263<a name="l00243"></a>00243 <span class="keywordflow">return</span>; 264<a name="l00244"></a>00244 } 265<a name="l00245"></a>00245 <span class="keywordflow">if</span>((<a class="code" href="a00152.html#g9f2196e2705036869611962425e404bf">IPBUF</a>->srcipaddr[1] & uip_netmask[1]) != 266<a name="l00246"></a>00246 (<a class="code" href="a00150.html#g7d3673f52f5846b6961d23b150decd54">uip_hostaddr</a>[1] & uip_netmask[1])) { 267<a name="l00247"></a>00247 <span class="keywordflow">return</span>; 268<a name="l00248"></a>00248 } 269<a name="l00249"></a>00249 uip_arp_update(<a class="code" href="a00152.html#g9f2196e2705036869611962425e404bf">IPBUF</a>->srcipaddr, &(<a class="code" href="a00152.html#g9f2196e2705036869611962425e404bf">IPBUF</a>->ethhdr.src)); 270<a name="l00250"></a>00250 271<a name="l00251"></a>00251 <span class="keywordflow">return</span>; 272<a name="l00252"></a>00252 } 273<a name="l00253"></a>00253 <span class="preprocessor">#endif </span><span class="comment">/* 0 */</span> 274<a name="l00254"></a>00254 <span class="comment">/*-----------------------------------------------------------------------------------*/</span><span class="comment"></span> 275<a name="l00255"></a>00255 <span class="comment">/**</span> 276<a name="l00256"></a>00256 <span class="comment"> * ARP processing for incoming ARP packets.</span> 277<a name="l00257"></a>00257 <span class="comment"> *</span> 278<a name="l00258"></a>00258 <span class="comment"> * This function should be called by the device driver when an ARP</span> 279<a name="l00259"></a>00259 <span class="comment"> * packet has been received. The function will act differently</span> 280<a name="l00260"></a>00260 <span class="comment"> * depending on the ARP packet type: if it is a reply for a request</span> 281<a name="l00261"></a>00261 <span class="comment"> * that we previously sent out, the ARP cache will be filled in with</span> 282<a name="l00262"></a>00262 <span class="comment"> * the values from the ARP reply. If the incoming ARP packet is an ARP</span> 283<a name="l00263"></a>00263 <span class="comment"> * request for our IP address, an ARP reply packet is created and put</span> 284<a name="l00264"></a>00264 <span class="comment"> * into the uip_buf[] buffer.</span> 285<a name="l00265"></a>00265 <span class="comment"> *</span> 286<a name="l00266"></a>00266 <span class="comment"> * When the function returns, the value of the global variable uip_len</span> 287<a name="l00267"></a>00267 <span class="comment"> * indicates whether the device driver should send out a packet or</span> 288<a name="l00268"></a>00268 <span class="comment"> * not. If uip_len is zero, no packet should be sent. If uip_len is</span> 289<a name="l00269"></a>00269 <span class="comment"> * non-zero, it contains the length of the outbound packet that is</span> 290<a name="l00270"></a>00270 <span class="comment"> * present in the uip_buf[] buffer.</span> 291<a name="l00271"></a>00271 <span class="comment"> *</span> 292<a name="l00272"></a>00272 <span class="comment"> * This function expects an ARP packet with a prepended Ethernet</span> 293<a name="l00273"></a>00273 <span class="comment"> * header in the uip_buf[] buffer, and the length of the packet in the</span> 294<a name="l00274"></a>00274 <span class="comment"> * global variable uip_len.</span> 295<a name="l00275"></a>00275 <span class="comment"> */</span> 296<a name="l00276"></a>00276 <span class="comment">/*-----------------------------------------------------------------------------------*/</span> 297<a name="l00277"></a>00277 <span class="keywordtype">void</span> 298<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>) 299<a name="l00279"></a>00279 { 300<a name="l00280"></a>00280 301<a name="l00281"></a>00281 <span class="keywordflow">if</span>(<a class="code" href="a00149.html#g12a33f0c09711167bdf3dd7d7cf8c5a1">uip_len</a> < <span class="keyword">sizeof</span>(<span class="keyword">struct</span> arp_hdr)) { 302<a name="l00282"></a>00282 <a class="code" href="a00149.html#g12a33f0c09711167bdf3dd7d7cf8c5a1">uip_len</a> = 0; 303<a name="l00283"></a>00283 <span class="keywordflow">return</span>; 304<a name="l00284"></a>00284 } 305<a name="l00285"></a>00285 <a class="code" href="a00149.html#g12a33f0c09711167bdf3dd7d7cf8c5a1">uip_len</a> = 0; 306<a name="l00286"></a>00286 307<a name="l00287"></a>00287 <span class="keywordflow">switch</span>(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->opcode) { 308<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>): 309<a name="l00289"></a>00289 <span class="comment">/* ARP request. If it asked for our address, we send out a</span> 310<a name="l00290"></a>00290 <span class="comment"> reply. */</span> 311<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>->dipaddr, <a class="code" href="a00150.html#g7d3673f52f5846b6961d23b150decd54">uip_hostaddr</a>)) { 312<a name="l00292"></a>00292 <span class="comment">/* First, we register the one who made the request in our ARP</span> 313<a name="l00293"></a>00293 <span class="comment"> table, since it is likely that we will do more communication</span> 314<a name="l00294"></a>00294 <span class="comment"> with this host in the future. */</span> 315<a name="l00295"></a>00295 uip_arp_update(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->sipaddr, &<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->shwaddr); 316<a name="l00296"></a>00296 317<a name="l00297"></a>00297 <span class="comment">/* The reply opcode is 2. */</span> 318<a name="l00298"></a>00298 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->opcode = <a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>(2); 319<a name="l00299"></a>00299 320<a name="l00300"></a>00300 memcpy(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->dhwaddr.addr, <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->shwaddr.addr, 6); 321<a name="l00301"></a>00301 memcpy(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->shwaddr.addr, <a class="code" href="a00150.html#g499bb98a0b4ae9a98553ede81317606d">uip_ethaddr</a>.<a class="code" href="a00089.html#aacd5fa1806e0f0dd0bc96dd36507ad8">addr</a>, 6); 322<a name="l00302"></a>00302 memcpy(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->ethhdr.src.addr, <a class="code" href="a00150.html#g499bb98a0b4ae9a98553ede81317606d">uip_ethaddr</a>.<a class="code" href="a00089.html#aacd5fa1806e0f0dd0bc96dd36507ad8">addr</a>, 6); 323<a name="l00303"></a>00303 memcpy(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->ethhdr.dest.addr, <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->dhwaddr.addr, 6); 324<a name="l00304"></a>00304 325<a name="l00305"></a>00305 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->dipaddr[0] = <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->sipaddr[0]; 326<a name="l00306"></a>00306 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->dipaddr[1] = <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->sipaddr[1]; 327<a name="l00307"></a>00307 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->sipaddr[0] = <a class="code" href="a00150.html#g7d3673f52f5846b6961d23b150decd54">uip_hostaddr</a>[0]; 328<a name="l00308"></a>00308 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->sipaddr[1] = <a class="code" href="a00150.html#g7d3673f52f5846b6961d23b150decd54">uip_hostaddr</a>[1]; 329<a name="l00309"></a>00309 330<a name="l00310"></a>00310 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->ethhdr.type = <a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>(<a class="code" href="a00152.html#g3e1562e8a6de32268e5df92a52152f91">UIP_ETHTYPE_ARP</a>); 331<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); 332<a name="l00312"></a>00312 } 333<a name="l00313"></a>00313 <span class="keywordflow">break</span>; 334<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>): 335<a name="l00315"></a>00315 <span class="comment">/* ARP reply. We insert or update the ARP table if it was meant</span> 336<a name="l00316"></a>00316 <span class="comment"> for us. */</span> 337<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>->dipaddr, <a class="code" href="a00150.html#g7d3673f52f5846b6961d23b150decd54">uip_hostaddr</a>)) { 338<a name="l00318"></a>00318 uip_arp_update(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->sipaddr, &<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->shwaddr); 339<a name="l00319"></a>00319 } 340<a name="l00320"></a>00320 <span class="keywordflow">break</span>; 341<a name="l00321"></a>00321 } 342<a name="l00322"></a>00322 343<a name="l00323"></a>00323 <span class="keywordflow">return</span>; 344<a name="l00324"></a>00324 } 345<a name="l00325"></a>00325 <span class="comment">/*-----------------------------------------------------------------------------------*/</span><span class="comment"></span> 346<a name="l00326"></a>00326 <span class="comment">/**</span> 347<a name="l00327"></a>00327 <span class="comment"> * Prepend Ethernet header to an outbound IP packet and see if we need</span> 348<a name="l00328"></a>00328 <span class="comment"> * to send out an ARP request.</span> 349<a name="l00329"></a>00329 <span class="comment"> *</span> 350<a name="l00330"></a>00330 <span class="comment"> * This function should be called before sending out an IP packet. The</span> 351<a name="l00331"></a>00331 <span class="comment"> * function checks the destination IP address of the IP packet to see</span> 352<a name="l00332"></a>00332 <span class="comment"> * what Ethernet MAC address that should be used as a destination MAC</span> 353<a name="l00333"></a>00333 <span class="comment"> * address on the Ethernet.</span> 354<a name="l00334"></a>00334 <span class="comment"> *</span> 355<a name="l00335"></a>00335 <span class="comment"> * If the destination IP address is in the local network (determined</span> 356<a name="l00336"></a>00336 <span class="comment"> * by logical ANDing of netmask and our IP address), the function</span> 357<a name="l00337"></a>00337 <span class="comment"> * checks the ARP cache to see if an entry for the destination IP</span> 358<a name="l00338"></a>00338 <span class="comment"> * address is found. If so, an Ethernet header is prepended and the</span> 359<a name="l00339"></a>00339 <span class="comment"> * function returns. If no ARP cache entry is found for the</span> 360<a name="l00340"></a>00340 <span class="comment"> * destination IP address, the packet in the uip_buf[] is replaced by</span> 361<a name="l00341"></a>00341 <span class="comment"> * an ARP request packet for the IP address. The IP packet is dropped</span> 362<a name="l00342"></a>00342 <span class="comment"> * and it is assumed that they higher level protocols (e.g., TCP)</span> 363<a name="l00343"></a>00343 <span class="comment"> * eventually will retransmit the dropped packet.</span> 364<a name="l00344"></a>00344 <span class="comment"> *</span> 365<a name="l00345"></a>00345 <span class="comment"> * If the destination IP address is not on the local network, the IP</span> 366<a name="l00346"></a>00346 <span class="comment"> * address of the default router is used instead.</span> 367<a name="l00347"></a>00347 <span class="comment"> *</span> 368<a name="l00348"></a>00348 <span class="comment"> * When the function returns, a packet is present in the uip_buf[]</span> 369<a name="l00349"></a>00349 <span class="comment"> * buffer, and the length of the packet is in the global variable</span> 370<a name="l00350"></a>00350 <span class="comment"> * uip_len.</span> 371<a name="l00351"></a>00351 <span class="comment"> */</span> 372<a name="l00352"></a>00352 <span class="comment">/*-----------------------------------------------------------------------------------*/</span> 373<a name="l00353"></a>00353 <span class="keywordtype">void</span> 374<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>) 375<a name="l00355"></a>00355 { 376<a name="l00356"></a>00356 <span class="keyword">struct </span>arp_entry *tabptr; 377<a name="l00357"></a>00357 378<a name="l00358"></a>00358 <span class="comment">/* Find the destination IP address in the ARP table and construct</span> 379<a name="l00359"></a>00359 <span class="comment"> the Ethernet header. If the destination IP addres isn't on the</span> 380<a name="l00360"></a>00360 <span class="comment"> local network, we use the default router's IP address instead.</span> 381<a name="l00361"></a>00361 <span class="comment"></span> 382<a name="l00362"></a>00362 <span class="comment"> If not ARP table entry is found, we overwrite the original IP</span> 383<a name="l00363"></a>00363 <span class="comment"> packet with an ARP request for the IP address. */</span> 384<a name="l00364"></a>00364 385<a name="l00365"></a>00365 <span class="comment">/* First check if destination is a local broadcast. */</span> 386<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>->destipaddr, broadcast_ipaddr)) { 387<a name="l00367"></a>00367 memcpy(<a class="code" href="a00152.html#g9f2196e2705036869611962425e404bf">IPBUF</a>->ethhdr.dest.addr, broadcast_ethaddr.<a class="code" href="a00089.html#aacd5fa1806e0f0dd0bc96dd36507ad8">addr</a>, 6); 388<a name="l00368"></a>00368 } <span class="keywordflow">else</span> { 389<a name="l00369"></a>00369 <span class="comment">/* Check if the destination address is on the local network. */</span> 390<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>->destipaddr, <a class="code" href="a00150.html#g7d3673f52f5846b6961d23b150decd54">uip_hostaddr</a>, uip_netmask)) { 391<a name="l00371"></a>00371 <span class="comment">/* Destination address was not on the local network, so we need to</span> 392<a name="l00372"></a>00372 <span class="comment"> use the default router's IP address instead of the destination</span> 393<a name="l00373"></a>00373 <span class="comment"> address when determining the MAC address. */</span> 394<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>); 395<a name="l00375"></a>00375 } <span class="keywordflow">else</span> { 396<a name="l00376"></a>00376 <span class="comment">/* Else, we use the destination IP address. */</span> 397<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>->destipaddr); 398<a name="l00378"></a>00378 } 399<a name="l00379"></a>00379 400<a name="l00380"></a>00380 <span class="keywordflow">for</span>(i = 0; i < <a class="code" href="a00153.html#gb1455b27c06532a399cf06d2c1d6d08d">UIP_ARPTAB_SIZE</a>; ++i) { 401<a name="l00381"></a>00381 tabptr = &arp_table[i]; 402<a name="l00382"></a>00382 <span class="keywordflow">if</span>(<a class="code" href="a00148.html#g210e629f7252e4bc8458cbdf260b3318">uip_ipaddr_cmp</a>(ipaddr, tabptr->ipaddr)) { 403<a name="l00383"></a>00383 <span class="keywordflow">break</span>; 404<a name="l00384"></a>00384 } 405<a name="l00385"></a>00385 } 406<a name="l00386"></a>00386 407<a name="l00387"></a>00387 <span class="keywordflow">if</span>(i == <a class="code" href="a00153.html#gb1455b27c06532a399cf06d2c1d6d08d">UIP_ARPTAB_SIZE</a>) { 408<a name="l00388"></a>00388 <span class="comment">/* The destination address was not in our ARP table, so we</span> 409<a name="l00389"></a>00389 <span class="comment"> overwrite the IP packet with an ARP request. */</span> 410<a name="l00390"></a>00390 411<a name="l00391"></a>00391 memset(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->ethhdr.dest.addr, 0xff, 6); 412<a name="l00392"></a>00392 memset(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->dhwaddr.addr, 0x00, 6); 413<a name="l00393"></a>00393 memcpy(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->ethhdr.src.addr, <a class="code" href="a00150.html#g499bb98a0b4ae9a98553ede81317606d">uip_ethaddr</a>.<a class="code" href="a00089.html#aacd5fa1806e0f0dd0bc96dd36507ad8">addr</a>, 6); 414<a name="l00394"></a>00394 memcpy(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->shwaddr.addr, <a class="code" href="a00150.html#g499bb98a0b4ae9a98553ede81317606d">uip_ethaddr</a>.<a class="code" href="a00089.html#aacd5fa1806e0f0dd0bc96dd36507ad8">addr</a>, 6); 415<a name="l00395"></a>00395 416<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>->dipaddr, ipaddr); 417<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>->sipaddr, <a class="code" href="a00150.html#g7d3673f52f5846b6961d23b150decd54">uip_hostaddr</a>); 418<a name="l00398"></a>00398 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->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> 419<a name="l00399"></a>00399 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->hwtype = <a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>(<a class="code" href="a00152.html#gbb56b549f7ab4d86e1cc39b8afc70d1e">ARP_HWTYPE_ETH</a>); 420<a name="l00400"></a>00400 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->protocol = <a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>(<a class="code" href="a00152.html#g03d140db75de3d3cdfbbab1c4fed8d8d">UIP_ETHTYPE_IP</a>); 421<a name="l00401"></a>00401 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->hwlen = 6; 422<a name="l00402"></a>00402 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->protolen = 4; 423<a name="l00403"></a>00403 <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->ethhdr.type = <a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>(<a class="code" href="a00152.html#g3e1562e8a6de32268e5df92a52152f91">UIP_ETHTYPE_ARP</a>); 424<a name="l00404"></a>00404 425<a name="l00405"></a>00405 <a class="code" href="a00150.html#g561b8eda32e059d4e7397f776268cc63">uip_appdata</a> = &<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>]; 426<a name="l00406"></a>00406 427<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); 428<a name="l00408"></a>00408 <span class="keywordflow">return</span>; 429<a name="l00409"></a>00409 } 430<a name="l00410"></a>00410 431<a name="l00411"></a>00411 <span class="comment">/* Build an ethernet header. */</span> 432<a name="l00412"></a>00412 memcpy(<a class="code" href="a00152.html#g9f2196e2705036869611962425e404bf">IPBUF</a>->ethhdr.dest.addr, tabptr->ethaddr.addr, 6); 433<a name="l00413"></a>00413 } 434<a name="l00414"></a>00414 memcpy(<a class="code" href="a00152.html#g9f2196e2705036869611962425e404bf">IPBUF</a>->ethhdr.src.addr, <a class="code" href="a00150.html#g499bb98a0b4ae9a98553ede81317606d">uip_ethaddr</a>.<a class="code" href="a00089.html#aacd5fa1806e0f0dd0bc96dd36507ad8">addr</a>, 6); 435<a name="l00415"></a>00415 436<a name="l00416"></a>00416 <a class="code" href="a00152.html#g9f2196e2705036869611962425e404bf">IPBUF</a>->ethhdr.type = <a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>(<a class="code" href="a00152.html#g03d140db75de3d3cdfbbab1c4fed8d8d">UIP_ETHTYPE_IP</a>); 437<a name="l00417"></a>00417 438<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>); 439<a name="l00419"></a>00419 } 440<a name="l00420"></a>00420 <span class="comment">/*-----------------------------------------------------------------------------------*/</span> 441<a name="l00421"></a>00421 <span class="comment"></span> 442<a name="l00422"></a>00422 <span class="comment">/** @} */</span><span class="comment"></span> 443<a name="l00423"></a>00423 <span class="comment">/** @} */</span> 444</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Jun 12 10:23:01 2006 for uIP 1.0 by 445<a href="http://www.doxygen.org/index.html"> 446<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.6 </small></address> 447</body> 448</html> 449