/// Bootp Header (DHCP is transported by BOOTP/UDP/IP) struct netBootpHeader { unsigned char op; ///< Message op-code / message type unsigned char htype; ///< Hardware address type (Ethernet=1) unsigned char hlen; ///< Hardware address length (Ethernet=6 byte MAC addr) unsigned char hops; ///< hop count (client set to zero) unsigned int xid; ///< Transaction ID (randomly chosen by client, must remain same) unsigned short secs; ///< Seconds elapsed since DHCP negotiation began (filled by client) unsigned short flags; ///< Flags unsigned int ciaddr; ///< Client IP address (filled only if already bound, renewing, or rebinding) unsigned int yiaddr; ///< 'Your' IP address (client) unsigned int siaddr; ///< Server IP address unsigned int giaddr; ///< Gateway IP address unsigned char chaddr[16]; ///< Client Hardware Address unsigned char sname[64]; ///< Server Host Name unsigned char file[128]; ///< Boot file name (null-term string) } __attribute__ ((packed)); #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 /// DHCP Header struct netDhcpHeader { struct netBootpHeader bootp; ///< BOOTP header unsigned int cookie; ///< magic cookie value unsigned char options[]; ///< DHCP options }__attribute__ ((packed)); #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_CLIENT_IDENT 61 ///< DHCP Client identifer #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. /* 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. */ int dhcpIn(char*, int, int, struct netDhcpHeader*); /* Request DHCP assigned network parameters. This function begins the DHCP process. The remainder of operations are handled in dhcpIn(). */ int dhcpRequest(char*, int); /* Periodic DHCP maintenance. This function is to be called once per second and will expire the DHCP lease. */ void dhcpTimer(void); /* Get a DHCP option from the option list. \param options is a pointer to the options field of a DHCP packet. \param optcode is the desired option number to retrieve. \param optlen is the maximum data length that should be retrieved (less data will be retrieved if option is shorter). \param optvalptr is a pointer to where the option value will be stored. \return actual length of the option data, as stored in the options list. */ unsigned char dhcpGetOption(unsigned char* options, unsigned char optcode, unsigned char optlen, void* optvalptr); /* Set a DHCP option in the option list. \param options is a pointer to the options field of a DHCP packet. \param optcode is the option number to write. \param optlen is the data length of the option value. \param optvalptr is a pointer to the option data to be read. \return pointer to write location of the next option. */ unsigned char* dhcpSetOption(unsigned char* options, unsigned char optcode, unsigned char optlen, void* optvalptr); /* Print diagnotic information about BOOTP/DHCP packet. */ void dhcpPrintHeader(struct netDhcpHeader* packet);