⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 udp_8c-source.html

📁 Freescale mcu OpenTCP-1.0.4.doc.html.zip 文档
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>/opentcp/udp.c Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><a class="qindex" href="main.html">Main Page</a> &nbsp; <a class="qindex" href="modules.html">Modules</a> &nbsp; <a class="qindex" href="annotated.html">Data Structures</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Data Fields</a> &nbsp; <a class="qindex" href="globals.html">Globals</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; <a class="qindex" href="examples.html">Examples</a> &nbsp; </center><hr><h1>/opentcp/udp.c</h1><a href="udp_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*</span>00002 <span class="comment"> *Copyright (c) 2000-2002 Viola Systems Ltd.</span>00003 <span class="comment"> *All rights reserved.</span>00004 <span class="comment"> *</span>00005 <span class="comment"> *Redistribution and use in source and binary forms, with or without </span>00006 <span class="comment"> *modification, are permitted provided that the following conditions </span>00007 <span class="comment"> *are met:</span>00008 <span class="comment"> *</span>00009 <span class="comment"> *1. Redistributions of source code must retain the above copyright </span>00010 <span class="comment"> *notice, this list of conditions and the following disclaimer.</span>00011 <span class="comment"> *</span>00012 <span class="comment"> *2. Redistributions in binary form must reproduce the above copyright </span>00013 <span class="comment"> *notice, this list of conditions and the following disclaimer in the </span>00014 <span class="comment"> *documentation and/or other materials provided with the distribution.</span>00015 <span class="comment"> *</span>00016 <span class="comment"> *3. The end-user documentation included with the redistribution, if </span>00017 <span class="comment"> *any, must include the following acknowledgment:</span>00018 <span class="comment"> *      "This product includes software developed by Viola </span>00019 <span class="comment"> *      Systems (http://www.violasystems.com/)."</span>00020 <span class="comment"> *</span>00021 <span class="comment"> *Alternately, this acknowledgment may appear in the software itself, </span>00022 <span class="comment"> *if and wherever such third-party acknowledgments normally appear.</span>00023 <span class="comment"> *</span>00024 <span class="comment"> *4. The names "OpenTCP" and "Viola Systems" must not be used to </span>00025 <span class="comment"> *endorse or promote products derived from this software without prior </span>00026 <span class="comment"> *written permission. For written permission, please contact </span>00027 <span class="comment"> *opentcp@opentcp.org.</span>00028 <span class="comment"> *</span>00029 <span class="comment"> *5. Products derived from this software may not be called "OpenTCP", </span>00030 <span class="comment"> *nor may "OpenTCP" appear in their name, without prior written </span>00031 <span class="comment"> *permission of the Viola Systems Ltd.</span>00032 <span class="comment"> *</span>00033 <span class="comment"> *THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED </span>00034 <span class="comment"> *WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF </span>00035 <span class="comment"> *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. </span>00036 <span class="comment"> *IN NO EVENT SHALL VIOLA SYSTEMS LTD. OR ITS CONTRIBUTORS BE LIABLE </span>00037 <span class="comment"> *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR </span>00038 <span class="comment"> *CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF </span>00039 <span class="comment"> *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR </span>00040 <span class="comment"> *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, </span>00041 <span class="comment"> *WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE </span>00042 <span class="comment"> *OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, </span>00043 <span class="comment"> *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>00044 <span class="comment"> *====================================================================</span>00045 <span class="comment"> *</span>00046 <span class="comment"> *OpenTCP is the unified open source TCP/IP stack available on a series </span>00047 <span class="comment"> *of 8/16-bit microcontrollers, please see &lt;http://www.opentcp.org&gt;.</span>00048 <span class="comment"> *</span>00049 <span class="comment"> *For more information on how to network-enable your devices, or how to </span>00050 <span class="comment"> *obtain commercial technical support for OpenTCP, please see </span>00051 <span class="comment"> *&lt;http://www.violasystems.com/&gt;.</span>00052 <span class="comment"> */</span>00053 00077 <span class="preprocessor">#include &lt;<a class="code" href="debug_8h.html">inet/debug.h</a>&gt;</span>00078 <span class="preprocessor">#include &lt;<a class="code" href="datatypes_8h.html">inet/datatypes.h</a>&gt;</span>00079 <span class="preprocessor">#include &lt;<a class="code" href="ethernet_8h.html">inet/ethernet.h</a>&gt;</span>00080 <span class="preprocessor">#include &lt;<a class="code" href="ip_8h.html">inet/ip.h</a>&gt;</span>00081 <span class="preprocessor">#include &lt;<a class="code" href="tcp__ip_8h.html">inet/tcp_ip.h</a>&gt;</span>00082 <span class="preprocessor">#include &lt;<a class="code" href="system_8h.html">inet/system.h</a>&gt;</span>00083 <a name="l00094"></a><a class="code" href="udp_8c.html#a0">00094</a> <span class="keyword">struct </span><a class="code" href="structucb.html">ucb</a> udp_socket[NO_OF_UDPSOCKETS];00095 <a name="l00101"></a><a class="code" href="udp_8c.html#a1">00101</a> <span class="keyword">struct </span><a class="code" href="structudp__frame.html">udp_frame</a> received_udp_packet;00102 <a name="l00118"></a><a class="code" href="udp_8c.html#a2">00118</a> INT8 <a class="code" href="group__core__initializer.html#a4">udp_init</a> (<span class="keywordtype">void</span>)00119 {00120         UINT8 i;00121         <span class="keyword">struct </span><a class="code" href="structucb.html">ucb</a>* soc;00122         00123         <span class="keywordflow">if</span>( NO_OF_UDPSOCKETS &lt; 0 )00124                 <span class="keywordflow">return</span>(-1);00125         00126         <span class="keywordflow">if</span>( NO_OF_UDPSOCKETS == 0 )00127                 <span class="keywordflow">return</span>(0);00128         00129         UDP_DEBUGOUT(<span class="stringliteral">"Initializing UDP"</span>);00130         00131         <span class="keywordflow">for</span>(i=0; i &lt; NO_OF_UDPSOCKETS; i++) {00132                 soc = &amp;udp_socket[i];                   <span class="comment">/* Get Socket   */</span>00133                 00134                 soc-&gt;<a class="code" href="structucb.html#m0">state</a> = <a class="code" href="tcp__ip_8h.html#a28">UDP_STATE_FREE</a>;00135                 soc-&gt;<a class="code" href="structucb.html#m1">tos</a> = 0;00136                 soc-&gt;<a class="code" href="structucb.html#m2">locport</a> = 0;00137                 soc-&gt;<a class="code" href="structucb.html#m3">opts</a> = <a class="code" href="tcp__ip_8h.html#a5">UDP_OPT_SEND_CS</a> | <a class="code" href="tcp__ip_8h.html#a6">UDP_OPT_CHECK_CS</a>;  00138                 soc-&gt;event_listener = 0;00139                 00140                 UDP_DEBUGOUT(<span class="stringliteral">"."</span>);00141                 00142         }00143         00144         UDP_DEBUGOUT(<span class="stringliteral">"\n\rUDP Initialized\n\r"</span>);00145         00146         <span class="comment">/* Return number of sockets initialized */</span>00147         00148         <span class="keywordflow">return</span>(i+1);00149 00150 }00151 <a name="l00175"></a><a class="code" href="udp_8c.html#a3">00175</a> INT8 <a class="code" href="udp_8c.html#a3">udp_getsocket</a> (UINT8 tos, INT32 (*listener)(INT8, UINT8, UINT32, UINT16, UINT16, UINT16), UINT8 opts )00176 {00177         INT8 i;00178         <span class="keyword">struct </span><a class="code" href="structucb.html">ucb</a>* soc;00179         00180         <span class="keywordflow">if</span>( NO_OF_UDPSOCKETS &lt; 0 )00181                 <span class="keywordflow">return</span>(-1);00182         00183         <span class="keywordflow">if</span>( NO_OF_UDPSOCKETS == 0 )00184                 <span class="keywordflow">return</span>(-1);00185         00186         00187         <span class="keywordflow">if</span>(listener == 0) {00188                 UDP_DEBUGOUT(<span class="stringliteral">"ERROR:Event listener function for UDP not specified\r\n"</span>);00189                 <span class="keywordflow">return</span>(-1);00190         }00191         00192         UDP_DEBUGOUT(<span class="stringliteral">"Searching for free UDP socket...\r\n"</span>);00193         00194         <span class="keywordflow">for</span>(i=0; i &lt; NO_OF_UDPSOCKETS; i++) {00195                 soc = &amp;udp_socket[i];                   <span class="comment">/* Get Socket   */</span>00196         00197                 <span class="keywordflow">if</span>(soc-&gt;<a class="code" href="structucb.html#m0">state</a> == <a class="code" href="tcp__ip_8h.html#a28">UDP_STATE_FREE</a>) {00198                         <span class="comment">/* We found it  */</span>00199                         00200                         UDP_DEBUGOUT(<span class="stringliteral">"Free socket found\r\n"</span>);00201                         00202                         soc-&gt;<a class="code" href="structucb.html#m0">state</a> = <a class="code" href="tcp__ip_8h.html#a29">UDP_STATE_CLOSED</a>;00203                         soc-&gt;<a class="code" href="structucb.html#m1">tos</a> = tos;00204                         soc-&gt;<a class="code" href="structucb.html#m2">locport</a> = 0;00205                         00206                         soc-&gt;<a class="code" href="structucb.html#m3">opts</a> = 0;00207                         00208                         <span class="keywordflow">if</span>(opts &amp; <a class="code" href="tcp__ip_8h.html#a5">UDP_OPT_SEND_CS</a>)00209                                 soc-&gt;<a class="code" href="structucb.html#m3">opts</a> |= <a class="code" href="tcp__ip_8h.html#a5">UDP_OPT_SEND_CS</a>;00210                         <span class="keywordflow">if</span>(opts &amp; <a class="code" href="tcp__ip_8h.html#a6">UDP_OPT_CHECK_CS</a>)00211                                 soc-&gt;<a class="code" href="structucb.html#m3">opts</a> |= <a class="code" href="tcp__ip_8h.html#a6">UDP_OPT_CHECK_CS</a>;00212                         00213                         soc-&gt;event_listener = listener;00214 00215                         <span class="comment">/* Return handle        */</span>00216                         00217                         <span class="keywordflow">return</span>(i);00218                 }00219         00220         }00221         00222         <span class="comment">/* We are there so no socket found      */</span>00223         00224         UDP_DEBUGOUT(<span class="stringliteral">"No UDP socket found\r\n"</span>);00225         <span class="keywordflow">return</span>(-1);00226 00227 }00228 00229 <a name="l00244"></a><a class="code" href="udp_8c.html#a4">00244</a> INT8 <a class="code" href="udp_8c.html#a4">udp_releasesocket</a> (INT8 sochandle)00245 {00246         <span class="keyword">struct </span><a class="code" href="structucb.html">ucb</a>* soc;00247         00248         <span class="keywordflow">if</span>( NO_OF_UDPSOCKETS &lt; 0 )00249                 <span class="keywordflow">return</span>(-1);00250         00251         <span class="keywordflow">if</span>( NO_OF_UDPSOCKETS == 0 )00252                 <span class="keywordflow">return</span>(-1);00253         00254         <span class="keywordflow">if</span>( sochandle &gt; NO_OF_UDPSOCKETS ) {00255                 UDP_DEBUGOUT(<span class="stringliteral">"Socket handle non-valid\r\n"</span>);00256                 <span class="keywordflow">return</span>(-1);00257         }00258         00259         <span class="keywordflow">if</span>( sochandle &lt; 0 ) {00260                 UDP_DEBUGOUT(<span class="stringliteral">"Socket handle non-valid\r\n"</span>);00261                 <span class="keywordflow">return</span>(-1);00262         }00263         00264         soc = &amp;udp_socket[sochandle];           <span class="comment">/* Get referense        */</span>00265         00266         soc-&gt;<a class="code" href="structucb.html#m0">state</a> = <a class="code" href="tcp__ip_8h.html#a28">UDP_STATE_FREE</a>;00267         soc-&gt;<a class="code" href="structucb.html#m1">tos</a> = 0;00268         soc-&gt;<a class="code" href="structucb.html#m2">locport</a> = 0;00269         soc-&gt;<a class="code" href="structucb.html#m3">opts</a> = <a class="code" href="tcp__ip_8h.html#a5">UDP_OPT_SEND_CS</a> | <a class="code" href="tcp__ip_8h.html#a6">UDP_OPT_CHECK_CS</a>; 00270         soc-&gt;event_listener = 0;00271 00272         <span class="keywordflow">return</span>(sochandle);00273 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -