summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2ee0742)
raw | patch | inline | side by side (parent: 2ee0742)
author | Florian Forster <octo@verplant.org> | |
Sat, 26 Jan 2008 09:35:08 +0000 (10:35 +0100) | ||
committer | Florian Forster <octo@verplant.org> | |
Sat, 26 Jan 2008 09:35:08 +0000 (10:35 +0100) |
Alex Brooks has reported that he cannot reliably remove hosts he added without
a fully qualified domain name, such as `foobar'. The reason is that the
`hostname' the user provided is replaced with the `canonical hostname', if they
differ. To fix this problem I introduced a new fields `username' which holds
the hostname as it was supplied by the user. This is the only name checked when
removing a host now.
Applications may access this name using the new `PING_INFO_USERNAME' option for
`ping_iterator_get_info'.
a fully qualified domain name, such as `foobar'. The reason is that the
`hostname' the user provided is replaced with the `canonical hostname', if they
differ. To fix this problem I introduced a new fields `username' which holds
the hostname as it was supplied by the user. This is the only name checked when
removing a host now.
Applications may access this name using the new `PING_INFO_USERNAME' option for
`ping_iterator_get_info'.
src/liboping.c | patch | blob | history | |
src/mans/ping_host_add.pod | patch | blob | history | |
src/mans/ping_iterator_get_info.pod | patch | blob | history | |
src/oping.h | patch | blob | history |
diff --git a/src/liboping.c b/src/liboping.c
index 9b91b6d40f0214963c025aeb6af9e7f3f4246575..fb7be3cc2735e8273f6ce5d73eada19b64375e8d 100644 (file)
--- a/src/liboping.c
+++ b/src/liboping.c
/**
* 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;
index c768be3197c04fe0af2e8426498bb41b94ea97f1..d2db982d218909dd20b26ab5e5ebe36d493b1d00 100644 (file)
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.
index d84c111371a433e3e8ef26bf323502506f7ade65..57322bbfa525446621cc84afc275ca178228f2e5 100644 (file)
=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.
diff --git a/src/oping.h b/src/oping.h
index b17e65920773985a0c232fdb0fe38a32b98b1658..d450d6cbe212d8b1c790883bbd8a947b576f3d14 100644 (file)
--- a/src/oping.h
+++ b/src/oping.h
/**
* 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