/a00423_source.html
HTML | 2007 lines | 2006 code | 0 blank | 1 comment | 0 complexity | 44e6f90b79e9e03f4ee7920aec28d317 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
- <title>Contiki 2.5: core/net/uip.c Source File</title>
- <link href="tabs.css" rel="stylesheet" type="text/css"/>
- <link href="doxygen.css" rel="stylesheet" type="text/css"/>
- </head>
- <body>
- <!-- Generated by Doxygen 1.6.1 -->
- <div class="navigation" id="top">
- <div class="tabs">
- <ul>
- <li><a href="main.html"><span>Main Page</span></a></li>
- <li><a href="pages.html"><span>Related Pages</span></a></li>
- <li><a href="modules.html"><span>Modules</span></a></li>
- <li><a href="annotated.html"><span>Data Structures</span></a></li>
- <li class="current"><a href="files.html"><span>Files</span></a></li>
- <li><a href="dirs.html"><span>Directories</span></a></li>
- <li><a href="examples.html"><span>Examples</span></a></li>
- </ul>
- </div>
- <div class="tabs">
- <ul>
- <li><a href="files.html"><span>File List</span></a></li>
- <li><a href="globals.html"><span>Globals</span></a></li>
- </ul>
- </div>
- <div class="navpath"><a class="el" href="dir_783dcb2b4bcfa12326370fa26c216025.html">core</a> » <a class="el" href="dir_0966c75b31335e5cb5b37dbb7a80da85.html">net</a>
- </div>
- </div>
- <div class="contents">
- <h1>uip.c</h1><a href="a00423.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#define DEBUG_PRINTF(...) </span><span class="comment">/*printf(__VA_ARGS__)*/</span>
- <a name="l00002"></a>00002 <span class="comment"></span>
- <a name="l00003"></a>00003 <span class="comment">/**</span>
- <a name="l00004"></a>00004 <span class="comment"> * \addtogroup uip</span>
- <a name="l00005"></a>00005 <span class="comment"> * @{</span>
- <a name="l00006"></a>00006 <span class="comment"> */</span>
- <a name="l00007"></a>00007 <span class="comment"></span>
- <a name="l00008"></a>00008 <span class="comment">/**</span>
- <a name="l00009"></a>00009 <span class="comment"> * \file</span>
- <a name="l00010"></a>00010 <span class="comment"> * The uIP TCP/IP stack code.</span>
- <a name="l00011"></a>00011 <span class="comment"> * \author Adam Dunkels <adam@dunkels.com></span>
- <a name="l00012"></a>00012 <span class="comment"> */</span>
- <a name="l00013"></a>00013
- <a name="l00014"></a>00014 <span class="comment">/*</span>
- <a name="l00015"></a>00015 <span class="comment"> * Copyright (c) 2001-2003, Adam Dunkels.</span>
- <a name="l00016"></a>00016 <span class="comment"> * All rights reserved.</span>
- <a name="l00017"></a>00017 <span class="comment"> *</span>
- <a name="l00018"></a>00018 <span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
- <a name="l00019"></a>00019 <span class="comment"> * modification, are permitted provided that the following conditions</span>
- <a name="l00020"></a>00020 <span class="comment"> * are met:</span>
- <a name="l00021"></a>00021 <span class="comment"> * 1. Redistributions of source code must retain the above copyright</span>
- <a name="l00022"></a>00022 <span class="comment"> * notice, this list of conditions and the following disclaimer.</span>
- <a name="l00023"></a>00023 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span>
- <a name="l00024"></a>00024 <span class="comment"> * notice, this list of conditions and the following disclaimer in the</span>
- <a name="l00025"></a>00025 <span class="comment"> * documentation and/or other materials provided with the distribution.</span>
- <a name="l00026"></a>00026 <span class="comment"> * 3. The name of the author may not be used to endorse or promote</span>
- <a name="l00027"></a>00027 <span class="comment"> * products derived from this software without specific prior</span>
- <a name="l00028"></a>00028 <span class="comment"> * written permission.</span>
- <a name="l00029"></a>00029 <span class="comment"> *</span>
- <a name="l00030"></a>00030 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS</span>
- <a name="l00031"></a>00031 <span class="comment"> * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED</span>
- <a name="l00032"></a>00032 <span class="comment"> * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</span>
- <a name="l00033"></a>00033 <span class="comment"> * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY</span>
- <a name="l00034"></a>00034 <span class="comment"> * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL</span>
- <a name="l00035"></a>00035 <span class="comment"> * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE</span>
- <a name="l00036"></a>00036 <span class="comment"> * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS</span>
- <a name="l00037"></a>00037 <span class="comment"> * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,</span>
- <a name="l00038"></a>00038 <span class="comment"> * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING</span>
- <a name="l00039"></a>00039 <span class="comment"> * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS</span>
- <a name="l00040"></a>00040 <span class="comment"> * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
- <a name="l00041"></a>00041 <span class="comment"> *</span>
- <a name="l00042"></a>00042 <span class="comment"> * This file is part of the uIP TCP/IP stack.</span>
- <a name="l00043"></a>00043 <span class="comment"> *</span>
- <a name="l00044"></a>00044 <span class="comment"> * $Id: uip.c,v 1.30 2010/10/19 18:29:04 adamdunkels Exp $</span>
- <a name="l00045"></a>00045 <span class="comment"> *</span>
- <a name="l00046"></a>00046 <span class="comment"> */</span>
- <a name="l00047"></a>00047
- <a name="l00048"></a>00048 <span class="comment">/*</span>
- <a name="l00049"></a>00049 <span class="comment"> * uIP is a small implementation of the IP, UDP and TCP protocols (as</span>
- <a name="l00050"></a>00050 <span class="comment"> * well as some basic ICMP stuff). The implementation couples the IP,</span>
- <a name="l00051"></a>00051 <span class="comment"> * UDP, TCP and the application layers very tightly. To keep the size</span>
- <a name="l00052"></a>00052 <span class="comment"> * of the compiled code down, this code frequently uses the goto</span>
- <a name="l00053"></a>00053 <span class="comment"> * statement. While it would be possible to break the uip_process()</span>
- <a name="l00054"></a>00054 <span class="comment"> * function into many smaller functions, this would increase the code</span>
- <a name="l00055"></a>00055 <span class="comment"> * size because of the overhead of parameter passing and the fact that</span>
- <a name="l00056"></a>00056 <span class="comment"> * the optimier would not be as efficient.</span>
- <a name="l00057"></a>00057 <span class="comment"> *</span>
- <a name="l00058"></a>00058 <span class="comment"> * The principle is that we have a small buffer, called the uip_buf,</span>
- <a name="l00059"></a>00059 <span class="comment"> * in which the device driver puts an incoming packet. The TCP/IP</span>
- <a name="l00060"></a>00060 <span class="comment"> * stack parses the headers in the packet, and calls the</span>
- <a name="l00061"></a>00061 <span class="comment"> * application. If the remote host has sent data to the application,</span>
- <a name="l00062"></a>00062 <span class="comment"> * this data is present in the uip_buf and the application read the</span>
- <a name="l00063"></a>00063 <span class="comment"> * data from there. It is up to the application to put this data into</span>
- <a name="l00064"></a>00064 <span class="comment"> * a byte stream if needed. The application will not be fed with data</span>
- <a name="l00065"></a>00065 <span class="comment"> * that is out of sequence.</span>
- <a name="l00066"></a>00066 <span class="comment"> *</span>
- <a name="l00067"></a>00067 <span class="comment"> * If the application whishes to send data to the peer, it should put</span>
- <a name="l00068"></a>00068 <span class="comment"> * its data into the uip_buf. The uip_appdata pointer points to the</span>
- <a name="l00069"></a>00069 <span class="comment"> * first available byte. The TCP/IP stack will calculate the</span>
- <a name="l00070"></a>00070 <span class="comment"> * checksums, and fill in the necessary header fields and finally send</span>
- <a name="l00071"></a>00071 <span class="comment"> * the packet back to the peer.</span>
- <a name="l00072"></a>00072 <span class="comment">*/</span>
- <a name="l00073"></a>00073
- <a name="l00074"></a>00074 <span class="preprocessor">#include "<a class="code" href="a00424.html" title="Header file for the uIP TCP/IP stack.">net/uip.h</a>"</span>
- <a name="l00075"></a>00075 <span class="preprocessor">#include "<a class="code" href="a00431.html" title="Configuration options for uIP.">net/uipopt.h</a>"</span>
- <a name="l00076"></a>00076 <span class="preprocessor">#include "<a class="code" href="a00428.html" title="Macros and definitions for the ARP module.">net/uip_arp.h</a>"</span>
- <a name="l00077"></a>00077 <span class="preprocessor">#include "<a class="code" href="a00426.html" title="Declarations of architecture specific functions.">net/uip_arch.h</a>"</span>
- <a name="l00078"></a>00078
- <a name="l00079"></a>00079 <span class="preprocessor">#if !UIP_CONF_IPV6 </span><span class="comment">/* If UIP_CONF_IPV6 is defined, we compile the</span>
- <a name="l00080"></a>00080 <span class="comment"> uip6.c file instead of this one. Therefore</span>
- <a name="l00081"></a>00081 <span class="comment"> this #ifndef removes the entire compilation</span>
- <a name="l00082"></a>00082 <span class="comment"> output of the uip.c file */</span>
- <a name="l00083"></a>00083
- <a name="l00084"></a>00084
- <a name="l00085"></a>00085 <span class="preprocessor">#if UIP_CONF_IPV6</span>
- <a name="l00086"></a>00086 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="a00414.html" title="Header file for database of link-local neighbors, used by IPv6 code and to be used...">net/uip-neighbor.h</a>"</span>
- <a name="l00087"></a>00087 <span class="preprocessor">#endif </span><span class="comment">/* UIP_CONF_IPV6 */</span>
- <a name="l00088"></a>00088
- <a name="l00089"></a>00089 <span class="preprocessor">#include <string.h></span>
- <a name="l00090"></a>00090
- <a name="l00091"></a>00091 <span class="comment">/*---------------------------------------------------------------------------*/</span>
- <a name="l00092"></a>00092 <span class="comment">/* Variable definitions. */</span>
- <a name="l00093"></a>00093
- <a name="l00094"></a>00094
- <a name="l00095"></a>00095 <span class="comment">/* The IP address of this host. If it is defined to be fixed (by</span>
- <a name="l00096"></a>00096 <span class="comment"> setting UIP_FIXEDADDR to 1 in uipopt.h), the address is set</span>
- <a name="l00097"></a>00097 <span class="comment"> here. Otherwise, the address */</span>
- <a name="l00098"></a>00098 <span class="preprocessor">#if UIP_FIXEDADDR > 0</span>
- <a name="l00099"></a>00099 <span class="preprocessor"></span><span class="keyword">const</span> <a class="code" href="a00106.html" title="Representation of an IP address.">uip_ipaddr_t</a> uip_hostaddr =
- <a name="l00100"></a>00100 { UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3 };
- <a name="l00101"></a>00101 <span class="keyword">const</span> <a class="code" href="a00106.html" title="Representation of an IP address.">uip_ipaddr_t</a> uip_draddr =
- <a name="l00102"></a>00102 { UIP_DRIPADDR0, UIP_DRIPADDR1, UIP_DRIPADDR2, UIP_DRIPADDR3 };
- <a name="l00103"></a>00103 <span class="keyword">const</span> <a class="code" href="a00106.html" title="Representation of an IP address.">uip_ipaddr_t</a> uip_netmask =
- <a name="l00104"></a>00104 { UIP_NETMASK0, UIP_NETMASK1, UIP_NETMASK2, UIP_NETMASK3 };
- <a name="l00105"></a>00105 <span class="preprocessor">#else</span>
- <a name="l00106"></a>00106 <span class="preprocessor"></span><a class="code" href="a00106.html" title="Representation of an IP address.">uip_ipaddr_t</a> uip_hostaddr, uip_draddr, uip_netmask;
- <a name="l00107"></a>00107 <span class="preprocessor">#endif </span><span class="comment">/* UIP_FIXEDADDR */</span>
- <a name="l00108"></a>00108
- <a name="l00109"></a>00109 <span class="keyword">const</span> <a class="code" href="a00106.html" title="Representation of an IP address.">uip_ipaddr_t</a> uip_broadcast_addr =
- <a name="l00110"></a>00110 <span class="preprocessor">#if UIP_CONF_IPV6</span>
- <a name="l00111"></a>00111 <span class="preprocessor"></span> { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- <a name="l00112"></a>00112 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
- <a name="l00113"></a>00113 <span class="preprocessor">#else </span><span class="comment">/* UIP_CONF_IPV6 */</span>
- <a name="l00114"></a>00114 { { 0xff, 0xff, 0xff, 0xff } };
- <a name="l00115"></a>00115 <span class="preprocessor">#endif </span><span class="comment">/* UIP_CONF_IPV6 */</span>
- <a name="l00116"></a>00116 <span class="keyword">const</span> <a class="code" href="a00106.html" title="Representation of an IP address.">uip_ipaddr_t</a> uip_all_zeroes_addr = { { 0x0, <span class="comment">/* rest is 0 */</span> } };
- <a name="l00117"></a>00117
- <a name="l00118"></a>00118 <span class="preprocessor">#if UIP_FIXEDETHADDR</span>
- <a name="l00119"></a>00119 <span class="preprocessor"></span><span class="keyword">const</span> <span class="keyword">struct </span><a class="code" href="a00102.html" title="802.3 address">uip_eth_addr</a> uip_ethaddr = {{UIP_ETHADDR0,
- <a name="l00120"></a>00120 UIP_ETHADDR1,
- <a name="l00121"></a>00121 UIP_ETHADDR2,
- <a name="l00122"></a>00122 UIP_ETHADDR3,
- <a name="l00123"></a>00123 UIP_ETHADDR4,
- <a name="l00124"></a>00124 UIP_ETHADDR5}};
- <a name="l00125"></a>00125 <span class="preprocessor">#else</span>
- <a name="l00126"></a>00126 <span class="preprocessor"></span><span class="keyword">struct </span><a class="code" href="a00102.html" title="802.3 address">uip_eth_addr</a> uip_ethaddr = {{0,0,0,0,0,0}};
- <a name="l00127"></a>00127 <span class="preprocessor">#endif</span>
- <a name="l00128"></a>00128 <span class="preprocessor"></span>
- <a name="l00129"></a>00129 <span class="comment">/* The packet buffer that contains incoming packets. */</span>
- <a name="l00130"></a><a class="code" href="a01574.html#ga1ff9096f765144168470cfe7ebf75fec">00130</a> <a class="code" href="a00091.html" title="The uIP packet buffer.">uip_buf_t</a> uip_aligned_buf;
- <a name="l00131"></a>00131
- <a name="l00132"></a><a class="code" href="a01684.html#gad5848369ab5b02f2fb02d8390ccbaf79">00132</a> <span class="keywordtype">void</span> *<a class="code" href="a01684.html#ga561b8eda32e059d4e7397f776268cc63" title="Pointer to the application data in the packet buffer.">uip_appdata</a>; <span class="comment">/* The uip_appdata pointer points to</span>
- <a name="l00133"></a>00133 <span class="comment"> application data. */</span>
- <a name="l00134"></a>00134 <span class="keywordtype">void</span> *uip_sappdata; <span class="comment">/* The uip_appdata pointer points to</span>
- <a name="l00135"></a>00135 <span class="comment"> the application data which is to</span>
- <a name="l00136"></a>00136 <span class="comment"> be sent. */</span>
- <a name="l00137"></a>00137 <span class="preprocessor">#if UIP_URGDATA > 0</span>
- <a name="l00138"></a>00138 <span class="preprocessor"></span><span class="keywordtype">void</span> *uip_urgdata; <span class="comment">/* The uip_urgdata pointer points to</span>
- <a name="l00139"></a>00139 <span class="comment"> urgent data (out-of-band data), if</span>
- <a name="l00140"></a>00140 <span class="comment"> present. */</span>
- <a name="l00141"></a>00141 <a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a> uip_urglen, uip_surglen;
- <a name="l00142"></a>00142 <span class="preprocessor">#endif </span><span class="comment">/* UIP_URGDATA > 0 */</span>
- <a name="l00143"></a>00143
- <a name="l00144"></a><a class="code" href="a01577.html#gac83200aec50ca08f657225b3c5b5c8dc">00144</a> <a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a> <a class="code" href="a01684.html#ga12a33f0c09711167bdf3dd7d7cf8c5a1" title="The length of the packet in the uip_buf buffer.">uip_len</a>, uip_slen;
- <a name="l00145"></a>00145 <span class="comment">/* The uip_len is either 8 or 16 bits,</span>
- <a name="l00146"></a>00146 <span class="comment"> depending on the maximum packet</span>
- <a name="l00147"></a>00147 <span class="comment"> size. */</span>
- <a name="l00148"></a>00148
- <a name="l00149"></a>00149 <a class="code" href="a01668.html#ga4caecabca98b43919dd11be1c0d4cd8e" title="The 8-bit unsigned data type.">u8_t</a> uip_flags; <span class="comment">/* The uip_flags variable is used for</span>
- <a name="l00150"></a>00150 <span class="comment"> communication between the TCP/IP stack</span>
- <a name="l00151"></a>00151 <span class="comment"> and the application program. */</span>
- <a name="l00152"></a><a class="code" href="a01684.html#ga76f4b1021e1a18d4d857ca8c121ec6e6">00152</a> <span class="keyword">struct </span><a class="code" href="a00092.html" title="Representation of a uIP TCP connection.">uip_conn</a> *<a class="code" href="a00092.html" title="Representation of a uIP TCP connection.">uip_conn</a>; <span class="comment">/* uip_conn always points to the current</span>
- <a name="l00153"></a>00153 <span class="comment"> connection. */</span>
- <a name="l00154"></a>00154
- <a name="l00155"></a>00155 <span class="keyword">struct </span>uip_conn uip_conns[<a class="code" href="a01585.html#gaf5fe83be78b78b9e7d9e7f1e34ab1cc5" title="The maximum number of simultaneously open TCP connections.">UIP_CONNS</a>];
- <a name="l00156"></a>00156 <span class="comment">/* The uip_conns array holds all TCP</span>
- <a name="l00157"></a>00157 <span class="comment"> connections. */</span>
- <a name="l00158"></a>00158 <a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a> uip_listenports[<a class="code" href="a01585.html#ga8f4ebd8ef6c0ea665ed351d87fec09fd" title="The maximum number of simultaneously listening TCP ports.">UIP_LISTENPORTS</a>];
- <a name="l00159"></a>00159 <span class="comment">/* The uip_listenports list all currently</span>
- <a name="l00160"></a>00160 <span class="comment"> listning ports. */</span>
- <a name="l00161"></a>00161 <span class="preprocessor">#if UIP_UDP</span>
- <a name="l00162"></a><a class="code" href="a01684.html#ga210f227119fc972e6222c9cb452e15a9">00162</a> <span class="preprocessor"></span><span class="keyword">struct </span><a class="code" href="a00119.html" title="Representation of a uIP UDP connection.">uip_udp_conn</a> *<a class="code" href="a00119.html" title="Representation of a uIP UDP connection.">uip_udp_conn</a>;
- <a name="l00163"></a>00163 <span class="keyword">struct </span>uip_udp_conn uip_udp_conns[<a class="code" href="a01584.html#ga196379ceb1219a99f4495e41ccc9bbfb" title="The maximum amount of concurrent UDP connections.">UIP_UDP_CONNS</a>];
- <a name="l00164"></a>00164 <span class="preprocessor">#endif </span><span class="comment">/* UIP_UDP */</span>
- <a name="l00165"></a>00165
- <a name="l00166"></a>00166 <span class="keyword">static</span> <a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a> ipid; <span class="comment">/* Ths ipid variable is an increasing</span>
- <a name="l00167"></a>00167 <span class="comment"> number that is used for the IP ID</span>
- <a name="l00168"></a>00168 <span class="comment"> field. */</span>
- <a name="l00169"></a>00169
- <a name="l00170"></a><a class="code" href="a01573.html#ga22f140b02c354dfebcc7ad481c3bcd68">00170</a> <span class="keywordtype">void</span> <a class="code" href="a01684.html#ga22f140b02c354dfebcc7ad481c3bcd68" title="uIP initialization function.">uip_setipid</a>(<a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a> <span class="keywordtype">id</span>) { ipid = id; }
- <a name="l00171"></a>00171
- <a name="l00172"></a>00172 <span class="keyword">static</span> <a class="code" href="a01668.html#ga4caecabca98b43919dd11be1c0d4cd8e" title="The 8-bit unsigned data type.">u8_t</a> iss[4]; <span class="comment">/* The iss variable is used for the TCP</span>
- <a name="l00173"></a>00173 <span class="comment"> initial sequence number. */</span>
- <a name="l00174"></a>00174
- <a name="l00175"></a>00175 <span class="preprocessor">#if UIP_ACTIVE_OPEN || UIP_UDP</span>
- <a name="l00176"></a>00176 <span class="preprocessor"></span><span class="keyword">static</span> <a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a> lastport; <span class="comment">/* Keeps track of the last port used for</span>
- <a name="l00177"></a>00177 <span class="comment"> a new connection. */</span>
- <a name="l00178"></a>00178 <span class="preprocessor">#endif </span><span class="comment">/* UIP_ACTIVE_OPEN || UIP_UDP */</span>
- <a name="l00179"></a>00179
- <a name="l00180"></a>00180 <span class="comment">/* Temporary variables. */</span>
- <a name="l00181"></a><a class="code" href="a01578.html#ga2a0cf5d86c58fab216414ce59bf1fea1">00181</a> <a class="code" href="a01668.html#ga4caecabca98b43919dd11be1c0d4cd8e" title="The 8-bit unsigned data type.">u8_t</a> <a class="code" href="a01684.html#ga2a0cf5d86c58fab216414ce59bf1fea1" title="4-byte array used for the 32-bit sequence number calculations.">uip_acc32</a>[4];
- <a name="l00182"></a>00182 <span class="keyword">static</span> <a class="code" href="a01668.html#ga4caecabca98b43919dd11be1c0d4cd8e" title="The 8-bit unsigned data type.">u8_t</a> c, opt;
- <a name="l00183"></a>00183 <span class="keyword">static</span> <a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a> tmp16;
- <a name="l00184"></a>00184
- <a name="l00185"></a>00185 <span class="comment">/* Structures and definitions. */</span>
- <a name="l00186"></a>00186 <span class="preprocessor">#define TCP_FIN 0x01</span>
- <a name="l00187"></a>00187 <span class="preprocessor"></span><span class="preprocessor">#define TCP_SYN 0x02</span>
- <a name="l00188"></a>00188 <span class="preprocessor"></span><span class="preprocessor">#define TCP_RST 0x04</span>
- <a name="l00189"></a>00189 <span class="preprocessor"></span><span class="preprocessor">#define TCP_PSH 0x08</span>
- <a name="l00190"></a>00190 <span class="preprocessor"></span><span class="preprocessor">#define TCP_ACK 0x10</span>
- <a name="l00191"></a>00191 <span class="preprocessor"></span><span class="preprocessor">#define TCP_URG 0x20</span>
- <a name="l00192"></a>00192 <span class="preprocessor"></span><span class="preprocessor">#define TCP_CTL 0x3f</span>
- <a name="l00193"></a>00193 <span class="preprocessor"></span>
- <a name="l00194"></a>00194 <span class="preprocessor">#define TCP_OPT_END 0 </span><span class="comment">/* End of TCP options list */</span>
- <a name="l00195"></a>00195 <span class="preprocessor">#define TCP_OPT_NOOP 1 </span><span class="comment">/* "No-operation" TCP option */</span>
- <a name="l00196"></a>00196 <span class="preprocessor">#define TCP_OPT_MSS 2 </span><span class="comment">/* Maximum segment size TCP option */</span>
- <a name="l00197"></a>00197
- <a name="l00198"></a>00198 <span class="preprocessor">#define TCP_OPT_MSS_LEN 4 </span><span class="comment">/* Length of TCP MSS option. */</span>
- <a name="l00199"></a>00199
- <a name="l00200"></a>00200 <span class="preprocessor">#define ICMP_ECHO_REPLY 0</span>
- <a name="l00201"></a>00201 <span class="preprocessor"></span><span class="preprocessor">#define ICMP_ECHO 8</span>
- <a name="l00202"></a>00202 <span class="preprocessor"></span>
- <a name="l00203"></a>00203 <span class="preprocessor">#define ICMP_DEST_UNREACHABLE 3</span>
- <a name="l00204"></a>00204 <span class="preprocessor"></span><span class="preprocessor">#define ICMP_PORT_UNREACHABLE 3</span>
- <a name="l00205"></a>00205 <span class="preprocessor"></span>
- <a name="l00206"></a>00206 <span class="preprocessor">#define ICMP6_ECHO_REPLY 129</span>
- <a name="l00207"></a>00207 <span class="preprocessor"></span><span class="preprocessor">#define ICMP6_ECHO 128</span>
- <a name="l00208"></a>00208 <span class="preprocessor"></span><span class="preprocessor">#define ICMP6_NEIGHBOR_SOLICITATION 135</span>
- <a name="l00209"></a>00209 <span class="preprocessor"></span><span class="preprocessor">#define ICMP6_NEIGHBOR_ADVERTISEMENT 136</span>
- <a name="l00210"></a>00210 <span class="preprocessor"></span>
- <a name="l00211"></a>00211 <span class="preprocessor">#define ICMP6_FLAG_S (1 << 6)</span>
- <a name="l00212"></a>00212 <span class="preprocessor"></span>
- <a name="l00213"></a>00213 <span class="preprocessor">#define ICMP6_OPTION_SOURCE_LINK_ADDRESS 1</span>
- <a name="l00214"></a>00214 <span class="preprocessor"></span><span class="preprocessor">#define ICMP6_OPTION_TARGET_LINK_ADDRESS 2</span>
- <a name="l00215"></a>00215 <span class="preprocessor"></span>
- <a name="l00216"></a>00216
- <a name="l00217"></a>00217 <span class="comment">/* Macros. */</span>
- <a name="l00218"></a>00218 <span class="preprocessor">#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])</span>
- <a name="l00219"></a>00219 <span class="preprocessor"></span><span class="preprocessor">#define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0])</span>
- <a name="l00220"></a>00220 <span class="preprocessor"></span><span class="preprocessor">#define ICMPBUF ((struct uip_icmpip_hdr *)&uip_buf[UIP_LLH_LEN])</span>
- <a name="l00221"></a>00221 <span class="preprocessor"></span><span class="preprocessor">#define UDPBUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])</span>
- <a name="l00222"></a>00222 <span class="preprocessor"></span>
- <a name="l00223"></a>00223
- <a name="l00224"></a>00224 <span class="preprocessor">#if UIP_STATISTICS == 1</span>
- <a name="l00225"></a>00225 <span class="preprocessor"></span><span class="keyword">struct </span><a class="code" href="a00118.html" title="The structure holding the TCP/IP statistics that are gathered if UIP_STATISTICS is...">uip_stats</a> uip_stat;
- <a name="l00226"></a>00226 <span class="preprocessor">#define UIP_STAT(s) s</span>
- <a name="l00227"></a>00227 <span class="preprocessor"></span><span class="preprocessor">#else</span>
- <a name="l00228"></a>00228 <span class="preprocessor"></span><span class="preprocessor">#define UIP_STAT(s)</span>
- <a name="l00229"></a>00229 <span class="preprocessor"></span><span class="preprocessor">#endif </span><span class="comment">/* UIP_STATISTICS == 1 */</span>
- <a name="l00230"></a>00230
- <a name="l00231"></a>00231 <span class="preprocessor">#if UIP_LOGGING == 1</span>
- <a name="l00232"></a>00232 <span class="preprocessor"></span><span class="preprocessor">#include <stdio.h></span>
- <a name="l00233"></a>00233 <span class="keywordtype">void</span> <a class="code" href="a01589.html#gab58e1ceb7cb73ca2bcd73146b6c1b4e7" title="Print out a uIP log message.">uip_log</a>(<span class="keywordtype">char</span> *msg);
- <a name="l00234"></a>00234 <span class="preprocessor">#define UIP_LOG(m) uip_log(m)</span>
- <a name="l00235"></a>00235 <span class="preprocessor"></span><span class="preprocessor">#else</span>
- <a name="l00236"></a>00236 <span class="preprocessor"></span><span class="preprocessor">#define UIP_LOG(m)</span>
- <a name="l00237"></a>00237 <span class="preprocessor"></span><span class="preprocessor">#endif </span><span class="comment">/* UIP_LOGGING == 1 */</span>
- <a name="l00238"></a>00238
- <a name="l00239"></a>00239 <span class="preprocessor">#if ! UIP_ARCH_ADD32</span>
- <a name="l00240"></a>00240 <span class="preprocessor"></span><span class="keywordtype">void</span>
- <a name="l00241"></a><a class="code" href="a01578.html#ga6832e4d2d046536b6472f7ac92340f68">00241</a> <a class="code" href="a01684.html#ga6832e4d2d046536b6472f7ac92340f68" title="Carry out a 32-bit addition.">uip_add32</a>(<a class="code" href="a01668.html#ga4caecabca98b43919dd11be1c0d4cd8e" title="The 8-bit unsigned data type.">u8_t</a> *op32, <a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a> op16)
- <a name="l00242"></a>00242 {
- <a name="l00243"></a>00243 <a class="code" href="a01684.html#ga2a0cf5d86c58fab216414ce59bf1fea1" title="4-byte array used for the 32-bit sequence number calculations.">uip_acc32</a>[3] = op32[3] + (op16 & 0xff);
- <a name="l00244"></a>00244 <a class="code" href="a01684.html#ga2a0cf5d86c58fab216414ce59bf1fea1" title="4-byte array used for the 32-bit sequence number calculations.">uip_acc32</a>[2] = op32[2] + (op16 >> 8);
- <a name="l00245"></a>00245 uip_acc32[1] = op32[1];
- <a name="l00246"></a>00246 uip_acc32[0] = op32[0];
- <a name="l00247"></a>00247
- <a name="l00248"></a>00248 <span class="keywordflow">if</span>(uip_acc32[2] < (op16 >> 8)) {
- <a name="l00249"></a>00249 ++uip_acc32[1];
- <a name="l00250"></a>00250 <span class="keywordflow">if</span>(uip_acc32[1] == 0) {
- <a name="l00251"></a>00251 ++uip_acc32[0];
- <a name="l00252"></a>00252 }
- <a name="l00253"></a>00253 }
- <a name="l00254"></a>00254
- <a name="l00255"></a>00255
- <a name="l00256"></a>00256 <span class="keywordflow">if</span>(uip_acc32[3] < (op16 & 0xff)) {
- <a name="l00257"></a>00257 ++uip_acc32[2];
- <a name="l00258"></a>00258 <span class="keywordflow">if</span>(uip_acc32[2] == 0) {
- <a name="l00259"></a>00259 ++uip_acc32[1];
- <a name="l00260"></a>00260 <span class="keywordflow">if</span>(uip_acc32[1] == 0) {
- <a name="l00261"></a>00261 ++uip_acc32[0];
- <a name="l00262"></a>00262 }
- <a name="l00263"></a>00263 }
- <a name="l00264"></a>00264 }
- <a name="l00265"></a>00265 }
- <a name="l00266"></a>00266
- <a name="l00267"></a>00267 <span class="preprocessor">#endif </span><span class="comment">/* UIP_ARCH_ADD32 */</span>
- <a name="l00268"></a>00268
- <a name="l00269"></a>00269 <span class="preprocessor">#if ! UIP_ARCH_CHKSUM</span>
- <a name="l00270"></a>00270 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------*/</span>
- <a name="l00271"></a>00271 <span class="keyword">static</span> <a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a>
- <a name="l00272"></a>00272 chksum(<a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a> sum, <span class="keyword">const</span> <a class="code" href="a01668.html#ga4caecabca98b43919dd11be1c0d4cd8e" title="The 8-bit unsigned data type.">u8_t</a> *data, <a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a> len)
- <a name="l00273"></a>00273 {
- <a name="l00274"></a>00274 <a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a> t;
- <a name="l00275"></a>00275 <span class="keyword">const</span> <a class="code" href="a01668.html#ga4caecabca98b43919dd11be1c0d4cd8e" title="The 8-bit unsigned data type.">u8_t</a> *dataptr;
- <a name="l00276"></a>00276 <span class="keyword">const</span> <a class="code" href="a01668.html#ga4caecabca98b43919dd11be1c0d4cd8e" title="The 8-bit unsigned data type.">u8_t</a> *last_byte;
- <a name="l00277"></a>00277
- <a name="l00278"></a>00278 dataptr = data;
- <a name="l00279"></a>00279 last_byte = data + len - 1;
- <a name="l00280"></a>00280
- <a name="l00281"></a>00281 <span class="keywordflow">while</span>(dataptr < last_byte) { <span class="comment">/* At least two more bytes */</span>
- <a name="l00282"></a>00282 t = (dataptr[0] << 8) + dataptr[1];
- <a name="l00283"></a>00283 sum += t;
- <a name="l00284"></a>00284 <span class="keywordflow">if</span>(sum < t) {
- <a name="l00285"></a>00285 sum++; <span class="comment">/* carry */</span>
- <a name="l00286"></a>00286 }
- <a name="l00287"></a>00287 dataptr += 2;
- <a name="l00288"></a>00288 }
- <a name="l00289"></a>00289
- <a name="l00290"></a>00290 <span class="keywordflow">if</span>(dataptr == last_byte) {
- <a name="l00291"></a>00291 t = (dataptr[0] << 8) + 0;
- <a name="l00292"></a>00292 sum += t;
- <a name="l00293"></a>00293 <span class="keywordflow">if</span>(sum < t) {
- <a name="l00294"></a>00294 sum++; <span class="comment">/* carry */</span>
- <a name="l00295"></a>00295 }
- <a name="l00296"></a>00296 }
- <a name="l00297"></a>00297
- <a name="l00298"></a>00298 <span class="comment">/* Return sum in host byte order. */</span>
- <a name="l00299"></a>00299 <span class="keywordflow">return</span> sum;
- <a name="l00300"></a>00300 }
- <a name="l00301"></a>00301 <span class="comment">/*---------------------------------------------------------------------------*/</span>
- <a name="l00302"></a>00302 <a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a>
- <a name="l00303"></a>00303 <a class="code" href="a01684.html#gab6683dd83fe1c8de9a24086d4b69e907" title="Calculate the Internet checksum over a buffer.">uip_chksum</a>(<a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a> *data, <a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a> len)
- <a name="l00304"></a>00304 {
- <a name="l00305"></a>00305 <span class="keywordflow">return</span> <a class="code" href="a01684.html#gae4394b6b3cd81f73b0e64a93e0558e00" title="Convert 16-bit quantity from host byte order to network byte order.">uip_htons</a>(chksum(0, (<a class="code" href="a01668.html#ga4caecabca98b43919dd11be1c0d4cd8e" title="The 8-bit unsigned data type.">u8_t</a> *)data, len));
- <a name="l00306"></a>00306 }
- <a name="l00307"></a>00307 <span class="comment">/*---------------------------------------------------------------------------*/</span>
- <a name="l00308"></a>00308 <span class="preprocessor">#ifndef UIP_ARCH_IPCHKSUM</span>
- <a name="l00309"></a>00309 <span class="preprocessor"></span><a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a>
- <a name="l00310"></a>00310 <a class="code" href="a01684.html#ga2addf34c7d457c1a7899a7e2171ef1e9" title="Calculate the IP header checksum of the packet header in uip_buf.">uip_ipchksum</a>(<span class="keywordtype">void</span>)
- <a name="l00311"></a>00311 {
- <a name="l00312"></a>00312 <a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a> sum;
- <a name="l00313"></a>00313
- <a name="l00314"></a>00314 sum = chksum(0, &uip_buf[<a class="code" href="a01589.html#gae6f4a2453dbd8bc60e6a82774552366a" title="The link level header length.">UIP_LLH_LEN</a>], UIP_IPH_LEN);
- <a name="l00315"></a>00315 DEBUG_PRINTF(<span class="stringliteral">"uip_ipchksum: sum 0x%04x\n"</span>, sum);
- <a name="l00316"></a>00316 <span class="keywordflow">return</span> (sum == 0) ? 0xffff : <a class="code" href="a01684.html#gae4394b6b3cd81f73b0e64a93e0558e00" title="Convert 16-bit quantity from host byte order to network byte order.">uip_htons</a>(sum);
- <a name="l00317"></a>00317 }
- <a name="l00318"></a>00318 <span class="preprocessor">#endif</span>
- <a name="l00319"></a>00319 <span class="preprocessor"></span><span class="comment">/*---------------------------------------------------------------------------*/</span>
- <a name="l00320"></a>00320 <span class="keyword">static</span> <a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a>
- <a name="l00321"></a>00321 upper_layer_chksum(<a class="code" href="a01668.html#ga4caecabca98b43919dd11be1c0d4cd8e" title="The 8-bit unsigned data type.">u8_t</a> proto)
- <a name="l00322"></a>00322 {
- <a name="l00323"></a>00323 <a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a> upper_layer_len;
- <a name="l00324"></a>00324 <a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a> sum;
- <a name="l00325"></a>00325
- <a name="l00326"></a>00326 <span class="preprocessor">#if UIP_CONF_IPV6</span>
- <a name="l00327"></a>00327 <span class="preprocessor"></span> upper_layer_len = (((<a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a>)(BUF->len[0]) << 8) + BUF->len[1]);
- <a name="l00328"></a>00328 <span class="preprocessor">#else </span><span class="comment">/* UIP_CONF_IPV6 */</span>
- <a name="l00329"></a>00329 upper_layer_len = (((<a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a>)(BUF->len[0]) << 8) + BUF->len[1]) - UIP_IPH_LEN;
- <a name="l00330"></a>00330 <span class="preprocessor">#endif </span><span class="comment">/* UIP_CONF_IPV6 */</span>
- <a name="l00331"></a>00331
- <a name="l00332"></a>00332 <span class="comment">/* First sum pseudoheader. */</span>
- <a name="l00333"></a>00333
- <a name="l00334"></a>00334 <span class="comment">/* IP protocol and length fields. This addition cannot carry. */</span>
- <a name="l00335"></a>00335 sum = upper_layer_len + proto;
- <a name="l00336"></a>00336 <span class="comment">/* Sum IP source and destination addresses. */</span>
- <a name="l00337"></a>00337 sum = chksum(sum, (<a class="code" href="a01668.html#ga4caecabca98b43919dd11be1c0d4cd8e" title="The 8-bit unsigned data type.">u8_t</a> *)&BUF->srcipaddr, 2 * <span class="keyword">sizeof</span>(<a class="code" href="a00106.html" title="Representation of an IP address.">uip_ipaddr_t</a>));
- <a name="l00338"></a>00338
- <a name="l00339"></a>00339 <span class="comment">/* Sum TCP header and data. */</span>
- <a name="l00340"></a>00340 sum = chksum(sum, &uip_buf[UIP_IPH_LEN + <a class="code" href="a01589.html#gae6f4a2453dbd8bc60e6a82774552366a" title="The link level header length.">UIP_LLH_LEN</a>],
- <a name="l00341"></a>00341 upper_layer_len);
- <a name="l00342"></a>00342
- <a name="l00343"></a>00343 <span class="keywordflow">return</span> (sum == 0) ? 0xffff : <a class="code" href="a01684.html#gae4394b6b3cd81f73b0e64a93e0558e00" title="Convert 16-bit quantity from host byte order to network byte order.">uip_htons</a>(sum);
- <a name="l00344"></a>00344 }
- <a name="l00345"></a>00345 <span class="comment">/*---------------------------------------------------------------------------*/</span>
- <a name="l00346"></a>00346 <span class="preprocessor">#if UIP_CONF_IPV6</span>
- <a name="l00347"></a>00347 <span class="preprocessor"></span><a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a>
- <a name="l00348"></a>00348 <a class="code" href="a01684.html#ga5e6741b8bd3e0961fb87e3f85da27a7f" title="Calculate the ICMP checksum of the packet in uip_buf.">uip_icmp6chksum</a>(<span class="keywordtype">void</span>)
- <a name="l00349"></a>00349 {
- <a name="l00350"></a>00350 <span class="keywordflow">return</span> upper_layer_chksum(UIP_PROTO_ICMP6);
- <a name="l00351"></a>00351
- <a name="l00352"></a>00352 }
- <a name="l00353"></a>00353 <span class="preprocessor">#endif </span><span class="comment">/* UIP_CONF_IPV6 */</span>
- <a name="l00354"></a>00354 <span class="comment">/*---------------------------------------------------------------------------*/</span>
- <a name="l00355"></a>00355 <a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a>
- <a name="l00356"></a>00356 <a class="code" href="a01684.html#ga85b65e38aa74eba18979156f97a94a87" title="Calculate the TCP checksum of the packet in uip_buf and uip_appdata.">uip_tcpchksum</a>(<span class="keywordtype">void</span>)
- <a name="l00357"></a>00357 {
- <a name="l00358"></a>00358 <span class="keywordflow">return</span> upper_layer_chksum(UIP_PROTO_TCP);
- <a name="l00359"></a>00359 }
- <a name="l00360"></a>00360 <span class="comment">/*---------------------------------------------------------------------------*/</span>
- <a name="l00361"></a>00361 <span class="preprocessor">#if UIP_UDP_CHECKSUMS</span>
- <a name="l00362"></a>00362 <span class="preprocessor"></span><a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a>
- <a name="l00363"></a>00363 <a class="code" href="a01684.html#ga7023a34ba9e9d03b5fbedbcb32924453" title="Calculate the UDP checksum of the packet in uip_buf and uip_appdata.">uip_udpchksum</a>(<span class="keywordtype">void</span>)
- <a name="l00364"></a>00364 {
- <a name="l00365"></a>00365 <span class="keywordflow">return</span> upper_layer_chksum(UIP_PROTO_UDP);
- <a name="l00366"></a>00366 }
- <a name="l00367"></a>00367 <span class="preprocessor">#endif </span><span class="comment">/* UIP_UDP_CHECKSUMS */</span>
- <a name="l00368"></a>00368 <span class="preprocessor">#endif </span><span class="comment">/* UIP_ARCH_CHKSUM */</span>
- <a name="l00369"></a>00369 <span class="comment">/*---------------------------------------------------------------------------*/</span>
- <a name="l00370"></a>00370 <span class="keywordtype">void</span>
- <a name="l00371"></a><a class="code" href="a01573.html#gac48ed5f0d27721ef62a3ed02a5ad8d2e">00371</a> <a class="code" href="a01684.html#gac48ed5f0d27721ef62a3ed02a5ad8d2e" title="uIP initialization function.">uip_init</a>(<span class="keywordtype">void</span>)
- <a name="l00372"></a>00372 {
- <a name="l00373"></a>00373 <span class="keywordflow">for</span>(c = 0; c < <a class="code" href="a01585.html#ga8f4ebd8ef6c0ea665ed351d87fec09fd" title="The maximum number of simultaneously listening TCP ports.">UIP_LISTENPORTS</a>; ++c) {
- <a name="l00374"></a>00374 uip_listenports[c] = 0;
- <a name="l00375"></a>00375 }
- <a name="l00376"></a>00376 <span class="keywordflow">for</span>(c = 0; c < <a class="code" href="a01585.html#gaf5fe83be78b78b9e7d9e7f1e34ab1cc5" title="The maximum number of simultaneously open TCP connections.">UIP_CONNS</a>; ++c) {
- <a name="l00377"></a>00377 uip_conns[c].<a class="code" href="a00092.html#aa5f58074435cdc180f17de69651beebd" title="TCP state and flags.">tcpstateflags</a> = UIP_CLOSED;
- <a name="l00378"></a>00378 }
- <a name="l00379"></a>00379 <span class="preprocessor">#if UIP_ACTIVE_OPEN || UIP_UDP</span>
- <a name="l00380"></a>00380 <span class="preprocessor"></span> lastport = 1024;
- <a name="l00381"></a>00381 <span class="preprocessor">#endif </span><span class="comment">/* UIP_ACTIVE_OPEN || UIP_UDP */</span>
- <a name="l00382"></a>00382
- <a name="l00383"></a>00383 <span class="preprocessor">#if UIP_UDP</span>
- <a name="l00384"></a>00384 <span class="preprocessor"></span> <span class="keywordflow">for</span>(c = 0; c < <a class="code" href="a01584.html#ga196379ceb1219a99f4495e41ccc9bbfb" title="The maximum amount of concurrent UDP connections.">UIP_UDP_CONNS</a>; ++c) {
- <a name="l00385"></a>00385 uip_udp_conns[c].<a class="code" href="a00119.html#a981392e295db4d024eea95805c51c371" title="The local port number in network byte order.">lport</a> = 0;
- <a name="l00386"></a>00386 }
- <a name="l00387"></a>00387 <span class="preprocessor">#endif </span><span class="comment">/* UIP_UDP */</span>
- <a name="l00388"></a>00388
- <a name="l00389"></a>00389
- <a name="l00390"></a>00390 <span class="comment">/* IPv4 initialization. */</span>
- <a name="l00391"></a>00391 <span class="preprocessor">#if UIP_FIXEDADDR == 0</span>
- <a name="l00392"></a>00392 <span class="preprocessor"></span> <span class="comment">/* uip_hostaddr[0] = uip_hostaddr[1] = 0;*/</span>
- <a name="l00393"></a>00393 <span class="preprocessor">#endif </span><span class="comment">/* UIP_FIXEDADDR */</span>
- <a name="l00394"></a>00394
- <a name="l00395"></a>00395 }
- <a name="l00396"></a>00396 <span class="comment">/*---------------------------------------------------------------------------*/</span>
- <a name="l00397"></a>00397 <span class="preprocessor">#if UIP_ACTIVE_OPEN</span>
- <a name="l00398"></a>00398 <span class="preprocessor"></span><span class="keyword">struct </span>uip_conn *
- <a name="l00399"></a>00399 <a class="code" href="a01575.html#ga8096b0c4b543dc408f4dd031ddae7240" title="Connect to a remote host using TCP.">uip_connect</a>(<a class="code" href="a00106.html" title="Representation of an IP address.">uip_ipaddr_t</a> *<a class="code" href="a00092.html#a79510aa86d3fa0a0fc6cfc49b1da7279" title="The IP address of the remote host.">ripaddr</a>, <a class="code" href="a01668.html#ga77570ac4fcab86864fa1916e55676da2" title="The 16-bit unsigned data type.">u16_t</a> <a class="code" href="a00092.html#a1df6aa054ef2fa634ac4c6f418228285" title="The local remote TCP port, in network byte order.">rport</a>)
- <a name="l00400"></a>00400 {
- <a name="l00401"></a>00401 <span class="keyword">register</span> <span class="keyword">struct </span>uip_conn *conn, *cconn;
- <a name="l00402"></a>00402
- <a name="l00403"></a>00403 <span class="comment">/* Find an unused local port. */</span>
- <a name="l00404"></a>00404 again:
- <a name="l00405"></a>00405 ++lastport;
- <a name="l00406"></a>00406
- <a name="l00407"></a>00407 <span class="keywordflow">if</span>(lastport >= 32000) {
- <a name="l00408"></a>00408 lastport = 4096;
- <a name="l00409"></a>00409 }
- <a name="l00410"></a>00410
- <a name="l00411"></a>00411 <span class="comment">/* Check if this port is already in use, and if so try to find</span>
- <a name="l00412"></a>00412 <span class="comment"> another one. */</span>
- <a name="l00413"></a>00413 <span class="keywordflow">for</span>(c = 0; c < <a class="code" href="a01585.html#gaf5fe83be78b78b9e7d9e7f1e34ab1cc5" title="The maximum number of simultaneously open TCP connections.">UIP_CONNS</a>; ++c) {
- <a name="l00414"></a>00414 conn = &uip_conns[c];
- <a name="l00415"></a>00415 <span class="keywordflow">if</span>(conn-><a class="code" href="a00092.html#aa5f58074435cdc180f17de69651beebd" title="TCP state and flags.">tcpstateflags</a> != UIP_CLOSED &&
- <a name="l00416"></a>00416 conn-><a class="code" href="a00092.html#a0cd09beee671e7e9efb0b4aced10249e" title="The local TCP port, in network byte order.">lport</a> == <a class="code" href="a01684.html#gae4394b6b3cd81f73b0e64a93e0558e00" title="Convert 16-bit quantity from host byte order to network byte order.">uip_htons</a>(lastport)) {
- <a name="l00417"></a>00417 <span class="keywordflow">goto</span> again;
- <a name="l00418"></a>00418 }
- <a name="l00419"></a>00419 }
- <a name="l00420"></a>00420
- <a name="l00421"></a>00421 conn = 0;
- <a name="l00422"></a>00422 <span class="keywordflow">for</span>(c = 0; c < UIP_CONNS; ++c) {
- <a name="l00423"></a>00423 cconn = &uip_conns[c];
- <a name="l00424"></a>00424 <span class="keywordflow">if</span>(cconn-><a class="code" href="a00092.html#aa5f58074435cdc180f17de69651beebd" title="TCP state and flags.">tcpstateflags</a> == UIP_CLOSED) {
- <a name="l00425"></a>00425 conn = cconn;
- <a name="l00426"></a>00426 <span class="keywordflow">break</span>;
- <a name="l00427"></a>00427 }
- <a name="l00428"></a>00428 <span class="keywordflow">if</span>(cconn-><a class="code" href="a00092.html#aa5f58074435cdc180f17de69651beebd" title="TCP state and flags.">tcpstateflags</a> == UIP_TIME_WAIT) {
- <a name="l00429"></a>00429 <span class="keywordflow">if</span>(conn == 0 ||
- <a name="l00430"></a>00430 cconn-><a class="code" href="a00092.html#a2d9732cf5752d30bd11cb25dc7d0c8d3" title="The retransmission timer.">timer</a> > conn-><a class="code" href="a00092.html#a2d9732cf5752d30bd11cb25dc7d0c8d3" title="The retransmission timer.">timer</a>) {
- <a name="l00431"></a>00431 conn = cconn;
- <a name="l00432"></a>00432 }
- <a name="l00433"></a>00433 }
- <a name="l00434"></a>00434 }
- <a name="l00435"></a>00435
- <a name="l00436"></a>00436 <span class="keywordflow">if</span>(conn == 0) {
- <a name="l00437"></a>00437 <span class="keywordflow">return</span> 0;
- <a name="l00438"></a>00438 }
- <a name="l00439"></a>00439
- <a name="l00440"></a>00440 conn-><a class="code" href="a00092.html#aa5f58074435cdc180f17de69651beebd" title="TCP state and flags.">tcpstateflags</a> = UIP_SYN_SENT;
- <a name="l00441"></a>00441
- <a name="l00442"></a>00442 conn-><a class="code" href="a00092.html#a8f6b08a5ba2a…
Large files files are truncated, but you can click here to view the full file