summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2599a5d)
raw | patch | inline | side by side (parent: 2599a5d)
author | Florian Forster <ff@octo.it> | |
Tue, 9 Aug 2016 14:22:55 +0000 (16:22 +0200) | ||
committer | Florian Forster <ff@octo.it> | |
Tue, 9 Aug 2016 14:59:06 +0000 (16:59 +0200) |
The definitions of struct icmphdr differ between platforms, while
ICMP_MINLEN is always 8, which is what we need here.
ICMP_MINLEN is always 8, which is what we need here.
src/liboping.c | patch | blob | history |
diff --git a/src/liboping.c b/src/liboping.c
index 396f489f3d0b1d0d2f9ef382dbfc266f2ea0c189..f3c850ec763d854dc129c3ec29aa16429b890d7f 100644 (file)
--- a/src/liboping.c
+++ b/src/liboping.c
buffer += ip_hdr_len;
buffer_len -= ip_hdr_len;
- if (buffer_len < sizeof (struct icmphdr))
+ if (buffer_len < ICMP_MINLEN)
return (NULL);
icmp_hdr = (struct icmp *) buffer;
- buffer += sizeof (struct icmphdr);
- buffer_len -= sizeof (struct icmphdr);
+ buffer += ICMP_MINLEN;
+ buffer_len -= ICMP_MINLEN;
if (icmp_hdr->icmp_type != ICMP_ECHOREPLY)
{
recv_checksum = icmp_hdr->icmp_cksum;
icmp_hdr->icmp_cksum = 0;
calc_checksum = ping_icmp4_checksum ((char *) icmp_hdr,
- sizeof (struct icmphdr) + buffer_len);
+ ICMP_MINLEN + buffer_len);
if (recv_checksum != calc_checksum)
{
pinghost_t *ptr;
- if (buffer_len < sizeof (struct icmp6_hdr))
+ if (buffer_len < ICMP_MINLEN)
return (NULL);
icmp_hdr = (struct icmp6_hdr *) buffer;
- buffer += sizeof (struct icmp);
- buffer_len -= sizeof (struct icmp);
+ buffer += ICMP_MINLEN;
+ buffer_len -= ICMP_MINLEN;
if (icmp_hdr->icmp6_type != ICMP6_ECHO_REPLY)
{
memset (buf, '\0', sizeof (buf));
icmp4 = (struct icmp *) buf;
- data = buf + sizeof (struct icmphdr);
+ data = buf + ICMP_MINLEN;
icmp4->icmp_type = ICMP_ECHO;
icmp4->icmp_code = 0;
icmp4->icmp_id = htons (ph->ident);
icmp4->icmp_seq = htons (ph->sequence);
- buflen = sizeof(buf) - sizeof (struct icmphdr);
+ buflen = sizeof(buf) - ICMP_MINLEN;
strncpy (data, ph->data, buflen);
datalen = strlen (data);
- buflen = datalen + sizeof (struct icmphdr);
+ buflen = datalen + ICMP_MINLEN;
icmp4->icmp_cksum = ping_icmp4_checksum (buf, buflen);
icmp6->icmp6_id = htons (ph->ident);
icmp6->icmp6_seq = htons (ph->sequence);
- buflen = 4096 - sizeof (struct icmp6_hdr);
+ buflen = 4096 - ICMP_MINLEN;
strncpy (data, ph->data, buflen);
datalen = strlen (data);
- buflen = datalen + sizeof (struct icmp6_hdr);
+ buflen = datalen + ICMP_MINLEN;
dprintf ("Sending ICMPv6 package with ID 0x%04x\n", ph->ident);