NetBurner 3.5.6
PDF Version
Ping

Ping Example

Overview

The Ping Test application is a network connectivity testing utility that allows users to verify the reach-ability and response time of remote devices on a network. This application demonstrates the basic implementation of ICMP ping functionality using hostname resolution and network diagnostics.

Features

  • Interactive Command Line Interface: User-friendly prompt-based interaction for entering target addresses
  • Hostname Resolution: Automatic DNS lookup to resolve hostnames to IP addresses
  • ICMP Ping Testing: Sends ping packets to test network connectivity
  • Response Time Measurement: Reports the time taken for ping responses in system ticks
  • Input Editing: Basic command-line editing with backspace support
  • Continuous Operation: Runs in a loop allowing multiple ping tests without restarting

How It Works

  1. User Input: The application prompts the user to enter an IP address or hostname
  2. DNS Resolution: Uses GetHostByName() to resolve hostnames to IP addresses
  3. Ping Execution: Sends an ICMP ping packet using the Ping() function
  4. Result Display: Shows the target IP address and response time or failure status
  5. Loop Continuation: Returns to step 1 for continuous testing

Key Functions

Gets_w_Edit(char *buf, int maxl)

Custom input function that provides basic line editing capabilities:

  • Handles character input with buffer management
  • Supports backspace (ASCII 8) for editing
  • Terminates input on carriage return or newline
  • Prevents buffer overflow by limiting input length

UserMain(void *pd)

Main application loop that:

  • Initializes the system and enables diagnostics
  • Manages the interactive ping testing cycle
  • Handles DNS resolution and ping execution
  • Displays results and error messages

Technical Details

  • Language: C/C++
  • Dependencies:
    • init.h - System initialization
    • dns.h - DNS resolution functions
  • Network Functions:
  • Timeout: DNS resolution timeout set to 30 seconds
  • Ping Parameters:
    • ID: 1
    • Sequence: 1
    • Maximum wait time: 100 ticks

Usage Example

Enter address to ping: google.com
Got:[google.com]
IP address is 172.217.12.110
Response Took 25 ticks
Enter address to ping: 8.8.8.8
Got:[8.8.8.8]
IP address is 8.8.8.8
Response Took 15 ticks
Enter address to ping: invalid-host.example
Got:[invalid-host.example]
Failed to resolve host

Error Handling

The application handles several error conditions:

  • DNS Resolution Failure: Displays "Failed to resolve host" when hostname cannot be resolved
  • Ping Failure: Shows "Ping Failed!" when the ping operation returns -1
  • Input Validation: Prevents buffer overflow in user input

System Requirements

  • Compatible embedded system or platform supporting the included header files
  • Network connectivity capability
  • ICMP protocol support
  • DNS resolution functionality

Development Notes

  • System diagnostics are enabled for debugging (should be disabled in production)
  • The application runs indefinitely until manually terminated
  • Input editing is basic but functional for typical use cases
  • Response times are measured in system-specific ticks

Purpose

This application serves as a fundamental example of network connectivity testing and demonstrates:

  • Basic network programming concepts
  • DNS resolution implementation
  • ICMP ping functionality
  • Interactive command-line application design
  • Error handling in network operations

The Ping Test utility is particularly useful for network troubleshooting, connectivity verification, and as a learning example for embedded network programming.