summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 73ce2c0)
raw | patch | inline | side by side (parent: 73ce2c0)
author | octo <octo> | |
Mon, 15 May 2006 20:56:32 +0000 (20:56 +0000) | ||
committer | octo <octo> | |
Mon, 15 May 2006 20:56:32 +0000 (20:56 +0000) |
But for now data can be assigned to ping_objs, it's inherited by ping_hosts and
can be retrieved by `ping_get_info'.
can be retrieved by `ping_get_info'.
src/liboping.c | patch | blob | history | |
src/oping.h | patch | blob | history |
diff --git a/src/liboping.c b/src/liboping.c
index 3c63521a65b12b7c15ea7e1587d606bc834c7a55..2892bebd6eaaf275bb376f1848e90c4c6e65b20b 100644 (file)
--- a/src/liboping.c
+++ b/src/liboping.c
int sequence;
struct timeval *timer;
double latency;
+ char *data;
void *context;
icmp4->icmp_seq = htons (ph->sequence);
buflen = 4096 - sizeof (struct icmp);
- if (obj->data != NULL)
- strncpy (data, obj->data, buflen);
- else
- strncpy (data, PING_DEF_DATA, buflen);
+ strncpy (data, ph->data, buflen);
datalen = strlen (data);
buflen = datalen + sizeof (struct icmp);
icmp6->icmp6_type = ICMP6_ECHO_REQUEST;
icmp6->icmp6_code = 0;
/* The checksum will be calculated by the TCP/IP stack. */
+ /* FIXME */
icmp6->icmp6_cksum = 0;
icmp6->icmp6_id = htons (ph->ident);
icmp6->icmp6_seq = htons (ph->sequence);
buflen = 4096 - sizeof (struct icmp6_hdr);
- if (obj->data != NULL)
- strncpy (data, obj->data, buflen);
- else
- strncpy (data, PING_DEF_DATA, buflen);
+ strncpy (data, ph->data, buflen);
datalen = strlen (data);
buflen = datalen + sizeof (struct icmp6_hdr);
if (ph->hostname != NULL)
free (ph->hostname);
+ if (ph->data != NULL)
+ free (ph->data);
+
free (ph);
}
obj->timeout = PING_DEF_TIMEOUT;
obj->ttl = PING_DEF_TTL;
obj->addrfamily = PING_DEF_AF;
+ obj->data = strdup (PING_DEF_DATA);
return (obj);
}
current = next;
}
+ if (obj->data != NULL)
+ free (obj->data);
+
free (obj);
return;
return (-1);
}
+ /* obj->data is not garuanteed to be != NULL */
+ if ((ph->data = strdup (obj->data == NULL ? PING_DEF_DATA : obj->data)) == 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");
ret = 0;
break;
- /* FIXME Return the sequence as an unsigned int */
case PING_INFO_SEQUENCE:
ret = ENOMEM;
*buffer_len = sizeof (unsigned int);
*((uint16_t *) buffer) = (uint16_t) iter->ident;
ret = 0;
break;
+
+ case PING_INFO_DATA:
+ ret = ENOMEM;
+ *buffer_len = strlen (iter->data);
+ if (orig_buffer_len < *buffer_len)
+ break;
+ strncpy ((char *) buffer, iter->data, orig_buffer_len);
+ ret = 0;
+ break;
}
return (ret);
diff --git a/src/oping.h b/src/oping.h
index 7463672ee4425ac96a1e5deb9a7ca1815ae38a0d..54d031017166495d0378ab7f6942902e123b4bf4 100644 (file)
--- a/src/oping.h
+++ b/src/oping.h
#define PING_INFO_LATENCY 4
#define PING_INFO_SEQUENCE 5
#define PING_INFO_IDENT 6
+#define PING_INFO_DATA 7
int ping_iterator_get_info (pingobj_iter_t *iter, int info,
void *buffer, size_t *buffer_len);