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);
=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