From fa42fc0f5ba64220f8c0905dfc75de773d2e7c76 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 12 Jun 2006 22:48:23 +0200 Subject: [PATCH] Actually bind to the configured address. D'oh! --- src/liboping.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) 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)); -- 2.30.2