📄 c-tcpip3.html
字号:
</dl><dl class="margin"><dd> <p class="table" callout><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td valign="top" width="40"><br><img border="0" alt="*" src="icons/note.gif"></td><td><hr><div class="CalloutCell"><a name="91748"><b class="symbol_UC"><font face="Helvetica, sans-serif" size="-1" class="sans">NOTE: </font></b></a>An OSPF-based router is available for VxWorks as a separately purchasable option. You can use this router instead of RIP to set up and maintain routing information.</div></td></tr><tr valign="top"><td></td><td><hr></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p callout></dl><dl class="margin"><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="86586">Adding a Route on Windows</a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="86588"> </a>The procedures vary according to your version of Windows and your networking software package. For the details, see the documentation for your system.</p></dl><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="86589">Adding a Route on UNIX</a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="86591"> </a>A UNIX system can be told explicitly about a gateway in one of two ways: by editing <b class="file">/etc/gateways</b> or by using the <b class="command">route</b> command. When the UNIX route daemon <b class="command">routed</b> is started (usually at boot time), it reads a static routing configuration from <b class="file">/etc/gateways</b>. Each line in <b class="file">/etc/gateways</b> specifies a network gateway in the following format:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86595">net <i class="textVariable">destinationAddr</i> gateway <i class="textVariable">gatewayAddr</i> metric <i class="textVariable">n</i> passive</a></b></pre></dl><dd><p class="Body"><a name="86597"> </a>where <i class="textVariable">n</i> is the <i class="term">hop count</i> from the host system to the destination network (the number of gateways between the host and the destination network) and "passive" indicates the entry is to remain in the routing tables.</p><dd><p class="Body"><a name="86598"> </a>For example, consider a system on network 150. The following line in <b class="file">/etc/gateways</b> describes a gateway between networks 150 and 161, with an Internet address 150.12.0.1 on network 150. A hop count (metric) of 1 specifies that the gateway is a direct connection between the two networks:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86599">net 161.27.0.0 gateway 150.12.0.1 metric 1 passive</a></b></pre></dl><dd><p class="Body"><a name="86600"> </a>After editing <b class="file">/etc/gateways</b>, you must kill the route daemon and restart it, because it only reads <b class="file">/etc/gateways</b> when it starts. After the route daemon is running, it is not aware of subsequent changes to the file.</p><dd><p class="Body"><a name="86601"> </a>Alternatively, you can use the <b class="command">route</b> command to add routing information explicitly:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86602"></b><tt class="output"># </tt><b>route add <i class="textVariable">destination-network</i> <i class="textVariable">gatewayAddr</i> <i class="textVariable">[metric]</i></a></b></pre></dl><dd><p class="Body"><a name="86603"> </a>For example, the following command configures the gateway in the same way as the previous example, which used the <b class="file">/etc/gateways</b> file:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86604"></b><tt class="output"># </tt><b>route add net 161.27.0.0 150.12.0.1 1</a></b></pre></dl><dd><p class="Body"><a name="86605"> </a>Note, however, that routes added with this manual method are lost the next time the system boots.</p><dd><p class="Body"><a name="86606"> </a>You can confirm that a route is in the routing table by using the UNIX command <b class="command">netstat -r</b>. </p></dl><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="86609">Adding a Route on VxWorks</a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="86611"> </a>VxWorks provides a set of functions that you can use to edit the routing table. However, before you edit the table, it is generally a good idea to look at what is already there. </p></dl><dl class="margin"><b class="HU-bullet"><li><a name="86613"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Inspecting the Routing Table</font></li></b></dl><dl class="margin"><dd><p class="Body"><a name="86615"> </a>To inspect the contents of the routing table, use <b class="routine"><i class="routine">routeShow</i></b><b>( )</b>. If a VxWorks target boots through an Ethernet network interface, a typical <b class="routine"><i class="routine">routeShow</i></b><b>( )</b> call would display the following:<sup><a href="#foot"><b class="FootnoteMarker">2</b></a></sup></p><dl class="margin"><dd><pre class="Code2"><b><a name="86619">-> routeShow() </b><tt class="output"> ROUTE NET TABLE destination gateway flags Refcnt Use Interface ---------------------------------------------------------------------- 147.11.44.0 147.11.44.165 101 0 0 ei0 ---------------------------------------------------------------------- ROUTE HOST TABLE destination gateway flags Refcnt Use Interface ---------------------------------------------------------------------- 127.0.0.1 127.0.0.1 5 1 0 lo0 ---------------------------------------------------------------------- value = 77 = 0x4d = `M'</tt><b></a></b></pre></dl><dd><p class="Body"><a name="86629"> </a>In the output shown above, the route entry for 147.11.44.0 shows that the flags <b class="symbol_UC">RTF_CLONING</b> (0x100) and <b class="symbol_UC">RTF_UP</b> (0x001, signifying that the route is available for use) are set. This route entry is set when the Ethernet network device "ei0" is initialized. This is a network route and the network mask associated with this route is <b class="symbol_UC">0xFFFFFF00</b>.</p></dl><dl class="margin"><b class="HU-bullet"><li><a name="86631"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Editing the Routing Table</font></li></b></dl><dl class="margin"><dd><p class="Body"><a name="86632"> </a>VxWorks includes a number of functions<b> </b>that you can use to edit the routing table. These functions are as follows:<b><sup><a href="#foot"><b class="FootnoteMarker">3</b></a></sup></b></p></dl><dl class="margin"><dd><div class="Item"><a name="86637"> </a><b class="routine"><i class="routine">routeAdd</i></b><b>( )</b></div><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="86638"> </a>Adds a route to the routing table. </div><br></dl></dl><dd><div class="Item"><a name="86640"> </a><b class="routine"><i class="routine">routeNetAdd</i></b><b>( )</b></div><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="86641"> </a>This function is the same as <b class="routine"><i class="routine">routeAdd</i></b><b>( )</b> except that the destination address is assumed to be a network. This is useful for adding a route to a sub-network that is not on the same physical network as the local network.</div><br></dl></dl><dd><div class="Item"><a name="86643"> </a><b class="routine"><i class="routine">routeDelete</i></b><b>( )</b></div><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="86644"> </a>Deletes a route from the routing table. </div><br></dl></dl><dd><div class="Item"><a name="86646"> </a><b></b><b class="routine"><i class="routine">mRouteAdd</i></b><b>( )</b> </div><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="86648"> </a>Adds routes differentiated by masks and service quality. </div><br></dl></dl><dd><div class="Item"><a name="86650"> </a><b></b><b class="routine"><i class="routine">mRouteDelete</i></b><b>( )</b> </div><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="86651"> </a>Deletes routes differentiated by masks and service quality. </div><br></dl></dl></dl></dl><dl class="margin"><dd><p class="table" callout><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td valign="top" width="40"><br><img border="0" alt="*" src="icons/note.gif"></td><td><hr><div class="CalloutCell"><a name="93019"><b class="symbol_UC"><font face="Helvetica, sans-serif" size="-1" class="sans">NOTE: </font></b></a>The functions <b class="routine"><i class="routine">routeAdd</i></b><b>( )</b>and <b class="routine"><i class="routine">routeDelete</i></b><b>( )</b> implicitly derive the netmask from the given destination and gateway address. Please refer to the manual pages for the function calls mentioned above.</div></td></tr><tr valign="top"><td></td><td><hr></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p callout><dl class="margin"><dd><p class="Body"><a name="86661"> </a>To add gateways to the VxWorks network routing tables, use <b class="routine"><i class="routine">routeAdd</i></b><b>( )</b> or <b class="routine"><i class="routine">mRouteAdd</i></b><b>( )</b>. For example, to use <b class="routine"><i class="routine">routeAdd</i></b><b>(</b> <b>)</b>:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86662">/* routeAdd ("<i class="textVariable">destinationAddr</i>", "<i class="textVariable">gatewayAddr</i>") */ /* To send to network 161.27.0.0 use 150.12.0.2 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -