From c08528de0a95743ef18df09e50356f35b2441b88 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 12 Jun 2006 22:46:08 +0200 Subject: [PATCH] Reset the address-family to `AF_UNSPEC' before setting the source address. In >90% of all cases you will pass an IP-address to that option anyway. After the address has been looked up, set `obj->addrfamily' accordingly. --- src/liboping.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/liboping.c b/src/liboping.c index d74659f..9fad0c2 100644 --- a/src/liboping.c +++ b/src/liboping.c @@ -890,9 +890,14 @@ int ping_setopt (pingobj_t *obj, int option, void *value) struct addrinfo ai_hints; struct addrinfo *ai_list; int status; - +#if WITH_DEBUG + if (obj->addrfamily != AF_UNSPEC) + { + dprintf ("Resetting obj->addrfamily to AF_UNSPEC.\n"); + } +#endif memset ((void *) &ai_hints, '\0', sizeof (ai_hints)); - ai_hints.ai_family = obj->addrfamily; + ai_hints.ai_family = obj->addrfamily = AF_UNSPEC; #if defined(AI_ADDRCONFIG) ai_hints.ai_flags = AI_ADDRCONFIG; #endif @@ -930,6 +935,7 @@ int ping_setopt (pingobj_t *obj, int option, void *value) memcpy ((void *) obj->srcaddr, (const void *) ai_list->ai_addr, ai_list->ai_addrlen); obj->srcaddrlen = ai_list->ai_addrlen; + obj->addrfamily = ai_list->ai_family; freeaddrinfo (ai_list); } /* case PING_OPT_SOURCE */ -- 2.30.2