X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fping.c;h=89e407b2467ae8893666db32eaf5411184164fd6;hb=61a4ed99b1a5b6d371bb745933d0efc5dff9505c;hp=1ffd72b7efbcdadea2d6d490faf7c9c87ecc97df;hpb=7ef225022164d12f4560d03789c9d418b442d4cf;p=collectd.git diff --git a/src/ping.c b/src/ping.c index 1ffd72b7..89e407b2 100644 --- a/src/ping.c +++ b/src/ping.c @@ -71,6 +71,7 @@ typedef struct hostlist_s hostlist_t; */ static hostlist_t *hostlist_head = NULL; +static int ping_af = PING_DEF_AF; static char *ping_source = NULL; #ifdef HAVE_OPING_1_3 static char *ping_device = NULL; @@ -87,7 +88,7 @@ static int ping_thread_loop = 0; static int ping_thread_error = 0; static pthread_t ping_thread_id; -static const char *config_keys[] = {"Host", "SourceAddress", +static const char *config_keys[] = {"Host", "SourceAddress", "AddressFamily", #ifdef HAVE_OPING_1_3 "Device", #endif @@ -242,6 +243,12 @@ static void *ping_thread(void *arg) /* {{{ */ return (void *)-1; } + if (ping_af != PING_DEF_AF) { + if (ping_setopt(pingobj, PING_OPT_AF, &ping_af) != 0) + ERROR("ping plugin: Failed to set address family: %s", + ping_get_error(pingobj)); + } + if (ping_source != NULL) if (ping_setopt(pingobj, PING_OPT_SOURCE, (void *)ping_source) != 0) ERROR("ping plugin: Failed to set source address: %s", @@ -291,7 +298,7 @@ static void *ping_thread(void *arg) /* {{{ */ pthread_mutex_lock(&ping_lock); while (ping_thread_loop > 0) { - _Bool send_successful = 0; + bool send_successful = 0; if (gettimeofday(&tv_begin, NULL) < 0) { ERROR("ping plugin: gettimeofday failed: %s", STRERRNO); @@ -468,6 +475,23 @@ static int ping_config(const char *key, const char *value) /* {{{ */ hl->latency_squared = 0.0; hl->next = hostlist_head; hostlist_head = hl; + } else if (strcasecmp(key, "AddressFamily") == 0) { + char *af = NULL; + int status = config_set_string(key, &af, value); + if (status != 0) + return status; + + if (strncmp(af, "any", 3) == 0) { + ping_af = AF_UNSPEC; + } else if (strncmp(af, "ipv4", 4) == 0) { + ping_af = AF_INET; + } else if (strncmp(af, "ipv6", 4) == 0) { + ping_af = AF_INET6; + } else { + WARNING("ping plugin: Ignoring invalid AddressFamily value %s", af); + } + free(af); + } else if (strcasecmp(key, "SourceAddress") == 0) { int status = config_set_string(key, &ping_source, value); if (status != 0)