📄 net-common-configuring-ip-addresses.html
字号:
<!-- Copyright (C) 2003 Red Hat, Inc. --><!-- This material may be distributed only subject to the terms --><!-- and conditions set forth in the Open Publication License, v1.0 --><!-- or later (the latest version is presently available at --><!-- http://www.opencontent.org/openpub/). --><!-- Distribution of the work or derivative of the work in any --><!-- standard (paper) book form is prohibited unless prior --><!-- permission is obtained from the copyright holder. --><HTML><HEAD><TITLE>Configuring IP Addresses</TITLE><meta name="MSSmartTagsPreventParsing" content="TRUE"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="eCos Reference Manual"HREF="ecos-ref.html"><LINKREL="UP"TITLE="TCP/IP Stack Support for eCos"HREF="net-common-tcpip.html"><LINKREL="PREVIOUS"TITLE="Sample Code"HREF="net-common-sample-code.html"><LINKREL="NEXT"TITLE="Tests and Demonstrations"HREF="net-common-tests-and-demonstrations.html"></HEAD><BODYCLASS="CHAPTER"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">eCos Reference Manual</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="net-common-sample-code.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="net-common-tests-and-demonstrations.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="CHAPTER"><H1><ANAME="NET-COMMON-CONFIGURING-IP-ADDRESSES">Chapter 35. Configuring IP Addresses</H1><P>Each interface (“eth0” and “eth1”)has independent configuration of its setup. Each can be set upmanually (in which case you must write code to do this), or by using<SPANCLASS="ACRONYM">BOOTP/DHCP</SPAN>,or explicitly, with configured values. If additionalinterfaces are added, these must be configured manually.</P><P>The configurable values are: </P><P></P><UL><LI><P>IP address</P></LI><LI><P>netmask</P></LI><LI><P>broadcast address</P></LI><LI><P>gateway/router</P></LI><LI><P>server address.</P></LI></UL><P>Server address is the DHCP server if applicable, but in addition,many test cases use it as “the machine to talk to” inwhatever manner the test exercises the protocol stack.</P><P>The initialization is invoked by calling the C routine <TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">void <TTCLASS="FUNCTION">init_all_network_interfaces</TT>(void);</PRE></TD></TR></TABLE></P><P>Additionally, if the system is configured to support IPv6 then eachinterface may have an address assigned which is a composite of a 64 bitprefix and the 32 bit IPv4 address for that interface.The prefix is controlled by the CDL setting CYGHWR_NET_DRIVER_ETH0_IPV6_PREFIX for “eth0”, etc.This is a CDL booldata type, allowing this address to be suppressed ifnot desired.</P><P>Refer to the test cases,<TTCLASS="FILENAME">…/packages/net/common/<TTCLASS="REPLACEABLE"><I>VERSION</I></TT>/tests/ftp_test.c</TT>for example usage, and the source files in<TTCLASS="FILENAME">…/packages/net/common/<TTCLASS="REPLACEABLE"><I>VERSION</I></TT>/src/bootp_support.c</TT>and<TTCLASS="FILENAME">network_support.c</TT>to see what that call does.</P><P>This assumes that the MAC address (also known as <SPANCLASS="ACRONYM">ESA</SPAN> or Ethernet Station Address)is already defined in theserial EEPROM or however the particular target implements this;support for setting the MAC address is hardware dependent.</P><P>DHCP support is active by default, and there are configurationoptions to control it. Firstly, in the top level of the“Networking” configurationtree, “Use full DHCP instead of BOOTP” enablesDHCP, and it contains an option to have the system provide a threadto renew DHCP leases and manage lease expiry. Secondly, the individualinterfaces “eth0” and “eth1” eachhave new options within the “Use BOOTP/DHCP toinitialize ‘<SPANCLASS="emphasis"><ICLASS="EMPHASIS">ethX</I></SPAN>’” toselect whether to use DHCP rather than BOOTP.</P><P>Note that you are completely at liberty to ignore this startup code and itsconfiguration in building your application.<TTCLASS="FUNCTION">init_all_network_interfaces()</TT>is provided for three main purposes:<P></P><UL><LI><P>For use by Red Hat's own test programs.</P></LI><LI><P>As an easy “get you going” utility fornewcomers to <SPANCLASS="PRODUCTNAME">eCos</SPAN>.</P></LI><LI><P>As readable example code from which further developmentmight start.</P></LI></UL></P><P>If your application has different requirements for bringing up available network interfaces, setting up routes, determining IP addressesand the like from the defaults that the example code provides, you canwrite your own initialization code to use whatever sequence of<TTCLASS="FUNCTION">ioctl()</TT> functioncalls carries out the desired setup. Analogously, in larger systems,a sequence of “ifconfig” invocations is used; these mostlymap to <TTCLASS="FUNCTION">ioctl()</TT> calls to manipulate the state ofthe interface in question.</P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="net-common-sample-code.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-ref.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="net-common-tests-and-demonstrations.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Sample Code</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="net-common-tcpip.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Tests and Demonstrations</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -