xref: /nrf52832-nimble/rt-thread/components/net/uip/doc/html/a00152.html (revision 042d53a763ad75cb1465103098bb88c245d95138)
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 Address Resolution Protocol</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&nbsp;Page</span></a></li>
11    <li><a href="modules.html"><span>Modules</span></a></li>
12    <li><a href="classes.html"><span>Data&nbsp;Structures</span></a></li>
13    <li><a href="files.html"><span>Files</span></a></li>
14    <li><a href="examples.html"><span>Examples</span></a></li>
15  </ul></div>
16<h1>uIP Address Resolution Protocol<br>
17<small>
18[<a class="el" href="a00150.html">The uIP TCP/IP stack</a>]</small>
19</h1><hr><a name="_details"></a><h2>Detailed Description</h2>
20The Address Resolution Protocol ARP is used for mapping between IP addresses and link level addresses such as the Ethernet MAC addresses.
21<p>
22ARP uses broadcast queries to ask for the link level address of a known IP address and the host which is configured with the IP address for which the query was meant, will respond with its link level address.<p>
23<dl compact><dt><b>Note:</b></dt><dd>This ARP implementation only supports Ethernet. </dd></dl>
24
25<p>
26<table border="0" cellpadding="0" cellspacing="0">
27<tr><td></td></tr>
28<tr><td colspan="2"><br><h2>Files</h2></td></tr>
29<tr><td class="memItemLeft" nowrap align="right" valign="top">file &nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00139.html">uip_arp.h</a></td></tr>
30
31<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Macros and definitions for the ARP module. <br></td></tr>
32
33<p>
34<tr><td class="memItemLeft" nowrap align="right" valign="top">file &nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00138.html">uip_arp.c</a></td></tr>
35
36<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Implementation of the ARP Address Resolution Protocol. <br></td></tr>
37
38<p>
39<tr><td colspan="2"><br><h2>Data Structures</h2></td></tr>
40<tr><td class="memItemLeft" nowrap align="right" valign="top">struct &nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00090.html">uip_eth_hdr</a></td></tr>
41
42<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">The Ethernet header.  <a href="a00090.html#_details">More...</a><br></td></tr>
43<tr><td colspan="2"><br><h2>Defines</h2></td></tr>
44<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g3e1562e8a6de32268e5df92a52152f91"></a><!-- doxytag: member="uiparp::UIP_ETHTYPE_ARP" ref="g3e1562e8a6de32268e5df92a52152f91" args="" -->
45#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00152.html#g3e1562e8a6de32268e5df92a52152f91">UIP_ETHTYPE_ARP</a>&nbsp;&nbsp;&nbsp;0x0806</td></tr>
46
47<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g03d140db75de3d3cdfbbab1c4fed8d8d"></a><!-- doxytag: member="uiparp::UIP_ETHTYPE_IP" ref="g03d140db75de3d3cdfbbab1c4fed8d8d" args="" -->
48#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00152.html#g03d140db75de3d3cdfbbab1c4fed8d8d">UIP_ETHTYPE_IP</a>&nbsp;&nbsp;&nbsp;0x0800</td></tr>
49
50<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="gbb558f3a9b1ec015e83c314aba694e35"></a><!-- doxytag: member="uiparp::UIP_ETHTYPE_IP6" ref="gbb558f3a9b1ec015e83c314aba694e35" args="" -->
51#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00152.html#gbb558f3a9b1ec015e83c314aba694e35">UIP_ETHTYPE_IP6</a>&nbsp;&nbsp;&nbsp;0x86dd</td></tr>
52
53<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g737337d6a51e31b236c8233d024138a8"></a><!-- doxytag: member="uiparp::uip_arp_ipin" ref="g737337d6a51e31b236c8233d024138a8" args="()" -->
54#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00152.html#g737337d6a51e31b236c8233d024138a8">uip_arp_ipin</a>()</td></tr>
55
56<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g7a7c46ffaba30477b8c9e3e61bd2e106"></a><!-- doxytag: member="uiparp::ARP_REQUEST" ref="g7a7c46ffaba30477b8c9e3e61bd2e106" args="" -->
57#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00152.html#g7a7c46ffaba30477b8c9e3e61bd2e106">ARP_REQUEST</a>&nbsp;&nbsp;&nbsp;1</td></tr>
58
59<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g06ba7b414e718081998f2814090debf1"></a><!-- doxytag: member="uiparp::ARP_REPLY" ref="g06ba7b414e718081998f2814090debf1" args="" -->
60#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00152.html#g06ba7b414e718081998f2814090debf1">ARP_REPLY</a>&nbsp;&nbsp;&nbsp;2</td></tr>
61
62<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="gbb56b549f7ab4d86e1cc39b8afc70d1e"></a><!-- doxytag: member="uiparp::ARP_HWTYPE_ETH" ref="gbb56b549f7ab4d86e1cc39b8afc70d1e" args="" -->
63#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00152.html#gbb56b549f7ab4d86e1cc39b8afc70d1e">ARP_HWTYPE_ETH</a>&nbsp;&nbsp;&nbsp;1</td></tr>
64
65<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g24f52ac52d6e714cb04a5aa01be3bdd0"></a><!-- doxytag: member="uiparp::BUF" ref="g24f52ac52d6e714cb04a5aa01be3bdd0" args="" -->
66#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00152.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>&nbsp;&nbsp;&nbsp;((struct arp_hdr *)&amp;<a class="el" href="a00150.html#gb81e78f890dbbee50c533a9734b74fd9">uip_buf</a>[0])</td></tr>
67
68<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g9f2196e2705036869611962425e404bf"></a><!-- doxytag: member="uiparp::IPBUF" ref="g9f2196e2705036869611962425e404bf" args="" -->
69#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00152.html#g9f2196e2705036869611962425e404bf">IPBUF</a>&nbsp;&nbsp;&nbsp;((struct ethip_hdr *)&amp;<a class="el" href="a00150.html#gb81e78f890dbbee50c533a9734b74fd9">uip_buf</a>[0])</td></tr>
70
71<tr><td colspan="2"><br><h2>Functions</h2></td></tr>
72<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g2d9d28afa353f662b9bb5234fc419f72"></a><!-- doxytag: member="uiparp::uip_arp_init" ref="g2d9d28afa353f662b9bb5234fc419f72" args="(void)" -->
73void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00152.html#g2d9d28afa353f662b9bb5234fc419f72">uip_arp_init</a> (void)</td></tr>
74
75<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Initialize the ARP module. <br></td></tr>
76<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00152.html#g902c4a360134096224bc2655f623aa5f">uip_arp_arpin</a> (void)</td></tr>
77
78<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">ARP processing for incoming ARP packets.  <a href="#g902c4a360134096224bc2655f623aa5f"></a><br></td></tr>
79<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00152.html#g54b27e45df15e10a0eb1a3e3a91417d2">uip_arp_out</a> (void)</td></tr>
80
81<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Prepend Ethernet header to an outbound IP packet and see if we need to send out an ARP request.  <a href="#g54b27e45df15e10a0eb1a3e3a91417d2"></a><br></td></tr>
82<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00152.html#g058a8e6025f67b021862281f1911fcef">uip_arp_timer</a> (void)</td></tr>
83
84<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Periodic ARP processing function.  <a href="#g058a8e6025f67b021862281f1911fcef"></a><br></td></tr>
85<tr><td colspan="2"><br><h2>Variables</h2></td></tr>
86<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g499bb98a0b4ae9a98553ede81317606d"></a><!-- doxytag: member="uiparp::uip_ethaddr" ref="g499bb98a0b4ae9a98553ede81317606d" args="" -->
87<a class="el" href="a00089.html">uip_eth_addr</a>&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00152.html#g499bb98a0b4ae9a98553ede81317606d">uip_ethaddr</a></td></tr>
88
89</table>
90<hr><h2>Function Documentation</h2>
91<a class="anchor" name="g902c4a360134096224bc2655f623aa5f"></a><!-- doxytag: member="uip_arp.h::uip_arp_arpin" ref="g902c4a360134096224bc2655f623aa5f" args="(void)" --><p>
92<table class="mdTable" cellpadding="2" cellspacing="0">
93  <tr>
94    <td class="mdRow">
95      <table cellpadding="0" cellspacing="0" border="0">
96        <tr>
97          <td class="md" nowrap valign="top">void uip_arp_arpin           </td>
98          <td class="md" valign="top">(&nbsp;</td>
99          <td class="md" nowrap valign="top">void&nbsp;</td>
100          <td class="mdname1" valign="top" nowrap>          </td>
101          <td class="md" valign="top">&nbsp;)&nbsp;</td>
102          <td class="md" nowrap></td>
103        </tr>
104      </table>
105    </td>
106  </tr>
107</table>
108<table cellspacing="5" cellpadding="0" border="0">
109  <tr>
110    <td>
111      &nbsp;
112    </td>
113    <td>
114
115<p>
116ARP processing for incoming ARP packets.
117<p>
118This function should be called by the device driver when an ARP packet has been received. The function will act differently depending on the ARP packet type: if it is a reply for a request that we previously sent out, the ARP cache will be filled in with the values from the ARP reply. If the incoming ARP packet is an ARP request for our IP address, an ARP reply packet is created and put into the uip_buf[] buffer.<p>
119When the function returns, the value of the global variable uip_len indicates whether the device driver should send out a packet or not. If uip_len is zero, no packet should be sent. If uip_len is non-zero, it contains the length of the outbound packet that is present in the uip_buf[] buffer.<p>
120This function expects an ARP packet with a prepended Ethernet header in the uip_buf[] buffer, and the length of the packet in the global variable uip_len. <dl compact><dt><b>Examples: </b></dt><dd>
121<a class="el" href="a00042.html#a76">example-mainloop-with-arp.c</a>.</dl>
122<p>
123Definition at line <a class="el" href="a00204.html#l00278">278</a> of file <a class="el" href="a00204.html">uip_arp.c</a>.
124<p>
125References <a class="el" href="a00202.html#l01543">uip_eth_addr::addr</a>, <a class="el" href="a00204.html#l00095">ARP_REPLY</a>, <a class="el" href="a00204.html#l00094">ARP_REQUEST</a>, <a class="el" href="a00201.html#l00226">BUF</a>, <a class="el" href="a00202.html#l01070">HTONS</a>, <a class="el" href="a00201.html#l00135">uip_ethaddr</a>, <a class="el" href="a00205.html#l00069">UIP_ETHTYPE_ARP</a>, <a class="el" href="a00201.html#l00110">uip_hostaddr</a>, <a class="el" href="a00202.html#l00911">uip_ipaddr_cmp</a>, and <a class="el" href="a00201.html#l00155">uip_len</a>.    </td>
126  </tr>
127</table>
128<a class="anchor" name="g54b27e45df15e10a0eb1a3e3a91417d2"></a><!-- doxytag: member="uip_arp.h::uip_arp_out" ref="g54b27e45df15e10a0eb1a3e3a91417d2" args="(void)" --><p>
129<table class="mdTable" cellpadding="2" cellspacing="0">
130  <tr>
131    <td class="mdRow">
132      <table cellpadding="0" cellspacing="0" border="0">
133        <tr>
134          <td class="md" nowrap valign="top">void uip_arp_out           </td>
135          <td class="md" valign="top">(&nbsp;</td>
136          <td class="md" nowrap valign="top">void&nbsp;</td>
137          <td class="mdname1" valign="top" nowrap>          </td>
138          <td class="md" valign="top">&nbsp;)&nbsp;</td>
139          <td class="md" nowrap></td>
140        </tr>
141      </table>
142    </td>
143  </tr>
144</table>
145<table cellspacing="5" cellpadding="0" border="0">
146  <tr>
147    <td>
148      &nbsp;
149    </td>
150    <td>
151
152<p>
153Prepend Ethernet header to an outbound IP packet and see if we need to send out an ARP request.
154<p>
155This function should be called before sending out an IP packet. The function checks the destination IP address of the IP packet to see what Ethernet MAC address that should be used as a destination MAC address on the Ethernet.<p>
156If the destination IP address is in the local network (determined by logical ANDing of netmask and our IP address), the function checks the ARP cache to see if an entry for the destination IP address is found. If so, an Ethernet header is prepended and the function returns. If no ARP cache entry is found for the destination IP address, the packet in the uip_buf[] is replaced by an ARP request packet for the IP address. The IP packet is dropped and it is assumed that they higher level protocols (e.g., TCP) eventually will retransmit the dropped packet.<p>
157If the destination IP address is not on the local network, the IP address of the default router is used instead.<p>
158When the function returns, a packet is present in the uip_buf[] buffer, and the length of the packet is in the global variable uip_len. <dl compact><dt><b>Examples: </b></dt><dd>
159<a class="el" href="a00042.html#a74">example-mainloop-with-arp.c</a>.</dl>
160<p>
161Definition at line <a class="el" href="a00204.html#l00354">354</a> of file <a class="el" href="a00204.html">uip_arp.c</a>.
162<p>
163References <a class="el" href="a00202.html#l01543">uip_eth_addr::addr</a>, <a class="el" href="a00204.html#l00117">IPBUF</a>, <a class="el" href="a00206.html#l00349">UIP_ARPTAB_SIZE</a>, <a class="el" href="a00201.html#l00110">uip_draddr</a>, <a class="el" href="a00201.html#l00110">uip_hostaddr</a>, <a class="el" href="a00202.html#l00911">uip_ipaddr_cmp</a>, <a class="el" href="a00202.html#l00882">uip_ipaddr_copy</a>, and <a class="el" href="a00202.html#l00941">uip_ipaddr_maskcmp</a>.    </td>
164  </tr>
165</table>
166<a class="anchor" name="g058a8e6025f67b021862281f1911fcef"></a><!-- doxytag: member="uip_arp.h::uip_arp_timer" ref="g058a8e6025f67b021862281f1911fcef" args="(void)" --><p>
167<table class="mdTable" cellpadding="2" cellspacing="0">
168  <tr>
169    <td class="mdRow">
170      <table cellpadding="0" cellspacing="0" border="0">
171        <tr>
172          <td class="md" nowrap valign="top">void uip_arp_timer           </td>
173          <td class="md" valign="top">(&nbsp;</td>
174          <td class="md" nowrap valign="top">void&nbsp;</td>
175          <td class="mdname1" valign="top" nowrap>          </td>
176          <td class="md" valign="top">&nbsp;)&nbsp;</td>
177          <td class="md" nowrap></td>
178        </tr>
179      </table>
180    </td>
181  </tr>
182</table>
183<table cellspacing="5" cellpadding="0" border="0">
184  <tr>
185    <td>
186      &nbsp;
187    </td>
188    <td>
189
190<p>
191Periodic ARP processing function.
192<p>
193This function performs periodic timer processing in the ARP module and should be called at regular intervals. The recommended interval is 10 seconds between the calls. <dl compact><dt><b>Examples: </b></dt><dd>
194<a class="el" href="a00042.html#a83">example-mainloop-with-arp.c</a>.</dl>
195<p>
196Definition at line <a class="el" href="a00204.html#l00142">142</a> of file <a class="el" href="a00204.html">uip_arp.c</a>.
197<p>
198References <a class="el" href="a00206.html#l00358">UIP_ARP_MAXAGE</a>, and <a class="el" href="a00206.html#l00349">UIP_ARPTAB_SIZE</a>.    </td>
199  </tr>
200</table>
201<hr size="1"><address style="align: right;"><small>Generated on Mon Jun 12 10:23:02 2006 for uIP 1.0 by&nbsp;
202<a href="http://www.doxygen.org/index.html">
203<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.6 </small></address>
204</body>
205</html>
206