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

📄 ppp_c source file.htm

📁 关于PPP点对点协议的一些详细资料
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0044)http://www.italios.it/os1/ppp_8c-source.html -->
<HTML><HEAD><TITLE>ppp.c Source File</TITLE>
<META http-equiv=Content-Type content=text/html;charset=iso-8859-1><LINK 
href="ppp_c Source File.files/doxygen.css" type=text/css rel=stylesheet>
<META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>
<BODY><!-- Generato da Doxygen 1.3-rc3 -->
<CENTER><A class=qindex href="http://www.italios.it/os1/index.html">Pagina 
Principale</A> &nbsp; <A class=qindex 
href="http://www.italios.it/os1/annotated.html">Lista dei composti</A> &nbsp; <A 
class=qindex href="http://www.italios.it/os1/files.html">Lista dei file</A> 
&nbsp; <A class=qindex href="http://www.italios.it/os1/functions.html">Membri 
dei composti</A> &nbsp; <A class=qindex 
href="http://www.italios.it/os1/globals.html">Membri dei file</A> &nbsp; 
</CENTER>
<HR>

<H1>ppp.c</H1><A href="http://www.italios.it/os1/ppp_8c.html">Vai alla 
documentazione di questo file.</A>
<DIV class=fragment><PRE>00001 <SPAN class=comment>/*</SPAN>
00002 <SPAN class=comment>ItaliOs</SPAN>
00003 <SPAN class=comment>This program is free software; you can redistribute it and/or</SPAN>
00004 <SPAN class=comment>modify it under the terms of the GNU General Public License</SPAN>
00005 <SPAN class=comment>as published by the Free Software Foundation; either version 2</SPAN>
00006 <SPAN class=comment>of the License, or (at your option) any later version.</SPAN>
00007 <SPAN class=comment></SPAN>
00008 <SPAN class=comment>This program is distributed in the hope that it will be useful,</SPAN>
00009 <SPAN class=comment>but WITHOUT ANY WARRANTY; without even the implied warranty of</SPAN>
00010 <SPAN class=comment>MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</SPAN>
00011 <SPAN class=comment>GNU General Public License for more details.</SPAN>
00012 <SPAN class=comment></SPAN>
00013 <SPAN class=comment>You should have received a copy of the GNU General Public License</SPAN>
00014 <SPAN class=comment>along with this program; if not, write to the Free Software</SPAN>
00015 <SPAN class=comment>Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.</SPAN>
00016 <SPAN class=comment>*/</SPAN>
00017 
00018 
00019 <SPAN class=comment>/* ppp.c: by miki00</SPAN>
00020 <SPAN class=comment></SPAN>
00021 <SPAN class=comment></SPAN>
00022 <SPAN class=comment>   0x7f,0xff,0x03,protocol[2]</SPAN>
00023 <SPAN class=comment></SPAN>
00024 <SPAN class=comment></SPAN>
00025 <SPAN class=comment>  status: PAP,</SPAN>
00026 <SPAN class=comment></SPAN>
00027 <SPAN class=comment></SPAN>
00028 <SPAN class=comment>#include "io.h"</SPAN>
00029 <SPAN class=comment>*/</SPAN>
00030 <SPAN class=preprocessor>#define r_PPP</SPAN>
00031 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#include "<A class=code href="http://www.italios.it/os1/net_2rete_8h.html">rete.h</A>"</SPAN>
00032 
00033 <SPAN class=preprocessor>#define ppp_flag (u_char)*ppp</SPAN>
00034 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define ppp_addr (u_char)*(ppp+1)</SPAN>
00035 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define ppp_control (u_char)*(ppp+2)</SPAN>
00036 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define ppp_proto *(u_short *)(ppp+3)</SPAN>
00037 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define ppp_code (u_char)*(ppp+5)</SPAN>
00038 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define ppp_id (u_char)*(ppp+6)</SPAN>
00039 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define ppp_len *(u_short *)(ppp+7)</SPAN>
00040 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define ppp_dati (ppp+9)</SPAN>
00041 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define ppp_fcs *(u_short *)(ppp+scbyte(ppp_len)+5)</SPAN>
00042 <SPAN class=preprocessor></SPAN>
00043 <SPAN class=preprocessor>#define ppplog_addr (u_char)*(ppplog+1)</SPAN>
00044 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define ppplog_control (u_char)*(ppplog+2)</SPAN>
00045 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define ppplog_proto *(u_short *)(ppplog+3)</SPAN>
00046 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define ppplog_code (u_char)*(ppplog+5)</SPAN>
00047 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define ppplog_id (u_char)*(ppplog+6)</SPAN>
00048 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define ppplog_len *(u_short *)(ppplog+7)</SPAN>
00049 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define ppplog_dati (ppplog+9)</SPAN>
00050 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define ppplog_fcs *(u_short *)(ppplog+scbyte(ppplog_len)+5)</SPAN>
00051 <SPAN class=preprocessor></SPAN>
00052 <SPAN class=preprocessor>#define pppout_flag (u_char)*pppout</SPAN>
00053 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define pppout_addr (u_char)*(pppout+1)</SPAN>
00054 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define pppout_control (u_char)*(pppout+2)</SPAN>
00055 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define pppout_proto *(u_short *)(pppout+3)</SPAN>
00056 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define pppout_code (u_char)*(pppout+5)</SPAN>
00057 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define pppout_id (u_char)*(pppout+6)</SPAN>
00058 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define pppout_len *(u_short *)(pppout+7)</SPAN>
00059 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define pppout_dati (pppout+9)</SPAN>
00060 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define pppout_fcs *(u_short *)(pppout+scbyte(pppout_len)+5)</SPAN>
00061 <SPAN class=preprocessor></SPAN>
00062 <SPAN class=preprocessor>#define IP_LUNGH scbyte(*(u_short *)(pppout+7))</SPAN>
00063 <SPAN class=preprocessor></SPAN>
00064 <SPAN class=preprocessor>#ifndef stderr</SPAN>
00065 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define stderr stdout </SPAN>
00066 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#endif</SPAN>
00067 <SPAN class=preprocessor></SPAN>
00068 <SPAN class=comment>/*</SPAN>
00069 <SPAN class=comment>#define Log nlog+=snprintf(log+nlog,200,</SPAN>
00070 <SPAN class=comment>#define Scrivilog {printf("%s\n",log);nlog=0;}</SPAN>
00071 <SPAN class=comment>*/</SPAN>
00072 <SPAN class=preprocessor>#define Log printf(</SPAN>
00073 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define Scrivilog printf("\n");</SPAN>
00074 <SPAN class=preprocessor></SPAN>
00075   <SPAN class=keywordtype>int</SPAN> t;
00076 
00077   u_int PPPtimeout=0;
00078   
00079 <SPAN class=comment>/*  u_char F_PPP=0; */</SPAN>
00080   u_char lastCH=0;
00081   u_char *ppp,*pppout,*ppplog;
00082   u_char *buff=0;
00083   u_char *buffRX=0;
00084   u_short buffRX1,buffRX2=0;
00085   <SPAN class=keywordtype>int</SPAN> punta[]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},npunta=0,npunta2=0,puntaP=-1;
00086   <SPAN class=keywordtype>char</SPAN> log[200],nlog=0,CLK=0;
00087   u_int stato=0;
00088   u_int IPlocale,IPremoto;
00089   u_int IPDNS1,IPDNS2;
00090   u_int asyncmap=0xffffffff,asyncmap2;
00091   u_char *bufTX=0;
00092   u_short bufTX1,bufTX2=0;
00093   u_int ritorno;  
00094   u_char ppp_confack,ppp_confnack,ppp_confrej;
00095   <SPAN class=keyword>extern</SPAN> u_char asyncmapno;
00096   
00097   <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>unsigned</SPAN> <SPAN class=keywordtype>short</SPAN> fcstab[256] = {
00098         0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
00099         0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
00100         0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
00101         0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
00102         0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
00103         0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
00104         0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
00105         0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
00106         0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
00107         0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
00108         0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
00109         0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
00110         0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
00111         0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
00112         0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
00113         0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
00114         0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
00115         0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
00116         0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
00117         0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
00118         0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
00119         0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
00120         0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
00121         0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
00122         0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
00123         0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
00124         0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
00125         0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
00126         0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
00127         0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
00128         0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
00129         0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
00130    };
00131 
00132 u_char leggiPPP() {     <SPAN class=comment>/* funzione che legge e marca un frame in Rx */</SPAN>
00133   u_char ch;
00134   ch=((ritorno=leggibyteseriale())&amp;0xff);<SPAN class=comment>/* leggibyte da seriale */</SPAN>
00135   <SPAN class=keywordflow>if</SPAN> (ritorno!=NO_DATA) {       <SPAN class=comment>/* se e' stato letto un byte */</SPAN>
00136   <SPAN class=keywordflow>if</SPAN> (ch==0x7e) {                <SPAN class=comment>/* se e' un flag */</SPAN>
00137    <SPAN class=keywordflow>if</SPAN> (lastCH!=0x7e)              <SPAN class=comment>/* se il penultimo byte non e' un flag */</SPAN>
00138     <SPAN class=keywordflow>if</SPAN> (puntaP&gt;=0) {               <SPAN class=comment>/* se e' un frame completo */</SPAN>
00139        punta[npunta]=puntaP;       <SPAN class=comment>/* allora trasmetti */</SPAN>
00140        npunta=(npunta+1)%10;
00141     }
00142     <SPAN class=keywordflow>if</SPAN> (buffRX2&gt;(10000-3000)) buffRX2=0;
00143     puntaP=buffRX2;                    <SPAN class=comment>/* marca frame successivo */</SPAN>
00144   }
00145   <SPAN class=keywordflow>if</SPAN> (ch==0x7d) {               <SPAN class=comment>/* se e' un codice di escape */</SPAN>
00146     <SPAN class=keywordflow>while</SPAN> ((ritorno=leggibyteseriale())==NO_DATA);
00147       ch=(ritorno&amp;0xff)^0x20;   <SPAN class=comment>/* leggi il prox byte e fai xor 0x20 */</SPAN>
00148   }
00149   buffRX[buffRX2]=ch;               <SPAN class=comment>/* salva carattere nel buffer */</SPAN>
00150   buffRX2++;<SPAN class=keywordflow>if</SPAN> (buffRX2&gt;10000) buffRX2=0;
00151   lastCH=ch;                          <SPAN class=comment>/* salva il carattere il lastCH */</SPAN>
00152   <SPAN class=keywordflow>return</SPAN> 1;
00153  } <SPAN class=keywordflow>else</SPAN> <SPAN class=keywordflow>return</SPAN> 0;
00154 }
00155 
00156 <SPAN class=preprocessor>   #define PPPINITFCS      0xffff  </SPAN><SPAN class=comment>/* Initial FCS value */</SPAN>
00157 
00158 
00159    <SPAN class=comment>/*</SPAN>
00160 <SPAN class=comment>    * Calculate a new fcs given the current fcs and the new data.</SPAN>
00161 <SPAN class=comment>    */</SPAN>
00162    u_short pppfcs(fcs, cp, len) <SPAN class=comment>/* funzione per il calcolo dell'FCS da RFC */</SPAN>
00163        <SPAN class=keyword>register</SPAN> <SPAN class=keywordtype>unsigned</SPAN> <SPAN class=keywordtype>short</SPAN> fcs;
00164        <SPAN class=keyword>register</SPAN> <SPAN class=keywordtype>unsigned</SPAN> <SPAN class=keywordtype>char</SPAN> *cp;
00165        <SPAN class=keyword>register</SPAN> <SPAN class=keywordtype>int</SPAN> len;
00166    {
00167        <SPAN class=keywordflow>while</SPAN> (len--) {
00168            fcs = (fcs &gt;&gt; 8) ^ fcstab[(fcs ^ *cp++) &amp; 0xff];
00169        }
00170        fcs=~fcs;
00171        <SPAN class=keywordflow>return</SPAN> fcs;
00172    }
00173 
00174 <SPAN class=keywordtype>void</SPAN> logga(u_char *ppplog,<SPAN class=keywordtype>char</SPAN> *iniz) { <SPAN class=comment>/* log su stdout */</SPAN>
00175 <SPAN class=keywordtype>int</SPAN> t;
00176 
00177 <SPAN class=keywordtype>void</SPAN> leggiOPZ() {
00178  <SPAN class=keywordtype>int</SPAN> t1;
00179   <SPAN class=keywordflow>for</SPAN> (t=0;t&lt;(scbyte(ppplog_len)-4);) { 
00180    <SPAN class=keywordflow>for</SPAN> (t1=0;t1&lt;ppplog_dati[t+1];t1++)
00181      Log <SPAN class=stringliteral>"%x."</SPAN>,ppplog_dati[t+t1]);
00182    t+=t1;Log <SPAN class=stringliteral>" "</SPAN>);
00183   }   
00184 }
00185 
00186 <SPAN class=keywordtype>void</SPAN> CoNf() {
00187          <SPAN class=keywordflow>switch</SPAN> (ppplog_code) {
00188            <SPAN class=keywordflow>case</SPAN> 1:  Log <SPAN class=stringliteral>"ConfReq "</SPAN>);<SPAN class=keywordflow>break</SPAN>;
00189            <SPAN class=keywordflow>case</SPAN> 2:  Log <SPAN class=stringliteral>"ConfAck "</SPAN>);<SPAN class=keywordflow>break</SPAN>;
00190            <SPAN class=keywordflow>case</SPAN> 3:  Log <SPAN class=stringliteral>"ConfNack "</SPAN>);<SPAN class=keywordflow>break</SPAN>;
00191            <SPAN class=keywordflow>case</SPAN> 4:  Log <SPAN class=stringliteral>"ConfRej "</SPAN>);<SPAN class=keywordflow>break</SPAN>;
00192            <SPAN class=keywordflow>case</SPAN> 5:  Log <SPAN class=stringliteral>"TermReq "</SPAN>);<SPAN class=keywordflow>break</SPAN>;
00193            <SPAN class=keywordflow>case</SPAN> 6:  Log <SPAN class=stringliteral>"TermAck "</SPAN>);<SPAN class=keywordflow>break</SPAN>;
00194          }
00195 }
00196 

⌨️ 快捷键说明

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