net-common-dhcp.html
来自「ecos3.0 beta 的官方文档,html格式」· HTML 代码 · 共 264 行
HTML
264 行
<!-- Copyright (C) 2009 Free Software Foundation, 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. -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>DHCP</TITLE
><meta name="MSSmartTagsPreventParsing" content="TRUE">
<META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="eCos Reference Manual"
HREF="ecos-ref.html"><LINK
REL="UP"
TITLE="Support Features"
HREF="net-common-support.html"><LINK
REL="PREVIOUS"
TITLE="Support Features"
HREF="net-common-support.html"><LINK
REL="NEXT"
TITLE="TCP/IP Library Reference"
HREF="tcpip-library-reference.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>eCos Reference Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="net-common-support.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 41. Support Features</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="tcpip-library-reference.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="NET-COMMON-DHCP"
>DHCP</A
></H1
><P
>This API publishes a routine to maintain DHCP state, and a
semaphore that is signalled when a lease requires attention: this
is your clue to call the aforementioned routine.</P
><P
>The intent with this API is that a simple DHCP client thread,
which maintains the state of the interfaces, can go as follows:
(after <CODE
CLASS="FUNCTION"
>init_all_network_interfaces()</CODE
> is
called from elsewhere)</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>while ( 1 ) {
while ( 1 ) {
cyg_semaphore_wait( &dhcp_needs_attention );
if ( ! dhcp_bind() ) // a lease expired
break; // If we need to re-bind
}
dhcp_halt(); // tear everything down
init_all_network_interfaces(); // re-initialize
}</PRE
></TD
></TR
></TABLE
><P
>and if the application does not want to suffer the overhead
of a separate thread and its stack for this, this functionality
can be placed in the app’s server loop in an obvious fashion.
That is the goal of breaking out these internal elements. For example,
some server might be arranged to poll DHCP from time to time like
this:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>while ( 1 ) {
init_all_network_interfaces();
open-my-listen-sockets();
while ( 1 ) {
serve-one-request();
// sleeps if no connections, but not forever;
// so this loop is polled a few times a minute...
if ( cyg_semaphore_trywait( &dhcp_needs_attention )) {
if ( ! dhcp_bind() ) {
close-my-listen-sockets();
dhcp_halt();
break;
}
}
}
}</PRE
></TD
></TR
></TABLE
><P
>If the configuration option CYGOPT_NET_DHCP_DHCP_THREAD
is defined, then eCos provides a thread as described initially.
Independent of this option, initialization of the interfaces still
occurs in <CODE
CLASS="FUNCTION"
>init_all_network_interfaces()</CODE
> and
your startup code can call that. It will start the DHCP management
thread if configured. If a lease fails to be renewed, the management
thread will shut down all interfaces and attempt to initialize all
the interfaces again from scratch. This may cause chaos in the
app, which is why managing the DHCP state in an application aware
thread is actually better, just far less convenient for testing.</P
><P
>If the configuration option CYGOPT_NET_DHCP_OPTION_HOST_NAME
is defined, then the TAG_HOST_NAME DHCP option will be included
in any DHCP lease requests. The text for the hostname is set by
calling <CODE
CLASS="FUNCTION"
>dhcp_set_hostname()</CODE
>. Any DHCP lease requests
made prior to calling <CODE
CLASS="FUNCTION"
>dhcp_set_hostname()</CODE
> will not
include the TAG_HOST_NAME DHCP option. The configuration option
CYGNUM_NET_DHCP_OPTION_HOST_NAME_LEN controls the maximum length allowed
for the hostname. This permits the hostname text to be determined at
run-time. Setting the hostname to the empty string will have the effect
of disabling the TAG_HOST_NAME DHCP option.</P
><P
>If the configuration option CYGOPT_NET_DHCP_OPTION_DHCP_CLIENTID_MAC
is defined, then the TAG_DHCP_CLIENTID DHCP option will be included
in any DHCP lease requests. The client ID used will be the current
MAC address of the network interface.</P
><P
>The option CYGOPT_NET_DHCP_PARM_REQ_LIST_ADDITIONAL allows
additional DHCP options to be added to the request sent to the DHCP
server. This option should be set to a comma separated list of options.</P
><P
> The option CYGOPT_NET_DHCP_PARM_REQ_LIST_REPLACE is similar to
CYGOPT_NET_DHCP_PARM_REQ_LIST_ADDITIONAL but in this case it
completely replaces the default list of options with the configured
set of comma separated options.</P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="net-common-support.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ecos-ref.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="tcpip-library-reference.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Support Features</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="net-common-support.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>TCP/IP Library Reference</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?