Skip to content

Conversation

@zs39
Copy link
Contributor

@zs39 zs39 commented Dec 26, 2025

Summary

The system checks connectivity with the input IP address; if no IP address is provided, it defaults to checking DNS server connectivity.

Impact

N/A

Testing

Use the following test cases for testing.

/****************************************************************************
 * apps/examples/hello/hello_main.c
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.  The
 * ASF licenses this file to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 *
 ****************************************************************************/

/****************************************************************************
 * Included Files
 ****************************************************************************/

#include <nuttx/config.h>
#include <stdio.h>

#ifdef CONFIG_NETUTILS_PING
#include "netutils/netlib.h"
#endif

/****************************************************************************
 * Public Functions
 ****************************************************************************/

/****************************************************************************
 * hello_main
 ****************************************************************************/

int main(int argc, FAR char *argv[])
{
  printf("Hello, World!!\n");

#ifdef CONFIG_NETUTILS_PING
  int replies;
  int timeout = 100;  /* 1 second in milliseconds */
  int retry = 10;        /* 3 ping attempts */

  printf("\n=== Network Connectivity Test ===\n");
  
  /* Test case 1: Ping a specific IP address */
  replies = netlib_check_ipconnectivity("223.5.5.5", timeout, retry);
  
  if (replies > 0)
    {
      printf("SUCCESS - Received %d/%d replies\n", replies, retry);
    }
  else if (replies == 0)
    {
      printf("FAILED - No replies received\n");
    }
  else
    {
      printf("ERROR - Error code: %d\n", replies);
    }

#ifdef CONFIG_NETDB_DNSSERVER_IPv4ADDR
  /* Test case 2: Ping default DNS server (from config) */
  printf("\n=== Test Default DNS Server ===\n");
  replies = netlib_check_ipconnectivity(NULL, timeout, retry);
  
  if (replies > 0)
    {
      printf("SUCCESS - Received %d/%d replies\n", replies, retry);
    }
  else if (replies == 0)
    {
      printf("FAILED - No replies received\n");
    }
  else
    {
      printf("ERROR - Error code: %d\n", replies);
    }
#else
  printf("\nDefault DNS server test skipped (CONFIG_NETDB_DNSSERVER_IPv4ADDR not configured)\n");
#endif

#else
  printf("\nNetwork connectivity test is not available\n");
  printf("(CONFIG_NETUTILS_PING is not enabled)\n");
#endif

  return 0;
}

The execution results are as follows

nsh> hello
Hello, World!!

=== Network Connectivity Test ===
SUCCESS - Received 10/10 replies

=== Test Default DNS Server ===
SUCCESS - Received 10/10 replies

The system checks connectivity with the input IP address; if no IP address is provided, it defaults to checking DNS server connectivity.

Signed-off-by: meijian <meijian@xiaomi.com>
@zs39
Copy link
Contributor Author

zs39 commented Dec 26, 2025

apache/nuttx#17685
Documentation supplement here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants