#include #include #include "icmp.h" #include "icmp_types.h" #include "internal/ping/output.h" /* Forward declarations */ static const char *error_msg_for(const icmp_reply_t *reply); /* -------------------- */ void ping_output_error(const icmp_reply_t *reply, const icmp_offending_packet_t *offending, uint16_t seq, const t_ping_config *config) { char from_str[INET_ADDRSTRLEN]; (void)offending; (void)config; inet_ntop(AF_INET, &reply->from, from_str, sizeof(from_str)); fprintf(stderr, "From %s: icmp_seq=%u %s\n", from_str, (unsigned int)seq, error_msg_for(reply)); } static const char * error_msg_for(const icmp_reply_t *reply) { if (ICMP_TYPE_TIME_EXCEEDED == reply->type) return ("Time to live exceeded"); if (ICMP_CODE_HOST_UNREACHABLE == reply->code) return ("Destination Host Unreachable"); return ("Destination Net Unreachable"); }