全析PPP Options選項設置
對于一個網絡協議來說,我們不僅僅要了解它的定義和概念,更要清楚它的設置與應用。那么今天我們就主要講解一下關于PPP Options 的相關內容,來幫助大家了解一下具體的選項配置。
Selecting PPP Options Using an Options Structure
PPP options may be set at run-time by filling in a PPP options structure and passing the structure location to the ppp Init( ) routine. This routine is the standard entry point for initializing a PPP link (see Initializing a PPP Link).
The PPP options structure is typedefed to PPP_OPTIONS, and its definition is located in h/netinet/ppp/options.h, which is included through h/pppLib.h.
PPP選項可以在運行的時候設置,設置PPP選項結構體并將這個結構體傳給pppInit()函數。這個函數是初始化PPP連接的標準入口點(請參考初始化PPP連接)。
The first field of the structure is an integer, flags, which is a bit field that holds the ORed value of the OPT_option macros displayed in column 2 of Table 3-3. Definitions for OPT_option are located in h/netinet/ppp/options.h. The remaining structure fields in column 2 are character pointers to the various PPP options specified by a string.
選項結構體的***個域是整型數,一個標志位,是幾個 OPT_xxx或運算之后的值,所有的OPT_xxx可以在Table 3-3中找到。OPT_xxx的定義在h/netinet/ppp/options.h中。。。。(不知所云)
The following code fragment is one way to set configuration options using the PPP options structure. It initializes a PPP interface that uses the target's second serial port (/tyCo/1). The local IP address is 90.0.0.1; the IP address of the remote peer is 90.0.0.10. The baud rate is the default rate for the tty device. The VJ compression and authentication options have been disabled, and LCP (Link Control Protocol) echo requests have been enabled.
下面的代碼段說明了使用PPP選項結構體配置連接的一種方式。用目標機的第二個串口(/tyCo/1)初始化一個PPP連接,本地IP是90.90.0.1,遠程機器的IP是90.90.0.10,波特率是tty設備缺省的速率。VJ壓縮和認證選項是禁用的,鏈路控制協議的echo請求是啟用的。
- PPP_OPTIONS pppOpt; /* PPP configuration options */
- void routine ()
- {
- pppOpt.flags = OPT_PASSIVE_MODE | OPT_NO_PAP | OPT_NO_CHAP |
- OPT_NO_VJ;
- pppOpt.lcp_echo_interval = "30";
- pppOpt.lcp_echo_failure = "10";
- pppInit (0, "/tyCo/1", "90.0.0.1", "90.0.0.10", 0, &pppOpt, NULL);
- }
Setting PPP Options Using an Options File
PPP options are most conveniently set using an options file. There is one restriction: the options file must be readable by the target without there being an active PPP link. Therefore the target must either have a local disk or RAM disk or an additional network connection. For more information about using file systems, see VxWorks Programmer's Guide: Local File Systems.
使用選項文件設置PPP選項是最方便的。有一個限制:選項文件必須在沒有PPP連接的時候也能夠訪問的到。因此目標機必須有一個本地磁盤、RAM或者另外一條網絡連接。關于使用文件系統的更多信息,請參考VxWorks程序員指南:本地文件系統。
This configuration method can be used with either usrPPPInit( ) or pppInit( ). It also can be used to modify the selection of PPP options previously configured using configuration constants in config.h or the option structure PPP_OPTION.
When using usrPPPInit( ) to initialize PPP, define the configuration constant PPP_OPTIONS_FILE to be the absolute path name of the options file (NULL by default). When using pppInit( ), pass in a character string that specifies the absolute path name of the options file.
可以使用usrPPPInit()或pppInit()來設置選項文件。它也可以用來修改之前通過config.h或者PPP_OPTION配置好的選項。
當你使用usrPPPInit()初始化一條連接的時候,要定義PPP_OPTIONS_FILE為選項文件的絕對路徑(缺省的是NULL)。使用pppInit()初始化的時候,要傳入一個參數指定選項文件的絕對路徑。
The options file format is one option per line; comment lines begin with #. For a description of option syntax, see the manual entry for pppInit( ).
The following code fragment generates the same results as the code example in Selecting PPP Options Using an Options Structure. The difference is that the configuration options are obtained from a file rather than a structure.
選項文件的格式是,一個選項占據一行; 注釋的部分以#開頭。具體的細節,請參考手冊中的pppInit()。
下面的代碼段的作用和Selecting PPP Options Using an Options Structure中的例子的效果是一樣的。不同的地方是,這里從一個文件獲取配置選項。
- pppFile = "mars:/tmp/ppp_options"; /* PPP config. options file */
- void routine ()
- {
- pppInit (0, "/tyCo/1", "90.0.0.1", "90.0.0.10", 0, NULL, pppFile);
- }
- In this example, mars:/tmp/ppp_options is a file that contains the following:
在這里例子里,mars:/tmp/ppp_options包含以下內容:
- passive
- no_pap
- no_chap
- no_vj
- lcp_echo_interval 30
- lcp_echo_failure 10