summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3ed22ab)
raw | patch | inline | side by side (parent: 3ed22ab)
author | Sebastian Harl <sh@tokkee.org> | |
Fri, 17 Jul 2009 12:05:17 +0000 (14:05 +0200) | ||
committer | Florian Forster <sifnfors@stud.informatik.uni-erlangen.de> | |
Fri, 17 Jul 2009 12:50:25 +0000 (14:50 +0200) |
This option may be used to set the outgoing network device to be used. The
value passed must be a char-pointer to a null-terminated string specifying an
interface name (e.g. eth0).
Please note that this might not be supported by all operating systems. In that
case, ping_setopt() sets the error to "operation not supported".
value passed must be a char-pointer to a null-terminated string specifying an
interface name (e.g. eth0).
Please note that this might not be supported by all operating systems. In that
case, ping_setopt() sets the error to "operation not supported".
src/liboping.c | patch | blob | history | |
src/mans/ping_setopt.pod | patch | blob | history | |
src/oping.h | patch | blob | history |
diff --git a/src/liboping.c b/src/liboping.c
index b21188b21abc9fc0654396f26a619e124bafdb9c..acbc715557023b52233b66d6459a1171aeb8b0f9 100644 (file)
--- a/src/liboping.c
+++ b/src/liboping.c
struct sockaddr *srcaddr;
socklen_t srcaddrlen;
+ char *device;
+
char errmsg[PING_ERRMSG_LEN];
pinghost_t *head;
if (obj->srcaddr != NULL)
free (obj->srcaddr);
+ if (obj->device != NULL)
+ free (obj->device);
+
free (obj);
return;
} /* case PING_OPT_SOURCE */
break;
+ case PING_OPT_DEVICE:
+ {
+#ifdef SO_BINDTODEVICE
+ char *device = strdup ((char *) value);
+
+ if (device == NULL)
+ {
+ ping_set_errno (obj, errno);
+ ret = -1;
+ break;
+ }
+
+ if (obj->device != NULL)
+ free (obj->device);
+ obj->device = device;
+#else /* ! SO_BINDTODEVICE */
+ ping_set_errno (obj, ENOTSUP);
+ ret = -1;
+#endif /* ! SO_BINDTODEVICE */
+ } /* case PING_OPT_DEVICE */
+ break;
+
default:
ret = -2;
} /* switch (option) */
}
}
+#ifdef SO_BINDTODEVICE
+ if (obj->device != NULL)
+ {
+ if (setsockopt (ph->fd, SOL_SOCKET, SO_BINDTODEVICE,
+ obj->device, strlen (obj->device) + 1) != 0)
+ {
+#if WITH_DEBUG
+ char errbuf[PING_ERRMSG_LEN];
+ dprintf ("setsockopt: %s\n",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+#endif
+ ping_set_errno (obj, errno);
+ close (ph->fd);
+ ph->fd = -1;
+ continue;
+ }
+ }
+#endif /* SO_BINDTODEVICE */
+
assert (sizeof (struct sockaddr_storage) >= ai_ptr->ai_addrlen);
memset (ph->addr, '\0', sizeof (struct sockaddr_storage));
memcpy (ph->addr, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
index 24527011d220c01f1c0b9a9f6dafb20a8f1b84b8..ad85979c7829cac5c11786c098f9d5dcb81917b2 100644 (file)
--- a/src/mans/ping_setopt.pod
+++ b/src/mans/ping_setopt.pod
=item B<PING_OPT_SOURCE>
Set the source address to use. The value passed must be a char-pointer to a
-null-terminated string. This option will ignore the address family setting (as
+null-terminated string specifying either a numerical network address or
+network hostname. This option will ignore the address family setting (as
set with B<PING_OPT_AF>) and will set the object's address family according to
the source address assigned.
+=item B<PING_OPT_DEVICE>
+
+Set the outgoing network device to be used. The value passed must be a
+char-pointer to a null-terminated string specifying an interface name
+(e.E<nbsp>g. C<eth0>). Please note that this might not be supported by all
+operating systems. In that case, B<ping_setopt> sets the error to C<operation
+not supported>.
+
=back
The I<val> argument is a pointer to the new value. It must not be NULL. It is
diff --git a/src/oping.h b/src/oping.h
index 0debadfda07830b8176127c7dba31592601f55be..2ffdf1f8f48bb355fccbc5c4106bdfdbf45a5900 100644 (file)
--- a/src/oping.h
+++ b/src/oping.h
#define PING_OPT_AF 0x04
#define PING_OPT_DATA 0x08
#define PING_OPT_SOURCE 0x10
+#define PING_OPT_DEVICE 0x20
#define PING_DEF_TIMEOUT 1.0
#define PING_DEF_TTL 255