int ping_timestamp (char *hostname) { ping_set_type (ping, ICMP_TIMESTAMP); ping_set_event_handler (ping, recv_timestamp, NULL); ping_set_packetsize (ping, ICMP_TSLEN); if (ping_set_dest (ping, hostname)) error (EXIT_FAILURE, 0, "unknown host"); printf ("PING %s (%s): sending timestamp requests\n", ping->ping_hostname, inet_ntoa (ping->ping_dest.ping_sockaddr.sin_addr)); return ping_run (ping, timestamp_finish); }
int ping_address (char *hostname) { ping_set_type (ping, ICMP_ADDRESS); ping_set_event_handler (ping, recv_address, NULL); ping_set_packetsize (ping, 12); /* FIXME: constant */ ping_set_count (ping, 1); if (ping_set_dest (ping, hostname)) error (EXIT_FAILURE, 0, "unknown host"); printf ("PING %s (%s): sending address mask request\n", ping->ping_hostname, inet_ntoa (ping->ping_dest.ping_sockaddr.sin_addr)); return ping_run (ping, address_finish); }
static int ping_echo (char *hostname) { int err; char buffer[256]; struct ping_stat ping_stat; int status; if (options & OPT_FLOOD && options & OPT_INTERVAL) error (EXIT_FAILURE, 0, "-f and -i incompatible options"); memset (&ping_stat, 0, sizeof (ping_stat)); ping_stat.tmin = 999999999.0; ping->ping_datalen = data_length; ping->ping_closure = &ping_stat; if (ping_set_dest (ping, hostname)) error (EXIT_FAILURE, 0, "unknown host %s", hostname); err = getnameinfo ((struct sockaddr *) &ping->ping_dest.ping_sockaddr6, sizeof (ping->ping_dest.ping_sockaddr6), buffer, sizeof (buffer), NULL, 0, NI_NUMERICHOST); if (err) { const char *errmsg; if (err == EAI_SYSTEM) errmsg = strerror (errno); else errmsg = gai_strerror (err); error (EXIT_FAILURE, 0, "getnameinfo: %s", errmsg); } printf ("PING %s (%s): %d data bytes\n", ping->ping_hostname, buffer, data_length); status = ping_run (ping, echo_finish); free (ping->ping_hostname); return status; }