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

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

📁 关于PPP点对点协议的一些详细资料
💻 HTM
📖 第 1 页 / 共 5 页
字号:
00599   <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a2">DWORD</A> val;
00600 
00601   <SPAN class=keywordflow>for</SPAN> (tp = xcp-&gt;types, os = xcp-&gt;opts; tp-&gt;type != -1; tp++, os++)
00602       os-&gt;peer_value = tp-&gt;default_value;
00603   bp   = state-&gt;bp;
00604   rlen = state-&gt;mlen;
00605   <SPAN class=keywordflow>while</SPAN> (rlen &gt; 0)
00606   {
00607     <SPAN class=keywordflow>for</SPAN> (tp = xcp-&gt;types; tp-&gt;type != -1; tp++)
00608         <SPAN class=keywordflow>if</SPAN> (tp-&gt;type == bp[0])
00609            <SPAN class=keywordflow>break</SPAN>;
00610 
00611     os  = xcp-&gt;opts + (tp - xcp-&gt;types);
00612     val = bp[2];
00613     <SPAN class=keywordflow>if</SPAN> (bp[1] &gt; 3)
00614        val = (val &lt;&lt; 8) + bp[3];
00615     <SPAN class=keywordflow>if</SPAN> (bp[1] &gt; 4)
00616        val = (val &lt;&lt; 8) + bp[4];
00617     <SPAN class=keywordflow>if</SPAN> (bp[1] &gt; 5)
00618        val = (val &lt;&lt; 8) + bp[5];
00619     os-&gt;peer_value = val;
00620     rlen -= bp[1];
00621     bp   += bp[1];
00622   }
00623 }
00624 
00625 <SPAN class=comment>/*</SPAN>
00626 <SPAN class=comment> * Perform RFC 1661 actions as indicated by state machine.</SPAN>
00627 <SPAN class=comment> */</SPAN>
00628 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>void</SPAN> dispatch_action (<SPAN class=keyword>struct</SPAN> ppp_state *state, <SPAN class=keyword>struct</SPAN> ppp_xcp *xcp,
00629                              <SPAN class=keyword>enum</SPAN> xcp_action act)
00630 {
00631   <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a0">BYTE</A> *bp;
00632 
00633   <SPAN class=keywordflow>if</SPAN> (act == acNull)
00634      <SPAN class=keywordflow>return</SPAN>;
00635 
00636   PRINTF (2, (<SPAN class=stringliteral>"%s action %s (%d)\n"</SPAN>, xcp-&gt;name, ac_str[act], act));
00637 
00638   <SPAN class=keywordflow>switch</SPAN> (act)
00639   {
00640     <SPAN class=keywordflow>case</SPAN> acNull:
00641          <SPAN class=keywordflow>break</SPAN>;
00642 
00643     <SPAN class=keywordflow>case</SPAN> acIrc:
00644          xcp-&gt;restart = state-&gt;phase == phTerminate ? MAX_TERMINATE : MAX_CONFIGURE;
00645          state-&gt;timeout_period = INITIAL_TIMEOUT;
00646          <SPAN class=keywordflow>break</SPAN>;
00647 
00648     <SPAN class=keywordflow>case</SPAN> acScr:
00649          <SPAN class=keywordflow>if</SPAN> (xcp-&gt;restart &gt; 0)
00650          {
00651            xcp-&gt;restart--;
00652            create_request (state, xcp);
00653            ppp_write (state, xcp, state-&gt;outbuffer, state-&gt;up - state-&gt;outbuffer);
00654          }
00655          xcp-&gt;timeout = time (NULL) + state-&gt;timeout_period;
00656          <SPAN class=keywordflow>break</SPAN>;
00657 
00658     <SPAN class=keywordflow>case</SPAN> acTls:
00659          <SPAN class=keywordflow>if</SPAN> (xcp == &amp;state-&gt;xcps[XCP_IPCP])
00660               send_event (state, &amp;state-&gt;xcps[XCP_LCP], evOpen);
00661          <SPAN class=keywordflow>else</SPAN> change_phase (state, phEstablish);
00662          <SPAN class=keywordflow>break</SPAN>;
00663 
00664     <SPAN class=keywordflow>case</SPAN> acTlf:
00665          <SPAN class=keywordflow>if</SPAN> (xcp == &amp;state-&gt;xcps[XCP_IPCP])
00666               send_event (state, &amp;state-&gt;xcps[XCP_LCP], evClose);
00667          <SPAN class=keywordflow>else</SPAN> change_phase (state, phTerminate);
00668          <SPAN class=keywordflow>break</SPAN>;
00669 
00670     <SPAN class=keywordflow>case</SPAN> acStr:
00671          <SPAN class=keywordflow>if</SPAN> (xcp-&gt;restart &gt; 0)
00672          {
00673            xcp-&gt;restart--;
00674            bp = code_id (state, xcp, CODE_TERM_REQ);
00675            ppp_write (state, xcp, state-&gt;outbuffer, bp - state-&gt;outbuffer);
00676          }
00677          xcp-&gt;timeout = time (NULL) + state-&gt;timeout_period;
00678          <SPAN class=keywordflow>break</SPAN>;
00679 
00680     <SPAN class=keywordflow>case</SPAN> acSta:
00681          bp = code_reply (state, xcp, CODE_TERM_ACK);
00682          ppp_write (state, xcp, state-&gt;outbuffer, bp - state-&gt;outbuffer);
00683          <SPAN class=keywordflow>break</SPAN>;
00684 
00685     <SPAN class=keywordflow>case</SPAN> acSca:
00686          copy_peer_values (state, xcp);
00687          state-&gt;inbuffer[2] = CODE_CONF_ACK;
00688          ppp_write (state, xcp, state-&gt;inbuffer, state-&gt;mlen +
00689                     (state-&gt;bp - state-&gt;inbuffer));
00690          <SPAN class=keywordflow>break</SPAN>;
00691 
00692     <SPAN class=keywordflow>case</SPAN> acScn:
00693          <SPAN class=keywordflow>if</SPAN> (xcp-&gt;naks_sent++ &gt;= MAX_FAILURE)
00694             state-&gt;outbuffer[4] = CODE_CONF_REJ;
00695          <SPAN class=comment>/* fall-through */</SPAN>
00696 
00697     <SPAN class=keywordflow>case</SPAN> acScj:
00698          ppp_write (state, xcp, state-&gt;outbuffer, state-&gt;up - state-&gt;outbuffer);
00699          <SPAN class=keywordflow>break</SPAN>;
00700 
00701     <SPAN class=keywordflow>case</SPAN> acTld:
00702          <SPAN class=keywordflow>if</SPAN> (xcp == &amp;state-&gt;xcps[XCP_LCP])
00703               change_phase (state, phTerminate);
00704          <SPAN class=keywordflow>else</SPAN> PRINTF (0, (<SPAN class=stringliteral>"IPCP down!\n"</SPAN>));
00705          <SPAN class=keywordflow>break</SPAN>;
00706 
00707     <SPAN class=keywordflow>case</SPAN> acTlu:
00708          <SPAN class=keywordflow>if</SPAN> (xcp == &amp;state-&gt;xcps[XCP_LCP])
00709             change_phase (state, phAuthenticate);
00710          <SPAN class=keywordflow>else</SPAN>
00711          {
00712            <SPAN class=keyword>struct </SPAN>option_state *os = find_option (xcp, 3);
00713            <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a2">DWORD</A>  addr = intel (os-&gt;my_value);
00714 
00715            <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01275.html#a9">my_ip_addr</A> = addr;
00716            PRINTF (0, (<SPAN class=stringliteral>"IPCP up!  Local address %s, "</SPAN>, <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01241.html#a0">_inet_ntoa</A>(tmp,addr)));
00717            addr = intel (os-&gt;peer_value);
00718            <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01237.html#a25">_arp_kill_gateways</A>();
00719            <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01237.html#a24">_arp_add_gateway</A> (NULL, addr);
00720            PRINTF (0, (<SPAN class=stringliteral>"remote %s\n"</SPAN>, <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01241.html#a0">_inet_ntoa</A>(tmp,addr)));
00721          }
00722          xcp-&gt;restart = MAX_CONFIGURE;
00723          xcp-&gt;timeout = 0;
00724          <SPAN class=keywordflow>break</SPAN>;
00725 
00726     <SPAN class=keywordflow>case</SPAN> acZrc:
00727          xcp-&gt;restart = 0;
00728          state-&gt;timeout_period = INITIAL_TIMEOUT;
00729          <SPAN class=keywordflow>break</SPAN>;
00730 
00731     <SPAN class=keywordflow>case</SPAN> acSer:
00732          state-&gt;inbuffer[2] = CODE_ECHO_REP;
00733          *(<SPAN class=keywordtype>long</SPAN>*) (state-&gt;inbuffer + 6) = intel (state-&gt;mymagic);
00734          ppp_write (state, xcp, state-&gt;inbuffer, state-&gt;mlen +
00735                     (state-&gt;bp - state-&gt;inbuffer));
00736          <SPAN class=keywordflow>break</SPAN>;
00737   }
00738 }
00739 
00740 <SPAN class=comment>/*</SPAN>
00741 <SPAN class=comment> * Issue event into XCP state machine -- go to next state and</SPAN>
00742 <SPAN class=comment> * invoke associated actions.</SPAN>
00743 <SPAN class=comment> */</SPAN>
00744 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>void</SPAN> send_event (<SPAN class=keyword>struct</SPAN> ppp_state *state, <SPAN class=keyword>struct</SPAN> ppp_xcp *xcp,
00745                         <SPAN class=keyword>enum</SPAN> ppp_event event)
00746 {
00747   <SPAN class=keyword>const</SPAN> <SPAN class=keyword>struct </SPAN>ppp_dispatch *dp = &amp;ppp_dispatch [xcp-&gt;state][event];
00748 
00749   <SPAN class=keywordflow>if</SPAN> (dp-&gt;next == stNoChange)
00750   {
00751     PRINTF (2, (<SPAN class=stringliteral>"%s got illegal %s event (%d) in %s state (%d)\n"</SPAN>
00752                 <SPAN class=stringliteral>"\t(RFC 1661 section 4.4)\n"</SPAN>,
00753                 xcp-&gt;name, ev_str[event], event, st_str[xcp-&gt;state],
00754                 xcp-&gt;state));
00755   }
00756   <SPAN class=keywordflow>else</SPAN>
00757   {
00758     PRINTF (2, (<SPAN class=stringliteral>"%s got %s event (%d) in %s state (%d), next is %s state (%d)\n"</SPAN>,
00759                 xcp-&gt;name, ev_str[event], event, st_str[xcp-&gt;state],
00760                 xcp-&gt;state, st_str[dp-&gt;next], dp-&gt;next));
00761     xcp-&gt;state = dp-&gt;next;
00762   }
00763   dispatch_action (state, xcp, dp-&gt;act[0]);
00764   dispatch_action (state, xcp, dp-&gt;act[1]);
00765   dispatch_action (state, xcp, dp-&gt;act[2]);
00766 }
00767 
00768 <SPAN class=comment>/*</SPAN>
00769 <SPAN class=comment> * Change overall link phase.  Central routine helps with</SPAN>
00770 <SPAN class=comment> * debugging.</SPAN>
00771 <SPAN class=comment> */</SPAN>
00772 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>void</SPAN> change_phase (<SPAN class=keyword>struct</SPAN> ppp_state *state, <SPAN class=keyword>enum</SPAN> ppp_phase phase)
00773 {
00774   PRINTF (2, (<SPAN class=stringliteral>"Current PPP phase is %s, switching to %s\n"</SPAN>,
00775               ph_str[state-&gt;phase], ph_str[phase]));
00776 
00777   <SPAN class=keywordflow>switch</SPAN> (phase)
00778   {
00779     <SPAN class=keywordflow>case</SPAN> phEstablish:
00780          <SPAN class=keywordflow>if</SPAN> (state-&gt;phase == phDead)
00781             send_event (state, &amp;state-&gt;xcps[XCP_LCP], evUp);
00782          <SPAN class=keywordflow>break</SPAN>;
00783     <SPAN class=keywordflow>case</SPAN> phAuthenticate:
00784          <SPAN class=keywordflow>break</SPAN>;
00785     <SPAN class=keywordflow>case</SPAN> phNetwork:
00786          <SPAN class=keywordflow>if</SPAN> (state-&gt;phase == phAuthenticate)
00787             send_event (state, &amp;state-&gt;xcps[XCP_IPCP], evUp);
00788          <SPAN class=keywordflow>break</SPAN>;
00789     <SPAN class=keywordflow>case</SPAN> phTerminate:
00790          send_event (state, &amp;state-&gt;xcps[XCP_IPCP], evDown);
00791          <SPAN class=keywordflow>break</SPAN>;
00792     <SPAN class=keywordflow>case</SPAN> phDead:
00793          <SPAN class=keywordflow>break</SPAN>;
00794   }
00795   state-&gt;phase = phase;
00796   <SPAN class=keywordflow>if</SPAN> (phase == phAuthenticate)
00797      change_phase (state, phNetwork); <SPAN class=comment>/* XXX - no auth yet */</SPAN>
00798 }

⌨️ 快捷键说明

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