ping.c File Reference

Ping utility. More...

#include "core/net.h"
#include "core/ping.h"
#include "core/ip.h"
#include "ipv4/ipv4.h"
#include "ipv4/ipv4_misc.h"
#include "ipv4/icmp.h"
#include "ipv6/ipv6.h"
#include "ipv6/ipv6_misc.h"
#include "ipv6/icmpv6.h"
#include "core/socket.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   PING_TRACE_LEVEL
 

Functions

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. More...
 
void pingInit (PingContext *context)
 Initialize ping context. More...
 
error_t pingSetTimeout (PingContext *context, systime_t timeout)
 Set timeout value. More...
 
error_t pingBindToInterface (PingContext *context, NetInterface *interface)
 Select a particular network interface. More...
 
error_t pingSendRequest (PingContext *context, const IpAddr *targetIpAddr, size_t size, uint8_t ttl)
 Send an ICMP Echo Request message. More...
 
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. More...
 
error_t pingWaitForReply (PingContext *context, IpAddr *targetIpAddr, systime_t *rtt)
 Wait for a matching ICMP Echo Reply message. More...
 
void pingRelease (PingContext *context)
 Release ping context. More...
 

Detailed Description

Ping utility.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file ping.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   PING_TRACE_LEVEL

Definition at line 32 of file ping.c.

Function Documentation

◆ ping()

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.

Ping operates by sending an ICMP Echo Request message to the target host and waiting for an ICMP Echo Reply message

Parameters
[in]interfaceUnderlying network interface (optional parameter)
[in]targetIpAddrIP address of the host to reach
[in]sizeSize of the data payload in bytes
[in]ttlTime-To-Live value to be used
[in]timeoutMaximum time to wait before giving up
[out]rttRound-trip time (optional parameter)
Returns
Error code

Definition at line 69 of file ping.c.

◆ pingBindToInterface()

error_t pingBindToInterface ( PingContext context,
NetInterface interface 
)

Select a particular network interface.

Parameters
[in]contextPointer to the ping context
[in]interfaceNetwork interface to be used
Returns
Error code

Definition at line 167 of file ping.c.

◆ pingCheckReply()

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.

Parameters
[in]contextPointer to the ping context
[in]srcIpAddrSource IP address
[in]destIpAddrDestination IP address
[in]messagePointer to the incoming ICMP message
[in]lengthLength of the message, in bytes
Returns
Error code

Definition at line 365 of file ping.c.

◆ pingInit()

void pingInit ( PingContext context)

Initialize ping context.

Parameters
[in]contextPointer to the ping context

Definition at line 125 of file ping.c.

◆ pingRelease()

void pingRelease ( PingContext context)

Release ping context.

Parameters
[in]contextPointer to the ping context

Definition at line 557 of file ping.c.

◆ pingSendRequest()

error_t pingSendRequest ( PingContext context,
const IpAddr targetIpAddr,
size_t  size,
uint8_t  ttl 
)

Send an ICMP Echo Request message.

Parameters
[in]contextPointer to the ping context
[in]targetIpAddrIP address of the host to reach
[in]sizeSize of the data payload, in bytes
[in]ttlTime-To-Live value to be used
Returns
Error code

Definition at line 190 of file ping.c.

◆ pingSetTimeout()

error_t pingSetTimeout ( PingContext context,
systime_t  timeout 
)

Set timeout value.

Parameters
[in]contextPointer to the ping context
[in]timeoutMaximum time to wait
Returns
Error code

Definition at line 146 of file ping.c.

◆ pingWaitForReply()

error_t pingWaitForReply ( PingContext context,
IpAddr targetIpAddr,
systime_t rtt 
)

Wait for a matching ICMP Echo Reply message.

Parameters
[in]contextPointer to the ping context
[out]targetIpAddrIP address of the remote host (optional parameter)
[out]rttRound-trip time (optional parameter)
Returns
Error code

Definition at line 459 of file ping.c.