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);
#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);