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