/**
* Object oriented C module to send ICMP and ICMPv6 `echo's.
- * Copyright (C) 2006 Florian octo Forster <octo at verplant.org>
+ * Copyright (C) 2006-2008 Florian octo Forster <octo at verplant.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
struct pinghost
{
+ /* username: name passed in by the user */
+ char *username;
+ /* hostname: name returned by the reverse lookup */
char *hostname;
struct sockaddr_storage *addr;
socklen_t addrlen;
if (ph->fd >= 0)
close (ph->fd);
+ if (ph->username != NULL)
+ free (ph->username);
+
if (ph->hostname != NULL)
free (ph->hostname);
{
while (ph != NULL)
{
- if (strcasecmp (ph->hostname, host) == 0)
+ if (strcasecmp (ph->username, host) == 0)
break;
ph = ph->next;
return (-1);
}
+ if ((ph->username = strdup (host)) == NULL)
+ {
+ dprintf ("Out of memory!\n");
+ ping_set_error (obj, "strdup", strerror (errno));
+ ping_free (ph);
+ return (-1);
+ }
+
if ((ph->hostname = strdup (host)) == NULL)
{
dprintf ("Out of memory!\n");
while (cur != NULL)
{
- if (strcasecmp (host, cur->hostname) == 0)
+ if (strcasecmp (host, cur->username) == 0)
break;
pre = cur;
switch (info)
{
+ case PING_INFO_USERNAME:
+ ret = ENOMEM;
+ *buffer_len = strlen (iter->username);
+ if (orig_buffer_len <= *buffer_len)
+ break;
+ /* Since (orig_buffer_len > *buffer_len) `strncpy'
+ * will copy `*buffer_len' and pad the rest of
+ * `buffer' with null-bytes */
+ strncpy (buffer, iter->username, orig_buffer_len);
+ ret = 0;
+ break;
+
case PING_INFO_HOSTNAME:
ret = ENOMEM;
*buffer_len = strlen (iter->hostname);
)
ret = ENOMEM;
else if (ret == EAI_SYSTEM)
- /* XXX: Not thread-safe! */
ret = errno;
else
ret = EINVAL;
The B<ping_host_remove> method looks for I<host> within I<obj> and remove it if
found. It will close the socket and deallocate the memory, too.
+The names passed to B<ping_host_add> and B<ping_host_remove> must match. This
+name can be queried using L<ping_iterator_get_info(3)>.
+
=head1 RETURN VALUE
If B<ping_host_add> succeeds it returns zero. If an error occurs a value less
liboping is written by Florian octo Forster E<lt>octo at verplant.orgE<gt>.
It's homepage can be found at L<http://verplant.org/liboping/>.
-(c) 2005, 2006 by Florian octo Forster.
+(c) 2005-2008 by Florian octo Forster.
=over 4
+=item B<PING_INFO_USERNAME>
+
+Return the hostname of the host the iterator points to as supplied by the user.
+This is the name you passed to L<ping_host_add(3)> and which you need to pass
+to C<ping_host_remove>, too.
+
=item B<PING_INFO_HOSTNAME>
Return the hostname of the host the iterator points to. Since the name is
liboping is written by Florian octo Forster E<lt>octo at verplant.orgE<gt>.
It's homepage can be found at L<http://verplant.org/liboping/>.
-(c) 2005, 2006 by Florian octo Forster.
+(c) 2005-2008 by Florian octo Forster.
/**
* Object oriented C module to send ICMP and ICMPv6 `echo's.
- * Copyright (C) 2006 Florian octo Forster <octo at verplant.org>
+ * Copyright (C) 2006-2008 Florian octo Forster <octo at verplant.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
pingobj_iter_t *ping_iterator_get (pingobj_t *obj);
pingobj_iter_t *ping_iterator_next (pingobj_iter_t *iter);
+#define PING_INFO_USERNAME 8
#define PING_INFO_HOSTNAME 1
#define PING_INFO_ADDRESS 2
#define PING_INFO_FAMILY 3