diff --git a/src/liboping.c b/src/liboping.c
index 9b91b6d40f0214963c025aeb6af9e7f3f4246575..22ab3a8672167b4d53248c4b92b9646ab82c05ee 100644 (file)
--- a/src/liboping.c
+++ b/src/liboping.c
/**
* Object oriented C module to send ICMP and ICMPv6 `echo's.
/**
* 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
*
* 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
{
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;
char *hostname;
struct sockaddr_storage *addr;
socklen_t addrlen;
@@ -288,6 +291,22 @@ static pinghost_t *ping_receive_ipv4 (pinghost_t *ph, char *buffer, size_t buffe
return (ptr);
}
return (ptr);
}
+#ifndef ICMP6_ECHO_REQUEST
+# ifdef ICMP6_ECHO /* AIX netinet/ip6_icmp.h */
+# define ICMP6_ECHO_REQUEST ICMP6_ECHO
+# else
+# define ICMP6_ECHO_REQUEST 128
+# endif
+#endif
+
+#ifndef ICMP6_ECHO_REPLY
+# ifdef ICMP6_ECHOREPLY /* AIX netinet/ip6_icmp.h */
+# define ICMP6_ECHO_REPLY ICMP6_ECHOREPLY
+# else
+# define ICMP6_ECHO_REPLY 129
+# endif
+#endif
+
static pinghost_t *ping_receive_ipv6 (pinghost_t *ph, char *buffer, size_t buffer_len)
{
struct icmp6_hdr *icmp_hdr;
static pinghost_t *ping_receive_ipv6 (pinghost_t *ph, char *buffer, size_t buffer_len)
{
struct icmp6_hdr *icmp_hdr;
if (ph->fd >= 0)
close (ph->fd);
if (ph->fd >= 0)
close (ph->fd);
+ if (ph->username != NULL)
+ free (ph->username);
+
if (ph->hostname != NULL)
free (ph->hostname);
if (ph->hostname != NULL)
free (ph->hostname);
if (status != 0)
{
ping_set_error (obj, "getaddrinfo",
if (status != 0)
{
ping_set_error (obj, "getaddrinfo",
- status == EAI_SYSTEM
- ? strerror (errno)
- : gai_strerror (status));
+#if defined(EAI_SYSTEM)
+ (status == EAI_SYSTEM)
+ ? strerror (errno) :
+#endif
+ gai_strerror (status));
ret = -1;
break;
}
ret = -1;
break;
}
{
while (ph != NULL)
{
{
while (ph != NULL)
{
- if (strcasecmp (ph->hostname, host) == 0)
+ if (strcasecmp (ph->username, host) == 0)
break;
ph = ph->next;
break;
ph = ph->next;
return (-1);
}
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");
if ((ph->hostname = strdup (host)) == NULL)
{
dprintf ("Out of memory!\n");
{
dprintf ("getaddrinfo failed\n");
ping_set_error (obj, "getaddrinfo",
{
dprintf ("getaddrinfo failed\n");
ping_set_error (obj, "getaddrinfo",
- (ai_return == EAI_SYSTEM)
- ? strerror (errno)
- : gai_strerror (ai_return));
+#if defined(EAI_SYSTEM)
+ (ai_return == EAI_SYSTEM)
+ ? strerror (errno) :
+#endif
+ gai_strerror (ai_return));
ping_free (ph);
return (-1);
}
ping_free (ph);
return (-1);
}
while (cur != NULL)
{
while (cur != NULL)
{
- if (strcasecmp (host, cur->hostname) == 0)
+ if (strcasecmp (host, cur->username) == 0)
break;
pre = cur;
break;
pre = cur;
switch (info)
{
switch (info)
{
+ case PING_INFO_USERNAME:
+ ret = ENOMEM;
+ *buffer_len = strlen (iter->username) + 1;
+ 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;
case PING_INFO_HOSTNAME:
ret = ENOMEM;
- *buffer_len = strlen (iter->hostname);
+ *buffer_len = strlen (iter->hostname) + 1;
if (orig_buffer_len <= *buffer_len)
break;
/* Since (orig_buffer_len > *buffer_len) `strncpy'
if (orig_buffer_len <= *buffer_len)
break;
/* Since (orig_buffer_len > *buffer_len) `strncpy'
#endif
)
ret = ENOMEM;
#endif
)
ret = ENOMEM;
+#if defined(EAI_SYSTEM)
else if (ret == EAI_SYSTEM)
else if (ret == EAI_SYSTEM)
- /* XXX: Not thread-safe! */
ret = errno;
ret = errno;
+#endif
else
ret = EINVAL;
}
else
ret = EINVAL;
}