summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ef7cc59)
raw | patch | inline | side by side (parent: ef7cc59)
author | Florian Forster <octo@collectd.org> | |
Fri, 4 Dec 2015 15:38:16 +0000 (16:38 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Fri, 4 Dec 2015 15:38:16 +0000 (16:38 +0100) |
A couple of coding style fixes have also been applied.
src/ping.c | patch | blob | history |
diff --git a/src/ping.c b/src/ping.c
index cac8a3fde43540c08249877e54138cefdc6e590f..85421647b1a0507cb6edf5598e52ca1ccbcf6fef 100644 (file)
--- a/src/ping.c
+++ b/src/ping.c
tmp, value);
}
else if (strcasecmp (key, "Size") == 0) {
- int size;
+ size_t size = (size_t) atoi (value);
- if (ping_data != NULL)
+ /* Max IP packet size - (IPv6 + ICMP) = 65535 - (40 + 8) = 65487 */
+ if (size <= 65487)
{
- free (ping_data);
- ping_data = NULL;
- }
+ size_t i;
- size = atoi (value);
- if ((size >= 0) && (size <= 65536))
- {
- int i;
- ping_data = (char *) malloc(size + 1);
+ sfree (ping_data);
+ ping_data = malloc (size + 1);
if (ping_data == NULL)
{
- char errbuf[1024];
- ERROR ("ping plugin: malloc failed: %s",
- sstrerror (errno, errbuf, sizeof (errbuf)));
+ ERROR ("ping plugin: malloc failed.");
return (1);
}
+
/* Note: By default oping is using constant string
* "liboping -- ICMP ping library <http://octo.it/liboping/>"
* which is exactly 56 bytes.
* printable characters, and not NUL character. */
ping_data[i] = ('0' + i % 64);
} /* }}} for (i = 0; i < size; i++) */
- ping_data[size] = '\0';
+ ping_data[size] = 0;
} else
- WARNING ("ping plugin: Ignoring invalid Size %i.", size);
+ WARNING ("ping plugin: Ignoring invalid Size %zu.", size);
}
else if (strcasecmp (key, "Timeout") == 0)
{