summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 51d8abd)
raw | patch | inline | side by side (parent: 51d8abd)
author | octo <octo> | |
Mon, 17 Apr 2006 08:51:03 +0000 (08:51 +0000) | ||
committer | octo <octo> | |
Mon, 17 Apr 2006 08:51:03 +0000 (08:51 +0000) |
- ping_set_error
- ping_get_error
- ping_get_error
src/liboping/liboping.c | patch | blob | history | |
src/liboping/liboping.h | patch | blob | history |
index 12cb74077f0b59566ea54d8cd657e10cb261dd27..225dfa760c39894a05edea00eb76347d2fa6a347 100644 (file)
--- a/src/liboping/liboping.c
+++ b/src/liboping/liboping.c
# define dprintf(...) /**/
#endif
+#define PING_ERRMSG_LEN 256
+
#define PING_DATA "Florian Forster <octo@verplant.org> http://verplant.org/"
struct pinghost
int ttl;
int addrfamily;
+ char errmsg[PING_ERRMSG_LEN];
+
pinghost_t *head;
};
/*
* private (static) functions
*/
+static void ping_set_error (pingobj_t *obj, const char *function,
+ const char *message)
+{
+ snprintf (obj->errmsg, PING_ERRMSG_LEN, "%s: %s", function, message);
+ obj->errmsg[PING_ERRMSG_LEN - 1] = '\0';
+}
+
static int ping_timeval_add (struct timeval *tv1, struct timeval *tv2,
struct timeval *res)
{
ptr->latency = -1.0;
if (gettimeofday (&nowtime, NULL) == -1)
+ {
+ ping_set_error (obj, "gettimeofday", strerror (errno));
return (-1);
+ }
/* Set up timeout */
timeout.tv_sec = (time_t) obj->timeout;
break;
if (gettimeofday (&nowtime, NULL) == -1)
+ {
+ ping_set_error (obj, "gettimeofday", strerror (errno));
return (-1);
+ }
if (ping_timeval_sub (&endtime, &nowtime, &timeout) == -1)
break;
status = select (max_readfds + 1, &readfds, NULL, NULL, &timeout);
if (gettimeofday (&nowtime, NULL) == -1)
+ {
+ ping_set_error (obj, "gettimeofday", strerror (errno));
return (-1);
+ }
if ((status == -1) && (errno == EINTR))
{
* +-> ping_send_one_ipv4 *
* `-> ping_send_one_ipv6 *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-ssize_t ping_sendto (pinghost_t *ph, const void *buf, size_t buflen)
+static ssize_t ping_sendto (pinghost_t *ph, const void *buf, size_t buflen)
{
ssize_t ret;
/*
* public methods
*/
+const char *ping_get_error (pingobj_t *obj)
+{
+ return (obj->errmsg);
+}
+
pingobj_t *ping_construct (void)
{
pingobj_t *obj;
if ((obj = (pingobj_t *) malloc (sizeof (pingobj_t))) == NULL)
return (NULL);
-
- obj->head = NULL;
+ memset (obj, '\0', sizeof (pingobj_t));
return (obj);
}
if ((ph->hostname = strdup (host)) == NULL)
{
dprintf ("Out of memory!\n");
+ ping_set_error (obj, "strdup", strerror (errno));
ping_free (ph);
return (-1);
}
if ((ai_return = getaddrinfo (host, NULL, &ai_hints, &ai_list)) != 0)
{
dprintf ("getaddrinfo failed\n");
+ ping_set_error (obj, "getaddrinfo",
+ (ai_return == EAI_SYSTEM)
+ ? strerror (errno)
+ : gai_strerror (ai_return));
ping_free (ph);
return (-1);
}
{
free (ph->hostname);
free (ph);
+ ping_set_error (obj, "ping_host_add", "Unable to open socket");
return (-1);
}
}
if (cur == NULL)
+ {
+ ping_set_error (obj, "ping_host_remove", "Host not found");
return (-1);
+ }
if (pre == NULL)
obj->head = cur->next;
index 9f854ebecc69d26221ced3eff6ae04acfddf02e7..9fd7597fa04dc264188734f8fcc969e14dfd6c41 100644 (file)
--- a/src/liboping/liboping.h
+++ b/src/liboping/liboping.h
const char *ping_iterator_get_host (pingobj_iter_t *iter);
double ping_iterator_get_latency (pingobj_iter_t *iter);
+const char *ping_get_error (pingobj_t *obj);
+
#endif /* OCTO_PING_H */