author | Florian Forster <ff@octo.it> | |
Thu, 18 Aug 2016 04:58:53 +0000 (06:58 +0200) | ||
committer | Florian Forster <ff@octo.it> | |
Thu, 18 Aug 2016 04:58:53 +0000 (06:58 +0200) |
configure.ac | patch | blob | history | |
src/Makefile.am | patch | blob | history | |
src/liboping.c | patch | blob | history | |
src/oping.c | patch | blob | history |
diff --git a/configure.ac b/configure.ac
index f83f5ab7a15667e263c1a6f30f5a7f8395af3296..aea4efba1b9d9c0d92ad30af0d89dfe3692d5f06 100644 (file)
--- a/configure.ac
+++ b/configure.ac
AC_SUBST(LIBOPING_PC_LIBS_PRIVATE)
-nanosleep_needs_rt="no"
-AC_CHECK_FUNCS(nanosleep, [],
- AC_CHECK_LIB(rt, nanosleep,
- [nanosleep_needs_rt="yes"],
- AC_MSG_ERROR(cannot find nanosleep)))
-AM_CONDITIONAL(BUILD_WITH_LIBRT, test "x$nanosleep_needs_rt" = "xyes")
+AC_SEARCH_LIBS([nanosleep],[rt],[],
+ [AC_MSG_ERROR([cannot find nanosleep])])
+AC_SEARCH_LIBS([clock_gettime],[rt],[],
+ [AC_MSG_ERROR([cannot find clock_gettime])])
with_ncurses="no"
AC_CHECK_HEADERS(ncursesw/ncurses.h ncurses.h, [with_ncurses="yes"], [])
diff --git a/src/Makefile.am b/src/Makefile.am
index ec4c398e933f2f06f3ba675035a574217eeea3b0..090d1b2947dda30682d811398a7e526ea640e452 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
oping_SOURCES = oping.c
oping_LDADD = liboping.la -lm
-if BUILD_WITH_LIBRT
-oping_LDADD += -lrt
-endif
if BUILD_WITH_LIBNCURSES
bin_PROGRAMS += noping
noping_SOURCES = oping.c
noping_CPPFLAGS = $(AM_CPPFLAGS) -DUSE_NCURSES=1
noping_LDADD = liboping.la -lm $(NCURSES_LIB)
-if BUILD_WITH_LIBRT
-noping_LDADD += -lrt
-endif
endif # BUILD_WITH_LIBNCURSES
install-exec-hook:
diff --git a/src/liboping.c b/src/liboping.c
index d99129ccc3c186d8ba7b8e6b5eec75ed2e0673bc..f8c5bfbf6a6c251f5ac2f91ec4e20acd2d64949f 100644 (file)
--- a/src/liboping.c
+++ b/src/liboping.c
buffer += ip_hdr_len;
buffer_len -= ip_hdr_len;
- if (buffer_len < sizeof (struct icmp))
+ if (buffer_len < ICMP_MINLEN)
return (NULL);
icmp_hdr = (struct icmp *) buffer;
- buffer += sizeof (struct icmp);
- buffer_len -= sizeof (struct icmp);
-
if (icmp_hdr->icmp_type != ICMP_ECHOREPLY)
{
- dprintf ("Unexpected ICMP type: %i\n", icmp_hdr->icmp_type);
+ dprintf ("Unexpected ICMP type: %"PRIu8"\n", icmp_hdr->icmp_type);
return (NULL);
}
recv_checksum = icmp_hdr->icmp_cksum;
+ /* This writes to buffer. */
icmp_hdr->icmp_cksum = 0;
- calc_checksum = ping_icmp4_checksum ((char *) icmp_hdr,
- sizeof (struct icmp) + buffer_len);
+ calc_checksum = ping_icmp4_checksum (buffer, 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)
{
struct icmp *icmp4;
int status;
- char buf[4096];
- int buflen;
+ char buf[4096] = {0};
+ size_t buflen;
char *data;
- int datalen;
+ size_t datalen;
dprintf ("ph->hostname = %s\n", ph->hostname);
- memset (buf, '\0', sizeof (buf));
icmp4 = (struct icmp *) buf;
- data = (char *) (icmp4 + 1);
-
- icmp4->icmp_type = ICMP_ECHO;
- icmp4->icmp_code = 0;
- icmp4->icmp_cksum = 0;
- icmp4->icmp_id = htons (ph->ident);
- icmp4->icmp_seq = htons (ph->sequence);
+ *icmp4 = (struct icmp) {
+ .icmp_type = ICMP_ECHO,
+ .icmp_id = htons (ph->ident),
+ .icmp_seq = htons (ph->sequence),
+ };
- buflen = 4096 - sizeof (struct icmp);
- strncpy (data, ph->data, buflen);
- datalen = strlen (data);
+ datalen = strlen (ph->data);
+ buflen = ICMP_MINLEN + datalen;
+ if (sizeof (buf) < buflen)
+ return (EINVAL);
- buflen = datalen + sizeof (struct icmp);
+ data = buf + ICMP_MINLEN;
+ memcpy (data, ph->data, datalen);
icmp4->icmp_cksum = ping_icmp4_checksum (buf, buflen);
struct icmp6_hdr *icmp6;
int status;
- char buf[4096];
+ char buf[4096] = {0};
int buflen;
char *data;
dprintf ("ph->hostname = %s\n", ph->hostname);
- memset (buf, '\0', sizeof (buf));
icmp6 = (struct icmp6_hdr *) buf;
- data = (char *) (icmp6 + 1);
+ *icmp6 = (struct icmp6_hdr) {
+ .icmp6_type = ICMP6_ECHO_REQUEST,
+ .icmp6_id = htons (ph->ident),
+ .icmp6_seq = htons (ph->sequence),
+ };
- 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);
+ datalen = strlen (ph->data);
+ buflen = sizeof (*icmp6) + datalen;
+ if (sizeof (buf) < buflen)
+ return (EINVAL);
- buflen = 4096 - sizeof (struct icmp6_hdr);
- strncpy (data, ph->data, buflen);
- datalen = strlen (data);
+ data = buf + ICMP_MINLEN;
+ memcpy (data, ph->data, datalen);
- buflen = datalen + sizeof (struct icmp6_hdr);
+ /* The checksum will be calculated by the TCP/IP stack. */
dprintf ("Sending ICMPv6 package with ID 0x%04x\n", ph->ident);
diff --git a/src/oping.c b/src/oping.c
index 0ec67947310e7b73d5d8ae1cb8afbf016bdc0577..0cfe64672065c0a99dd3a1d2e9ca8bc9bd5763ce 100644 (file)
--- a/src/oping.c
+++ b/src/oping.c
free (opt_outfile);
opt_outfile = strdup (optarg);
}
+ break;
case 'P':
{