107 lines
10 KiB
HTML
107 lines
10 KiB
HTML
<!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: example-mainloop-with-arp.c</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 Page</span></a></li>
|
|
<li><a href="modules.html"><span>Modules</span></a></li>
|
|
<li><a href="classes.html"><span>Data Structures</span></a></li>
|
|
<li><a href="files.html"><span>Files</span></a></li>
|
|
<li><a href="examples.html"><span>Examples</span></a></li>
|
|
</ul></div>
|
|
<h1>example-mainloop-with-arp.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include "<a class="code" href="a00136.html">uip.h</a>"</span>
|
|
<a name="l00002"></a>00002 <span class="preprocessor">#include "<a class="code" href="a00139.html">uip_arp.h</a>"</span>
|
|
<a name="l00003"></a>00003 <span class="preprocessor">#include "network-device.h"</span>
|
|
<a name="l00004"></a>00004 <span class="preprocessor">#include "httpd.h"</span>
|
|
<a name="l00005"></a>00005 <span class="preprocessor">#include "<a class="code" href="a00130.html">timer.h</a>"</span>
|
|
<a name="l00006"></a>00006
|
|
<a name="l00007"></a>00007 <span class="preprocessor">#define BUF ((struct uip_eth_hdr *)&uip_buf[0])</span>
|
|
<a name="l00008"></a>00008 <span class="preprocessor"></span>
|
|
<a name="l00009"></a>00009 <span class="comment">/*---------------------------------------------------------------------------*/</span>
|
|
<a name="l00010"></a>00010 <span class="keywordtype">int</span>
|
|
<a name="l00011"></a>00011 main(<span class="keywordtype">void</span>)
|
|
<a name="l00012"></a>00012 {
|
|
<a name="l00013"></a>00013 <span class="keywordtype">int</span> i;
|
|
<a name="l00014"></a>00014 <a name="a60"></a><a class="code" href="a00150.html#g1ef35301f43a5bbb9f89f07b5a36b9a0">uip_ipaddr_t</a> ipaddr;
|
|
<a name="l00015"></a>00015 <span class="keyword">struct </span><a name="_a61"></a><a class="code" href="a00087.html">timer</a> periodic_timer, arp_timer;
|
|
<a name="l00016"></a>00016
|
|
<a name="l00017"></a>00017 <a name="a62"></a><a class="code" href="a00156.html#g6614d96fdfcd95c95ec6e6f63071ff51">timer_set</a>(&periodic_timer, <a name="a63"></a><a class="code" href="a00157.html#ge3ced0551b26c9b99cb45a86f34d100a">CLOCK_SECOND</a> / 2);
|
|
<a name="l00018"></a>00018 <a class="code" href="a00156.html#g6614d96fdfcd95c95ec6e6f63071ff51">timer_set</a>(&arp_timer, <a class="code" href="a00157.html#ge3ced0551b26c9b99cb45a86f34d100a">CLOCK_SECOND</a> * 10);
|
|
<a name="l00019"></a>00019
|
|
<a name="l00020"></a>00020 network_device_init();
|
|
<a name="l00021"></a>00021 <a name="a64"></a><a class="code" href="a00145.html#gc48ed5f0d27721ef62a3ed02a5ad8d2e">uip_init</a>();
|
|
<a name="l00022"></a>00022
|
|
<a name="l00023"></a>00023 <a name="a65"></a><a class="code" href="a00148.html#g87f0b54ade0d159fba495089128a4932">uip_ipaddr</a>(ipaddr, 192,168,0,2);
|
|
<a name="l00024"></a>00024 <a name="a66"></a><a class="code" href="a00144.html#g12b467f314489259dd718228d0827a51">uip_sethostaddr</a>(ipaddr);
|
|
<a name="l00025"></a>00025
|
|
<a name="l00026"></a>00026 <a name="a67"></a><a class="code" href="a00164.html#gc364305cee969a0be43c071722b136e6">httpd_init</a>();
|
|
<a name="l00027"></a>00027
|
|
<a name="l00028"></a>00028 <span class="keywordflow">while</span>(1) {
|
|
<a name="l00029"></a>00029 <a name="a68"></a><a class="code" href="a00149.html#g12a33f0c09711167bdf3dd7d7cf8c5a1">uip_len</a> = network_device_read();
|
|
<a name="l00030"></a>00030 <span class="keywordflow">if</span>(<a class="code" href="a00149.html#g12a33f0c09711167bdf3dd7d7cf8c5a1">uip_len</a> > 0) {
|
|
<a name="l00031"></a>00031 <span class="keywordflow">if</span>(<a name="a69"></a><a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->type == <a name="a70"></a><a class="code" href="a00148.html#ga22b04cac8cf283ca12f028578bebc06">htons</a>(<a name="a71"></a><a class="code" href="a00152.html#g03d140db75de3d3cdfbbab1c4fed8d8d">UIP_ETHTYPE_IP</a>)) {
|
|
<a name="l00032"></a>00032 <a name="a72"></a><a class="code" href="a00152.html#g737337d6a51e31b236c8233d024138a8">uip_arp_ipin</a>();
|
|
<a name="l00033"></a>00033 <a name="a73"></a><a class="code" href="a00146.html#ga4360412ee9350fba725f98a137169fe">uip_input</a>();
|
|
<a name="l00034"></a>00034 <span class="comment">/* If the above function invocation resulted in data that</span>
|
|
<a name="l00035"></a>00035 <span class="comment"> should be sent out on the network, the global variable</span>
|
|
<a name="l00036"></a>00036 <span class="comment"> uip_len is set to a value > 0. */</span>
|
|
<a name="l00037"></a>00037 <span class="keywordflow">if</span>(<a class="code" href="a00149.html#g12a33f0c09711167bdf3dd7d7cf8c5a1">uip_len</a> > 0) {
|
|
<a name="l00038"></a>00038 <a name="a74"></a><a class="code" href="a00152.html#g54b27e45df15e10a0eb1a3e3a91417d2">uip_arp_out</a>();
|
|
<a name="l00039"></a>00039 network_device_send();
|
|
<a name="l00040"></a>00040 }
|
|
<a name="l00041"></a>00041 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>->type == <a class="code" href="a00148.html#ga22b04cac8cf283ca12f028578bebc06">htons</a>(<a name="a75"></a><a class="code" href="a00152.html#g3e1562e8a6de32268e5df92a52152f91">UIP_ETHTYPE_ARP</a>)) {
|
|
<a name="l00042"></a>00042 <a name="a76"></a><a class="code" href="a00152.html#g902c4a360134096224bc2655f623aa5f">uip_arp_arpin</a>();
|
|
<a name="l00043"></a>00043 <span class="comment">/* If the above function invocation resulted in data that</span>
|
|
<a name="l00044"></a>00044 <span class="comment"> should be sent out on the network, the global variable</span>
|
|
<a name="l00045"></a>00045 <span class="comment"> uip_len is set to a value > 0. */</span>
|
|
<a name="l00046"></a>00046 <span class="keywordflow">if</span>(<a class="code" href="a00149.html#g12a33f0c09711167bdf3dd7d7cf8c5a1">uip_len</a> > 0) {
|
|
<a name="l00047"></a>00047 network_device_send();
|
|
<a name="l00048"></a>00048 }
|
|
<a name="l00049"></a>00049 }
|
|
<a name="l00050"></a>00050
|
|
<a name="l00051"></a>00051 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(<a name="a77"></a><a class="code" href="a00156.html#g6d71dececfce707c668e6257aad5906e">timer_expired</a>(&periodic_timer)) {
|
|
<a name="l00052"></a>00052 <a name="a78"></a><a class="code" href="a00156.html#gedaf3e48c2b04229b85455fb948468d6">timer_reset</a>(&periodic_timer);
|
|
<a name="l00053"></a>00053 <span class="keywordflow">for</span>(i = 0; i < <a name="a79"></a><a class="code" href="a00153.html#gf5fe83be78b78b9e7d9e7f1e34ab1cc5">UIP_CONNS</a>; i++) {
|
|
<a name="l00054"></a>00054 <a name="a80"></a><a class="code" href="a00146.html#g1024f8a5fa65e82bf848b2e6590d9628">uip_periodic</a>(i);
|
|
<a name="l00055"></a>00055 <span class="comment">/* If the above function invocation resulted in data that</span>
|
|
<a name="l00056"></a>00056 <span class="comment"> should be sent out on the network, the global variable</span>
|
|
<a name="l00057"></a>00057 <span class="comment"> uip_len is set to a value > 0. */</span>
|
|
<a name="l00058"></a>00058 <span class="keywordflow">if</span>(<a class="code" href="a00149.html#g12a33f0c09711167bdf3dd7d7cf8c5a1">uip_len</a> > 0) {
|
|
<a name="l00059"></a>00059 <a class="code" href="a00152.html#g54b27e45df15e10a0eb1a3e3a91417d2">uip_arp_out</a>();
|
|
<a name="l00060"></a>00060 network_device_send();
|
|
<a name="l00061"></a>00061 }
|
|
<a name="l00062"></a>00062 }
|
|
<a name="l00063"></a>00063
|
|
<a name="l00064"></a>00064 <span class="preprocessor">#if UIP_UDP</span>
|
|
<a name="l00065"></a>00065 <span class="preprocessor"></span> <span class="keywordflow">for</span>(i = 0; i < <a name="a81"></a><a class="code" href="a00153.html#g196379ceb1219a99f4495e41ccc9bbfb">UIP_UDP_CONNS</a>; i++) {
|
|
<a name="l00066"></a>00066 <a name="a82"></a><a class="code" href="a00146.html#g2c64c8c36bc84f9336f6a2184ea51883">uip_udp_periodic</a>(i);
|
|
<a name="l00067"></a>00067 <span class="comment">/* If the above function invocation resulted in data that</span>
|
|
<a name="l00068"></a>00068 <span class="comment"> should be sent out on the network, the global variable</span>
|
|
<a name="l00069"></a>00069 <span class="comment"> uip_len is set to a value > 0. */</span>
|
|
<a name="l00070"></a>00070 <span class="keywordflow">if</span>(<a class="code" href="a00149.html#g12a33f0c09711167bdf3dd7d7cf8c5a1">uip_len</a> > 0) {
|
|
<a name="l00071"></a>00071 <a class="code" href="a00152.html#g54b27e45df15e10a0eb1a3e3a91417d2">uip_arp_out</a>();
|
|
<a name="l00072"></a>00072 network_device_send();
|
|
<a name="l00073"></a>00073 }
|
|
<a name="l00074"></a>00074 }
|
|
<a name="l00075"></a>00075 <span class="preprocessor">#endif </span><span class="comment">/* UIP_UDP */</span>
|
|
<a name="l00076"></a>00076
|
|
<a name="l00077"></a>00077 <span class="comment">/* Call the ARP timer function every 10 seconds. */</span>
|
|
<a name="l00078"></a>00078 <span class="keywordflow">if</span>(<a class="code" href="a00156.html#g6d71dececfce707c668e6257aad5906e">timer_expired</a>(&arp_timer)) {
|
|
<a name="l00079"></a>00079 <a class="code" href="a00156.html#gedaf3e48c2b04229b85455fb948468d6">timer_reset</a>(&arp_timer);
|
|
<a name="l00080"></a>00080 <a name="a83"></a><a class="code" href="a00152.html#g058a8e6025f67b021862281f1911fcef">uip_arp_timer</a>();
|
|
<a name="l00081"></a>00081 }
|
|
<a name="l00082"></a>00082 }
|
|
<a name="l00083"></a>00083 }
|
|
<a name="l00084"></a>00084 <span class="keywordflow">return</span> 0;
|
|
<a name="l00085"></a>00085 }
|
|
<a name="l00086"></a>00086 <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
|
|
<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>
|