From: Florian Forster Date: Mon, 12 Jun 2006 20:48:23 +0000 (+0200) Subject: Actually bind to the configured address. X-Git-Tag: liboping-0.3.0~7 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=fa42fc0f5ba64220f8c0905dfc75de773d2e7c76;p=liboping.git Actually bind to the configured address. D'oh! --- diff --git a/src/liboping.c b/src/liboping.c index 9fad0c2..21855e1 100644 --- a/src/liboping.c +++ b/src/liboping.c @@ -1092,21 +1092,20 @@ int ping_host_add (pingobj_t *obj, const char *host) continue; } -/* - * The majority vote of operating systems has decided that you don't need to - * bind here. This code should be reactivated to bind to a specific address, - * though. See the `-I' option of `ping(1)' (GNU). -octo - */ -#if 0 - if (bind (ph->fd, (struct sockaddr *) &sockaddr, sockaddr_len) == -1) + if (obj->srcaddr != NULL) { - dprintf ("bind: %s\n", strerror (errno)); - ping_set_error (obj, "bind", strerror (errno)); - close (ph->fd); - ph->fd = -1; - continue; + assert (obj->srcaddrlen > 0); + assert (obj->srcaddrlen <= sizeof (struct sockaddr_storage)); + + if (bind (ph->fd, (struct sockaddr *) obj->srcaddr, obj->srcaddrlen) == -1) + { + dprintf ("bind: %s\n", strerror (errno)); + ping_set_error (obj, "bind", strerror (errno)); + close (ph->fd); + ph->fd = -1; + continue; + } } -#endif assert (sizeof (struct sockaddr_storage) >= ai_ptr->ai_addrlen); memset (ph->addr, '\0', sizeof (struct sockaddr_storage));