Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages | Examples

dhcpc.c File Reference


Detailed Description

DHCP client.

 *
 * $Log: dhcpc.c,v $
 * Revision 1.22  2006/08/01 07:38:41  haraldkipp
 * DHCP client failed because of alignment errors. Removed the dispensable
 * 'packed' attribute from the dyn_cfg structure.
 *
 * Revision 1.21  2006/01/23 19:52:10  haraldkipp
 * Added required typecasts before left shift.
 *
 * Revision 1.20  2006/01/23 17:35:54  haraldkipp
 * BOOTP and DYNCFG structures must be packed.
 * Fixed memory alignment bug, which retrieved wrong values from DHCP options.
 *
 * Revision 1.19  2005/08/02 17:47:04  haraldkipp
 * Major API documentation update.
 *
 * Revision 1.18  2005/04/05 17:44:57  haraldkipp
 * Made stack space configurable.
 *
 * Revision 1.17  2005/03/28 18:26:59  mrjones4u
 * Fixed non-release bug in DCHP client
 *
 * Revision 1.16  2005/02/03 14:33:56  haraldkipp
 * Several bug fixes and enhancements. The most important fix will
 * avoid hanging, when Ethernut is reset while ICMP pings are
 * received. A large number of changes make the client to follow
 * RFC 2131 more closely, like maintaining renewal and rebind time.
 * Two new API calls, NutDhcpStatus() and NutDhcpError(), allow
 * to query the current status of the DHCP client. The previously
 * introduced API call NutDhcpIsConfigured() has been marked
 * deprecated. Another problem was with timeout, because the client
 * continued negotiation with the server after the timeout time
 * given in the API called elapsed. Now all internal timeouts are
 * adjusted to the API timeout. Furthermore the previous version
 * let the client continue on fatal errors like UDP receive or UDP
 * broadcast failures. Now the client stops on such errors and
 * informs the caller. Finally the documentation has been enhanced.
 *
 * Revision 1.15  2004/12/31 10:51:40  drsung
 * Bugfixes from Michel Hendriks applied:
 * Allocate empty dyncfg's to prevent freeing twice of domain/hostname
 * Clear pointer after ReleaseDynCfg to prevent freeing twice
 * Make sure SelectOffer is never called with 0 offers
 * When falling back from rebooting to selecting, clear
 * the received ip address so NutDhcpIfConfig does not
 * assume it has been configured properly
 *
 * Revision 1.14  2004/04/15 07:16:47  drsung
 * Now it works... :-/
 *
 * Revision 1.13  2004/04/15 07:11:50  drsung
 * Added hostname support to NutDHCPDiscover
 *
 * Revision 1.12  2004/03/18 11:24:01  haraldkipp
 * Deprecated functions removed
 *
 * Revision 1.11  2004/03/03 17:53:28  drsung
 * Support for new field 'hostname' in structure confos added.
 *
 * Revision 1.10  2004/02/25 16:34:32  haraldkipp
 * New API added to relinguish the DHCP lease. Collecting more
 * than one offer is now disabled, if the application sets timeout
 * below three times of MAX_DHCP_WAIT (5 seconds). The lease renewal
 * will now start when 3/4 has elapsed, opposed to 1/2 used previously.
 * Finally the DHCP thread will sleep as long as possible, while the
 * previous version woke up every ten seconds.
 *
 * Revision 1.9  2004/02/02 18:54:43  drsung
 * gateway ip address was not set, if static network configuration from EEPROM is used.
 *
 * Revision 1.8  2004/01/14 17:50:41  drsung
 * Fix for Win2k DHCP server applied. Thanks to Damian Slee
 *
 * Revision 1.7  2003/11/03 16:22:59  haraldkipp
 * Renewal disabled if lease time is set to zero
 *
 * Revision 1.6  2003/10/13 10:18:08  haraldkipp
 * Using new seconds counter
 *
 * Revision 1.5  2003/08/07 09:09:08  haraldkipp
 * Redesign to follow RFC 2131 more closely.
 *
 * Revision 1.4  2003/07/20 18:25:40  haraldkipp
 * Support secondary DNS.
 *
 * Revision 1.3  2003/07/17 09:44:14  haraldkipp
 * Removed default MAC address and let the caller have a second chance.
 *
 * Revision 1.2  2003/05/15 14:25:38  haraldkipp
 * Some DHCP servers discard discover telegrams.
 * Thanks to Tomohiro Haraikawa.
 *
 * Revision 1.1.1.1  2003/05/09 14:41:57  haraldkipp
 * Initial using 3.2.1
 *
 * 


