ping.h
Go to the documentation of this file.
1 /**
2  * @file ping.h
3  * @brief Ping utility
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 #ifndef _PING_H
32 #define _PING_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "ipv4/icmp.h"
37 #include "ipv6/icmpv6.h"
38 
39 //Ping utility support
40 #ifndef PING_SUPPORT
41  #define PING_SUPPORT ENABLED
42 #elif (PING_SUPPORT != ENABLED && PING_SUPPORT != DISABLED)
43  #error PING_SUPPORT parameter is not valid
44 #endif
45 
46 //Default timeout value
47 #ifndef PING_DEFAULT_TIMEOUT
48  #define PING_DEFAULT_TIMEOUT 1000
49 #elif (PING_DEFAULT_TIMEOUT < 0)
50  #error PING_DEFAULT_TIMEOUT parameter is not valid
51 #endif
52 
53 //Maximum size of the data payload
54 #ifndef PING_MAX_DATA_SIZE
55  #define PING_MAX_DATA_SIZE 32
56 #elif (PING_MAX_DATA_SIZE < 0)
57  #error PING_MAX_DATA_SIZE parameter is not valid
58 #endif
59 
60 //Size of the internal buffer
61 #define PING_BUFFER_SIZE (sizeof(IcmpEchoMessage) + PING_MAX_DATA_SIZE)
62 
63 //C++ guard
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
68 
69 /**
70  * @brief Ping context
71  **/
72 
73 typedef struct
74 {
78  uint16_t identifier;
79  uint16_t sequenceNumber;
83  uint8_t buffer[PING_BUFFER_SIZE];
84 } PingContext;
85 
86 
87 //Ping related functions
88 error_t ping(NetInterface *interface, const IpAddr *targetIpAddr,
89  size_t size, uint8_t ttl, systime_t timeout, systime_t *rtt);
90 
91 void pingInit(PingContext *context);
92 error_t pingSetTimeout(PingContext *context, systime_t timeout);
94 
96  const IpAddr *targetIpAddr, size_t size, uint8_t ttl);
97 
99  IpAddr *targetIpAddr, systime_t *rtt);
100 
101 void pingRelease(PingContext *context);
102 
103 //C++ guard
104 #ifdef __cplusplus
105 }
106 #endif
107 
108 #endif
error_t pingSendRequest(PingContext *context, const IpAddr *targetIpAddr, size_t size, uint8_t ttl)
Send an ICMP Echo Request message.
Definition: ping.c:190
error_t ping(NetInterface *interface, const IpAddr *targetIpAddr, size_t size, uint8_t ttl, systime_t timeout, systime_t *rtt)
Test the reachability of a host.
Definition: ping.c:69
IP network address.
Definition: ip.h:90
systime_t timeout
Definition: ping.h:81
#define PING_BUFFER_SIZE
Definition: ping.h:61
Socket * socket
Definition: ping.h:76
error_t pingWaitForReply(PingContext *context, IpAddr *targetIpAddr, systime_t *rtt)
Wait for a matching ICMP Echo Reply message.
Definition: ping.c:459
Ping context.
Definition: ping.h:74
systime_t timestamp
Definition: ping.h:80
ICMPv6 (Internet Control Message Protocol Version 6)
ICMP (Internet Control Message Protocol)
error_t
Error codes.
Definition: error.h:43
uint16_t sequenceNumber
Definition: ping.h:79
error_t pingBindToInterface(PingContext *context, NetInterface *interface)
Select a particular network interface.
Definition: ping.c:167
#define NetInterface
Definition: net.h:36
void pingInit(PingContext *context)
Initialize ping context.
Definition: ping.c:125
uint32_t systime_t
System time.
#define Socket
Definition: socket.h:36
NetInterface * interface
Definition: ping.h:75
void pingRelease(PingContext *context)
Release ping context.
Definition: ping.c:557
error_t pingSetTimeout(PingContext *context, systime_t timeout)
Set timeout value.
Definition: ping.c:146
uint32_t ttl
Definition: dns_common.h:221
systime_t rtt
Definition: ping.h:82
TCP/IP stack core.
uint16_t identifier
Definition: ping.h:78
size_t dataPayloadSize
Definition: ping.h:77