diff --git a/src/liboping.c b/src/liboping.c
index f4cf614ca0704258a63bf79f32261d88e21e5f06..eca5c162d578655dc3cd7e7ea1b1f473d4c80e14 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-2016 Florian octo Forster <ff at octo.it>
+ * Copyright (C) 2006-2017 Florian octo Forster <ff at octo.it>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
static void ping_free (pinghost_t *ph)
{
static void ping_free (pinghost_t *ph)
{
- if (ph->username != NULL)
- free (ph->username);
-
- if (ph->hostname != NULL)
- free (ph->hostname);
+ if (ph == NULL)
+ return;
- if (ph->data != NULL)
- free (ph->data);
+ free (ph->username);
+ free (ph->hostname);
+ free (ph->data);
free (ph);
}
free (ph);
}
#ifdef SO_TIMESTAMP
if (1) /* {{{ */
{
#ifdef SO_TIMESTAMP
if (1) /* {{{ */
{
- int status;
- int opt = 1;
-
- status = setsockopt (fd,
- SOL_SOCKET, SO_TIMESTAMP,
- &opt, sizeof (opt));
+ int status = setsockopt (fd, SOL_SOCKET, SO_TIMESTAMP,
+ &(int){1}, sizeof(int));
if (status != 0)
{
ping_set_errno (obj, errno);
if (status != 0)
{
ping_set_errno (obj, errno);
if (addrfam == AF_INET)
{
if (addrfam == AF_INET)
{
- int opt;
-
#ifdef IP_RECVTOS
/* Enable receiving the TOS field */
#ifdef IP_RECVTOS
/* Enable receiving the TOS field */
- opt = 1;
- setsockopt (fd, IPPROTO_IP, IP_RECVTOS,
- &opt, sizeof (opt));
+ setsockopt (fd, IPPROTO_IP, IP_RECVTOS, &(int){1}, sizeof(int));
#endif /* IP_RECVTOS */
/* Enable receiving the TTL field */
#endif /* IP_RECVTOS */
/* Enable receiving the TTL field */
- opt = 1;
- setsockopt (fd, IPPROTO_IP, IP_RECVTTL,
- &opt, sizeof (opt));
+ setsockopt (fd, IPPROTO_IP, IP_RECVTTL, &(int){1}, sizeof(int));
}
#if defined(IPV6_RECVHOPLIMIT) || defined(IPV6_RECVTCLASS)
else if (addrfam == AF_INET6)
{
}
#if defined(IPV6_RECVHOPLIMIT) || defined(IPV6_RECVTCLASS)
else if (addrfam == AF_INET6)
{
- int opt;
-
# if defined(IPV6_RECVHOPLIMIT)
/* For details see RFC 3542, section 6.3. */
# if defined(IPV6_RECVHOPLIMIT)
/* For details see RFC 3542, section 6.3. */
- opt = 1;
setsockopt (fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT,
setsockopt (fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT,
- &opt, sizeof (opt));
+ &(int){1}, sizeof(int));
# endif /* IPV6_RECVHOPLIMIT */
# if defined(IPV6_RECVTCLASS)
/* For details see RFC 3542, section 6.5. */
# endif /* IPV6_RECVHOPLIMIT */
# if defined(IPV6_RECVTCLASS)
/* For details see RFC 3542, section 6.5. */
- opt = 1;
setsockopt (fd, IPPROTO_IPV6, IPV6_RECVTCLASS,
setsockopt (fd, IPPROTO_IPV6, IPV6_RECVTCLASS,
- &opt, sizeof (opt));
+ &(int){1}, sizeof(int));
# endif /* IPV6_RECVTCLASS */
}
#endif /* IPV6_RECVHOPLIMIT || IPV6_RECVTCLASS */
# endif /* IPV6_RECVTCLASS */
}
#endif /* IPV6_RECVHOPLIMIT || IPV6_RECVTCLASS */
{
pingobj_t *obj;
{
pingobj_t *obj;
- if ((obj = (pingobj_t *) malloc (sizeof (pingobj_t))) == NULL)
+ if ((obj = malloc (sizeof (*obj))) == NULL)
return (NULL);
return (NULL);
- memset (obj, 0, sizeof (pingobj_t));
+ memset (obj, 0, sizeof (*obj));
obj->timeout = PING_DEF_TIMEOUT;
obj->ttl = PING_DEF_TTL;
obj->timeout = PING_DEF_TIMEOUT;
obj->ttl = PING_DEF_TTL;
void ping_destroy (pingobj_t *obj)
{
pinghost_t *current;
void ping_destroy (pingobj_t *obj)
{
pinghost_t *current;
- pinghost_t *next;
if (obj == NULL)
return;
current = obj->head;
if (obj == NULL)
return;
current = obj->head;
- next = NULL;
while (current != NULL)
{
while (current != NULL)
{
- next = current->next;
+ pinghost_t *next = current->next;
ping_free (current);
current = next;
}
ping_free (current);
current = next;
}
- if (obj->data != NULL)
- free (obj->data);
-
- if (obj->srcaddr != NULL)
- free (obj->srcaddr);
-
- if (obj->device != NULL)
- free (obj->device);
+ free (obj->data);
+ free (obj->srcaddr);
+ free (obj->device);
if (obj->fd4 != -1)
close(obj->fd4);
if (obj->fd4 != -1)
close(obj->fd4);
return ((pingobj_iter_t *) iter->next);
}
return ((pingobj_iter_t *) iter->next);
}
+int ping_iterator_count (pingobj_t *obj)
+{
+ if (obj == NULL)
+ return 0;
+
+ int count = 0;
+ pingobj_iter_t *iter = obj->head;
+ while (iter) {
+ count++;
+ iter = iter->next;
+ }
+ return count;
+}
+
int ping_iterator_get_info (pingobj_iter_t *iter, int info,
void *buffer, size_t *buffer_len)
{
int ping_iterator_get_info (pingobj_iter_t *iter, int info,
void *buffer, size_t *buffer_len)
{