📄 watt-32 tcp-ip src-ppp_c source file.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0047)http://www.bgnett.no/~giva/watt-doc/a01606.html -->
<HTML><HEAD><TITLE>Watt-32 tcp/ip: SRC/PPP.C Source File</TITLE>
<META http-equiv=Content-Type content=text/html;charset=iso-8859-1><LINK
href="Watt-32 tcp-ip SRC-PPP_C Source File.files/watt-doc.css" type=text/css
rel=stylesheet>
<META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>
<BODY><!-- Generated by Doxygen 1.3.1 -->
<CENTER><A class=qindex
href="http://www.bgnett.no/~giva/watt-doc/main.html">Main Page</A> <A
class=qindex
href="http://www.bgnett.no/~giva/watt-doc/classes.html">Alphabetical List</A>
<A class=qindex
href="http://www.bgnett.no/~giva/watt-doc/annotated.html">Data Structures</A>
<A class=qindex
href="http://www.bgnett.no/~giva/watt-doc/files.html">File List</A> <A
class=qindex href="http://www.bgnett.no/~giva/watt-doc/functions.html">Data
Fields</A> <A class=qindex
href="http://www.bgnett.no/~giva/watt-doc/globals.html">Globals</A> <A
class=qindex href="http://www.bgnett.no/~giva/watt-doc/pages.html">Related
Pages</A> </CENTER>
<HR>
<H1>SRC/PPP.C</H1><A href="http://www.bgnett.no/~giva/watt-doc/a01282.html">Go
to the documentation of this file.</A>
<DIV class=fragment><PRE>00001
00025 <SPAN class=preprocessor>#include <stdio.h></SPAN>
00026 <SPAN class=preprocessor>#include <stdlib.h></SPAN>
00027 <SPAN class=preprocessor>#include <string.h></SPAN>
00028 <SPAN class=preprocessor>#include <ctype.h></SPAN>
00029 <SPAN class=preprocessor>#include <time.h></SPAN>
00030 <SPAN class=preprocessor>#include <limits.h></SPAN>
00031 <SPAN class=preprocessor>#include <<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01077.html">netinet/in.h</A>></SPAN>
00032
00033 <SPAN class=preprocessor>#include "<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html">wattcp.h</A>"</SPAN>
00034 <SPAN class=preprocessor>#include "<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01227.html">misc.h</A>"</SPAN>
00035 <SPAN class=preprocessor>#include "<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01323.html">strings.h</A>"</SPAN>
00036 <SPAN class=preprocessor>#include "<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01248.html">pcdbug.h</A>"</SPAN>
00037 <SPAN class=preprocessor>#include "<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01265.html">pcqueue.h</A>"</SPAN>
00038 <SPAN class=preprocessor>#include "<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01246.html">pcconfig.h</A>"</SPAN>
00039 <SPAN class=preprocessor>#include "<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01242.html">pcbsd.h</A>"</SPAN>
00040 <SPAN class=preprocessor>#include "<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01238.html">pcarp.h</A>"</SPAN>
00041 <SPAN class=preprocessor>#include "<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01271.html">pcsed.h</A>"</SPAN>
00042 <SPAN class=preprocessor>#include "<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01261.html">pcpkt.h</A>"</SPAN>
00043 <SPAN class=preprocessor>#include "<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01276.html">pctcp.h</A>"</SPAN>
00044 <SPAN class=preprocessor>#include "<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01212.html">ip4_in.h</A>"</SPAN>
00045 <SPAN class=preprocessor>#include "<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01285.html">pppoe.h</A>"</SPAN>
00046 <SPAN class=preprocessor>#include "<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01283.html">ppp.h</A>"</SPAN>
00047
00048 <SPAN class=preprocessor>#if defined(USE_PPPOE)</SPAN>
00049 <SPAN class=preprocessor></SPAN>
00050 <SPAN class=preprocessor>#define INITIAL_TIMEOUT 2</SPAN>
00051 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define MAX_TERMINATE 2</SPAN>
00052 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define MAX_CONFIGURE 10</SPAN>
00053 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define MAX_FAILURE 5</SPAN>
00054 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define MAX_TIMEOUT 8</SPAN>
00055 <SPAN class=preprocessor></SPAN>
00056
00057 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>int</SPAN> remote_ip_base = 0x0A000000;
00058 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>int</SPAN> remote_ip_mask = 0xFF000000;
00059 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>int</SPAN> debug = 0;
00060 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>char</SPAN> tmp[20];
00061
00062 <SPAN class=keyword>static</SPAN> <SPAN class=keyword>const</SPAN> <SPAN class=keywordtype>char</SPAN> *ph_str[] = {
00063 <SPAN class=stringliteral>"Dead"</SPAN>, <SPAN class=stringliteral>"Establish"</SPAN>, <SPAN class=stringliteral>"Authenticate"</SPAN>,
00064 <SPAN class=stringliteral>"Network"</SPAN>, <SPAN class=stringliteral>"Terminate"</SPAN>
00065 };
00066
00067 <SPAN class=keyword>static</SPAN> <SPAN class=keyword>const</SPAN> <SPAN class=keywordtype>char</SPAN> *ev_str[] = {
00068 <SPAN class=stringliteral>"Up"</SPAN>, <SPAN class=stringliteral>"Down"</SPAN>, <SPAN class=stringliteral>"Open"</SPAN>, <SPAN class=stringliteral>"Close"</SPAN>, <SPAN class=stringliteral>"TO+"</SPAN>, <SPAN class=stringliteral>"TO-"</SPAN>,
00069 <SPAN class=stringliteral>"RCR+"</SPAN>, <SPAN class=stringliteral>"RCR-"</SPAN>, <SPAN class=stringliteral>"RCA"</SPAN>, <SPAN class=stringliteral>"RCN"</SPAN>, <SPAN class=stringliteral>"RTR"</SPAN>, <SPAN class=stringliteral>"RTA"</SPAN>,
00070 <SPAN class=stringliteral>"RUC"</SPAN>, <SPAN class=stringliteral>"RXJ+"</SPAN>, <SPAN class=stringliteral>"RXJ-"</SPAN>, <SPAN class=stringliteral>"RXR"</SPAN>
00071 };
00072
00073 <SPAN class=keyword>static</SPAN> <SPAN class=keyword>const</SPAN> <SPAN class=keywordtype>char</SPAN> *st_str[] = {
00074 <SPAN class=stringliteral>"Initial"</SPAN>, <SPAN class=stringliteral>"Starting"</SPAN>, <SPAN class=stringliteral>"Closed"</SPAN>, <SPAN class=stringliteral>"Stopped"</SPAN>,
00075 <SPAN class=stringliteral>"Closing"</SPAN>, <SPAN class=stringliteral>"Stopping"</SPAN>, <SPAN class=stringliteral>"Req-Sent"</SPAN>, <SPAN class=stringliteral>"Ack-Rcvd"</SPAN>,
00076 <SPAN class=stringliteral>"Ack-Sent"</SPAN>, <SPAN class=stringliteral>"Opened"</SPAN>, <SPAN class=stringliteral>"No-Change"</SPAN>
00077 };
00078
00079 <SPAN class=keyword>static</SPAN> <SPAN class=keyword>const</SPAN> <SPAN class=keywordtype>char</SPAN> *ac_str[] = {
00080 <SPAN class=stringliteral>"Null"</SPAN>, <SPAN class=stringliteral>"irc"</SPAN>, <SPAN class=stringliteral>"scr"</SPAN>, <SPAN class=stringliteral>"tls"</SPAN>, <SPAN class=stringliteral>"tlf"</SPAN>, <SPAN class=stringliteral>"str"</SPAN>, <SPAN class=stringliteral>"sta"</SPAN>,
00081 <SPAN class=stringliteral>"sca"</SPAN>, <SPAN class=stringliteral>"scn"</SPAN>, <SPAN class=stringliteral>"scj"</SPAN>, <SPAN class=stringliteral>"tld"</SPAN>, <SPAN class=stringliteral>"tlu"</SPAN>, <SPAN class=stringliteral>"zrc"</SPAN>, <SPAN class=stringliteral>"ser"</SPAN>
00082 };
00083
00084
00085 <SPAN class=keyword>static</SPAN> <SPAN class=keyword>struct </SPAN>ppp_state mystate;
00086
00087 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>void</SPAN> ipcp_addr_req (<SPAN class=keyword>struct</SPAN> ppp_state *state,
00088 <SPAN class=keyword>struct</SPAN> ppp_xcp *xcp, <SPAN class=keyword>const</SPAN> <SPAN class=keyword>struct</SPAN> xcp_type *tp,
00089 <SPAN class=keyword>const</SPAN> BYTE *buf, <SPAN class=keywordtype>int</SPAN> len);
00090
00091 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>void</SPAN> ipcp_addr_nak (<SPAN class=keyword>struct</SPAN> ppp_state *state,
00092 <SPAN class=keyword>struct</SPAN> ppp_xcp *xcp, <SPAN class=keyword>const</SPAN> <SPAN class=keyword>struct</SPAN> xcp_type *tp,
00093 <SPAN class=keyword>const</SPAN> BYTE *buf, <SPAN class=keywordtype>int</SPAN> len);
00094
00095 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>void</SPAN> ipcp_addr_show (<SPAN class=keyword>struct</SPAN> ppp_state *state,
00096 <SPAN class=keyword>struct</SPAN> ppp_xcp *xcp, <SPAN class=keyword>const</SPAN> <SPAN class=keyword>struct</SPAN> xcp_type *tp,
00097 <SPAN class=keyword>const</SPAN> BYTE *buf, <SPAN class=keywordtype>int</SPAN> len);
00098
00099 <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,
00100 <SPAN class=keyword>enum</SPAN> ppp_event event);
00101
00102 <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);
00103
00104
00105 <SPAN class=keyword>static</SPAN> <SPAN class=keyword>const</SPAN> <SPAN class=keyword>struct </SPAN>xcp_type lcp_types[] = {
00106 { NULL, -1, 0, 0, 0, 0, NULL, NULL, NULL }
00107 };
00108
00109 <SPAN class=keyword>static</SPAN> <SPAN class=keyword>const</SPAN> <SPAN class=keyword>struct </SPAN>xcp_type ipcp_types[] = {
00110 { <SPAN class=stringliteral>"IP-Address"</SPAN>, 3, 1, 6, 6, 0, ipcp_addr_req,
00111 ipcp_addr_nak, ipcp_addr_show },
00112 { NULL, -1, 0, 0, 0, 0, NULL, NULL, NULL }
00113 };
00114
00115
00116 <SPAN class=comment>/* Dispatch table from RFC 1661</SPAN>
00117 <SPAN class=comment> */</SPAN>
00118 <SPAN class=keyword>static</SPAN> <SPAN class=keyword>const</SPAN> <SPAN class=keyword>struct </SPAN>ppp_dispatch {
00119 <SPAN class=keyword>enum</SPAN> xcp_state next;
00120 <SPAN class=keyword>enum</SPAN> xcp_action act[3];
00121 } ppp_dispatch[10][16] = {
00122
00123 { <SPAN class=comment>/* stInitial */</SPAN>
00124 <SPAN class=comment>/* evUp */</SPAN> { stClosed, { acNull, acNull, acNull } },
00125 <SPAN class=comment>/* evDown */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00126 <SPAN class=comment>/* evOpen */</SPAN> { stStarting, { acTls, acNull, acNull } },
00127 <SPAN class=comment>/* evClose */</SPAN> { stClosed, { acNull, acNull, acNull } },
00128 <SPAN class=comment>/* evTOp */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00129 <SPAN class=comment>/* evTOm */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00130 <SPAN class=comment>/* evRCRp */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00131 <SPAN class=comment>/* evRCRm */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00132 <SPAN class=comment>/* evRCA */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00133 <SPAN class=comment>/* evRCN */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00134 <SPAN class=comment>/* evRTR */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00135 <SPAN class=comment>/* evRTA */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00136 <SPAN class=comment>/* evRUC */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00137 <SPAN class=comment>/* evRXJp */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00138 <SPAN class=comment>/* evRXJm */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00139 <SPAN class=comment>/* evRXR */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00140 },
00141 { <SPAN class=comment>/* stStarting */</SPAN>
00142 <SPAN class=comment>/* evUp */</SPAN> { stReqSent, { acIrc, acScr, acNull } },
00143 <SPAN class=comment>/* evDown */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00144 <SPAN class=comment>/* evOpen */</SPAN> { stStarting, { acNull, acNull, acNull } },
00145 <SPAN class=comment>/* evClose */</SPAN> { stInitial, { acTlf, acNull, acNull } },
00146 <SPAN class=comment>/* evTOp */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00147 <SPAN class=comment>/* evTOm */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00148 <SPAN class=comment>/* evRCRp */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00149 <SPAN class=comment>/* evRCRm */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00150 <SPAN class=comment>/* evRCA */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00151 <SPAN class=comment>/* evRCN */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00152 <SPAN class=comment>/* evRTR */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00153 <SPAN class=comment>/* evRTA */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00154 <SPAN class=comment>/* evRUC */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00155 <SPAN class=comment>/* evRXJp */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00156 <SPAN class=comment>/* evRXJm */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00157 <SPAN class=comment>/* evRXR */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00158 },
00159 { <SPAN class=comment>/* stClosed */</SPAN>
00160 <SPAN class=comment>/* evUp */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00161 <SPAN class=comment>/* evDown */</SPAN> { stInitial, { acNull, acNull, acNull } },
00162 <SPAN class=comment>/* evOpen */</SPAN> { stReqSent, { acIrc, acScr, acNull } },
00163 <SPAN class=comment>/* evClose */</SPAN> { stClosed, { acNull, acNull, acNull } },
00164 <SPAN class=comment>/* evTOp */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00165 <SPAN class=comment>/* evTOm */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00166 <SPAN class=comment>/* evRCRp */</SPAN> { stClosed, { acSta, acNull, acNull } },
00167 <SPAN class=comment>/* evRCRm */</SPAN> { stClosed, { acSta, acNull, acNull } },
00168 <SPAN class=comment>/* evRCA */</SPAN> { stClosed, { acSta, acNull, acNull } },
00169 <SPAN class=comment>/* evRCN */</SPAN> { stClosed, { acSta, acNull, acNull } },
00170 <SPAN class=comment>/* evRTR */</SPAN> { stClosed, { acSta, acNull, acNull } },
00171 <SPAN class=comment>/* evRTA */</SPAN> { stClosed, { acNull, acNull, acNull } },
00172 <SPAN class=comment>/* evRUC */</SPAN> { stClosed, { acScj, acNull, acNull } },
00173 <SPAN class=comment>/* evRXJp */</SPAN> { stClosed, { acNull, acNull, acNull } },
00174 <SPAN class=comment>/* evRXJm */</SPAN> { stClosed, { acTlf, acNull, acNull } },
00175 <SPAN class=comment>/* evRXR */</SPAN> { stClosed, { acNull, acNull, acNull } },
00176 },
00177 { <SPAN class=comment>/* stStopped */</SPAN>
00178 <SPAN class=comment>/* evUp */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00179 <SPAN class=comment>/* evDown */</SPAN> { stStarting, { acTls, acNull, acNull } },
00180 <SPAN class=comment>/* evOpen */</SPAN> { stStopped, { acNull, acNull, acNull } },
00181 <SPAN class=comment>/* evClose */</SPAN> { stClosed, { acNull, acNull, acNull } },
00182 <SPAN class=comment>/* evTOp */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00183 <SPAN class=comment>/* evTOm */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00184 <SPAN class=comment>/* evRCRp */</SPAN> { stAckSent, { acIrc, acScr, acSca } },
00185 <SPAN class=comment>/* evRCRm */</SPAN> { stReqSent, { acIrc, acScr, acScn } },
00186 <SPAN class=comment>/* evRCA */</SPAN> { stStopped, { acSta, acNull, acNull } },
00187 <SPAN class=comment>/* evRCN */</SPAN> { stStopped, { acSta, acNull, acNull } },
00188 <SPAN class=comment>/* evRTR */</SPAN> { stStopped, { acSta, acNull, acNull } },
00189 <SPAN class=comment>/* evRTA */</SPAN> { stStopped, { acNull, acNull, acNull } },
00190 <SPAN class=comment>/* evRUC */</SPAN> { stStopped, { acScj, acNull, acNull } },
00191 <SPAN class=comment>/* evRXJp */</SPAN> { stStopped, { acNull, acNull, acNull } },
00192 <SPAN class=comment>/* evRXJm */</SPAN> { stStopped, { acTlf, acNull, acNull } },
00193 <SPAN class=comment>/* evRXR */</SPAN> { stStopped, { acNull, acNull, acNull } },
00194 },
00195 { <SPAN class=comment>/* stClosing */</SPAN>
00196 <SPAN class=comment>/* evUp */</SPAN> { stNoChange, { acNull, acNull, acNull } },
00197 <SPAN class=comment>/* evDown */</SPAN> { stInitial, { acNull, acNull, acNull } },
00198 <SPAN class=comment>/* evOpen */</SPAN> { stStopping, { acNull, acNull, acNull } },
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -