ping.c
Go to the documentation of this file.
1 /**
2  * @file ping.c
3  * @brief Ping utility
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 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.6.6
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL PING_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "core/ping.h"
37 #include "core/ip.h"
38 #include "ipv4/ipv4.h"
39 #include "ipv4/ipv4_misc.h"
40 #include "ipv4/icmp.h"
41 #include "ipv6/ipv6.h"
42 #include "ipv6/ipv6_misc.h"
43 #include "ipv6/icmpv6.h"
44 #include "core/socket.h"
45 #include "debug.h"
46 
47 //Check TCP/IP stack configuration
48 #if (PING_SUPPORT == ENABLED && RAW_SOCKET_SUPPORT == ENABLED)
49 
50 //Sequence number field
51 static uint16_t pingSequenceNumber = 0;
52 
53 
54 /**
55  * @brief Test the reachability of a host
56  *
57  * Ping operates by sending an ICMP Echo Request message to the
58  * target host and waiting for an ICMP Echo Reply message
59  *
60  * @param[in] interface Underlying network interface (optional parameter)
61  * @param[in] targetIpAddr IP address of the host to reach
62  * @param[in] size Size of the data payload in bytes
63  * @param[in] ttl Time-To-Live value to be used
64  * @param[in] timeout Maximum time to wait before giving up
65  * @param[out] rtt Round-trip time (optional parameter)
66  * @return Error code
67  **/
68 
69 error_t ping(NetInterface *interface, const IpAddr *targetIpAddr, size_t size,
70  uint8_t ttl, systime_t timeout, systime_t *rtt)
71 {
72  error_t error;
73  PingContext context;
74 
75  //Check parameters
76  if(targetIpAddr == NULL)
78 
79  //Initialize context
80  pingInit(&context);
81 
82  //Start of exception handling block
83  do
84  {
85  //Select the specified network interface
86  error = pingBindToInterface(&context, interface);
87  //Any error to report?
88  if(error)
89  break;
90 
91  //Set timeout value
92  error = pingSetTimeout(&context, timeout);
93  //Any error to report?
94  if(error)
95  break;
96 
97  //Send an ICMP Echo Request message
98  error = pingSendRequest(&context, targetIpAddr, size, ttl);
99  //Any error to report?
100  if(error)
101  break;
102 
103  //Wait for a matching Echo Reply message
104  error = pingWaitForReply(&context, NULL, rtt);
105  //Any error to report?
106  if(error)
107  break;
108 
109  //End of exception handling block
110  } while(0);
111 
112  //Release resources
113  pingRelease(&context);
114 
115  //Return status code
116  return error;
117 }
118 
119 
120 /**
121  * @brief Initialize ping context
122  * @param[in] context Pointer to the ping context
123  **/
124 
125 void pingInit(PingContext *context)
126 {
127  //Make sure the context is valid
128  if(context != NULL)
129  {
130  //Initialize context
131  osMemset(context, 0, sizeof(PingContext));
132 
133  //Attach TCP/IP stack context
134  context->netContext = netGetDefaultContext();
135 
136  //Set the default timeout to be used
137  context->timeout = PING_DEFAULT_TIMEOUT;
138  }
139 }
140 
141 
142 /**
143  * @brief Set timeout value
144  * @param[in] context Pointer to the ping context
145  * @param[in] timeout Maximum time to wait
146  * @return Error code
147  **/
148 
150 {
151  //Invalid context?
152  if(context == NULL)
154 
155  //Save timeout value
156  context->timeout = timeout;
157 
158  //Successful processing
159  return NO_ERROR;
160 }
161 
162 
163 /**
164  * @brief Select a particular network interface
165  * @param[in] context Pointer to the ping context
166  * @param[in] interface Network interface to be used
167  * @return Error code
168  **/
169 
171 {
172  //Invalid context?
173  if(context == NULL)
175 
176  //Select the specified network interface
177  context->interface = interface;
178 
179  //Attach TCP/IP stack context
180  if(interface != NULL)
181  {
182  context->netContext = interface->netContext;
183  }
184 
185  //Successful processing
186  return NO_ERROR;
187 }
188 
189 
190 /**
191  * @brief Send an ICMP Echo Request message
192  * @param[in] context Pointer to the ping context
193  * @param[in] targetIpAddr IP address of the host to reach
194  * @param[in] size Size of the data payload, in bytes
195  * @param[in] ttl Time-To-Live value to be used
196  * @return Error code
197  **/
198 
199 error_t pingSendRequest(PingContext *context, const IpAddr *targetIpAddr,
200  size_t size, uint8_t ttl)
201 {
202  error_t error;
203  size_t i;
204  size_t length;
205  NetInterface *interface;
207 
208  //Invalid context?
209  if(context == NULL)
211 
212  //Limit the size of the data payload
213  context->dataPayloadSize = MIN (size, PING_MAX_DATA_SIZE);
214 
215  //Close existing socket, if necessary
216  if(context->socket != NULL)
217  {
218  socketClose(context->socket);
219  context->socket = NULL;
220  }
221 
222  //Identifier field is used to help matching requests and replies
225 
226  //Sequence Number field is incremented each time an Echo Request is sent
227  context->sequenceNumber = pingSequenceNumber++;
228 
229  //Point to the buffer where to format the ICMP message
230  message = (IcmpEchoMessage *) context->buffer;
231 
232  //Format ICMP Echo Request message
234  message->code = 0;
235  message->checksum = 0;
236  message->identifier = htons(context->identifier);
237  message->sequenceNumber = htons(context->sequenceNumber);
238 
239  //Initialize data payload
240  for(i = 0; i < context->dataPayloadSize; i++)
241  {
242  message->data[i] = i & 0xFF;
243  }
244 
245  //Length of the complete ICMP message including header and data
246  length = sizeof(IcmpEchoMessage) + context->dataPayloadSize;
247 
248  //Select the relevant network interface
249  interface = context->interface;
250 
251 #if (IPV4_SUPPORT == ENABLED)
252  //Is target address an IPv4 address?
253  if(targetIpAddr->length == sizeof(Ipv4Addr))
254  {
256 
257  //Select the source IPv4 address and the relevant network interface to
258  //use when pinging the specified host
259  error = ipv4SelectSourceAddr(context->netContext, &interface,
260  targetIpAddr->ipv4Addr, &srcIpAddr);
261  //Any error to report?
262  if(error)
263  return error;
264 
265  //ICMP Echo Request message
267  //Message checksum calculation
268  message->checksum = ipCalcChecksum(message, length);
269 
270  //Open a raw socket
271  context->socket = socketOpenEx(context->netContext, SOCKET_TYPE_RAW_IP,
273  }
274  else
275 #endif
276 #if (IPV6_SUPPORT == ENABLED)
277  //Is target address an IPv6 address?
278  if(targetIpAddr->length == sizeof(Ipv6Addr))
279  {
280  Ipv6PseudoHeader pseudoHeader;
281 
282  //Select the source IPv6 address and the relevant network interface to
283  //use when pinging the specified host
284  error = ipv6SelectSourceAddr(context->netContext, &interface,
285  &targetIpAddr->ipv6Addr, &pseudoHeader.srcAddr);
286  //Any error to report?
287  if(error)
288  return error;
289 
290  //ICMPv6 Echo Request message
292 
293  //Format IPv6 pseudo header
294  pseudoHeader.destAddr = targetIpAddr->ipv6Addr;
295  pseudoHeader.length = htonl(length);
296  pseudoHeader.reserved[0] = 0;
297  pseudoHeader.reserved[1] = 0;
298  pseudoHeader.reserved[2] = 0;
299  pseudoHeader.nextHeader = IPV6_ICMPV6_HEADER;
300 
301  //Message checksum calculation
302  message->checksum = ipCalcUpperLayerChecksum(&pseudoHeader,
303  sizeof(Ipv6PseudoHeader), message, length);
304 
305  //Open a raw socket
306  context->socket = socketOpenEx(context->netContext, SOCKET_TYPE_RAW_IP,
308  }
309  else
310 #endif
311  //Invalid target address?
312  {
313  //Report an error
314  return ERROR_INVALID_ADDRESS;
315  }
316 
317  //Failed to open socket?
318  if(context->socket == NULL)
319  return ERROR_OPEN_FAILED;
320 
321  //Set the TTL value to be used
322  context->socket->ttl = ttl;
323 
324  //Start of exception handling block
325  do
326  {
327  //Associate the newly created socket with the relevant interface
328  error = socketBindToInterface(context->socket, interface);
329  //Unable to bind the socket to the desired interface?
330  if(error)
331  break;
332 
333  //Debug message
334  TRACE_INFO("Sending ICMP echo request to %s (%" PRIuSIZE " bytes)...\r\n",
335  ipAddrToString(targetIpAddr, NULL), length);
336 
337  //Send Echo Request message
338  error = socketSendTo(context->socket, targetIpAddr, 0, message, length,
339  NULL, 0);
340  //Failed to send message ?
341  if(error)
342  break;
343 
344  //Save the time at which the request was sent
345  context->timestamp = osGetSystemTime();
346 
347  //End of exception handling block
348  } while(0);
349 
350  //Any error to report?
351  if(error)
352  {
353  //Clean up side effects
354  socketClose(context->socket);
355  context->socket = NULL;
356  }
357 
358  //Return status code
359  return error;
360 }
361 
362 
363 /**
364  * @brief Check whether an incoming ICMP message is acceptable
365  * @param[in] context Pointer to the ping context
366  * @param[in] srcIpAddr Source IP address
367  * @param[in] destIpAddr Destination IP address
368  * @param[in] message Pointer to the incoming ICMP message
369  * @param[in] length Length of the message, in bytes
370  * @return Error code
371  **/
372 
374  const IpAddr *destIpAddr, const IcmpEchoMessage *message, size_t length)
375 {
376  size_t i;
377 
378  //Malformed ICMP message?
379  if(length < sizeof(IcmpHeader))
380  return ERROR_INVALID_MESSAGE;
381 
382 #if (IPV4_SUPPORT == ENABLED)
383  //Is target address an IPv4 address?
384  if(context->socket->protocol == SOCKET_IP_PROTO_ICMP)
385  {
386  //Check address type
387  if(destIpAddr->length != sizeof(Ipv4Addr))
388  return ERROR_INVALID_MESSAGE;
389 
390  //Check message type
391  if(message->type == ICMP_TYPE_ECHO_REPLY)
392  {
393  //Continue processing
394  }
395  else if(message->type == ICMP_TYPE_TIME_EXCEEDED)
396  {
397  //If the gateway processing a packet finds the TTL field is zero, then
398  //it notifies the source host via an ICMP Time Exceeded message
399  return ERROR_TTL_EXCEEDED;
400  }
401  else
402  {
403  //Report an error
404  return ERROR_INVALID_MESSAGE;
405  }
406 
407  //Verify checksum value
408  if(ipCalcChecksum(message, length) != 0x0000)
409  return ERROR_INVALID_MESSAGE;
410  }
411  else
412 #endif
413 #if (IPV6_SUPPORT == ENABLED)
414  //Is target address an IPv6 address?
415  if(context->socket->protocol == SOCKET_IP_PROTO_ICMPV6)
416  {
417  Ipv6PseudoHeader pseudoHeader;
418 
419  //Check address type
420  if(destIpAddr->length != sizeof(Ipv6Addr))
421  return ERROR_INVALID_MESSAGE;
422 
423  //Check message type
424  if(message->type == ICMPV6_TYPE_ECHO_REPLY)
425  {
426  //Continue processing
427  }
428  else if(message->type == ICMPV6_TYPE_TIME_EXCEEDED)
429  {
430  //If the gateway processing a packet finds the Hop Limit field is zero,
431  //then it notifies the source host via an ICMPv6 Time Exceeded message
432  return ERROR_TTL_EXCEEDED;
433  }
434  else
435  {
436  //Report an error
437  return ERROR_INVALID_MESSAGE;
438  }
439 
440  //Format IPv6 pseudo header
441  pseudoHeader.srcAddr = srcIpAddr->ipv6Addr;
442  pseudoHeader.destAddr = destIpAddr->ipv6Addr;
443  pseudoHeader.length = htonl(length);
444  pseudoHeader.reserved[0] = 0;
445  pseudoHeader.reserved[1] = 0;
446  pseudoHeader.reserved[2] = 0;
447  pseudoHeader.nextHeader = IPV6_ICMPV6_HEADER;
448 
449  //Verify checksum value
450  if(ipCalcUpperLayerChecksum(&pseudoHeader,
451  sizeof(Ipv6PseudoHeader), message, length) != 0x0000)
452  {
453  //The checksum is not valid
454  return ERROR_INVALID_MESSAGE;
455  }
456  }
457  else
458 #endif
459  //Invalid target address?
460  {
461  //Report an error
462  return ERROR_INVALID_ADDRESS;
463  }
464 
465  //Malformed ICMP Echo Reply message?
466  if(length < sizeof(IcmpEchoMessage))
467  return ERROR_INVALID_MESSAGE;
468 
469  //Make sure the response identifier matches the request identifier
470  if(ntohs(message->identifier) != context->identifier)
471  return ERROR_INVALID_MESSAGE;
472 
473  //Make sure the sequence number is correct
474  if(ntohs(message->sequenceNumber) != context->sequenceNumber)
475  return ERROR_INVALID_MESSAGE;
476 
477  //Check message length
478  if(length != (sizeof(IcmpEchoMessage) + context->dataPayloadSize))
479  return ERROR_INVALID_MESSAGE;
480 
481  //Verify data payload
482  for(i = 0; i < context->dataPayloadSize; i++)
483  {
484  //Compare received data against expected data pattern
485  if(message->data[i] != (i & 0xFF))
486  return ERROR_INVALID_MESSAGE;
487  }
488 
489  //The ICMP Echo Reply message is acceptable
490  return NO_ERROR;
491 }
492 
493 
494 /**
495  * @brief Wait for a matching ICMP Echo Reply message
496  * @param[in] context Pointer to the ping context
497  * @param[out] hostIpAddr IP address of the intermediate host (optional parameter)
498  * @param[out] rtt Round-trip time (optional parameter)
499  * @return Error code
500  **/
501 
503  systime_t *rtt)
504 {
505  error_t error;
506  systime_t time;
507  systime_t timeout;
508  SocketMsg msg;
509 
510  //Invalid context?
511  if(context == NULL)
513 
514  //Wait for an ICMP Echo Reply message
515  do
516  {
517  //Get current time
518  time = osGetSystemTime();
519 
520  //Compute the timeout to be used
521  if(timeCompare(time, context->timestamp + context->timeout) < 0)
522  {
523  timeout = context->timestamp + context->timeout - time;
524  }
525  else
526  {
527  timeout = 0;
528  }
529 
530  //Adjust receive timeout
531  error = socketSetTimeout(context->socket, timeout);
532  //Any error to report?
533  if(error)
534  break;
535 
536  //Point to the receive buffer
537  msg = SOCKET_DEFAULT_MSG;
538  msg.data = context->buffer;
539  msg.size = PING_BUFFER_SIZE;
540 
541  //Wait for an incoming ICMP message
542  error = socketReceiveMsg(context->socket, &msg, 0);
543 
544 #if (NET_RTOS_SUPPORT == DISABLED)
545  //Catch timeout exception
546  if(error == ERROR_TIMEOUT)
547  {
548  error = ERROR_WOULD_BLOCK;
549  }
550 #endif
551 
552  //Get current time
553  time = osGetSystemTime();
554 
555  //Check status code
556  if(!error)
557  {
558  //Check whether the incoming ICMP message is acceptable
559  error = pingCheckReply(context, &msg.srcIpAddr, &msg.destIpAddr,
560  (IcmpEchoMessage *) context->buffer, msg.length);
561  }
562 
563  //Check status code
564  if(error == NO_ERROR || error == ERROR_TTL_EXCEEDED)
565  {
566  //Calculate round-trip time
567  context->rtt = time - context->timestamp;
568 
569  //Debug message
570  if(error == NO_ERROR)
571  {
572  TRACE_INFO("ICMP echo reply received from %s (%" PRIu32 " ms)...\r\n",
573  ipAddrToString(&srcIpAddr, NULL), context->rtt);
574  }
575  else
576  {
577  TRACE_INFO("ICMP time exceeded received from %s (%" PRIu32 " ms)...\r\n",
578  ipAddrToString(&srcIpAddr, NULL), context->rtt);
579  }
580 
581  //Return the IP address of the host
582  if(hostIpAddr != NULL)
583  {
584  *hostIpAddr = msg.srcIpAddr;
585  }
586 
587  //Return the round-trip time
588  if(rtt != NULL)
589  {
590  *rtt = context->rtt;
591  }
592  }
593  else
594  {
595  //Timeout value exceeded?
596  if(timeCompare(time, context->timestamp + context->timeout) >= 0)
597  {
598  //Report an error
599  error = ERROR_TIMEOUT;
600  }
601  }
602 
603  //Wait for the next incoming ICMP message
604  } while(error == ERROR_INVALID_MESSAGE);
605 
606  //Return status code
607  return error;
608 }
609 
610 
611 /**
612  * @brief Release ping context
613  * @param[in] context Pointer to the ping context
614  **/
615 
616 void pingRelease(PingContext *context)
617 {
618  //Make sure the context is valid
619  if(context != NULL)
620  {
621  //Close underlying socket
622  if(context->socket != NULL)
623  {
624  socketClose(context->socket);
625  context->socket = NULL;
626  }
627  }
628 }
629 
630 #endif
#define htons(value)
Definition: cpu_endian.h:413
#define PING_MAX_DATA_SIZE
Definition: ping.h:55
IPv6 (Internet Protocol Version 6)
error_t pingCheckReply(PingContext *context, const IpAddr *srcIpAddr, const IpAddr *destIpAddr, const IcmpEchoMessage *message, size_t length)
Check whether an incoming ICMP message is acceptable.
Definition: ping.c:373
void pingRelease(PingContext *context)
Release ping context.
Definition: ping.c:616
@ ERROR_WOULD_BLOCK
Definition: error.h:96
IP network address.
Definition: ip.h:94
systime_t timeout
Definition: ping.h:82
uint32_t netGetRandRange(NetContext *context, uint32_t min, uint32_t max)
Generate a random value in the specified range.
Definition: net.c:473
uint8_t message[]
Definition: chap.h:154
@ SOCKET_IP_PROTO_ICMPV6
Definition: socket.h:109
Message and ancillary data.
Definition: socket.h:241
void socketClose(Socket *socket)
Close an existing socket.
Definition: socket.c:2057
error_t pingWaitForReply(PingContext *context, IpAddr *hostIpAddr, systime_t *rtt)
Wait for a matching ICMP Echo Reply message.
Definition: ping.c:502
#define PING_DEFAULT_TIMEOUT
Definition: ping.h:48
error_t pingBindToInterface(PingContext *context, NetInterface *interface)
Select a particular network interface.
Definition: ping.c:170
#define ICMP_QUERY_ID_MAX
Definition: icmp.h:57
char_t * ipAddrToString(const IpAddr *ipAddr, char_t *str)
Convert a binary IP address to a string representation.
Definition: ip.c:810
Ipv6Addr
Definition: ipv6.h:282
void * data
Pointer to the payload.
Definition: socket.h:242
#define PING_BUFFER_SIZE
Definition: ping.h:61
@ ICMP_TYPE_TIME_EXCEEDED
Definition: icmp.h:93
NetContext * netContext
TCP/IP stack context.
Definition: ping.h:75
@ IPV6_ICMPV6_HEADER
Definition: ipv6.h:215
@ ERROR_INVALID_MESSAGE
Definition: error.h:105
Ipv4Addr srcIpAddr
Definition: ipcp.h:79
#define IPV4_SUPPORT
Definition: ipv4.h:49
Socket * socket
Raw socket.
Definition: ping.h:77
#define timeCompare(t1, t2)
Definition: os_port.h:40
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:324
Ping context.
Definition: ping.h:74
systime_t timestamp
Definition: ping.h:81
@ ICMPV6_TYPE_ECHO_REQUEST
Definition: icmpv6.h:75
IcmpHeader
Definition: icmp.h:149
@ ERROR_OPEN_FAILED
Definition: error.h:75
@ ICMPV6_TYPE_ECHO_REPLY
Definition: icmpv6.h:76
error_t pingSendRequest(PingContext *context, const IpAddr *targetIpAddr, size_t size, uint8_t ttl)
Send an ICMP Echo Request message.
Definition: ping.c:199
Helper functions for IPv4.
const SocketMsg SOCKET_DEFAULT_MSG
Definition: socket.c:49
size_t length
Actual length of the payload, in bytes.
Definition: socket.h:244
ICMPv6 (Internet Control Message Protocol Version 6)
@ ERROR_INVALID_PARAMETER
Invalid parameter.
Definition: error.h:47
#define htonl(value)
Definition: cpu_endian.h:414
ICMP (Internet Control Message Protocol)
Ping utility.
error_t
Error codes.
Definition: error.h:43
uint16_t sequenceNumber
Definition: ping.h:80
#define Ipv6PseudoHeader
Definition: ipv6.h:44
@ ERROR_INVALID_ADDRESS
Definition: error.h:103
error_t ipv4SelectSourceAddr(NetContext *context, NetInterface **interface, Ipv4Addr destAddr, Ipv4Addr *srcAddr)
IPv4 source address selection.
Definition: ipv4_misc.c:173
#define NetInterface
Definition: net.h:40
IpAddr srcIpAddr
Source IP address.
Definition: socket.h:249
error_t socketReceiveMsg(Socket *socket, SocketMsg *message, uint_t flags)
Receive a message from a connectionless socket.
Definition: socket.c:1889
Helper functions for IPv6.
NetContext * netGetDefaultContext(void)
Get default TCP/IP stack context.
Definition: net.c:527
IcmpEchoMessage
Definition: icmp.h:179
@ SOCKET_TYPE_RAW_IP
Definition: socket.h:94
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
@ ICMP_TYPE_ECHO_REQUEST
Definition: icmp.h:90
#define TRACE_INFO(...)
Definition: debug.h:105
uint8_t length
Definition: tcp.h:375
#define MIN(a, b)
Definition: os_port.h:63
size_t length
Definition: ip.h:95
#define ICMP_QUERY_ID_MIN
Definition: icmp.h:50
#define ENABLED
Definition: os_port.h:37
#define socketBindToInterface
Definition: net_legacy.h:193
uint8_t buffer[PING_BUFFER_SIZE]
Definition: ping.h:84
@ ERROR_TTL_EXCEEDED
Definition: error.h:314
uint32_t systime_t
System time.
#define ntohs(value)
Definition: cpu_endian.h:421
uint16_t ipCalcUpperLayerChecksum(const void *pseudoHeader, size_t pseudoHeaderLen, const void *data, size_t dataLen)
Calculate IP upper-layer checksum.
Definition: ip.c:664
IpAddr destIpAddr
Destination IP address.
Definition: socket.h:251
@ ERROR_TIMEOUT
Definition: error.h:95
Ipv4Addr ipv4Addr
Definition: ip.h:99
uint32_t time
IPv4 and IPv6 common routines.
@ ICMP_TYPE_ECHO_REPLY
Definition: icmp.h:85
error_t pingSetTimeout(PingContext *context, systime_t timeout)
Set timeout value.
Definition: ping.c:149
@ SOCKET_IP_PROTO_ICMP
Definition: socket.h:105
Socket * socketOpenEx(NetContext *context, uint_t type, uint_t protocol)
Create a socket.
Definition: socket.c:143
size_t size
Size of the payload, in bytes.
Definition: socket.h:243
Socket API.
error_t socketSendTo(Socket *socket, const IpAddr *destIpAddr, uint16_t destPort, const void *data, size_t length, size_t *written, uint_t flags)
Send a datagram to a specific destination.
Definition: socket.c:1532
NetInterface * interface
Underlying network interface.
Definition: ping.h:76
IPv4 (Internet Protocol Version 4)
uint32_t ttl
Definition: dns_common.h:226
Ipv6Addr ipv6Addr
Definition: ip.h:102
#define PRIuSIZE
systime_t rtt
Definition: ping.h:83
#define osMemset(p, value, length)
Definition: os_port.h:141
TCP/IP stack core.
void pingInit(PingContext *context)
Initialize ping context.
Definition: ping.c:125
uint16_t identifier
Definition: ping.h:79
error_t socketSetTimeout(Socket *socket, systime_t timeout)
Set timeout value for blocking operations.
Definition: socket.c:166
error_t ipv6SelectSourceAddr(NetContext *context, NetInterface **interface, const Ipv6Addr *destAddr, Ipv6Addr *srcAddr)
IPv6 source address selection.
Definition: ipv6_misc.c:891
@ NO_ERROR
Success.
Definition: error.h:44
@ ICMPV6_TYPE_TIME_EXCEEDED
Definition: icmpv6.h:73
Debugging facilities.
size_t dataPayloadSize
Definition: ping.h:78
uint16_t ipCalcChecksum(const void *data, size_t length)
IP checksum calculation.
Definition: ip.c:471
systime_t osGetSystemTime(void)
Retrieve system time.
Ipv4Addr destIpAddr
Definition: ipcp.h:80