DHCP Client Configuration

The Nut/OS Configurator may be used to override the default values.

#define DHCP_SERVERPORT   67
 UDP port of DHCP server.
#define DHCP_CLIENTPORT   68
 UDP port of DHCP client.
#define MAX_DHCP_MSGSIZE   576
 Maximum DHCP message size we can accept.
#define MIN_DHCP_MSGSIZE   300
 Minimum DHCP message length.
#define MAX_DHCP_BUFSIZE   1728
 Maximum UDP buffer size used by the DHCP client.
#define MIN_DHCP_WAIT   4000
 Minimum number of milliseconds to wait for a response.
#define MAX_DHCP_WAIT   64000
 Maximum number of milliseconds to wait for a response.
#define MAX_DCHP_RETRIES   3
 Maximum number of request retries.
#define MAX_DCHP_RELEASE_RETRIES   0
 Maximum number of release retries.
#define DHCP_DEFAULT_LEASE   43200
 Default lease time in seconds.
#define MAX_DHCP_NAPTIME   4294967
 Maximum sleep time in seconds.
#define NUT_THREAD_DHCPSTACK   512
 Stack size of the DHCP client thread.

DHCP Message Types

See RFC 2131.

#define DHCP_DISCOVER   1
 Client broadcast to locate available servers.
#define DHCP_OFFER   2
 Server to client in response to DHCP_DISCOVER.
#define DHCP_REQUEST   3
 Client message to servers.
#define DHCP_DECLINE   4
 Client to server indicating network address is already in use.
#define DHCP_ACK   5
 Server to client with configuration parameters.
#define DHCP_NAK   6
 Server to client indicating client's notion of network address is incorrect.
#define DHCP_RELEASE   7
 Client to server relinquishing network address and cancelling remaining lease.
#define DHCP_INFORM   8
 Client to server, asking only for local configuration parameters.

DHCP Options

Nut/Net recognizes a subset of options defined in RFC 2132.

#define DHCPOPT_PAD   0
 DHCP pad option.
#define DHCPOPT_NETMASK   1
 DHCP subnet mask option.
#define DHCPOPT_GATEWAY   3
 DHCP router option.
#define DHCPOPT_DNS   6
 DHCP domain name server option.
#define DHCPOPT_HOSTNAME   12
 DHCP host name option.
#define DHCPOPT_DOMAIN   15
 DHCP domain name option.
#define DHCPOPT_BROADCAST   28
 DHCP broadcast address option.
#define DHCPOPT_REQESTIP   50
 DHCP requested IP address option.
#define DHCPOPT_LEASETIME   51
 DHCP IP address lease time option.
#define DHCPOPT_MSGTYPE   53
 DHCP message type option.
#define DHCPOPT_SID   54
 DHCP server identifier option.
#define DHCPOPT_PARAMREQUEST   55
 DHCP parameter request list option.
#define DHCPOPT_MAXMSGSIZE   57
 Maximum DHCP message size option.
#define DHCPOPT_RENEWALTIME   58
 DHCP renewal time option.
#define DHCPOPT_REBINDTIME   59
 DHCP rebinding time option.
#define DHCPOPT_END   255
 DHCP end option.

Typedefs

typedef bootp BOOTP
 BOOTP message structure type.
typedef dyn_cfg DYNCFG
 Dynamic configuration structure type.

Functions

void NutDhcpClient (void *arg)
 DHCP client thread.
int NutDhcpIfConfig (CONST char *name, u_char *mac, u_long timeout)
 Automatically configure an Ethernet network interface.
int NutDhcpRelease (CONST char *name, u_long timeout)
 Relinguish our DHCP lease.
int NutDhcpInform (CONST char *name, u_long timeout)
 Inform DHCP about an allocated address.
int NutDhcpStatus (CONST char *name)
 Return DHCP client status.
int NutDhcpError (CONST char *name)
 Return DHCP error code.
int NutDhcpIsConfigured (void)
 Check if DHCP has configured our interface.


© 2000-2006 by egnite Software GmbH - visit http://www.ethernut.de/