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

📄 ip_8c-source.html

📁 Freescale mcu OpenTCP-1.0.4.doc.html.zip 文档
💻 HTML
📖 第 1 页 / 共 3 页
字号:
00401         <span class="keywordflow">return</span>(len);00402         00403         00404 }00405 <a name="l00417"></a><a class="code" href="ip_8c.html#a5">00417</a> UINT32 <a class="code" href="ip_8c.html#a5">ip_construct_cs</a> (<span class="keyword">struct</span> <a class="code" href="structip__frame.html">ip_frame</a>* frame)00418 {00419         UINT16 ip_cs;00420         UINT8 cs_cnt;00421         UINT8 olen;00422         UINT8 i;00423         00424         ip_cs = 0;00425         cs_cnt = 0;00426         00427         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, frame-&gt;<a class="code" href="structip__frame.html#m0">vihl</a>, cs_cnt++);00428         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, frame-&gt;<a class="code" href="structip__frame.html#m1">tos</a>, cs_cnt++);00429         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)(frame-&gt;<a class="code" href="structip__frame.html#m2">tlen</a> &gt;&gt; 8), cs_cnt++);00430         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)frame-&gt;<a class="code" href="structip__frame.html#m2">tlen</a>, cs_cnt++);00431         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)(frame-&gt;<a class="code" href="structip__frame.html#m3">id</a> &gt;&gt; 8), cs_cnt++);00432         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)frame-&gt;<a class="code" href="structip__frame.html#m3">id</a>, cs_cnt++);00433         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)(frame-&gt;<a class="code" href="structip__frame.html#m4">frags</a> &gt;&gt; 8), cs_cnt++);00434         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)frame-&gt;<a class="code" href="structip__frame.html#m4">frags</a>, cs_cnt++);00435         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, frame-&gt;<a class="code" href="structip__frame.html#m5">ttl</a>, cs_cnt++);00436         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, frame-&gt;<a class="code" href="structip__frame.html#m6">protocol</a>, cs_cnt++);00437         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)(frame-&gt;<a class="code" href="structip__frame.html#m8">sip</a> &gt;&gt; 24), cs_cnt++);00438         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)(frame-&gt;<a class="code" href="structip__frame.html#m8">sip</a> &gt;&gt; 16), cs_cnt++);00439         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)(frame-&gt;<a class="code" href="structip__frame.html#m8">sip</a> &gt;&gt; 8), cs_cnt++);00440         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)frame-&gt;<a class="code" href="structip__frame.html#m8">sip</a>, cs_cnt++);00441         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)(frame-&gt;<a class="code" href="structip__frame.html#m9">dip</a> &gt;&gt; 24), cs_cnt++);00442         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)(frame-&gt;<a class="code" href="structip__frame.html#m9">dip</a> &gt;&gt; 16), cs_cnt++);00443         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)(frame-&gt;<a class="code" href="structip__frame.html#m9">dip</a> &gt;&gt; 8), cs_cnt++);00444         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)frame-&gt;<a class="code" href="structip__frame.html#m9">dip</a>, cs_cnt++);        00445         00446         <span class="comment">/* Is there options?                            */</span>00447                 00448         olen = ((frame-&gt;<a class="code" href="structip__frame.html#m0">vihl</a> &amp; 0x0F) &lt;&lt; 2) - IP_MIN_HLEN;00449         00450         <span class="keywordflow">for</span>( i=0; i&lt;olen; i++)00451                 ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)frame-&gt;<a class="code" href="structip__frame.html#m10">opt</a>[i], cs_cnt++);00452         00453         <span class="comment">/* Take complement      */</span>00454         00455         ip_cs = ~ ip_cs;00456 00457         <span class="keywordflow">return</span>(ip_cs);00458 00459 }00460 <a name="l00474"></a><a class="code" href="ip_8c.html#a6">00474</a> UINT8 <a class="code" href="ip_8c.html#a6">ip_check_cs</a> (<span class="keyword">struct</span> <a class="code" href="structip__frame.html">ip_frame</a>* frame)00475 {00476         UINT16 ip_cs;00477         UINT8 cs_cnt;00478         UINT8 olen;00479         UINT8 i;00480         00481         ip_cs = 0;00482         cs_cnt = 0;00483         00484         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, frame-&gt;<a class="code" href="structip__frame.html#m0">vihl</a>, cs_cnt++);00485         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, frame-&gt;<a class="code" href="structip__frame.html#m1">tos</a>, cs_cnt++);00486         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)(frame-&gt;<a class="code" href="structip__frame.html#m2">tlen</a> &gt;&gt; 8), cs_cnt++);00487         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)frame-&gt;<a class="code" href="structip__frame.html#m2">tlen</a>, cs_cnt++);00488         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)(frame-&gt;<a class="code" href="structip__frame.html#m3">id</a> &gt;&gt; 8), cs_cnt++);00489         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)frame-&gt;<a class="code" href="structip__frame.html#m3">id</a>, cs_cnt++);00490         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)(frame-&gt;<a class="code" href="structip__frame.html#m4">frags</a> &gt;&gt; 8), cs_cnt++);00491         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)frame-&gt;<a class="code" href="structip__frame.html#m4">frags</a>, cs_cnt++);00492         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, frame-&gt;<a class="code" href="structip__frame.html#m5">ttl</a>, cs_cnt++);00493         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, frame-&gt;<a class="code" href="structip__frame.html#m6">protocol</a>, cs_cnt++);00494         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)(frame-&gt;<a class="code" href="structip__frame.html#m7">checksum</a> &gt;&gt; 8), cs_cnt++);00495         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)frame-&gt;<a class="code" href="structip__frame.html#m7">checksum</a>, cs_cnt++);00496         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)(frame-&gt;<a class="code" href="structip__frame.html#m8">sip</a> &gt;&gt; 24), cs_cnt++);00497         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)(frame-&gt;<a class="code" href="structip__frame.html#m8">sip</a> &gt;&gt; 16), cs_cnt++);00498         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)(frame-&gt;<a class="code" href="structip__frame.html#m8">sip</a> &gt;&gt; 8), cs_cnt++);00499         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)frame-&gt;<a class="code" href="structip__frame.html#m8">sip</a>, cs_cnt++);00500         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)(frame-&gt;<a class="code" href="structip__frame.html#m9">dip</a> &gt;&gt; 24), cs_cnt++);00501         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)(frame-&gt;<a class="code" href="structip__frame.html#m9">dip</a> &gt;&gt; 16), cs_cnt++);00502         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)(frame-&gt;<a class="code" href="structip__frame.html#m9">dip</a> &gt;&gt; 8), cs_cnt++);00503         ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)frame-&gt;<a class="code" href="structip__frame.html#m9">dip</a>, cs_cnt++);        00504         00505         <span class="comment">/* Is there options?                            */</span>00506                 00507         olen = ((frame-&gt;<a class="code" href="structip__frame.html#m0">vihl</a> &amp; 0x0F) &lt;&lt; 2) - IP_MIN_HLEN;00508         00509         <span class="keywordflow">for</span>( i=0; i&lt;olen; i++)00510                 ip_cs = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(ip_cs, (UINT8)frame-&gt;<a class="code" href="structip__frame.html#m10">opt</a>[i], cs_cnt++);00511         00512         <span class="comment">/* Analyze the result   */</span>00513         00514         ip_cs = ~ ip_cs;00515         00516         <span class="keywordflow">if</span>(ip_cs == IP_GOOD_CS)00517                 <span class="keywordflow">return</span> 1;00518         00519         <span class="comment">/* Fuck, it failed!     */</span>00520         00521         <span class="keywordflow">return</span> 0;00522         00523 00524 }00525 <a name="l00539"></a><a class="code" href="ip_8c.html#a7">00539</a> UINT16 <a class="code" href="ip_8c.html#a7">ip_checksum</a> (UINT16 cs, UINT8 dat, UINT8 count)00540 {00541         UINT8 b = dat;00542         UINT8 cs_l;00543         UINT8 cs_h;00544         00545         cs_h = (UINT8)(cs &gt;&gt; 8); 00546         cs_l = (UINT8)cs;00547 00548         <span class="keywordflow">if</span>( count &amp; 0x01 ) {00549                 <span class="comment">/* We are processing LSB        */</span>00550                 00551                 <span class="keywordflow">if</span>( (cs_l = cs_l + b) &lt; b ) {00552                         <span class="keywordflow">if</span>( ++cs_h == 0 )00553                                 cs_l++;00554                 }00555                 00556         } <span class="keywordflow">else</span> {00557                 <span class="comment">/* We are processing MSB        */</span>00558                 00559                 <span class="keywordflow">if</span>( (cs_h = cs_h + b) &lt; b )     {00560                         <span class="keywordflow">if</span>( ++cs_l == 0 )00561                                 cs_h++;00562                 }00563         }00564 00565         <span class="keywordflow">return</span>( ( (UINT16)cs_h &lt;&lt; 8 ) + cs_l);00566 00567 }00568 00569 <a name="l00582"></a><a class="code" href="ip_8c.html#a8">00582</a> UINT32 <a class="code" href="ip_8c.html#a8">ip_checksum_buf</a> (UINT16 cs, UINT8* buf, UINT16 len)00583 {00584         UINT16 dat;00585         UINT32 temp;00586         00587         temp = cs;00588         00589         <span class="keywordflow">while</span>(len&gt;1)00590         {00591                 len -= 2;00592                 dat = *buf++;00593                 dat &lt;&lt;= 8;00594                 dat |= *buf++;00595                 temp += dat;00596         }00597         00598         temp = (temp &gt;&gt; 16) + (temp &amp; 0xFFFF);  <span class="comment">/* Add in carry         */</span>00599         temp += (temp &gt;&gt;16);                                    <span class="comment">/* Maybe one more       */</span>00600         00601         <span class="keywordflow">if</span>(len)00602                 temp = <a class="code" href="ip_8c.html#a7">ip_checksum</a>(temp, *buf, 0);00603         00604         <span class="keywordflow">return</span>( (UINT16) temp );00605 00606 }00607 </pre></div><hr><address style="align: right;"><small>Generated on Sun Aug 3 20:33:00 2003 for OpenTCP by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.18 </small></address></body></html>

⌨️ 快捷键说明

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