X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fping.c;h=b619e37abf94c354af53cad79fface07371dd6b9;hb=d57e8e17bff41587242dd91df72bdda8f105eae9;hp=d269cd18b9bc33e16f22c273556cd787fd5b9389;hpb=1019a2002f891f9661fbc9f0f5ebf83c3194ac97;p=collectd.git diff --git a/src/ping.c b/src/ping.c index d269cd18..b619e37a 100644 --- a/src/ping.c +++ b/src/ping.c @@ -71,7 +71,7 @@ typedef struct hostlist_s hostlist_t; */ static hostlist_t *hostlist_head = NULL; -static char *ping_af = NULL; +static int ping_af = PING_DEF_AF; static char *ping_source = NULL; #ifdef HAVE_OPING_1_3 static char *ping_device = NULL; @@ -243,18 +243,8 @@ static void *ping_thread(void *arg) /* {{{ */ return (void *)-1; } - if (ping_af != NULL) { - int af = PING_DEF_AF; - if (strncmp(ping_af, "any", 3) == 0) { - af = AF_UNSPEC; - } else if (strncmp(ping_af, "ipv4", 4) == 0) { - af = AF_INET; - } else if (strncmp(ping_af, "ipv6", 4) == 0) { - af = AF_INET6; - } else { - ERROR("ping plugin: Bad address family: %s. Using default.", ping_af); - } - if (ping_setopt(pingobj, PING_OPT_AF, &af) != 0) + 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)); } @@ -486,9 +476,22 @@ static int ping_config(const char *key, const char *value) /* {{{ */ hl->next = hostlist_head; hostlist_head = hl; } else if (strcasecmp(key, "AddressFamily") == 0) { - int status = config_set_string(key, &ping_af, value); + 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)