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

📄 dns_8c-source.html

📁 Freescale mcu OpenTCP-1.0.4.doc.html.zip 文档
💻 HTML
📖 第 1 页 / 共 3 页
字号:
00223         <span class="keywordflow">switch</span>(event){00224                 <span class="keywordflow">case</span> <a class="code" href="tcp__ip_8h.html#a31">UDP_EVENT_DATA</a>:00225                         <span class="comment">/* only process data while not in ready state */</span>00226                         <span class="keywordflow">if</span>(<a class="code" href="dns_8c.html#a3">dns_state</a>==DNS_STATE_READY){00227                                 DEBUGOUT(<span class="stringliteral">"DNS: Received answer in wrong state\r\n"</span>);00228                                 <span class="keywordflow">return</span> (-1);00229                         }00230 00231                         <span class="comment">/* inital size checking. Every DNS reply will be bigger</span>00232 <span class="comment">                                than 16 bytes */</span>00233                         <span class="keywordflow">if</span>(datalen&lt;16){00234                                 DEBUGOUT(<span class="stringliteral">"DNS: UDP packet way to short for DNS!\r\n"</span>);00235                                 <span class="keywordflow">return</span> (-1);00236                         }00237 00238                         <span class="comment">/* some data received, check if it's what we're waiting for */</span>00239                         tmp_int=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00240                         tmp_int=(tmp_int&lt;&lt;8)+<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00241                         <span class="keywordflow">if</span>(tmp_int!=0xaaaa){00242                                 DEBUGOUT(<span class="stringliteral">"DNS: ERROR: ID wrong!\r\n"</span>);00243                                 <span class="keywordflow">return</span> (-1);00244                         }00245 00246                         tmp_byte=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00247 00248                         <span class="keywordflow">if</span>(!(tmp_byte&amp;0x80)){00249                                 DEBUGOUT(<span class="stringliteral">"DNS: THIS IS NOT AN ANSWER! WE'RE NOT A DNS SERVER!\r\n"</span>);00250                                 <span class="keywordflow">return</span> (-1);00251                         }00252 00253                         <span class="comment">/* opcode or truncated ? */</span>00254                         <span class="keywordflow">if</span>(tmp_byte&amp;0x7a){00255                                 DEBUGOUT(<span class="stringliteral">"DNS: Opcode not zero or message truncated. \r\n"</span>);00256                                 dns_event_listener(<a class="code" href="dns_8h.html#a4">DNS_EVENT_ERROR</a>,<a class="code" href="dns_8h.html#a12">DNS_ERROR_GENERAL</a>);00257                                 <span class="keywordflow">return</span> (-1);00258                         }00259 00260                         tmp_byte=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00261 00262                         <span class="comment">/* check RCODE */</span>00263                         <span class="keywordflow">if</span>((tmp_byte&amp;0x7f)&amp;&amp;(tmp_byte&amp;0x80)){00264                                 <span class="comment">/* RCODE not zero, and recursion is available   */</span>00265                                 <span class="comment">/* There was an error. Inform listener                  */</span>00266                                 DEBUGOUT(<span class="stringliteral">"DNS: RCODE not zero and recursion available! \r\n"</span>);00267                                 dns_event_listener(<a class="code" href="dns_8h.html#a4">DNS_EVENT_ERROR</a>,tmp_byte&amp;0x7f);00268                                 <span class="keywordflow">return</span> (-1);00269                         }00270 00271                         <span class="comment">/* question count == 1 ? */</span>00272                         tmp_int=(((UINT16)<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())&lt;&lt;8);00273                         tmp_int+=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00274                         <span class="keywordflow">if</span>(tmp_int != 1){00275                                 DEBUGOUT(<span class="stringliteral">"DNS: we only sent one question and received a couple of answers!!\r\n"</span>);00276                                 dns_event_listener(<a class="code" href="dns_8h.html#a4">DNS_EVENT_ERROR</a>,<a class="code" href="dns_8h.html#a12">DNS_ERROR_GENERAL</a>);00277                                 <span class="keywordflow">return</span> (-1);00278                         }00279 00280                         dns_ancount=(((UINT16)<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())&lt;&lt;8);00281                         dns_ancount+=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00282 00283                         dns_nscount=(((UINT16)<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())&lt;&lt;8);00284                         dns_nscount+=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00285 00286                         <span class="comment">/* skip ARCOUNT */</span>00287                         <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00288                         <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00289 00290                         <span class="comment">/* got to the data, let's process it */</span>00291                         <span class="comment">/* check if question section is appropriate (QNAME the same</span>00292 <span class="comment">                                and QTYPE=QCLASS=1</span>00293 <span class="comment">                        */</span>00294                         tmp_ptr=<a class="code" href="dns_8c.html#a8">dns_hostptr</a>;00295                         <span class="keywordflow">while</span>((tmp_byte=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())!=0){00296                                 <span class="keywordflow">while</span>((tmp_byte--)!=0){00297                                         <span class="keywordflow">if</span>(*tmp_ptr++!=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>()){00298                                                 DEBUGOUT(<span class="stringliteral">"DNS: QNAME not the same!!!! \r\n"</span>);00299                                                 <span class="comment">/* we'll assume that this was from some previous</span>00300 <span class="comment">                                                        query and just exit here */</span>00301                                                 <span class="keywordflow">return</span> (-1);00302                                         }00303                                 }00304                                 <span class="comment">/* reached the end of the label. Is it dot or end of string? */</span>00305 00306                                 <span class="keywordflow">if</span>(*tmp_ptr==<span class="charliteral">'\0'</span>){00307                                         <span class="keywordflow">continue</span>;00308                                 }00309 00310                                 <span class="keywordflow">if</span>(*tmp_ptr++!=<span class="charliteral">'.'</span>){00311                                         DEBUGOUT(<span class="stringliteral">"DNS: DOT not where it's supposed to be!\r\n"</span>);00312                                         <span class="keywordflow">return</span> (-1);00313                                 }00314                         }00315 00316 00317                         <span class="comment">/* qtype and qclass */</span>00318                         tmp_int=(((UINT16)<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())&lt;&lt;8);00319                         tmp_int+=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00320 00321                         tmp_int|=((UINT16)(<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())&lt;&lt;8);00322                         tmp_int|=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00323 00324                         <span class="keywordflow">if</span>(tmp_int!=0x0001){00325                                 DEBUGOUT(<span class="stringliteral">"DNS: Question section QTYPE and/or QCLASS not ok!\r\n"</span>);00326                                 dns_event_listener(<a class="code" href="dns_8h.html#a4">DNS_EVENT_ERROR</a>,<a class="code" href="dns_8h.html#a12">DNS_ERROR_GENERAL</a>);00327                                 <span class="keywordflow">return</span> (-1);00328                         }00329 00330                         <span class="comment">/* process all answer RRs and try to find answer */</span>00331 00332                         <span class="comment">/* simply try to find INET class RR. It is</span>00333 <span class="comment">                                _PROBABLY_ what we're after. More extensive checking</span>00334 <span class="comment">                                would demand buffering the reply which may not be</span>00335 <span class="comment">                                desireable.</span>00336 <span class="comment">                         */</span>00337                         <span class="keywordflow">while</span>(dns_ancount||dns_nscount){00338                                 <span class="keywordflow">do</span>{00339                                         tmp_byte=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00340                                 }<span class="keywordflow">while</span>((tmp_byte!=0)&amp;&amp;((tmp_byte&amp;0xc0)!=0xc0));00341 00342                                 <span class="keywordflow">if</span>(tmp_byte!=0) <span class="comment">/*second offset byte used in compression*/</span>00343                                         <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00344 00345                                 <span class="comment">/* TYPE */</span>00346                                 tmp_int=((UINT16)<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())&lt;&lt;8;00347                                 tmp_int|=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00348 00349                                 <span class="comment">/* CLASS */</span>00350                                 tmp_int|=(((UINT16)<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())&lt;&lt;8);00351                                 tmp_int|=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00352 00353                                 <span class="comment">/* CLASS==INET and TYPE=A ? */</span>00354                                 <span class="keywordflow">if</span>(tmp_int==0x0001){00355 00356                                         <span class="comment">/* got it. Skip TTL and read RDLENGTH */</span>00357                                         <span class="keywordflow">for</span>(tmp_byte=0;tmp_byte&lt;6;tmp_byte++){00358                                                 tmp_int=(tmp_int&lt;&lt;8)+<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00359                                         }00360 00361                                         <span class="keywordflow">if</span>(tmp_int==0x0004){00362                                                 <span class="comment">/* great, read IP address*/</span>00363                                                 <a class="code" href="dns_8c.html#a7">dns_tmp_ip</a>=((UINT32)<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())&lt;&lt;24;00364                                                 <a class="code" href="dns_8c.html#a7">dns_tmp_ip</a>+=((UINT32)<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())&lt;&lt;16;00365                                                 <a class="code" href="dns_8c.html#a7">dns_tmp_ip</a>+=((UINT32)<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>())&lt;&lt;8;00366                                                 <a class="code" href="dns_8c.html#a7">dns_tmp_ip</a>+=<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00367 00368                                                 <span class="comment">/* we got some IP address. Is it what we asked for</span>00369 <span class="comment">                                                        or a NS IP addr*/</span>00370                                                 <span class="keywordflow">if</span>(dns_ancount){00371                                                         DEBUGOUT(<span class="stringliteral">"DNS: Got IP address!\r\n"</span>);00372                                                         dns_event_listener(<a class="code" href="dns_8h.html#a5">DNS_EVENT_SUCCESS</a>,<a class="code" href="dns_8c.html#a7">dns_tmp_ip</a>);00373                                                         <a class="code" href="dns_8c.html#a3">dns_state</a>=DNS_STATE_READY;00374                                                 }<span class="keywordflow">else</span>{00375                                                         DEBUGOUT(<span class="stringliteral">"DNS: Got auth DNS IP addr!\r\n"</span>);00376                                                         <span class="comment">/* invoke another query to the authority */</span>00377                                                         <a class="code" href="dns_8c.html#a11">dns_retransmit</a>();

⌨️ 快捷键说明

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