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

📄 ip_8c-source.html

📁 Freescale mcu OpenTCP-1.0.4.doc.html.zip 文档
💻 HTML
📖 第 1 页 / 共 3 页
字号:
00207         olen = ((received_ip_packet.<a class="code" href="structip__frame.html#m0">vihl</a> &amp; 0x0F) &lt;&lt; 2) - IP_MIN_HLEN;00208         00209         <span class="comment">/* Somebody bluffing with too long option field?        */</span>00210         00211         <span class="keywordflow">if</span>(olen &gt; MAX_IP_OPTLEN) {00212                 IP_DEBUGOUT(<span class="stringliteral">"ERROR:Size of maximum allowed IP option lengt exceeded!\n\r"</span>);00213                 <span class="keywordflow">return</span>(-1);00214         }00215         00216         <span class="keywordflow">if</span>( olen &gt; (frame-&gt;<a class="code" href="structethernet__frame.html#m2">frame_size</a> - ETH_HEADER_LEN - IP_HLEN) )     {00217                 IP_DEBUGOUT(<span class="stringliteral">"ERROR:IP option field too long!\n\r"</span>);00218                 <span class="keywordflow">return</span>(-1);00219         }00220                 00221         <span class="keywordflow">for</span>( i=0; i &lt; olen; i++ ) {00222                 received_ip_packet.<a class="code" href="structip__frame.html#m10">opt</a>[i] = <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();        00223                 IP_DEBUGOUT(<span class="stringliteral">"IP Options..\n\r"</span>);00224         }00225         00226         <span class="keywordflow">if</span>(received_ip_packet.<a class="code" href="structip__frame.html#m2">tlen</a> &gt;  (frame-&gt;<a class="code" href="structethernet__frame.html#m2">frame_size</a> - ETH_HEADER_LEN) ) {00227                 IP_DEBUGOUT(<span class="stringliteral">"ERROR: Total len too long\r\n"</span>);00228                 <span class="keywordflow">return</span>(-1);00229         }00230         00231         <span class="comment">/* Is the checksum OK?  */</span>00232         00233         IP_DEBUGOUT(<span class="stringliteral">"Validating the IP checksum..\n\r"</span>);00234         00235         <span class="keywordflow">if</span> ( <a class="code" href="ip_8c.html#a6">ip_check_cs</a>(&amp;received_ip_packet) != <a class="code" href="system_8h.html#a1">TRUE</a> ) {00236                 IP_DEBUGOUT(<span class="stringliteral">"IP Checksum Corrupted..\n\r"</span>);00237                 <span class="keywordflow">return</span>(-1);00238         }       00239         00240         IP_DEBUGOUT(<span class="stringliteral">"..Checksum OK!\n\r"</span>);      00241         00242         <span class="comment">/* Add the address to ARP cache */</span>00243         00244         <span class="keywordflow">if</span>( received_ip_packet.<a class="code" href="structip__frame.html#m8">sip</a> != IP_BROADCAST_ADDRESS)00245                 <a class="code" href="arp_8c.html#a7">arp_add</a>( received_ip_packet.<a class="code" href="structip__frame.html#m8">sip</a>, &amp;frame-&gt;<a class="code" href="structethernet__frame.html#m1">source</a>[0], <a class="code" href="arp_8h.html#a17">ARP_TEMP_IP</a>);00246         00247         <span class="comment">/* Calculate the start of next layer data       */</span>00248         00249         received_ip_packet.<a class="code" href="structip__frame.html#m11">buf_index</a> = frame-&gt;<a class="code" href="structethernet__frame.html#m4">buf_index</a> + IP_HLEN + olen;00250         00251         <span class="comment">/* Is this packet fragmented?                                           */</span>00252         <span class="comment">/* We don't deal with those                                                     */</span>00253         <span class="comment">/* TODO: Implement Stub handler for more mem. uP's      */</span>00254         00255         <span class="keywordflow">if</span>( received_ip_packet.<a class="code" href="structip__frame.html#m4">frags</a> &amp; (IP_MOREFRAGS | IP_FRAGOFF) ) {00256                 IP_DEBUGOUT(<span class="stringliteral">"Fragmented IP packet\r\n"</span>);00257                 <span class="keywordflow">return</span>(-1);00258         }00259         <span class="comment">/* checking moved upwards!</span>00260 <span class="comment">        if( received_ip_packet.frags &amp; IP_FRAGOFF )     {</span>00261 <span class="comment">                IP_DEBUGOUT("Fragmented IP packet\r\n");</span>00262 <span class="comment">                return(-1);</span>00263 <span class="comment">        }</span>00264 <span class="comment">        */</span>00265         00266         IP_DEBUGOUT(<span class="stringliteral">"Leaving IP succesfully..\n\r"</span>);00267         00268         <span class="keywordflow">return</span>(received_ip_packet.<a class="code" href="structip__frame.html#m2">tlen</a> - IP_HLEN - olen);00269         00270 }00271 <a name="l00300"></a><a class="code" href="ip_8c.html#a4">00300</a> INT16 <a class="code" href="ip_8c.html#a4">process_ip_out</a> (UINT32 ipadr, UINT8 pcol, UINT8 tos, UINT8 ttl, UINT8* dat, UINT16 len)00301 {00302         <span class="keyword">struct </span><a class="code" href="structarp__entry.html">arp_entry</a> *qstruct;00303         UINT16 i;00304         00305         <span class="comment">/* Try to get MAC address from ARP cache        */</span>00306         00307         qstruct = <a class="code" href="arp_8c.html#a8">arp_find</a>(ipadr, &amp;localmachine, <a class="code" href="arp_8h.html#a17">ARP_TEMP_IP</a>);00308         00309         <span class="keywordflow">if</span>( qstruct == 0 )              <span class="comment">/* Not ready yet        */</span>00310                 <span class="keywordflow">return</span>(-2);00311                 00312         <span class="comment">/* Select network buffer                                                */</span>00313         <span class="comment">/* TODO: This network related stuff should              */</span>00314         <span class="comment">/* be moved and abstracted to Ethernet layer    */</span>00315         00316         <span class="keywordflow">switch</span>(pcol) {00317                 <span class="keywordflow">case</span> <a class="code" href="ip_8h.html#a1">IP_ICMP</a>:00318                 00319                         <a class="code" href="system_8h.html#a17">NETWORK_SEND_INITIALIZE</a>(<a class="code" href="ethernet_8h.html#a36">ICMP_BUF</a>);00320                         IP_DEBUGOUT(<span class="stringliteral">"Assembling IP packet to ICMP buffer\n\r"</span>);00321                         00322                         <span class="keywordflow">break</span>;00323                         00324                 <span class="keywordflow">case</span> <a class="code" href="ip_8h.html#a2">IP_UDP</a>:00325                 00326                         <a class="code" href="system_8h.html#a17">NETWORK_SEND_INITIALIZE</a>(<a class="code" href="ethernet_8h.html#a38">UDP_BUF</a>);00327                         IP_DEBUGOUT(<span class="stringliteral">"Assembling IP packet to UDP buffer\n\r"</span>);00328                         00329                         <span class="keywordflow">break</span>;00330                         00331                 <span class="keywordflow">case</span> <a class="code" href="ip_8h.html#a3">IP_TCP</a>:00332                 00333                         <a class="code" href="system_8h.html#a17">NETWORK_SEND_INITIALIZE</a>(<a class="code" href="ethernet_8h.html#a37">TCP_BUF</a>);00334                         IP_DEBUGOUT(<span class="stringliteral">"Assembling IP packet to TCP buffer\n\r"</span>);00335                         00336                         <span class="keywordflow">break</span>;00337         00338                 <span class="keywordflow">default</span>:                        <span class="comment">/* Unknown protocol     */</span>00339                         <span class="keywordflow">return</span>(-1);00340         }00341         00342         <span class="comment">/* Fill the Ethernet information        */</span>00343         00344         <span class="keywordflow">for</span>( i=0; i&lt;<a class="code" href="arp_8h.html#a0">MAXHWALEN</a>; i++)     {00345                 send_frame.destination[i] = qstruct-&gt;<a class="code" href="structarp__entry.html#m4">hwadr</a>[i];00346                 send_frame.source[i] = localmachine.localHW[i];00347         }00348         00349         send_frame.protocol = <a class="code" href="ethernet_8h.html#a4">PROTOCOL_IP</a>;00350         00351         <a class="code" href="system_8h.html#a18">NETWORK_ADD_DATALINK</a>(&amp;send_frame);00352         00353         <span class="comment">/* Construct the IP header      */</span>00354         00355         send_ip_packet.<a class="code" href="structip__frame.html#m0">vihl</a> = IP_DEF_VIHL;00356         send_ip_packet.<a class="code" href="structip__frame.html#m1">tos</a> = tos;00357         send_ip_packet.<a class="code" href="structip__frame.html#m2">tlen</a> = IP_HLEN + len;00358         send_ip_packet.<a class="code" href="structip__frame.html#m3">id</a> = <a class="code" href="ip_8c.html#a2">ip_id</a>++;00359         send_ip_packet.<a class="code" href="structip__frame.html#m4">frags</a> = 0;00360         send_ip_packet.<a class="code" href="structip__frame.html#m5">ttl</a> = ttl;00361         send_ip_packet.<a class="code" href="structip__frame.html#m6">protocol</a> = pcol;00362         send_ip_packet.<a class="code" href="structip__frame.html#m7">checksum</a> = 0;00363         send_ip_packet.<a class="code" href="structip__frame.html#m8">sip</a> = localmachine.localip;00364         send_ip_packet.<a class="code" href="structip__frame.html#m9">dip</a> = ipadr;00365         00366         <span class="comment">/* Calculate checksum for the IP header */</span>00367         00368         send_ip_packet.<a class="code" href="structip__frame.html#m7">checksum</a> = <a class="code" href="ip_8c.html#a5">ip_construct_cs</a>( &amp;send_ip_packet );00369         00370         <span class="comment">/* Assemble bytes to network    */</span>00371         00372         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>(send_ip_packet.<a class="code" href="structip__frame.html#m0">vihl</a>);00373         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>(send_ip_packet.<a class="code" href="structip__frame.html#m1">tos</a>);00374         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (UINT8)(send_ip_packet.<a class="code" href="structip__frame.html#m2">tlen</a> &gt;&gt; 8) );00375         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (UINT8)send_ip_packet.<a class="code" href="structip__frame.html#m2">tlen</a> );           00376         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (UINT8)(send_ip_packet.<a class="code" href="structip__frame.html#m3">id</a> &gt;&gt; 8) );00377         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (UINT8)send_ip_packet.<a class="code" href="structip__frame.html#m3">id</a> );00378         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (UINT8)(send_ip_packet.<a class="code" href="structip__frame.html#m4">frags</a> &gt;&gt; 8) );00379         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (UINT8)send_ip_packet.<a class="code" href="structip__frame.html#m4">frags</a> );00380         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>(send_ip_packet.<a class="code" href="structip__frame.html#m5">ttl</a>);00381         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>(send_ip_packet.<a class="code" href="structip__frame.html#m6">protocol</a>);        00382         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (UINT8)(send_ip_packet.<a class="code" href="structip__frame.html#m7">checksum</a> &gt;&gt; 8) );00383         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (UINT8)send_ip_packet.<a class="code" href="structip__frame.html#m7">checksum</a> );00384         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (UINT8)(send_ip_packet.<a class="code" href="structip__frame.html#m8">sip</a> &gt;&gt; 24) );00385         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (UINT8)(send_ip_packet.<a class="code" href="structip__frame.html#m8">sip</a> &gt;&gt; 16) );00386         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (UINT8)(send_ip_packet.<a class="code" href="structip__frame.html#m8">sip</a> &gt;&gt; 8) );00387         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (UINT8)send_ip_packet.<a class="code" href="structip__frame.html#m8">sip</a> );00388         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (UINT8)(send_ip_packet.<a class="code" href="structip__frame.html#m9">dip</a> &gt;&gt; 24) );00389         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (UINT8)(send_ip_packet.<a class="code" href="structip__frame.html#m9">dip</a> &gt;&gt; 16) );00390         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (UINT8)(send_ip_packet.<a class="code" href="structip__frame.html#m9">dip</a> &gt;&gt; 8) );00391         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (UINT8)send_ip_packet.<a class="code" href="structip__frame.html#m9">dip</a> );00392         00393         <span class="comment">/* Assemble data        */</span>00394         00395         <a class="code" href="system_8h.html#a12">SEND_NETWORK_BUF</a>(dat,len);00396                 00397         <span class="comment">/* Launch it            */</span>00398         00399         <a class="code" href="system_8h.html#a16">NETWORK_COMPLETE_SEND</a>( send_ip_packet.<a class="code" href="structip__frame.html#m2">tlen</a> );00400         

⌨️ 快捷键说明

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