DHCP Test Application
Overview
This application demonstrates advanced DHCP (Dynamic Host Configuration Protocol) client functionality by providing direct control and monitoring of DHCP services. Unlike simple applications that use the GetDhcpAddress() function, this example creates and manages a DHCP object directly, giving you fine-grained control over the DHCP process.
Purpose
The application serves both educational and testing purposes:
- Educational: Shows internal DHCP workings by displaying UDP packet information and DHCP variables
- Testing: Provides interactive control over DHCP services for debugging and validation
- Demonstration: Illustrates how to access and manipulate DHCP object properties programmatically
Key Features
DHCP State Monitoring
The application displays comprehensive DHCP state information including:
- DHCP_NOTSTARTED - System not initialized
- DHCP_DISCOVER - Discovering DHCP servers
- DHCP_OFFER - Responding to server offers
- DHCP_ACK - Acknowledging offers
- DHCP_INIT - Reinitializing
- DHCP_CMPL - Valid lease obtained
- DHCP_RENEW - Lease renewal in progress
- DHCP_REBIND - Rebinding after failed renewal
- DHCP_RELEASE - Releasing lease
- SBOOTP_TRANSMITTING/DONE - BOOTP fallback states
- DHCP_FAILED - Failed to obtain lease
Interactive Menu System
The application provides a command-line interface with the following options:
- **'t'** - Display remaining lease time and timing information
- **'s'** - Show detailed DHCP status (debug mode only)
- **'v'** - Validate current DHCP lease
- **'1'** - Set system timer to 5 seconds before renew time
- **'2'** - Set system timer to 5 seconds before rebind time
- **'3'** - Set system timer to 5 seconds before lease expiration
- **'4'** - Force DHCP renewal
- **'5'** - Force DHCP rebinding
- **'a'** - Show ARP table
Advanced Timing Control
The application allows manipulation of DHCP timing for testing scenarios:
- Simulate approaching renewal deadlines
- Test rebinding behavior
- Verify lease expiration handling
- Force state transitions for validation
Technical Implementation
Architecture
- Creates a global DHCP object variable
- Uses semaphore monitoring for DHCP completion
- Accesses private class variables for detailed debugging (educational purposes only)
- Integrates with the NetBurner network stack
Debug Information
When debug mode is enabled, the application displays:
- UDP packet details
- Internal DHCP variables
- Low-level state information
- Timing and lease parameters
Setup and Configuration
Debug Mode Setup
To enable detailed debugging information:
- Edit
\nburn\system\dhcpc.cpp
- Uncomment the line:
#define DHCP_DEBUG 1
- Rebuild the application
- Warning
- Comment out
#define DHCP_DEBUG 1 when finished with testing. This should not be enabled in production applications.
Build Configuration
- The application uses conditional compilation with
DHCPTEST_DEBUG
- System diagnostics are enabled for development (consider removing for production)
- Serial output is directed to UART0 by default (viewable with MTTTY)
Usage
- Flash the application to your NetBurner device
- Connect via serial terminal (MTTTY recommended)
- The application will automatically start DHCP and display the menu
- Use the menu commands to interact with and test DHCP functionality
- Monitor the output for state changes and debugging information
Educational Value
This application is designed to teach:
- DHCP protocol states and transitions
- Lease timing and renewal processes
- Error handling and fallback mechanisms
- Network debugging techniques
- Embedded network programming patterns
For comprehensive DHCP protocol information, refer to RFC 2131.
Development Notes
- Application name appears as "DHCPTest" in IPSetup
- Uses NetBurner-specific APIs and classes
- Demonstrates both high-level and low-level DHCP access patterns
- Shows proper integration with the NetBurner timeout management system
Warning
This example accesses private class variables of the DHCP object for educational purposes. This approach is NOT recommended for production applications and should only be used for learning and debugging.
Dependencies
- NetBurner RTOS and network stack
- Serial communication support
- DHCP client library
- ARP functionality modify the system timer, and display dhcp status.