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

📄 watt-32 tcp-ip src-ppp_c source file.htm

📁 关于PPP点对点协议的一些详细资料
💻 HTM
📖 第 1 页 / 共 5 页
字号:
00799 
00800 <SPAN class=comment>/*</SPAN>
00801 <SPAN class=comment> * Check for time-outs</SPAN>
00802 <SPAN class=comment> */</SPAN>
00803 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>void</SPAN> check_timeouts (<SPAN class=keywordtype>void</SPAN>)
00804 {
00805   time_t now;
00806   <SPAN class=keywordtype>int</SPAN>    i;
00807 
00808   <SPAN class=keywordflow>if</SPAN> (mystate.timeout_period &lt; MAX_TIMEOUT)
00809       mystate.timeout_period &lt;&lt;= 1;
00810   now = time (NULL);
00811 
00812   <SPAN class=keywordflow>for</SPAN> (i = 0; i &lt; DIM(mystate.xcps); i++)
00813   {
00814     <SPAN class=keywordflow>if</SPAN> (mystate.xcps[i].timeout &amp;&amp; now &gt;= mystate.xcps[i].timeout)
00815     {
00816       mystate.xcps[i].timeout = 0;
00817 
00818       <SPAN class=comment>/* Hack -- send with same ID on timeout.</SPAN>
00819 <SPAN class=comment>       */</SPAN>
00820       <SPAN class=keywordflow>if</SPAN> (mystate.xcps[i].restart &gt; 0)
00821           mystate.xcps[i].ident--;
00822 
00823       PRINTF (4, (<SPAN class=stringliteral>"Sending TO%c to %s\n"</SPAN>,
00824                   mystate.xcps[i].restart &gt; 0 ? <SPAN class=charliteral>'+'</SPAN> : <SPAN class=charliteral>'-'</SPAN>,
00825                   mystate.xcps[i].name));
00826 
00827       send_event (&amp;mystate, mystate.xcps+i,
00828                   mystate.xcps[i].restart &gt; 0 ? evTOp : evTOm);
00829     }
00830   }
00831 }
00832 
00833 <SPAN class=comment>/*</SPAN>
00834 <SPAN class=comment> * PPP input handler.</SPAN>
00835 <SPAN class=comment> */</SPAN>
00836 <SPAN class=keywordtype>void</SPAN> ppp_input (<SPAN class=keyword>const</SPAN> BYTE *inbuffer, <SPAN class=keywordtype>int</SPAN> len)
00837 {
00838   <SPAN class=keyword>struct </SPAN>ppp_state *state = &amp;mystate;
00839   <SPAN class=keywordtype>int</SPAN>    i;
00840   <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a1">WORD</A>   proto;
00841 
00842   state-&gt;inbuffer = (<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a0">BYTE</A>*) inbuffer;
00843 
00844 <SPAN class=preprocessor>#if defined(USE_DEBUG)</SPAN>
00845 <SPAN class=preprocessor></SPAN>  <SPAN class=keywordflow>if</SPAN> (debug &gt; 3)
00846      buffer_print (<SPAN class=stringliteral>"Received"</SPAN>, state-&gt;inbuffer, len);
00847 <SPAN class=preprocessor>#endif</SPAN>
00848 <SPAN class=preprocessor></SPAN>
00849 <SPAN class=preprocessor>#if 0   </SPAN><SPAN class=comment>/* no p-compression used in PPPoE */</SPAN>
00850   <SPAN class=keywordflow>if</SPAN> (state-&gt;inbuffer[0] &amp; 0x1)
00851   {
00852     proto = state-&gt;inbuffer[0];
00853     state-&gt;inbuffer++;
00854     len--;
00855   }
00856   <SPAN class=keywordflow>else</SPAN> <SPAN class=keywordflow>if</SPAN> (state-&gt;inbuffer[1] &amp; 0x1)
00857   {
00858     proto = intel16 (*(WORD*)state-&gt;inbuffer);
00859     state-&gt;inbuffer += 2;
00860     len -=2;
00861   }
00862   <SPAN class=keywordflow>else</SPAN>
00863   {
00864     proto = intel16 (*(WORD*)state-&gt;inbuffer);
00865     PRINTF (0, (<SPAN class=stringliteral>"Bad protocol field %04X\n"</SPAN>, proto));
00866     <SPAN class=keywordflow>return</SPAN>;
00867   }
00868 <SPAN class=preprocessor>#else</SPAN>
00869 <SPAN class=preprocessor></SPAN>  proto = intel16 (*(WORD*)state-&gt;inbuffer);
00870   state-&gt;inbuffer += 2;
00871   len -=2;
00872 <SPAN class=preprocessor>#endif</SPAN>
00873 <SPAN class=preprocessor></SPAN>
00874   <SPAN class=keywordflow>if</SPAN> (proto == PPP_IP)
00875   {
00876     _ip4_handler ((<SPAN class=keyword>const</SPAN> <A class=code href="http://www.bgnett.no/~giva/watt-doc/a00732.html">in_Header</A>*)state-&gt;inbuffer, FALSE);
00877     <SPAN class=keywordflow>return</SPAN>;
00878   }
00879 
00880   <SPAN class=comment>/* Find XCP (IPCP/LCP) for indicated protocol</SPAN>
00881 <SPAN class=comment>   */</SPAN>
00882   <SPAN class=keywordflow>for</SPAN> (i = 0; i &lt; DIM(state-&gt;xcps); i++)
00883       <SPAN class=keywordflow>if</SPAN> (state-&gt;xcps[i].proto == proto)
00884          <SPAN class=keywordflow>break</SPAN>;
00885 
00886   <SPAN class=keywordflow>if</SPAN> (i &gt;= DIM(state-&gt;xcps))
00887   {
00888     <SPAN class=comment>/* Generate LCP Protocol-Reject for unknown things.</SPAN>
00889 <SPAN class=comment>     */</SPAN>
00890     PRINTF (0, (<SPAN class=stringliteral>"Unknown protocol 0x%04X\n"</SPAN>, proto));
00891 
00892     <SPAN class=keywordflow>if</SPAN> (state-&gt;xcps[XCP_LCP].state == stOpened)
00893     {
00894       <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a0">BYTE</A> *bp = code_id (state, &amp;state-&gt;xcps[XCP_LCP], CODE_PROTO_REJ);
00895 
00896       i = <SPAN class=keyword>sizeof</SPAN>(state-&gt;outbuffer) - (bp - state-&gt;outbuffer);
00897       <SPAN class=keywordflow>if</SPAN> (len &gt; i)
00898           len = i;
00899       memcpy (bp, state-&gt;inbuffer-2, len);
00900       len += bp - state-&gt;outbuffer;
00901       *(<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a1">WORD</A>*) (state-&gt;outbuffer+2) = intel16 (len-4);
00902       ppp_write (state, &amp;state-&gt;xcps[XCP_LCP], state-&gt;outbuffer, len);
00903     }
00904     <SPAN class=keywordflow>return</SPAN>;
00905   }
00906 
00907   state-&gt;bp   = state-&gt;inbuffer;
00908   state-&gt;mlen = len;
00909   (*state-&gt;xcps[i].deliver) (state, state-&gt;xcps + i);
00910 }
00911 
00912 <SPAN class=comment>/*</SPAN>
00913 <SPAN class=comment> * Add current option to list of options to be sent in Configure-Reject.</SPAN>
00914 <SPAN class=comment> */</SPAN>
00915 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>void</SPAN> set_reject (<SPAN class=keyword>struct</SPAN> ppp_state *state, <SPAN class=keyword>struct</SPAN> ppp_xcp *xcp,
00916                         <SPAN class=keyword>const</SPAN> BYTE *bp)
00917 {
00918   <SPAN class=keywordtype>int</SPAN> i;
00919 
00920   <SPAN class=keywordflow>if</SPAN> (state-&gt;parse_state == psBad)
00921      <SPAN class=keywordflow>return</SPAN>;
00922 
00923   <SPAN class=comment>/* If this is the first reject for this packet, then set up.</SPAN>
00924 <SPAN class=comment>   */</SPAN>
00925   <SPAN class=keywordflow>if</SPAN> (state-&gt;parse_state != psRej)
00926   {
00927     state-&gt;up = code_reply (state, xcp, CODE_CONF_REJ);
00928     state-&gt;parse_state = psRej;
00929   }
00930 
00931   <SPAN class=comment>/* Handle malformed options; make sure we don't send anything illegal</SPAN>
00932 <SPAN class=comment>   * to the peer (even if he's sending us junk).</SPAN>
00933 <SPAN class=comment>   */</SPAN>
00934   i = bp[1];
00935   <SPAN class=keywordflow>if</SPAN> (i &lt; 2)
00936       i = 2;
00937   memcpy (state-&gt;up, bp, i);
00938   state-&gt;up[1] = i;
00939   state-&gt;up += i;
00940 }
00941 
00942 <SPAN class=comment>/*</SPAN>
00943 <SPAN class=comment> * Add current option to list of options to be sent in Configure-Nak.</SPAN>
00944 <SPAN class=comment> */</SPAN>
00945 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>void</SPAN> set_nak (<SPAN class=keyword>struct</SPAN> ppp_state *state, <SPAN class=keyword>struct</SPAN> ppp_xcp *xcp, <SPAN class=keywordtype>int</SPAN> type,
00946                      <SPAN class=keywordtype>int</SPAN> len, <SPAN class=keyword>const</SPAN> BYTE *bp)
00947 {
00948   <SPAN class=comment>/* If we're rejecting, then no point in doing naks.</SPAN>
00949 <SPAN class=comment>   */</SPAN>
00950   <SPAN class=keywordflow>if</SPAN> (state-&gt;parse_state == psBad || state-&gt;parse_state == psRej)
00951      <SPAN class=keywordflow>return</SPAN>;
00952 
00953   <SPAN class=comment>/* If this is the first nak for this packet, then set up.</SPAN>
00954 <SPAN class=comment>   */</SPAN>
00955   <SPAN class=keywordflow>if</SPAN> (state-&gt;parse_state != psNak)
00956   {
00957     state-&gt;up = code_reply (state, xcp, CODE_CONF_NAK);
00958     state-&gt;parse_state = psNak;
00959   }
00960   *state-&gt;up++ = type;
00961   *state-&gt;up++ = len;
00962   <SPAN class=keywordflow>while</SPAN> (--len &gt; 1)
00963     *state-&gt;up++ = *bp++;
00964 }
00965 
00966 <SPAN class=comment>/*</SPAN>
00967 <SPAN class=comment> * Check Configure-Request options from peer against list of</SPAN>
00968 <SPAN class=comment> * known, valid, and desired options.</SPAN>
00969 <SPAN class=comment> */</SPAN>
00970 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>int</SPAN> validate_request (<SPAN class=keyword>struct</SPAN> ppp_state *state, <SPAN class=keyword>struct</SPAN> ppp_xcp *xcp)
00971 {
00972   <SPAN class=keyword>const</SPAN> <SPAN class=keyword>struct </SPAN>xcp_type *tp;
00973   <SPAN class=keyword>const</SPAN> <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a0">BYTE</A>  *bp;
00974   <SPAN class=keywordtype>int</SPAN>   rlen, i;
00975 
00976   state-&gt;parse_state = psOK;
00977   rlen = state-&gt;mlen;
00978   bp = state-&gt;bp;
00979 
00980   <SPAN class=keywordflow>while</SPAN> (rlen &gt; 0)
00981   {
00982     <SPAN class=keywordflow>if</SPAN> (rlen &lt; 2 || bp[1] &gt; rlen)
00983     {
00984       state-&gt;parse_state = psBad;
00985       <SPAN class=keywordflow>break</SPAN>;
00986     }
00987     <SPAN class=keywordflow>for</SPAN> (tp = xcp-&gt;types; tp-&gt;type != -1; tp++)
00988         <SPAN class=keywordflow>if</SPAN> (tp-&gt;type == bp[0])
00989            <SPAN class=keywordflow>break</SPAN>;
00990 
00991     <SPAN class=keywordflow>if</SPAN> (tp-&gt;type == -1)
00992        set_reject (state, xcp, bp);
00993     <SPAN class=keywordflow>else</SPAN> <SPAN class=keywordflow>if</SPAN> (bp[1] &lt; tp-&gt;minlen)
00994        set_nak (s

⌨️ 快捷键说明

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