DHCP client. More...
#include <cfg/os.h>
#include <sys/thread.h>
#include <sys/event.h>
#include <sys/timer.h>
#include <sys/confnet.h>
#include <sys/confos.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <memdebug.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netdb.h>
#include <net/route.h>
#include <sys/socket.h>
#include <pro/dhcp.h>
#include <net/netdebug.h>
Go to the source code of this file.
Data Structures | |
struct | bootp |
BOOTP message structure. More... | |
struct | dyn_cfg |
Dynamic configuration structure. More... | |
Typedefs | |
typedef struct bootp | BOOTP |
BOOTP message structure type. | |
typedef struct dyn_cfg | DYNCFG |
Dynamic configuration structure type. | |
Functions | |
void | DhcpStateDebug (uint_fast8_t n, uint_fast8_t s, int li, int lt, ureg_t retries) |
void | NutDhcpClient (void *arg) |
DHCP client thread. | |
int | NutDhcpIfConfig (CONST char *name, uint8_t *mac, uint32_t timeout) |
Automatically configure an Ethernet network interface. | |
int | NutDhcpRelease (CONST char *name, uint32_t timeout) |
Relinguish our DHCP lease. | |
int | NutDhcpInform (CONST char *name, uint32_t 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. | |
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 | |
#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 | |
#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. |
DHCP client.
* * $Log$ * Revision 1.27 2009/02/13 14:52:05 haraldkipp * Include memdebug.h for heap management debugging support. * * Revision 1.26 2009/02/06 15:37:40 haraldkipp * Added stack space multiplier and addend. Adjusted stack space. * * Revision 1.25 2009/01/17 11:26:52 haraldkipp * Getting rid of two remaining BSD types in favor of stdint. * Replaced 'u_int' by 'unsinged int' and 'uptr_t' by 'uintptr_t'. * * Revision 1.24 2008/10/05 16:46:15 haraldkipp * Added missing attributes 'packed'. This may fix a problem with * different ARM compiler optimization settings. * * Revision 1.23 2008/08/11 07:00:34 haraldkipp * BSD types replaced by stdint types (feature request #1282721). * * 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 * *
Definition in file dhcpc.c.