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

DHCP Protocol Library (dhcp.c)
[Network Library]


Detailed Description

 #include "net/dhcp.h" 
Description
This library provides a limited implementation of DHCP (Dynamic Host Configuration Protocol) as described in RFC2131. DHCP allows a network device to automatically obtain an IP address and other network configuration settings from a DHCP server.
Note:
This code is currently below version 1.0, and therefore is considered to be lacking in some functionality or documentation, or may not be fully tested. Nonetheless, you can expect most functions to work.


Data Structures

struct  netBootpHeader
 Bootp Header (DHCP is transported by BOOTP/UDP/IP). More...
struct  netDhcpHeader
 DHCP Header. More...

Defines

#define BOOTP_HEADER_LEN   236
 length of BOOTP header not including options
#define BOOTP_OP_BOOTREQUEST   1
 BOOTP Request operation (message from client to server).
#define BOOTP_OP_BOOTREPLY   2
 BOOTP Reply operation (message from server to client).
#define BOOTP_HTYPE_ETHERNET   1
#define BOOTP_HLEN_ETHERNET   6
#define DHCP_HEADER_LEN   240
 length of DHCP header not including options
#define DHCP_UDP_SERVER_PORT   67
 UDP port where DHCP requests should be sent.
#define DHCP_UDP_CLIENT_PORT   68
 UDP port clients will receive DHCP replies.
#define DHCP_OPT_PAD   0
 token padding value (make be skipped)
#define DHCP_OPT_NETMASK   1
 subnet mask client should use (4 byte mask)
#define DHCP_OPT_ROUTERS   3
 routers client should use (IP addr list)
#define DHCP_OPT_TIMESERVERS   4
 time servers client should use (IP addr list)
#define DHCP_OPT_NAMESERVERS   5
 name servers client should use (IP addr list)
#define DHCP_OPT_DNSSERVERS   6
 DNS servers client should use (IP addr list).
#define DHCP_OPT_HOSTNAME   12
 host name client should use (string)
#define DHCP_OPT_DOMAINNAME   15
 domain name client should use (string)
#define DHCP_OPT_REQUESTEDIP   50
 IP address requested by client (IP address).
#define DHCP_OPT_LEASETIME   51
 DHCP Lease Time (uint32 seconds).
#define DHCP_OPT_DHCPMSGTYPE   53
 DHCP message type (1 byte).
#define DHCP_OPT_SERVERID   54
 Server Identifier (IP address).
#define DHCP_OPT_PARAMREQLIST   55
 Paramerter Request List (n OPT codes).
#define DHCP_OPT_RENEWALTIME   58
 DHCP Lease Renewal Time (uint32 seconds).
#define DHCP_OPT_REBINDTIME   59
 DHCP Lease Rebinding Time (uint32 seconds).
#define DHCP_OPT_END   255
 token end value (marks end of options list)
#define DHCP_MSG_DHCPDISCOVER   1
 DISCOVER is broadcast by client to solicit OFFER from any/all DHCP servers.
#define DHCP_MSG_DHCPOFFER   2
 OFFER(s) are made to client by server to offer IP address and config info.
#define DHCP_MSG_DHCPREQUEST   3
 REQUEST is made my client in response to best/favorite OFFER message.
#define DHCP_MSG_DHCPDECLINE   4
 DECLINE may be sent by client to server to indicate IP already in use.
#define DHCP_MSG_DHCPACK   5
 ACK is sent to client by server in confirmation of REQUEST, contains config and IP.
#define DHCP_MSG_DHCPNAK   6
 NAK is sent to client by server to indicate problem with REQUEST.
#define DHCP_MSG_DHCPRELEASE   7
 RELEASE is sent by client to server to relinquish DHCP lease on IP address, etc.
#define DHCP_MSG_DHCPINFORM   8
 INFORM is sent by client to server to request config info, IP address configured locally.
#define GNUC_PACKED   __attribute__((packed))
 DHCP Header.

Functions

void dhcpInit (void)
void dhcpIn (unsigned int len, struct netDhcpHeader *packet)
void dhcpRequest (void)
void dhcpRelease (void)
void dhcpTimer (void)
uint8_t dhcpGetOption (uint8_t *options, uint8_t optcode, uint8_t optlen, void *optvalptr)
uint8_t * dhcpSetOption (uint8_t *options, uint8_t optcode, uint8_t optlen, void *optvalptr)
void dhcpPrintHeader (struct netDhcpHeader *packet)

Variables

netBootpHeader GNUC_PACKED
 Bootp Header (DHCP is transported by BOOTP/UDP/IP).


Function Documentation

uint8_t dhcpGetOption uint8_t *  options,
uint8_t  optcode,
uint8_t  optlen,
void *  optvalptr
 

Get a DHCP option from the option list.

Parameters:
options is a pointer to the options field of a DHCP packet.
optcode is the desired option number to retrieve.
optlen is the maximum data length that should be retrieved (less data will be retrieved if option is shorter).
optvalptr is a pointer to where the option value will be stored.
Returns:
actual length of the option data, as stored in the options list.

Definition at line 212 of file dhcp.c.

void dhcpIn unsigned int  len,
struct netDhcpHeader packet
 

Processes incoming DHCP packets from UDP port 68. This function is to be called by the stack when a DHCP packet arrives over the network. The DHCP packet will be parsed, handled, and a response will be generated and sent if needed. When the DHCP process completes, the IP addressing will be automatically updated.

Definition at line 42 of file dhcp.c.

void dhcpInit void   ) 
 

Initialize DHCP system. Prepares DHCP for use and initializes lease time to zero.

Definition at line 30 of file dhcp.c.

void dhcpPrintHeader struct netDhcpHeader packet  ) 
 

Print diagnotic information about BOOTP/DHCP packet.

void dhcpRelease void   ) 
 

Release DHCP lease and assigned network parameters. This function releases the DHCP assigned address and allows the DHCP server to reallocate it.

Definition at line 158 of file dhcp.c.

void dhcpRequest void   ) 
 

Request DHCP assigned network parameters. This function begins the DHCP process. The remainder of operations are handled in dhcpIn().

Definition at line 123 of file dhcp.c.

uint8_t* dhcpSetOption uint8_t *  options,
uint8_t  optcode,
uint8_t  optlen,
void *  optvalptr
 

Set a DHCP option in the option list.

Parameters:
options is a pointer to the options field of a DHCP packet.
optcode is the option number to write.
optlen is the data length of the option value.
optvalptr is a pointer to the option data to be read.
Returns:
pointer to write location of the next option.

Definition at line 253 of file dhcp.c.

void dhcpTimer void   ) 
 

Periodic DHCP maintenance. This function is to be called once per second and will expire the DHCP lease.

Definition at line 203 of file dhcp.c.


Generated on Sun Oct 29 03:41:09 2006 for Procyon AVRlib by  doxygen 1.4.2