1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** NetX Component */
16 /** */
17 /** Internet Control Message Protocol (ICMP) */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define NX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "nx_api.h"
28 #include "nx_icmp.h"
29 #include "nx_ip.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _nx_icmp_ping PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* Yuxin Zhou, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function finds a suitable interface and calls interface ping. */
45 /* */
46 /* INPUT */
47 /* */
48 /* ip_ptr Pointer to IP instance */
49 /* ip_address IP address to ping */
50 /* data_ptr User Data pointer */
51 /* data_size Size of User Data */
52 /* response_ptr Pointer to Response Packet */
53 /* wait_option Suspension option */
54 /* */
55 /* OUTPUT */
56 /* */
57 /* None */
58 /* */
59 /* CALLS */
60 /* */
61 /* _nx_ip_route_find Find suitable interface */
62 /* _nx_icmp_interface_ping Send ping packet */
63 /* */
64 /* CALLED BY */
65 /* */
66 /* Application Code */
67 /* */
68 /* RELEASE HISTORY */
69 /* */
70 /* DATE NAME DESCRIPTION */
71 /* */
72 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
73 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
74 /* resulting in version 6.1 */
75 /* */
76 /**************************************************************************/
_nx_icmp_ping(NX_IP * ip_ptr,ULONG ip_address,CHAR * data_ptr,ULONG data_size,NX_PACKET ** response_ptr,ULONG wait_option)77 UINT _nx_icmp_ping(NX_IP *ip_ptr, ULONG ip_address,
78 CHAR *data_ptr, ULONG data_size,
79 NX_PACKET **response_ptr, ULONG wait_option)
80 {
81
82 #ifndef NX_DISABLE_IPV4
83 ULONG next_hop_address;
84 NX_INTERFACE *interface_ptr = NX_NULL;
85
86
87 /* Find a suitable interface for sending the ping packet. */
88 if (_nx_ip_route_find(ip_ptr, ip_address, &interface_ptr, &next_hop_address) != NX_SUCCESS)
89 {
90
91 /* No suitable interface configured. */
92 /* Clear the destination pointer. */
93 *response_ptr = NX_NULL;
94
95 /* Return the error status. */
96 return(NX_IP_ADDRESS_ERROR);
97 }
98
99 /* Call interface ping service. */
100 /*lint -e{644} suppress variable might not be initialized, since "interface_ptr" and "next_hop_address" were initialized in _nx_ip_route_find. */
101 return(_nx_icmp_interface_ping(ip_ptr, ip_address, interface_ptr, next_hop_address,
102 data_ptr, data_size, response_ptr, wait_option));
103 #else /* NX_DISABLE_IPV4 */
104 NX_PARAMETER_NOT_USED(ip_ptr);
105 NX_PARAMETER_NOT_USED(ip_address);
106 NX_PARAMETER_NOT_USED(data_ptr);
107 NX_PARAMETER_NOT_USED(data_size);
108 NX_PARAMETER_NOT_USED(response_ptr);
109 NX_PARAMETER_NOT_USED(wait_option);
110
111 return(NX_NOT_SUPPORTED);
112 #endif /* !NX_DISABLE_IPV4 */
113 }
114
115