Ping
gxsPing sends ICMP and ICMPv6 echo requests. ICMP cannot be encrypted, so ping is a diagnostic tool.
Contents
Overview
On Linux unprivileged ICMP datagram sockets are used when the system allows them (net.ipv4.ping_group_range), and raw sockets otherwise, which need root or CAP_NET_RAW. On Windows the IcmpSendEcho functions are used, which need no administrator rights.
gxsPing ping;
gxsPingResult r;
if(ping.Ping("example.com", r) == 0)
std::cout << r.address << " " << r.rtt_ms << " ms\n";
Functions
int gxsPing::Ping(const std::string &host, gxsPingResult &result, int family = AF_UNSPEC)Sends one echo request and waits for the reply. Returns 0 if a reply arrived. result holds ok, rtt_ms, ttl (-1 if not known), the numeric address and an error description.
void gxsPing::SetTimeout(int milliseconds)Reply timeout (1000 ms by default).