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

📄 dns_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/dns/dns.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/dns/dns.c</h1><a href="dns_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 00054 00075 <span class="preprocessor">#include &lt;<a class="code" href="debug_8h.html">inet/debug.h</a>&gt;</span>00076 <span class="preprocessor">#include &lt;<a class="code" href="datatypes_8h.html">inet/datatypes.h</a>&gt;</span>00077 <span class="preprocessor">#include &lt;<a class="code" href="globalvariables_8h.html">inet/globalvariables.h</a>&gt;</span>00078 <span class="preprocessor">#include &lt;<a class="code" href="system_8h.html">inet/system.h</a>&gt;</span>00079 <span class="preprocessor">#include &lt;<a class="code" href="timers_8h.html">inet/timers.h</a>&gt;</span>00080 <span class="preprocessor">#include &lt;<a class="code" href="tcp__ip_8h.html">inet/tcp_ip.h</a>&gt;</span>00081 <span class="preprocessor">#include &lt;<a class="code" href="dns_8h.html">inet/dns/dns.h</a>&gt;</span>00082 00083 00084 <span class="preprocessor">#define DNS_STATE_READY         0</span>00085 <span class="preprocessor"></span><span class="preprocessor">#define DNS_STATE_BUSY          1</span>00086 <span class="preprocessor"></span><span class="preprocessor">#define DNS_STATE_RESEND        2       </span><span class="comment">/* retransmit request */</span>00087 <a name="l00088"></a><a class="code" href="dns_8c.html#a3">00088</a> UINT8 <a class="code" href="dns_8c.html#a3">dns_state</a>; <a name="l00089"></a><a class="code" href="dns_8c.html#a4">00089</a> UINT8 <a class="code" href="dns_8c.html#a4">dns_socket</a>; <a name="l00090"></a><a class="code" href="dns_8c.html#a5">00090</a> UINT8 <a class="code" href="dns_8c.html#a5">dns_timer</a>; <a name="l00091"></a><a class="code" href="dns_8c.html#a6">00091</a> UINT8 <a class="code" href="dns_8c.html#a6">dns_retries</a>; <a name="l00093"></a><a class="code" href="dns_8c.html#a7">00093</a> UINT32 <a class="code" href="dns_8c.html#a7">dns_tmp_ip</a>; <a name="l00095"></a><a class="code" href="dns_8c.html#a8">00095</a> UINT8 *<a class="code" href="dns_8c.html#a8">dns_hostptr</a>;     00098 void (*dns_event_listener)(UINT8 event, UINT32 data);00099 <a name="l00108"></a><a class="code" href="dns_8c.html#a10">00108</a> <span class="keywordtype">void</span> <a class="code" href="dns_8c.html#a10">dns_init</a>(<span class="keywordtype">void</span>){00109 00110         <a class="code" href="dns_8c.html#a3">dns_state</a> = DNS_STATE_READY;00111 00112         <a class="code" href="dns_8c.html#a4">dns_socket</a>=<a class="code" href="udp_8c.html#a3">udp_getsocket</a>(0 , <a class="code" href="dns_8c.html#a13">dns_eventlistener</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>);00113 00114         <span class="keywordflow">if</span>(<a class="code" href="dns_8c.html#a4">dns_socket</a> == -1){00115                 DEBUGOUT(<span class="stringliteral">"DNS: No free UDP sockets!! \r\n"</span>);00116                 <span class="keywordflow">return</span>;00117         }00118 00119         <span class="comment">/* open socket */</span>00120         <a class="code" href="udp_8c.html#a5">udp_open</a>(<a class="code" href="dns_8c.html#a4">dns_socket</a>,<a class="code" href="dns_8h.html#a0">DNS_UDP_PORT</a>);00121 00122         <span class="comment">/* now the timer. This will be used for retransmitting the requests */</span>00123         <a class="code" href="dns_8c.html#a5">dns_timer</a>=<a class="code" href="timers_8c.html#a2">get_timer</a>();00124 00125         <span class="comment">/* TODO: if GetTimer is modified so that it doesn't reset system if</span>00126 <span class="comment">                no timers available, check return value! */</span>00127 00128         DEBUGOUT(<span class="stringliteral">"Initialized DNS client\r\n"</span>);00129 00130 }00131 <a name="l00142"></a><a class="code" href="dns_8c.html#a11">00142</a> <span class="keywordtype">void</span> <a class="code" href="dns_8c.html#a11">dns_retransmit</a>(<span class="keywordtype">void</span>){00143         <span class="keywordflow">if</span>(<a class="code" href="dns_8c.html#a6">dns_retries</a>!=0){00144                 <a class="code" href="dns_8c.html#a3">dns_state</a>=DNS_STATE_RESEND;00145                 <a class="code" href="dns_8c.html#a6">dns_retries</a>--;00146                 <a class="code" href="dns_8c.html#a14">get_host_by_name</a>(<a class="code" href="dns_8c.html#a8">dns_hostptr</a>,dns_event_listener);00147                 <a class="code" href="timers_8c.html#a6">init_timer</a>(<a class="code" href="dns_8c.html#a5">dns_timer</a>,<a class="code" href="dns_8h.html#a2">DNS_RESEND_PERIOD</a>*<a class="code" href="timers_8h.html#a1">TIMERTIC</a>);00148         }<span class="keywordflow">else</span>{00149 00150                 <span class="comment">/* timeout happened */</span>00151                 <a class="code" href="dns_8c.html#a3">dns_state</a>=DNS_STATE_READY;00152 00153                 dns_event_listener(<a class="code" href="dns_8h.html#a4">DNS_EVENT_ERROR</a>,<a class="code" href="dns_8h.html#a11">DNS_ERROR_TIMEOUT</a>);00154 00155         }00156 00157 }00158 <a name="l00168"></a><a class="code" href="dns_8c.html#a12">00168</a> <span class="keywordtype">void</span> <a class="code" href="dns_8c.html#a12">dns_run</a>(<span class="keywordtype">void</span>){00169         <span class="keywordflow">if</span>((<a class="code" href="dns_8c.html#a3">dns_state</a>==DNS_STATE_BUSY)||(<a class="code" href="dns_8c.html#a3">dns_state</a>==DNS_STATE_RESEND)){00170                 <span class="comment">/* checking retransmission timer */</span>00171                 <span class="keywordflow">if</span>(!<a class="code" href="timers_8c.html#a7">check_timer</a>(<a class="code" href="dns_8c.html#a5">dns_timer</a>)){00172 00173                         DEBUGOUT(<span class="stringliteral">"DNS: retransmitting the request \r\n"</span>);00174                         <span class="comment">/* timeout, send another one */</span>00175                         <a class="code" href="dns_8c.html#a11">dns_retransmit</a>();00176 00177                 }00178         }00179 }00180 <a name="l00205"></a><a class="code" href="dns_8c.html#a13">00205</a> INT32 <a class="code" href="dns_8c.html#a13">dns_eventlistener</a>(INT8 cbhandle, UINT8 event, UINT32 ipaddr, UINT16 port, UINT16 buffindex, UINT16 datalen){00206         UINT8 tmp_byte;00207         UINT16 tmp_int;00208         UINT8 *tmp_ptr;00209         UINT8 count;00210         <span class="comment">/* it will fit in 8bits most of the time but... */</span>00211         UINT16 dns_ancount;00212         UINT16 dns_nscount;00213 00214         <span class="keywordflow">if</span>(cbhandle!=<a class="code" href="dns_8c.html#a4">dns_socket</a>){00215                 DEBUGOUT(<span class="stringliteral">"DNS: not my handle!!!!"</span>);00216                 <span class="keywordflow">return</span> (-1);00217         }00218 00219         <span class="keywordflow">if</span>(ipaddr!=<a class="code" href="dns_8c.html#a7">dns_tmp_ip</a>){00220                 DEBUGOUT(<span class="stringliteral">"DNS: received DNS but IP addr not OK!\r\n"</span>);00221         }00222 

⌨️ 快捷键说明

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