Code

Reset the address-family to `AF_UNSPEC' before setting the source address.
authorFlorian Forster <octo@verplant.org>
Mon, 12 Jun 2006 20:46:08 +0000 (22:46 +0200)
committerFlorian Forster <octo@verplant.org>
Mon, 12 Jun 2006 20:46:08 +0000 (22:46 +0200)
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

index d74659fd24df0a9a7d48dd3763d2cdb2878a303c..9fad0c2dc09dbabf353a1fa9f28772c72ce28d6f 100644 (file)
@@ -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 */