NetBurner 3.5.6
PDF Version
DHCP Client - Change IP Address Via Webpage

DHCP Client - Change IP Address Via Webpage

This application demonstrates how to view and change IPv4 IP settings between DHCP and static configurations using both a web interface and serial console interface.

Overview

The application allows users to:

  • View current runtime IP settings and DHCP status
  • Switch between DHCP and static IP address modes
  • Configure IP settings through a web-based interface
  • Monitor network interface status and configuration
  • Handle multiple network interfaces (Ethernet, WiFi)

Key Features

Web Interface

  • Interactive Configuration: Web-based form (changeip.html) for modifying IP settings
  • Real-time Status: Display current IP addresses, DHCP state, and interface information
  • Automatic Redirection: After configuration changes, the web interface automatically redirects to the new IP address
  • Multi-interface Support: Handles multiple network interfaces simultaneously

Serial Console Interface

  • Runtime Settings Display: View current IPv4 settings for all interfaces
  • DHCP State Monitoring: Real-time DHCP client status information
  • Manual Mode Switching: Change between DHCP and static modes via console commands
  • Network Link Status: Monitor physical network connection status

DHCP Client Features

  • Full DHCP State Machine: Complete implementation with all DHCP states
  • DHCP with Fallback: Option to fall back to static IP if DHCP fails
  • Lease Management: Automatic DHCP lease renewal and rebinding
  • BOOTP Support: Fallback to BOOTP protocol when DHCP is unavailable

File Structure

  • main.cpp: Main application with serial console interface and core networking logic
  • web.cpp: Web server implementation with form handling and IP configuration management
  • ip_util.h: Utility functions for IP address display and network operations

Configuration Modes

DHCP Mode

  • Automatically obtains IP address from DHCP server
  • Handles lease renewal and network changes
  • Supports DHCP with fallback to static configuration

Static Mode

  • Uses pre-configured static IP settings
  • Settings stored in configuration flash memory
  • Can be configured via web interface or application code

Runtime vs. Persistent Settings

  • Runtime Changes: Immediate effect without reboot
  • Persistent Changes: Saved to flash memory and survive reboots
  • Configuration Storage: Uses built-in configuration server for settings persistence

Usage Instructions

Changing from DHCP to Static:

  1. Access the web interface or serial console
  2. Read current static settings from configuration record
  3. Set address mode to "Static"
  4. Save configuration to flash memory
  5. Choose to reboot or apply runtime settings immediately

Changing from Static to DHCP:

  1. Access the web interface or serial console
  2. Set address mode to "DHCP" or "DHCP w Fallback"
  3. Save configuration to flash memory
  4. Choose to reboot or restart DHCP client immediately

Serial Console Commands:

  • 1: Display current runtime IPv4 settings
  • 2: Change to static address mode (without reboot)
  • 3: Change to DHCP address mode (without reboot)

Technical Implementation

DHCP State Machine

The application implements a complete DHCP client state machine with the following states:

  • SDHCP_NOTSTARTED: System not initialized
  • SDHCP_DISCOVER: Discovering DHCP servers
  • SDHCP_OFFER: Processing server offers
  • SDHCP_ACK: Acknowledging lease
  • SDHCP_CMPL: DHCP lease complete
  • SDHCP_RENEW: Renewing lease
  • SDHCP_REBIND: Rebinding after renewal failure
  • SDHCP_RELEASE: Releasing lease
  • SDHCP_FAILED: DHCP process failed

Web Server Integration

  • HTTP Server: Built-in web server on port 80
  • Form Processing: POST request handling for configuration changes
  • Dynamic Content: Real-time display of network interface status
  • Redirect Logic: Automatic redirection after IP address changes

Network Interface Management

  • Multi-interface Support: Handles ethernet and WiFi interfaces
  • Interface Discovery: Automatic detection of available interfaces
  • Configuration Persistence: Settings saved across reboots
  • Runtime Flexibility: Changes can be applied with or without reboot

Optional Features

WiFi Support

  • Uncomment #define USE_WIFI (1) to enable WiFi functionality
  • Requires additional WiFi driver initialization
  • Supports dual ethernet/WiFi configurations

Custom Static IP Assignment

  • Option to define static IP values in application code
  • Alternative to using configuration server settings
  • Useful for embedded applications with fixed network requirements

Dependencies

  • NetBurner NNDK (NetBurner Network Development Kit)
  • Standard C++ libraries
  • NetBurner networking stack
  • Configuration server module
  • HTTP server module

Build Configuration

The application uses pragma directives to suppress GCC warnings for NetBurner-specific format specifiers (HI, I) used in network address printing.

Network Diagnostics

The application includes comprehensive network diagnostics:

  • Interface status monitoring
  • Link state detection
  • IP address validation
  • DHCP lease status tracking
  • Network connectivity verification