PageRenderTime 336ms CodeModel.GetById 81ms app.highlight 163ms RepoModel.GetById 38ms app.codeStats 3ms

/rtt-1.1.0b/rt-thread_os/components/net/uip/doc/html/a00201.html

https://bitbucket.org/darcyg/shenzhou-iv-stm32f107-rt-thread
HTML | 1922 lines | 1921 code | 0 blank | 1 comment | 0 complexity | 19f1eae25452a103ce8b0cc7368a3534 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  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.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&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 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&nbsp;List</span></a></li>
 19    <li><a href="globals.html"><span>Globals</span></a></li>
 20  </ul></div>
 21<h1>uip/uip.c</h1><a href="a00135.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a><a class="code" href="a00135.html#534d9e416324fb8ecca6b9cb4b1f6a6a">00001</a> <span class="preprocessor">#define DEBUG_PRINTF(...) </span><span class="comment">/*printf(__VA_ARGS__)*/</span>
 22<a name="l00002"></a>00002 <span class="comment"></span>
 23<a name="l00003"></a>00003 <span class="comment">/**</span>
 24<a name="l00004"></a>00004 <span class="comment"> * \defgroup uip The uIP TCP/IP stack</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"> * uIP is an implementation of the TCP/IP protocol stack intended for</span>
 28<a name="l00008"></a>00008 <span class="comment"> * small 8-bit and 16-bit microcontrollers.</span>
 29<a name="l00009"></a>00009 <span class="comment"> *</span>
 30<a name="l00010"></a>00010 <span class="comment"> * uIP provides the necessary protocols for Internet communication,</span>
 31<a name="l00011"></a>00011 <span class="comment"> * with a very small code footprint and RAM requirements - the uIP</span>
 32<a name="l00012"></a>00012 <span class="comment"> * code size is on the order of a few kilobytes and RAM usage is on</span>
 33<a name="l00013"></a>00013 <span class="comment"> * the order of a few hundred bytes.</span>
 34<a name="l00014"></a>00014 <span class="comment"> */</span>
 35<a name="l00015"></a>00015 <span class="comment"></span>
 36<a name="l00016"></a>00016 <span class="comment">/**</span>
 37<a name="l00017"></a>00017 <span class="comment"> * \file</span>
 38<a name="l00018"></a>00018 <span class="comment"> * The uIP TCP/IP stack code.</span>
 39<a name="l00019"></a>00019 <span class="comment"> * \author Adam Dunkels &lt;adam@dunkels.com&gt;</span>
 40<a name="l00020"></a>00020 <span class="comment"> */</span>
 41<a name="l00021"></a>00021 
 42<a name="l00022"></a>00022 <span class="comment">/*</span>
 43<a name="l00023"></a>00023 <span class="comment"> * Copyright (c) 2001-2003, Adam Dunkels.</span>
 44<a name="l00024"></a>00024 <span class="comment"> * All rights reserved.</span>
 45<a name="l00025"></a>00025 <span class="comment"> *</span>
 46<a name="l00026"></a>00026 <span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
 47<a name="l00027"></a>00027 <span class="comment"> * modification, are permitted provided that the following conditions</span>
 48<a name="l00028"></a>00028 <span class="comment"> * are met:</span>
 49<a name="l00029"></a>00029 <span class="comment"> * 1. Redistributions of source code must retain the above copyright</span>
 50<a name="l00030"></a>00030 <span class="comment"> *    notice, this list of conditions and the following disclaimer.</span>
 51<a name="l00031"></a>00031 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span>
 52<a name="l00032"></a>00032 <span class="comment"> *    notice, this list of conditions and the following disclaimer in the</span>
 53<a name="l00033"></a>00033 <span class="comment"> *    documentation and/or other materials provided with the distribution.</span>
 54<a name="l00034"></a>00034 <span class="comment"> * 3. The name of the author may not be used to endorse or promote</span>
 55<a name="l00035"></a>00035 <span class="comment"> *    products derived from this software without specific prior</span>
 56<a name="l00036"></a>00036 <span class="comment"> *    written permission.</span>
 57<a name="l00037"></a>00037 <span class="comment"> *</span>
 58<a name="l00038"></a>00038 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS</span>
 59<a name="l00039"></a>00039 <span class="comment"> * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED</span>
 60<a name="l00040"></a>00040 <span class="comment"> * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</span>
 61<a name="l00041"></a>00041 <span class="comment"> * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY</span>
 62<a name="l00042"></a>00042 <span class="comment"> * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL</span>
 63<a name="l00043"></a>00043 <span class="comment"> * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE</span>
 64<a name="l00044"></a>00044 <span class="comment"> * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS</span>
 65<a name="l00045"></a>00045 <span class="comment"> * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,</span>
 66<a name="l00046"></a>00046 <span class="comment"> * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING</span>
 67<a name="l00047"></a>00047 <span class="comment"> * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS</span>
 68<a name="l00048"></a>00048 <span class="comment"> * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
 69<a name="l00049"></a>00049 <span class="comment"> *</span>
 70<a name="l00050"></a>00050 <span class="comment"> * This file is part of the uIP TCP/IP stack.</span>
 71<a name="l00051"></a>00051 <span class="comment"> *</span>
 72<a name="l00052"></a>00052 <span class="comment"> * $Id: uip.c,v 1.65 2006/06/11 21:46:39 adam Exp $</span>
 73<a name="l00053"></a>00053 <span class="comment"> *</span>
 74<a name="l00054"></a>00054 <span class="comment"> */</span>
 75<a name="l00055"></a>00055 
 76<a name="l00056"></a>00056 <span class="comment">/*</span>
 77<a name="l00057"></a>00057 <span class="comment"> * uIP is a small implementation of the IP, UDP and TCP protocols (as</span>
 78<a name="l00058"></a>00058 <span class="comment"> * well as some basic ICMP stuff). The implementation couples the IP,</span>
 79<a name="l00059"></a>00059 <span class="comment"> * UDP, TCP and the application layers very tightly. To keep the size</span>
 80<a name="l00060"></a>00060 <span class="comment"> * of the compiled code down, this code frequently uses the goto</span>
 81<a name="l00061"></a>00061 <span class="comment"> * statement. While it would be possible to break the uip_process()</span>
 82<a name="l00062"></a>00062 <span class="comment"> * function into many smaller functions, this would increase the code</span>
 83<a name="l00063"></a>00063 <span class="comment"> * size because of the overhead of parameter passing and the fact that</span>
 84<a name="l00064"></a>00064 <span class="comment"> * the optimier would not be as efficient.</span>
 85<a name="l00065"></a>00065 <span class="comment"> *</span>
 86<a name="l00066"></a>00066 <span class="comment"> * The principle is that we have a small buffer, called the uip_buf,</span>
 87<a name="l00067"></a>00067 <span class="comment"> * in which the device driver puts an incoming packet. The TCP/IP</span>
 88<a name="l00068"></a>00068 <span class="comment"> * stack parses the headers in the packet, and calls the</span>
 89<a name="l00069"></a>00069 <span class="comment"> * application. If the remote host has sent data to the application,</span>
 90<a name="l00070"></a>00070 <span class="comment"> * this data is present in the uip_buf and the application read the</span>
 91<a name="l00071"></a>00071 <span class="comment"> * data from there. It is up to the application to put this data into</span>
 92<a name="l00072"></a>00072 <span class="comment"> * a byte stream if needed. The application will not be fed with data</span>
 93<a name="l00073"></a>00073 <span class="comment"> * that is out of sequence.</span>
 94<a name="l00074"></a>00074 <span class="comment"> *</span>
 95<a name="l00075"></a>00075 <span class="comment"> * If the application whishes to send data to the peer, it should put</span>
 96<a name="l00076"></a>00076 <span class="comment"> * its data into the uip_buf. The uip_appdata pointer points to the</span>
 97<a name="l00077"></a>00077 <span class="comment"> * first available byte. The TCP/IP stack will calculate the</span>
 98<a name="l00078"></a>00078 <span class="comment"> * checksums, and fill in the necessary header fields and finally send</span>
 99<a name="l00079"></a>00079 <span class="comment"> * the packet back to the peer.</span>
100<a name="l00080"></a>00080 <span class="comment">*/</span>
101<a name="l00081"></a>00081 
102<a name="l00082"></a>00082 <span class="preprocessor">#include "<a class="code" href="a00136.html">uip.h</a>"</span>
103<a name="l00083"></a>00083 <span class="preprocessor">#include "<a class="code" href="a00140.html">uipopt.h</a>"</span>
104<a name="l00084"></a>00084 <span class="preprocessor">#include "<a class="code" href="a00137.html">uip_arch.h</a>"</span>
105<a name="l00085"></a>00085 
106<a name="l00086"></a>00086 <span class="preprocessor">#if UIP_CONF_IPV6</span>
107<a name="l00087"></a>00087 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="a00132.html">uip-neighbor.h</a>"</span>
108<a name="l00088"></a>00088 <span class="preprocessor">#endif </span><span class="comment">/* UIP_CONF_IPV6 */</span>
109<a name="l00089"></a>00089 
110<a name="l00090"></a>00090 <span class="preprocessor">#include &lt;string.h&gt;</span>
111<a name="l00091"></a>00091 
112<a name="l00092"></a>00092 <span class="comment">/*---------------------------------------------------------------------------*/</span>
113<a name="l00093"></a>00093 <span class="comment">/* Variable definitions. */</span>
114<a name="l00094"></a>00094 
115<a name="l00095"></a>00095 
116<a name="l00096"></a>00096 <span class="comment">/* The IP address of this host. If it is defined to be fixed (by</span>
117<a name="l00097"></a>00097 <span class="comment">   setting UIP_FIXEDADDR to 1 in uipopt.h), the address is set</span>
118<a name="l00098"></a>00098 <span class="comment">   here. Otherwise, the address */</span>
119<a name="l00099"></a>00099 <span class="preprocessor">#if UIP_FIXEDADDR &gt; 0</span>
120<a name="l00100"></a>00100 <span class="preprocessor"></span><span class="keyword">const</span> <a class="code" href="a00150.html#g1ef35301f43a5bbb9f89f07b5a36b9a0">uip_ipaddr_t</a> <a class="code" href="a00150.html#g7d3673f52f5846b6961d23b150decd54">uip_hostaddr</a> =
121<a name="l00101"></a>00101   {<a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>((UIP_IPADDR0 &lt;&lt; 8) | UIP_IPADDR1),
122<a name="l00102"></a>00102    <a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>((UIP_IPADDR2 &lt;&lt; 8) | UIP_IPADDR3)};
123<a name="l00103"></a>00103 <span class="keyword">const</span> <a class="code" href="a00150.html#g1ef35301f43a5bbb9f89f07b5a36b9a0">uip_ipaddr_t</a> <a class="code" href="a00150.html#g20df5c82f2a15a508c19e505b5d9de2b">uip_draddr</a> =
124<a name="l00104"></a>00104   {<a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>((UIP_DRIPADDR0 &lt;&lt; 8) | UIP_DRIPADDR1),
125<a name="l00105"></a>00105    <a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>((UIP_DRIPADDR2 &lt;&lt; 8) | UIP_DRIPADDR3)};
126<a name="l00106"></a>00106 <span class="keyword">const</span> <a class="code" href="a00150.html#g1ef35301f43a5bbb9f89f07b5a36b9a0">uip_ipaddr_t</a> <a class="code" href="a00150.html#g3237be0d9ec457de0177689ee23c0d5c">uip_netmask</a> =
127<a name="l00107"></a>00107   {<a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>((UIP_NETMASK0 &lt;&lt; 8) | UIP_NETMASK1),
128<a name="l00108"></a>00108    <a class="code" href="a00148.html#g69a7a4951ff21b302267532c21ee78fc">HTONS</a>((UIP_NETMASK2 &lt;&lt; 8) | UIP_NETMASK3)};
129<a name="l00109"></a>00109 <span class="preprocessor">#else</span>
130<a name="l00110"></a><a class="code" href="a00150.html#g3237be0d9ec457de0177689ee23c0d5c">00110</a> <span class="preprocessor"></span><a class="code" href="a00150.html#g1ef35301f43a5bbb9f89f07b5a36b9a0">uip_ipaddr_t</a> <a class="code" href="a00150.html#g7d3673f52f5846b6961d23b150decd54">uip_hostaddr</a>, <a class="code" href="a00150.html#g20df5c82f2a15a508c19e505b5d9de2b">uip_draddr</a>, uip_netmask;
131<a name="l00111"></a>00111 <span class="preprocessor">#endif </span><span class="comment">/* UIP_FIXEDADDR */</span>
132<a name="l00112"></a>00112 
133<a name="l00113"></a>00113 <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="a00150.html#g1ef35301f43a5bbb9f89f07b5a36b9a0">uip_ipaddr_t</a> all_ones_addr =
134<a name="l00114"></a>00114 <span class="preprocessor">#if UIP_CONF_IPV6</span>
135<a name="l00115"></a>00115 <span class="preprocessor"></span>  {0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff};
136<a name="l00116"></a>00116 <span class="preprocessor">#else </span><span class="comment">/* UIP_CONF_IPV6 */</span>
137<a name="l00117"></a>00117   {0xffff,0xffff};
138<a name="l00118"></a>00118 <span class="preprocessor">#endif </span><span class="comment">/* UIP_CONF_IPV6 */</span>
139<a name="l00119"></a>00119 <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="a00150.html#g1ef35301f43a5bbb9f89f07b5a36b9a0">uip_ipaddr_t</a> all_zeroes_addr =
140<a name="l00120"></a>00120 <span class="preprocessor">#if UIP_CONF_IPV6</span>
141<a name="l00121"></a>00121 <span class="preprocessor"></span>  {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};
142<a name="l00122"></a>00122 <span class="preprocessor">#else </span><span class="comment">/* UIP_CONF_IPV6 */</span>
143<a name="l00123"></a>00123   {0x0000,0x0000};
144<a name="l00124"></a>00124 <span class="preprocessor">#endif </span><span class="comment">/* UIP_CONF_IPV6 */</span>
145<a name="l00125"></a>00125 
146<a name="l00126"></a>00126 
147<a name="l00127"></a>00127 <span class="preprocessor">#if UIP_FIXEDETHADDR</span>
148<a name="l00128"></a>00128 <span class="preprocessor"></span><span class="keyword">const</span> <span class="keyword">struct </span><a class="code" href="a00089.html">uip_eth_addr</a> <a class="code" href="a00150.html#g499bb98a0b4ae9a98553ede81317606d">uip_ethaddr</a> = {{UIP_ETHADDR0,
149<a name="l00129"></a>00129                                           UIP_ETHADDR1,
150<a name="l00130"></a>00130                                           UIP_ETHADDR2,
151<a name="l00131"></a>00131                                           UIP_ETHADDR3,
152<a name="l00132"></a>00132                                           UIP_ETHADDR4,
153<a name="l00133"></a>00133                                           UIP_ETHADDR5}};
154<a name="l00134"></a>00134 <span class="preprocessor">#else</span>
155<a name="l00135"></a><a class="code" href="a00152.html#g499bb98a0b4ae9a98553ede81317606d">00135</a> <span class="preprocessor"></span><span class="keyword">struct </span><a class="code" href="a00089.html">uip_eth_addr</a> <a class="code" href="a00150.html#g499bb98a0b4ae9a98553ede81317606d">uip_ethaddr</a> = {{0,0,0,0,0,0}};
156<a name="l00136"></a>00136 <span class="preprocessor">#endif</span>
157<a name="l00137"></a>00137 <span class="preprocessor"></span>
158<a name="l00138"></a>00138 <span class="preprocessor">#ifndef UIP_CONF_EXTERNAL_BUFFER</span>
159<a name="l00139"></a><a class="code" href="a00150.html#gb81e78f890dbbee50c533a9734b74fd9">00139</a> <span class="preprocessor"></span><a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> <a class="code" href="a00146.html#gb81e78f890dbbee50c533a9734b74fd9">uip_buf</a>[<a class="code" href="a00153.html#g3589822ecb9d9c4145209756396b8a6b">UIP_BUFSIZE</a> + 2];   <span class="comment">/* The packet buffer that contains</span>
160<a name="l00140"></a>00140 <span class="comment">                                    incoming packets. */</span>
161<a name="l00141"></a>00141 <span class="preprocessor">#endif </span><span class="comment">/* UIP_CONF_EXTERNAL_BUFFER */</span>
162<a name="l00142"></a>00142 
163<a name="l00143"></a><a class="code" href="a00150.html#g561b8eda32e059d4e7397f776268cc63">00143</a> <span class="keywordtype">void</span> *<a class="code" href="a00150.html#g561b8eda32e059d4e7397f776268cc63">uip_appdata</a>;               <span class="comment">/* The uip_appdata pointer points to</span>
164<a name="l00144"></a>00144 <span class="comment">                                    application data. */</span>
165<a name="l00145"></a><a class="code" href="a00150.html#ga05a3dde2048480fa3ab2a5961898d18">00145</a> <span class="keywordtype">void</span> *<a class="code" href="a00150.html#ga05a3dde2048480fa3ab2a5961898d18">uip_sappdata</a>;              <span class="comment">/* The uip_appdata pointer points to</span>
166<a name="l00146"></a>00146 <span class="comment">                                    the application data which is to</span>
167<a name="l00147"></a>00147 <span class="comment">                                    be sent. */</span>
168<a name="l00148"></a>00148 <span class="preprocessor">#if UIP_URGDATA &gt; 0</span>
169<a name="l00149"></a>00149 <span class="preprocessor"></span><span class="keywordtype">void</span> *uip_urgdata;               <span class="comment">/* The uip_urgdata pointer points to</span>
170<a name="l00150"></a>00150 <span class="comment">                                    urgent data (out-of-band data), if</span>
171<a name="l00151"></a>00151 <span class="comment">                                    present. */</span>
172<a name="l00152"></a>00152 <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> uip_urglen, uip_surglen;
173<a name="l00153"></a>00153 <span class="preprocessor">#endif </span><span class="comment">/* UIP_URGDATA &gt; 0 */</span>
174<a name="l00154"></a>00154 
175<a name="l00155"></a><a class="code" href="a00150.html#g5b5615dc240daed20949c0fded2b4679">00155</a> <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> <a class="code" href="a00149.html#g12a33f0c09711167bdf3dd7d7cf8c5a1">uip_len</a>, <a class="code" href="a00150.html#g5b5615dc240daed20949c0fded2b4679">uip_slen</a>;
176<a name="l00156"></a>00156                              <span class="comment">/* The uip_len is either 8 or 16 bits,</span>
177<a name="l00157"></a>00157 <span class="comment">                                depending on the maximum packet</span>
178<a name="l00158"></a>00158 <span class="comment">                                size. */</span>
179<a name="l00159"></a>00159 
180<a name="l00160"></a><a class="code" href="a00150.html#gb4ef6b00924990e7a293f66715b6d1d1">00160</a> <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> <a class="code" href="a00150.html#gb4ef6b00924990e7a293f66715b6d1d1">uip_flags</a>;     <span class="comment">/* The uip_flags variable is used for</span>
181<a name="l00161"></a>00161 <span class="comment">                                communication between the TCP/IP stack</span>
182<a name="l00162"></a>00162 <span class="comment">                                and the application program. */</span>
183<a name="l00163"></a><a class="code" href="a00150.html#g788ffac72342f6172343d7f8099cbe1a">00163</a> <span class="keyword">struct </span><a class="code" href="a00088.html">uip_conn</a> *<a class="code" href="a00088.html">uip_conn</a>;   <span class="comment">/* uip_conn always points to the current</span>
184<a name="l00164"></a>00164 <span class="comment">                                connection. */</span>
185<a name="l00165"></a>00165 
186<a name="l00166"></a><a class="code" href="a00150.html#gf703683056d2bfa5c81fa157dcb20fe2">00166</a> <span class="keyword">struct </span><a class="code" href="a00150.html#g788ffac72342f6172343d7f8099cbe1a">uip_conn</a> <a class="code" href="a00150.html#gf703683056d2bfa5c81fa157dcb20fe2">uip_conns</a>[<a class="code" href="a00153.html#gf5fe83be78b78b9e7d9e7f1e34ab1cc5">UIP_CONNS</a>];
187<a name="l00167"></a>00167                              <span class="comment">/* The uip_conns array holds all TCP</span>
188<a name="l00168"></a>00168 <span class="comment">                                connections. */</span>
189<a name="l00169"></a><a class="code" href="a00150.html#g236d5c7872f59c8fe7b701c7252b976e">00169</a> <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> <a class="code" href="a00150.html#g236d5c7872f59c8fe7b701c7252b976e">uip_listenports</a>[<a class="code" href="a00153.html#g8f4ebd8ef6c0ea665ed351d87fec09fd">UIP_LISTENPORTS</a>];
190<a name="l00170"></a>00170                              <span class="comment">/* The uip_listenports list all currently</span>
191<a name="l00171"></a>00171 <span class="comment">                                listning ports. */</span>
192<a name="l00172"></a>00172 <span class="preprocessor">#if UIP_UDP</span>
193<a name="l00173"></a><a class="code" href="a00150.html#g210f227119fc972e6222c9cb452e15a9">00173</a> <span class="preprocessor"></span><span class="keyword">struct </span><a class="code" href="a00095.html">uip_udp_conn</a> *<a class="code" href="a00095.html">uip_udp_conn</a>;
194<a name="l00174"></a><a class="code" href="a00150.html#geb533744817cf6695d75293369c2248b">00174</a> <span class="keyword">struct </span><a class="code" href="a00150.html#g210f227119fc972e6222c9cb452e15a9">uip_udp_conn</a> <a class="code" href="a00150.html#geb533744817cf6695d75293369c2248b">uip_udp_conns</a>[<a class="code" href="a00153.html#g196379ceb1219a99f4495e41ccc9bbfb">UIP_UDP_CONNS</a>];
195<a name="l00175"></a>00175 <span class="preprocessor">#endif </span><span class="comment">/* UIP_UDP */</span>
196<a name="l00176"></a>00176 
197<a name="l00177"></a>00177 <span class="keyword">static</span> <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> ipid;           <span class="comment">/* Ths ipid variable is an increasing</span>
198<a name="l00178"></a>00178 <span class="comment">                                number that is used for the IP ID</span>
199<a name="l00179"></a>00179 <span class="comment">                                field. */</span>
200<a name="l00180"></a>00180 
201<a name="l00181"></a><a class="code" href="a00150.html#g22f140b02c354dfebcc7ad481c3bcd68">00181</a> <span class="keywordtype">void</span> <a class="code" href="a00145.html#g22f140b02c354dfebcc7ad481c3bcd68">uip_setipid</a>(<a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> <span class="keywordtype">id</span>) { ipid = id; }
202<a name="l00182"></a>00182 
203<a name="l00183"></a>00183 <span class="keyword">static</span> <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> iss[4];          <span class="comment">/* The iss variable is used for the TCP</span>
204<a name="l00184"></a>00184 <span class="comment">                                initial sequence number. */</span>
205<a name="l00185"></a>00185 
206<a name="l00186"></a>00186 <span class="preprocessor">#if UIP_ACTIVE_OPEN</span>
207<a name="l00187"></a>00187 <span class="preprocessor"></span><span class="keyword">static</span> <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> lastport;       <span class="comment">/* Keeps track of the last port used for</span>
208<a name="l00188"></a>00188 <span class="comment">                                a new connection. */</span>
209<a name="l00189"></a>00189 <span class="preprocessor">#endif </span><span class="comment">/* UIP_ACTIVE_OPEN */</span>
210<a name="l00190"></a>00190 
211<a name="l00191"></a>00191 <span class="comment">/* Temporary variables. */</span>
212<a name="l00192"></a><a class="code" href="a00150.html#g2a0cf5d86c58fab216414ce59bf1fea1">00192</a> <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> <a class="code" href="a00151.html#g2a0cf5d86c58fab216414ce59bf1fea1">uip_acc32</a>[4];
213<a name="l00193"></a>00193 <span class="keyword">static</span> <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> c, opt;
214<a name="l00194"></a>00194 <span class="keyword">static</span> <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> tmp16;
215<a name="l00195"></a>00195 
216<a name="l00196"></a>00196 <span class="comment">/* Structures and definitions. */</span>
217<a name="l00197"></a><a class="code" href="a00150.html#g88e60aa2cf23e1c65d630701db08c743">00197</a> <span class="preprocessor">#define TCP_FIN 0x01</span>
218<a name="l00198"></a><a class="code" href="a00150.html#g6020613f5062417d9811cfa837215c83">00198</a> <span class="preprocessor"></span><span class="preprocessor">#define TCP_SYN 0x02</span>
219<a name="l00199"></a><a class="code" href="a00150.html#g5ca559def464ef20d8b1f7d32f2f160d">00199</a> <span class="preprocessor"></span><span class="preprocessor">#define TCP_RST 0x04</span>
220<a name="l00200"></a><a class="code" href="a00150.html#g1320fd0006a2f70138bc2d0018dda829">00200</a> <span class="preprocessor"></span><span class="preprocessor">#define TCP_PSH 0x08</span>
221<a name="l00201"></a><a class="code" href="a00150.html#g44b3b1ab31a403ba28ec135adfcbefef">00201</a> <span class="preprocessor"></span><span class="preprocessor">#define TCP_ACK 0x10</span>
222<a name="l00202"></a><a class="code" href="a00150.html#gc84f499cba8a02fc0e306c10b2acabf0">00202</a> <span class="preprocessor"></span><span class="preprocessor">#define TCP_URG 0x20</span>
223<a name="l00203"></a><a class="code" href="a00150.html#g1425d4a0c2760adb653a04c0fb137a8d">00203</a> <span class="preprocessor"></span><span class="preprocessor">#define TCP_CTL 0x3f</span>
224<a name="l00204"></a>00204 <span class="preprocessor"></span>
225<a name="l00205"></a><a class="code" href="a00150.html#g1215163245304bad20d6c5608ad75ab7">00205</a> <span class="preprocessor">#define TCP_OPT_END     0   </span><span class="comment">/* End of TCP options list */</span>
226<a name="l00206"></a><a class="code" href="a00150.html#g9f1822e1d231235edacad691f3cb7bbb">00206</a> <span class="preprocessor">#define TCP_OPT_NOOP    1   </span><span class="comment">/* "No-operation" TCP option */</span>
227<a name="l00207"></a><a class="code" href="a00150.html#g691688604655ea8943d15f14c60027d8">00207</a> <span class="preprocessor">#define TCP_OPT_MSS     2   </span><span class="comment">/* Maximum segment size TCP option */</span>
228<a name="l00208"></a>00208 
229<a name="l00209"></a><a class="code" href="a00150.html#g12f3bf821224b8e7b48a57ed3cea15cf">00209</a> <span class="preprocessor">#define TCP_OPT_MSS_LEN 4   </span><span class="comment">/* Length of TCP MSS option. */</span>
230<a name="l00210"></a>00210 
231<a name="l00211"></a><a class="code" href="a00150.html#g5c5b1834e497f53ad0ef947bbe9777fa">00211</a> <span class="preprocessor">#define ICMP_ECHO_REPLY 0</span>
232<a name="l00212"></a><a class="code" href="a00150.html#gd58231410d58e34b455328b888a9e73c">00212</a> <span class="preprocessor"></span><span class="preprocessor">#define ICMP_ECHO       8</span>
233<a name="l00213"></a>00213 <span class="preprocessor"></span>
234<a name="l00214"></a><a class="code" href="a00150.html#g207d17b633cd095120a74bc1f2257b17">00214</a> <span class="preprocessor">#define ICMP6_ECHO_REPLY             129</span>
235<a name="l00215"></a><a class="code" href="a00150.html#g4cc3e223b63f27b546d62e9a258dba5a">00215</a> <span class="preprocessor"></span><span class="preprocessor">#define ICMP6_ECHO                   128</span>
236<a name="l00216"></a><a class="code" href="a00150.html#g1cea57e3ea526f210b1068e6dcf7b4f4">00216</a> <span class="preprocessor"></span><span class="preprocessor">#define ICMP6_NEIGHBOR_SOLICITATION  135</span>
237<a name="l00217"></a><a class="code" href="a00150.html#g62c03e0a308cc23929a80fe8d8f9dc1e">00217</a> <span class="preprocessor"></span><span class="preprocessor">#define ICMP6_NEIGHBOR_ADVERTISEMENT 136</span>
238<a name="l00218"></a>00218 <span class="preprocessor"></span>
239<a name="l00219"></a><a class="code" href="a00150.html#g1d3211dbbdfb22d6a47b60dddcf945e8">00219</a> <span class="preprocessor">#define ICMP6_FLAG_S (1 &lt;&lt; 6)</span>
240<a name="l00220"></a>00220 <span class="preprocessor"></span>
241<a name="l00221"></a><a class="code" href="a00150.html#g42288d5c3cf4b10becefec657f441e54">00221</a> <span class="preprocessor">#define ICMP6_OPTION_SOURCE_LINK_ADDRESS 1</span>
242<a name="l00222"></a><a class="code" href="a00150.html#g8387881de3a8bfd3c0d57b9d04ac9b7e">00222</a> <span class="preprocessor"></span><span class="preprocessor">#define ICMP6_OPTION_TARGET_LINK_ADDRESS 2</span>
243<a name="l00223"></a>00223 <span class="preprocessor"></span>
244<a name="l00224"></a>00224 
245<a name="l00225"></a>00225 <span class="comment">/* Macros. */</span>
246<a name="l00226"></a><a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">00226</a> <span class="preprocessor">#define BUF ((struct uip_tcpip_hdr *)&amp;uip_buf[UIP_LLH_LEN])</span>
247<a name="l00227"></a><a class="code" href="a00150.html#g96544dedc1cdc71ad2ad54bf1d5e5433">00227</a> <span class="preprocessor"></span><span class="preprocessor">#define FBUF ((struct uip_tcpip_hdr *)&amp;uip_reassbuf[0])</span>
248<a name="l00228"></a><a class="code" href="a00150.html#g4309376690872fa4beb4f025f5cc199b">00228</a> <span class="preprocessor"></span><span class="preprocessor">#define ICMPBUF ((struct uip_icmpip_hdr *)&amp;uip_buf[UIP_LLH_LEN])</span>
249<a name="l00229"></a><a class="code" href="a00150.html#gb9435261753469accec0c9bf8a5a2686">00229</a> <span class="preprocessor"></span><span class="preprocessor">#define UDPBUF ((struct uip_udpip_hdr *)&amp;uip_buf[UIP_LLH_LEN])</span>
250<a name="l00230"></a>00230 <span class="preprocessor"></span>
251<a name="l00231"></a>00231 
252<a name="l00232"></a>00232 <span class="preprocessor">#if UIP_STATISTICS == 1</span>
253<a name="l00233"></a>00233 <span class="preprocessor"></span><span class="keyword">struct </span><a class="code" href="a00093.html">uip_stats</a> <a class="code" href="a00150.html#g9ee50a40597e67fce96541ab56c3b712">uip_stat</a>;
254<a name="l00234"></a>00234 <span class="preprocessor">#define UIP_STAT(s) s</span>
255<a name="l00235"></a>00235 <span class="preprocessor"></span><span class="preprocessor">#else</span>
256<a name="l00236"></a><a class="code" href="a00150.html#g9c0814ed491fa452ec97910c0728d410">00236</a> <span class="preprocessor"></span><span class="preprocessor">#define UIP_STAT(s)</span>
257<a name="l00237"></a>00237 <span class="preprocessor"></span><span class="preprocessor">#endif </span><span class="comment">/* UIP_STATISTICS == 1 */</span>
258<a name="l00238"></a>00238 
259<a name="l00239"></a>00239 <span class="preprocessor">#if UIP_LOGGING == 1</span>
260<a name="l00240"></a>00240 <span class="preprocessor"></span><span class="preprocessor">#include &lt;stdio.h&gt;</span>
261<a name="l00241"></a>00241 <span class="keywordtype">void</span> <a class="code" href="a00153.html#gb58e1ceb7cb73ca2bcd73146b6c1b4e7">uip_log</a>(<span class="keywordtype">char</span> *msg);
262<a name="l00242"></a>00242 <span class="preprocessor">#define UIP_LOG(m) uip_log(m)</span>
263<a name="l00243"></a>00243 <span class="preprocessor"></span><span class="preprocessor">#else</span>
264<a name="l00244"></a><a class="code" href="a00150.html#g013c3a06a8b58589a77f4a3442f89c2a">00244</a> <span class="preprocessor"></span><span class="preprocessor">#define UIP_LOG(m)</span>
265<a name="l00245"></a>00245 <span class="preprocessor"></span><span class="preprocessor">#endif </span><span class="comment">/* UIP_LOGGING == 1 */</span>
266<a name="l00246"></a>00246 
267<a name="l00247"></a>00247 <span class="preprocessor">#if ! UIP_ARCH_ADD32</span>
268<a name="l00248"></a>00248 <span class="preprocessor"></span><span class="keywordtype">void</span>
269<a name="l00249"></a><a class="code" href="a00151.html#g6832e4d2d046536b6472f7ac92340f68">00249</a> <a class="code" href="a00150.html#g6832e4d2d046536b6472f7ac92340f68">uip_add32</a>(<a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> *op32, <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> op16)
270<a name="l00250"></a>00250 {
271<a name="l00251"></a>00251   uip_acc32[3] = op32[3] + (op16 &amp; 0xff);
272<a name="l00252"></a>00252   uip_acc32[2] = op32[2] + (op16 &gt;&gt; 8);
273<a name="l00253"></a>00253   uip_acc32[1] = op32[1];
274<a name="l00254"></a>00254   uip_acc32[0] = op32[0];
275<a name="l00255"></a>00255   
276<a name="l00256"></a>00256   <span class="keywordflow">if</span>(uip_acc32[2] &lt; (op16 &gt;&gt; 8)) {
277<a name="l00257"></a>00257     ++uip_acc32[1];
278<a name="l00258"></a>00258     <span class="keywordflow">if</span>(uip_acc32[1] == 0) {
279<a name="l00259"></a>00259       ++uip_acc32[0];
280<a name="l00260"></a>00260     }
281<a name="l00261"></a>00261   }
282<a name="l00262"></a>00262   
283<a name="l00263"></a>00263   
284<a name="l00264"></a>00264   <span class="keywordflow">if</span>(uip_acc32[3] &lt; (op16 &amp; 0xff)) {
285<a name="l00265"></a>00265     ++uip_acc32[2];
286<a name="l00266"></a>00266     <span class="keywordflow">if</span>(uip_acc32[2] == 0) {
287<a name="l00267"></a>00267       ++uip_acc32[1];
288<a name="l00268"></a>00268       <span class="keywordflow">if</span>(uip_acc32[1] == 0) {
289<a name="l00269"></a>00269         ++uip_acc32[0];
290<a name="l00270"></a>00270       }
291<a name="l00271"></a>00271     }
292<a name="l00272"></a>00272   }
293<a name="l00273"></a>00273 }
294<a name="l00274"></a>00274 
295<a name="l00275"></a>00275 <span class="preprocessor">#endif </span><span class="comment">/* UIP_ARCH_ADD32 */</span>
296<a name="l00276"></a>00276 
297<a name="l00277"></a>00277 <span class="preprocessor">#if ! UIP_ARCH_CHKSUM</span>
298<a name="l00278"></a>00278 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------*/</span>
299<a name="l00279"></a>00279 <span class="keyword">static</span> <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a>
300<a name="l00280"></a>00280 chksum(<a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> sum, <span class="keyword">const</span> <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> *data, <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> len)
301<a name="l00281"></a>00281 {
302<a name="l00282"></a>00282   <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> t;
303<a name="l00283"></a>00283   <span class="keyword">const</span> <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> *dataptr;
304<a name="l00284"></a>00284   <span class="keyword">const</span> <a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> *last_byte;
305<a name="l00285"></a>00285 
306<a name="l00286"></a>00286   dataptr = data;
307<a name="l00287"></a>00287   last_byte = data + len - 1;
308<a name="l00288"></a>00288   
309<a name="l00289"></a>00289   <span class="keywordflow">while</span>(dataptr &lt; last_byte) {  <span class="comment">/* At least two more bytes */</span>
310<a name="l00290"></a>00290     t = (dataptr[0] &lt;&lt; 8) + dataptr[1];
311<a name="l00291"></a>00291     sum += t;
312<a name="l00292"></a>00292     <span class="keywordflow">if</span>(sum &lt; t) {
313<a name="l00293"></a>00293       sum++;            <span class="comment">/* carry */</span>
314<a name="l00294"></a>00294     }
315<a name="l00295"></a>00295     dataptr += 2;
316<a name="l00296"></a>00296   }
317<a name="l00297"></a>00297   
318<a name="l00298"></a>00298   <span class="keywordflow">if</span>(dataptr == last_byte) {
319<a name="l00299"></a>00299     t = (dataptr[0] &lt;&lt; 8) + 0;
320<a name="l00300"></a>00300     sum += t;
321<a name="l00301"></a>00301     <span class="keywordflow">if</span>(sum &lt; t) {
322<a name="l00302"></a>00302       sum++;            <span class="comment">/* carry */</span>
323<a name="l00303"></a>00303     }
324<a name="l00304"></a>00304   }
325<a name="l00305"></a>00305 
326<a name="l00306"></a>00306   <span class="comment">/* Return sum in host byte order. */</span>
327<a name="l00307"></a>00307   <span class="keywordflow">return</span> sum;
328<a name="l00308"></a>00308 }
329<a name="l00309"></a>00309 <span class="comment">/*---------------------------------------------------------------------------*/</span>
330<a name="l00310"></a>00310 <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a>
331<a name="l00311"></a><a class="code" href="a00150.html#gb6683dd83fe1c8de9a24086d4b69e907">00311</a> <a class="code" href="a00150.html#gb6683dd83fe1c8de9a24086d4b69e907">uip_chksum</a>(<a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> *data, <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> len)
332<a name="l00312"></a>00312 {
333<a name="l00313"></a>00313   <span class="keywordflow">return</span> <a class="code" href="a00148.html#ga22b04cac8cf283ca12f028578bebc06">htons</a>(chksum(0, (<a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> *)data, len));
334<a name="l00314"></a>00314 }
335<a name="l00315"></a>00315 <span class="comment">/*---------------------------------------------------------------------------*/</span>
336<a name="l00316"></a>00316 <span class="preprocessor">#ifndef UIP_ARCH_IPCHKSUM</span>
337<a name="l00317"></a>00317 <span class="preprocessor"></span><a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a>
338<a name="l00318"></a><a class="code" href="a00150.html#g2addf34c7d457c1a7899a7e2171ef1e9">00318</a> <a class="code" href="a00150.html#g2addf34c7d457c1a7899a7e2171ef1e9">uip_ipchksum</a>(<span class="keywordtype">void</span>)
339<a name="l00319"></a>00319 {
340<a name="l00320"></a>00320   <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> sum;
341<a name="l00321"></a>00321 
342<a name="l00322"></a>00322   sum = chksum(0, &amp;uip_buf[<a class="code" href="a00153.html#ge6f4a2453dbd8bc60e6a82774552366a">UIP_LLH_LEN</a>], <a class="code" href="a00150.html#g6bc12c6c7b56f73ce5d57abfdcdc6eb5">UIP_IPH_LEN</a>);
343<a name="l00323"></a>00323   <a class="code" href="a00135.html#534d9e416324fb8ecca6b9cb4b1f6a6a">DEBUG_PRINTF</a>(<span class="stringliteral">"uip_ipchksum: sum 0x%04x\n"</span>, sum);
344<a name="l00324"></a>00324   <span class="keywordflow">return</span> (sum == 0) ? 0xffff : <a class="code" href="a00148.html#ga22b04cac8cf283ca12f028578bebc06">htons</a>(sum);
345<a name="l00325"></a>00325 }
346<a name="l00326"></a>00326 <span class="preprocessor">#endif</span>
347<a name="l00327"></a>00327 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------*/</span>
348<a name="l00328"></a>00328 <span class="keyword">static</span> <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a>
349<a name="l00329"></a>00329 upper_layer_chksum(<a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> proto)
350<a name="l00330"></a>00330 {
351<a name="l00331"></a>00331   <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> upper_layer_len;
352<a name="l00332"></a>00332   <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> sum;
353<a name="l00333"></a>00333   
354<a name="l00334"></a>00334 <span class="preprocessor">#if UIP_CONF_IPV6</span>
355<a name="l00335"></a>00335 <span class="preprocessor"></span>  upper_layer_len = (((<a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a>)(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;len[0]) &lt;&lt; 8) + <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;len[1]);
356<a name="l00336"></a>00336 <span class="preprocessor">#else </span><span class="comment">/* UIP_CONF_IPV6 */</span>
357<a name="l00337"></a>00337   upper_layer_len = (((<a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a>)(<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;len[0]) &lt;&lt; 8) + <a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;len[1]) - <a class="code" href="a00150.html#g6bc12c6c7b56f73ce5d57abfdcdc6eb5">UIP_IPH_LEN</a>;
358<a name="l00338"></a>00338 <span class="preprocessor">#endif </span><span class="comment">/* UIP_CONF_IPV6 */</span>
359<a name="l00339"></a>00339   
360<a name="l00340"></a>00340   <span class="comment">/* First sum pseudoheader. */</span>
361<a name="l00341"></a>00341   
362<a name="l00342"></a>00342   <span class="comment">/* IP protocol and length fields. This addition cannot carry. */</span>
363<a name="l00343"></a>00343   sum = upper_layer_len + proto;
364<a name="l00344"></a>00344   <span class="comment">/* Sum IP source and destination addresses. */</span>
365<a name="l00345"></a>00345   sum = chksum(sum, (<a class="code" href="a00153.html#g4caecabca98b43919dd11be1c0d4cd8e">u8_t</a> *)&amp;<a class="code" href="a00150.html#g24f52ac52d6e714cb04a5aa01be3bdd0">BUF</a>-&gt;srcipaddr[0], 2 * <span class="keyword">sizeof</span>(<a class="code" href="a00150.html#g1ef35301f43a5bbb9f89f07b5a36b9a0">uip_ipaddr_t</a>));
366<a name="l00346"></a>00346 
367<a name="l00347"></a>00347   <span class="comment">/* Sum TCP header and data. */</span>
368<a name="l00348"></a>00348   sum = chksum(sum, &amp;uip_buf[<a class="code" href="a00150.html#g6bc12c6c7b56f73ce5d57abfdcdc6eb5">UIP_IPH_LEN</a> + <a class="code" href="a00153.html#ge6f4a2453dbd8bc60e6a82774552366a">UIP_LLH_LEN</a>],
369<a name="l00349"></a>00349                upper_layer_len);
370<a name="l00350"></a>00350     
371<a name="l00351"></a>00351   <span class="keywordflow">return</span> (sum == 0) ? 0xffff : <a class="code" href="a00148.html#ga22b04cac8cf283ca12f028578bebc06">htons</a>(sum);
372<a name="l00352"></a>00352 }
373<a name="l00353"></a>00353 <span class="comment">/*---------------------------------------------------------------------------*/</span>
374<a name="l00354"></a>00354 <span class="preprocessor">#if UIP_CONF_IPV6</span>
375<a name="l00355"></a>00355 <span class="preprocessor"></span><a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a>
376<a name="l00356"></a>00356 uip_icmp6chksum(<span class="keywordtype">void</span>)
377<a name="l00357"></a>00357 {
378<a name="l00358"></a>00358   <span class="keywordflow">return</span> upper_layer_chksum(<a class="code" href="a00150.html#gad0321f4c570f9983c6de81ece3ddc20">UIP_PROTO_ICMP6</a>);
379<a name="l00359"></a>00359   
380<a name="l00360"></a>00360 }
381<a name="l00361"></a>00361 <span class="preprocessor">#endif </span><span class="comment">/* UIP_CONF_IPV6 */</span>
382<a name="l00362"></a>00362 <span class="comment">/*---------------------------------------------------------------------------*/</span>
383<a name="l00363"></a>00363 <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a>
384<a name="l00364"></a><a class="code" href="a00150.html#g85b65e38aa74eba18979156f97a94a87">00364</a> <a class="code" href="a00150.html#g85b65e38aa74eba18979156f97a94a87">uip_tcpchksum</a>(<span class="keywordtype">void</span>)
385<a name="l00365"></a>00365 {
386<a name="l00366"></a>00366   <span class="keywordflow">return</span> upper_layer_chksum(<a class="code" href="a00150.html#g517c770991459cc62dc009c0d3875c6a">UIP_PROTO_TCP</a>);
387<a name="l00367"></a>00367 }
388<a name="l00368"></a>00368 <span class="comment">/*---------------------------------------------------------------------------*/</span>
389<a name="l00369"></a>00369 <span class="preprocessor">#if UIP_UDP_CHECKSUMS</span>
390<a name="l00370"></a>00370 <span class="preprocessor"></span><a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a>
391<a name="l00371"></a>00371 <a class="code" href="a00150.html#g7023a34ba9e9d03b5fbedbcb32924453">uip_udpchksum</a>(<span class="keywordtype">void</span>)
392<a name="l00372"></a>00372 {
393<a name="l00373"></a>00373   <span class="keywordflow">return</span> upper_layer_chksum(<a class="code" href="a00150.html#gf72d7b9a737707dcfb2c41fec2b6792e">UIP_PROTO_UDP</a>);
394<a name="l00374"></a>00374 }
395<a name="l00375"></a>00375 <span class="preprocessor">#endif </span><span class="comment">/* UIP_UDP_CHECKSUMS */</span>
396<a name="l00376"></a>00376 <span class="preprocessor">#endif </span><span class="comment">/* UIP_ARCH_CHKSUM */</span>
397<a name="l00377"></a>00377 <span class="comment">/*---------------------------------------------------------------------------*/</span>
398<a name="l00378"></a>00378 <span class="keywordtype">void</span>
399<a name="l00379"></a><a class="code" href="a00150.html#gc48ed5f0d27721ef62a3ed02a5ad8d2e">00379</a> <a class="code" href="a00145.html#gc48ed5f0d27721ef62a3ed02a5ad8d2e">uip_init</a>(<span class="keywordtype">void</span>)
400<a name="l00380"></a>00380 {
401<a name="l00381"></a>00381   <span class="keywordflow">for</span>(c = 0; c &lt; <a class="code" href="a00153.html#g8f4ebd8ef6c0ea665ed351d87fec09fd">UIP_LISTENPORTS</a>; ++c) {
402<a name="l00382"></a>00382     uip_listenports[c] = 0;
403<a name="l00383"></a>00383   }
404<a name="l00384"></a>00384   <span class="keywordflow">for</span>(c = 0; c &lt; <a class="code" href="a00153.html#gf5fe83be78b78b9e7d9e7f1e34ab1cc5">UIP_CONNS</a>; ++c) {
405<a name="l00385"></a>00385     <a class="code" href="a00150.html#gf703683056d2bfa5c81fa157dcb20fe2">uip_conns</a>[c].tcpstateflags = <a class="code" href="a00150.html#g28eda870cff3d8e3cf2949e6f57a502b">UIP_CLOSED</a>;
406<a name="l00386"></a>00386   }
407<a name="l00387"></a>00387 <span class="preprocessor">#if UIP_ACTIVE_OPEN</span>
408<a name="l00388"></a>00388 <span class="preprocessor"></span>  lastport = 1024;
409<a name="l00389"></a>00389 <span class="preprocessor">#endif </span><span class="comment">/* UIP_ACTIVE_OPEN */</span>
410<a name="l00390"></a>00390 
411<a name="l00391"></a>00391 <span class="preprocessor">#if UIP_UDP</span>
412<a name="l00392"></a>00392 <span class="preprocessor"></span>  <span class="keywordflow">for</span>(c = 0; c &lt; <a class="code" href="a00153.html#g196379ceb1219a99f4495e41ccc9bbfb">UIP_UDP_CONNS</a>; ++c) {
413<a name="l00393"></a>00393     <a class="code" href="a00150.html#geb533744817cf6695d75293369c2248b">uip_udp_conns</a>[c].lport = 0;
414<a name="l00394"></a>00394   }
415<a name="l00395"></a>00395 <span class="preprocessor">#endif </span><span class="comment">/* UIP_UDP */</span>
416<a name="l00396"></a>00396   
417<a name="l00397"></a>00397 
418<a name="l00398"></a>00398   <span class="comment">/* IPv4 initialization. */</span>
419<a name="l00399"></a>00399 <span class="preprocessor">#if UIP_FIXEDADDR == 0</span>
420<a name="l00400"></a>00400 <span class="preprocessor"></span>  <span class="comment">/*  uip_hostaddr[0] = uip_hostaddr[1] = 0;*/</span>
421<a name="l00401"></a>00401 <span class="preprocessor">#endif </span><span class="comment">/* UIP_FIXEDADDR */</span>
422<a name="l00402"></a>00402 
423<a name="l00403"></a>00403 }
424<a name="l00404"></a>00404 <span class="comment">/*---------------------------------------------------------------------------*/</span>
425<a name="l00405"></a>00405 <span class="preprocessor">#if UIP_ACTIVE_OPEN</span>
426<a name="l00406"></a>00406 <span class="preprocessor"></span><span class="keyword">struct </span><a class="code" href="a00150.html#g788ffac72342f6172343d7f8099cbe1a">uip_conn</a> *
427<a name="l00407"></a><a class="code" href="a00150.html#g9c24fba2cd8f7f62accb0a0d5bbe4dad">00407</a> <a class="code" href="a00147.html#g8096b0c4b543dc408f4dd031ddae7240">uip_connect</a>(<a class="code" href="a00150.html#g1ef35301f43a5bbb9f89f07b5a36b9a0">uip_ipaddr_t</a> *<a class="code" href="a00088.html#79510aa86d3fa0a0fc6cfc49b1da7279">ripaddr</a>, <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> <a class="code" href="a00088.html#1df6aa054ef2fa634ac4c6f418228285">rport</a>)
428<a name="l00408"></a>00408 {
429<a name="l00409"></a>00409   <span class="keyword">register</span> <span class="keyword">struct </span><a class="code" href="a00150.html#g788ffac72342f6172343d7f8099cbe1a">uip_conn</a> *conn, *cconn;
430<a name="l00410"></a>00410   
431<a name="l00411"></a>00411   <span class="comment">/* Find an unused local port. */</span>
432<a name="l00412"></a>00412  again:
433<a name="l00413"></a>00413   ++lastport;
434<a name="l00414"></a>00414 
435<a name="l00415"></a>00415   <span class="keywordflow">if</span>(lastport &gt;= 32000) {
436<a name="l00416"></a>00416     lastport = 4096;
437<a name="l00417"></a>00417   }
438<a name="l00418"></a>00418 
439<a name="l00419"></a>00419   <span class="comment">/* Check if this port is already in use, and if so try to find</span>
440<a name="l00420"></a>00420 <span class="comment">     another one. */</span>
441<a name="l00421"></a>00421   <span class="keywordflow">for</span>(c = 0; c &lt; <a class="code" href="a00153.html#gf5fe83be78b78b9e7d9e7f1e34ab1cc5">UIP_CONNS</a>; ++c) {
442<a name="l00422"></a>00422     conn = &amp;<a class="code" href="a00150.html#gf703683056d2bfa5c81fa157dcb20fe2">uip_conns</a>[c];
443<a name="l00423"></a>00423     <span class="keywordflow">if</span>(conn-&gt;<a class="code" href="a00088.html#a5f58074435cdc180f17de69651beebd">tcpstateflags</a> != <a class="code" href="a00150.html#g28eda870cff3d8e3cf2949e6f57a502b">UIP_CLOSED</a> &amp;&amp;
444<a name="l00424"></a>00424        conn-&gt;<a class="code" href="a00088.html#0cd09beee671e7e9efb0b4aced10249e">lport</a> == <a class="code" href="a00148.html#ga22b04cac8cf283ca12f028578bebc06">htons</a>(lastport)) {
445<a name="l00425"></a>00425       <span class="keywordflow">goto</span> again;
446<a name="l00426"></a>00426     }
447<a name="l00427"></a>00427   }
448<a name="l00428"></a>00428 
449<a name="l00429"></a>00429   conn = 0;
450<a name="l00430"></a>00430   <span class="keywordflow">for</span>(c = 0; c &lt; <a class="code" href="a00153.html#gf5fe83be78b78b9e7d9e7f1e34ab1cc5">UIP_CONNS</a>; ++c) {
451<a name="l00431"></a>00431     cconn = &amp;<a class="code" href="a00150.html#gf70368305…

Large files files are truncated, but you can click here to view the full file