From 709c2f01a10303bf658de27f6816dcdfcb7f2c27 Mon Sep 17 00:00:00 2001 From: Tonton Th Date: Sun, 6 Jan 2013 17:55:38 +0100 Subject: [PATCH 01/29] Add an option to limit the number of packet sent. --- echoc.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/echoc.c b/echoc.c index f5ddb69..80fc9ff 100644 --- a/echoc.c +++ b/echoc.c @@ -36,13 +36,12 @@ struct sockaddr *server; socklen_t serverlen; unsigned int seq = 0; -static void -usage(void) -{ - errx(2, "usage: echoc [-i ms][-t ms][-v] server"); -} - -static void + static void + usage(void) + { + errx(2, "usage: echoc [-c nbr][-i ms][-t ms][-v] server"); + } + static void send_packet(int unused) { if (sendto(sock, &seq, sizeof(seq), 0, server, @@ -74,11 +73,16 @@ main(int argc, char *argv[]) int nfds, received = 0; int error, buffer, last = -1; int disconnected; + int we_count = 0, counter; /* don't loop forever */ extern int optind; setbuf(stdout, NULL); - while ((ch = getopt(argc, argv, "i:t:v")) != -1) { + while ((ch = getopt(argc, argv, "c:i:t:v")) != -1) { switch (ch) { + case 'c': + we_count++; + counter = atoi(optarg); + break; case 'i': interval = atoi(optarg); break; @@ -99,7 +103,8 @@ main(int argc, char *argv[]) if (interval <= 0 || timeout <= 0) errx(2, "interval and timeout must be > 0"); - + if (counter < 2) + errx(2, "can't count down from nothing"); /* force timeout >= interval */ if (timeout < interval) { timeout = interval; @@ -205,6 +210,13 @@ main(int argc, char *argv[]) if (verbose) printf("received %d %ld.%06ld\n", buffer, (long)diff.tv_sec, diff.tv_usec); + if (we_count) { + counter--; + if (counter == 0) { + printf("all job done\n"); + break; + } + } } close(sock); exit(0); From 3e9361d58a80f0632c9fd6be9b142c61143f006c Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Sat, 6 Apr 2013 16:25:30 +0200 Subject: [PATCH 02/29] White space fix --- echoc.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/echoc.c b/echoc.c index 80fc9ff..cb014a9 100644 --- a/echoc.c +++ b/echoc.c @@ -36,12 +36,13 @@ struct sockaddr *server; socklen_t serverlen; unsigned int seq = 0; - static void - usage(void) - { +static void +usage(void) +{ errx(2, "usage: echoc [-c nbr][-i ms][-t ms][-v] server"); - } - static void +} + +static void send_packet(int unused) { if (sendto(sock, &seq, sizeof(seq), 0, server, From 32900c1c94df065000e3b89825a37fb6e07458d0 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Wed, 9 Jan 2013 14:25:11 +0100 Subject: [PATCH 03/29] White space fixes --- echoc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/echoc.c b/echoc.c index cb014a9..221499e 100644 --- a/echoc.c +++ b/echoc.c @@ -50,7 +50,7 @@ send_packet(int unused) if (verbose) warn("sendto"); } - if (verbose) + if (verbose) printf("sent %d\n", seq); seq++; } @@ -137,11 +137,11 @@ main(int argc, char *argv[]) memset(&client, 0, sizeof(client)); /* timer values */ - itv.it_interval.tv_usec = interval*1000; + itv.it_interval.tv_usec = interval*1000; itv.it_interval.tv_sec = 0; itv.it_value.tv_usec = interval*1000; itv.it_value.tv_sec = 0; - if (setitimer(ITIMER_REAL, &itv, NULL) == -1) + if (setitimer(ITIMER_REAL, &itv, NULL) == -1) err(2, "setitimer"); signal(SIGALRM, send_packet); @@ -167,10 +167,10 @@ main(int argc, char *argv[]) } } if ((nfds == 0)) { - if (verbose) + if (verbose) printf("%d packet(s) dropped in %ld.%06ld s\n", seq - last, diff.tv_sec, diff.tv_usec); - + if (disconnected == 1) { tm = localtime((time_t *)&last_ts.tv_sec); strftime(buf, sizeof(buf), "%F %T", tm); @@ -209,7 +209,7 @@ main(int argc, char *argv[]) last = buffer; memcpy(&last_ts, &now, sizeof(struct timeval)); if (verbose) - printf("received %d %ld.%06ld\n", buffer, + printf("received %d %ld.%06ld\n", buffer, (long)diff.tv_sec, diff.tv_usec); if (we_count) { counter--; From 96147119964dfb420c731904cd2edcf1e62bdf27 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Tue, 29 Apr 2014 18:59:46 +0200 Subject: [PATCH 04/29] Fix infinite loop mode. --- echoc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/echoc.c b/echoc.c index 221499e..4d97727 100644 --- a/echoc.c +++ b/echoc.c @@ -104,7 +104,7 @@ main(int argc, char *argv[]) if (interval <= 0 || timeout <= 0) errx(2, "interval and timeout must be > 0"); - if (counter < 2) + if (we_count && counter < 2) errx(2, "can't count down from nothing"); /* force timeout >= interval */ if (timeout < interval) { From d84b68a63ad3985fee32460287db78dfe5eae990 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Tue, 29 Sep 2015 15:28:22 +0200 Subject: [PATCH 05/29] Add length & port control options --- echoc.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/echoc.c b/echoc.c index 4d97727..5cf4c80 100644 --- a/echoc.c +++ b/echoc.c @@ -35,18 +35,22 @@ int verbose = 0; struct sockaddr *server; socklen_t serverlen; unsigned int seq = 0; +size_t len = 10; static void usage(void) { - errx(2, "usage: echoc [-c nbr][-i ms][-t ms][-v] server"); + errx(2, "usage: echoc [-c nbr][-i ms][-l len][-p port][-t ms][-v] server"); } static void send_packet(int unused) { - if (sendto(sock, &seq, sizeof(seq), 0, server, - serverlen) != sizeof(seq)) { + char buf[len]; + + snprintf(buf, len, "%d", seq); + if (sendto(sock, buf, len, 0, server, + serverlen) != len) { if (verbose) warn("sendto"); } @@ -59,7 +63,8 @@ int main(int argc, char *argv[]) { char name[NI_MAXHOST]; - char buf[80]; + char *buf; + char *port = "echo"; struct sockaddr_storage client; struct addrinfo hints, *res, *res0; struct itimerval itv; @@ -78,7 +83,7 @@ main(int argc, char *argv[]) extern int optind; setbuf(stdout, NULL); - while ((ch = getopt(argc, argv, "c:i:t:v")) != -1) { + while ((ch = getopt(argc, argv, "c:i:l:p:t:v")) != -1) { switch (ch) { case 'c': we_count++; @@ -87,6 +92,12 @@ main(int argc, char *argv[]) case 'i': interval = atoi(optarg); break; + case 'l': + len = atoi(optarg); + break; + case 'p': + port = optarg; + break; case 't': timeout = atoi(optarg); break; @@ -117,7 +128,7 @@ main(int argc, char *argv[]) memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; - error = getaddrinfo(argv[0], "echo", &hints, &res0); + error = getaddrinfo(argv[0], port, &hints, &res0); if (error) errx(1, "%s: %s", argv[0], gai_strerror(error)); @@ -148,6 +159,10 @@ main(int argc, char *argv[]) gettimeofday(&last_ts, NULL); + buf = malloc(len); + if (buf == NULL) + err(2, "malloc receive buffer"); + while (1) { /* poll() loop to handle interruptions by SIGALRM */ while (1) { From d625d804c6a2b985ab941233140f05f964ebcbbc Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Tue, 29 Sep 2015 18:53:51 +0200 Subject: [PATCH 06/29] Add -d to set the IP 'DF' flag on outgoing packets. Without -d it won't be set, regardless of the ip_no_pmtu_disc sysctl setting on Linux. --- echoc.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/echoc.c b/echoc.c index 5cf4c80..9ea5790 100644 --- a/echoc.c +++ b/echoc.c @@ -40,7 +40,7 @@ size_t len = 10; static void usage(void) { - errx(2, "usage: echoc [-c nbr][-i ms][-l len][-p port][-t ms][-v] server"); + errx(2, "usage: echoc [-c nbr][-d][-i ms][-l len][-p port][-t ms][-v] server"); } static void @@ -79,16 +79,20 @@ main(int argc, char *argv[]) int nfds, received = 0; int error, buffer, last = -1; int disconnected; + int nofragment = 0; int we_count = 0, counter; /* don't loop forever */ extern int optind; setbuf(stdout, NULL); - while ((ch = getopt(argc, argv, "c:i:l:p:t:v")) != -1) { + while ((ch = getopt(argc, argv, "c:di:l:p:t:v")) != -1) { switch (ch) { case 'c': we_count++; counter = atoi(optarg); break; + case 'd': + nofragment++; + break; case 'i': interval = atoi(optarg); break; @@ -163,6 +167,14 @@ main(int argc, char *argv[]) if (buf == NULL) err(2, "malloc receive buffer"); + /* set the DF flag ? */ + if (nofragment) + ch = IP_PMTUDISC_DO; + else + ch = IP_PMTUDISC_DONT; + if (setsockopt(sock, IPPROTO_IP, IP_MTU_DISCOVER, &ch, sizeof(ch)) < 0) + err(2, "setsockopt IP_MTU_DISCOVER"); + while (1) { /* poll() loop to handle interruptions by SIGALRM */ while (1) { From 77734c3cb758efe19df3c7d53f574b827164c742 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Tue, 29 Sep 2015 19:18:07 +0200 Subject: [PATCH 07/29] Not all systems have the IP_MTU_DISCOVER sockopt --- echoc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/echoc.c b/echoc.c index 9ea5790..5319a41 100644 --- a/echoc.c +++ b/echoc.c @@ -167,6 +167,7 @@ main(int argc, char *argv[]) if (buf == NULL) err(2, "malloc receive buffer"); +#ifdef IP_MTU_DISCOVER /* set the DF flag ? */ if (nofragment) ch = IP_PMTUDISC_DO; @@ -174,7 +175,7 @@ main(int argc, char *argv[]) ch = IP_PMTUDISC_DONT; if (setsockopt(sock, IPPROTO_IP, IP_MTU_DISCOVER, &ch, sizeof(ch)) < 0) err(2, "setsockopt IP_MTU_DISCOVER"); - +#endif while (1) { /* poll() loop to handle interruptions by SIGALRM */ while (1) { From 56da27815169ba9885ad8586877f2b44605aee13 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Tue, 29 Sep 2015 19:52:17 +0200 Subject: [PATCH 08/29] Add man page --- echoc.1 | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 echoc.1 diff --git a/echoc.1 b/echoc.1 new file mode 100644 index 0000000..3907f74 --- /dev/null +++ b/echoc.1 @@ -0,0 +1,59 @@ +.Dd $Mdocdate: September 29 2015 $ +.Dt ECHOC 1 +.Os +.Sh NAME +.Nm echoc +.Nd send UDP packets to network hosts and wait for replies +.Sh SYNOPSYS +.Nm echoc +.Bk -words +.Op Fl dv +.Op Fl c Ar count +.Op Fl i Ar ms +.Op Fl l Ar len +.Op Fl p Ar port +.Op Fl t Ar ms +.Ar host +.Ek +.Sh DESCRIPTION +.Nm +sends UDP packets to the +.Dv ECHO +service on the remote +.Ar host . +The options ar as follow: +.Bl -tag -width Ds +.It Fl c Ar count +Stop sending after +.Ar count +packets have been sent. +.It Fl d +Set the +.Dv Don't Fragment +bit. +.It Fl i Ar ms +wait +.Ar i +milliseconds between every packet (default: 100 ms). +.It Fl l Ar len +Send packets of length +.Ar len +bytes (default: 10). +.It Fl p Ar port +Set destination port to +.Ar port +(default: 7 - echo). +.It Fl t Ar ms +Wait at most +.Ar t +milliseconds for the reply before declaring the connection dead. +.El +.Sh SEE ALSO +.Xr nc 1 , +.Xr ping 8 , +.Xr ping6 8 +.Sh AUTHOR +The +.Nm +utility was written for tetaneutral.net by Matthieu Herrb. + From 50fe2999f892dc90fcbaf60d645a5ca52247be68 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Wed, 30 Sep 2015 10:49:06 +0200 Subject: [PATCH 09/29] tweaks --- README | 2 +- echoc.1 | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README b/README index d3b4dc8..bf6504b 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ echoc is a small network test program that sends UDP packets to the echo service (it should be activated in [x]inetd on the target host). echoc displays the start/end date of loss of connectivity. -It's distributed under the ISC license: +It is distributed under the ISC license: /* * Copyright (c) 2012 Matthieu Herrb diff --git a/echoc.1 b/echoc.1 index 3907f74..2f659b7 100644 --- a/echoc.1 +++ b/echoc.1 @@ -21,7 +21,9 @@ sends UDP packets to the .Dv ECHO service on the remote .Ar host . -The options ar as follow: +.Nm +displays the start/end date of loss of connectivity. +The options are as follow: .Bl -tag -width Ds .It Fl c Ar count Stop sending after @@ -30,10 +32,13 @@ packets have been sent. .It Fl d Set the .Dv Don't Fragment -bit. +bit on outgoing datagrams, on systems that allow programs to control it. +On some systems (MacOSX, OpenBSD) this option will do nothing and the +generated datagrams will have the DF bit set or not, depending on +system settings. .It Fl i Ar ms wait -.Ar i +.Ar ms milliseconds between every packet (default: 100 ms). .It Fl l Ar len Send packets of length @@ -45,8 +50,9 @@ Set destination port to (default: 7 - echo). .It Fl t Ar ms Wait at most -.Ar t -milliseconds for the reply before declaring the connection dead. +.Ar ms +milliseconds for the reply before declaring the connection dead +(default: 500ms). .El .Sh SEE ALSO .Xr nc 1 , From ae13384faafab6fe6d230ce756c771ca5e5ee705 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Wed, 30 Sep 2015 11:10:16 +0200 Subject: [PATCH 10/29] Fix decoding of replies after addition of the -l option --- Makefile | 2 +- echoc.c | 36 +++++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index ac8c90b..16f7a91 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ SRCS= echoc.c OBJS= $(SRCS:%.c=%.o) -LIBS= +LIBS= -lbsd all: $(PROG) diff --git a/echoc.c b/echoc.c index 5319a41..f923e81 100644 --- a/echoc.c +++ b/echoc.c @@ -18,6 +18,9 @@ #include #include +#include +#include + #include #include #include @@ -46,8 +49,11 @@ usage(void) static void send_packet(int unused) { - char buf[len]; + char *buf; + buf = malloc(len); + if (buf == NULL) + return; snprintf(buf, len, "%d", seq); if (sendto(sock, buf, len, 0, server, serverlen) != len) { @@ -63,7 +69,9 @@ int main(int argc, char *argv[]) { char name[NI_MAXHOST]; - char *buf; + char *recvbuf; + const char *errstr; + char date[80]; char *port = "echo"; struct sockaddr_storage client; struct addrinfo hints, *res, *res0; @@ -77,7 +85,7 @@ main(int argc, char *argv[]) long timeout = 500; /* default timeout (ms) */ int ch; int nfds, received = 0; - int error, buffer, last = -1; + int error, last = -1; int disconnected; int nofragment = 0; int we_count = 0, counter; /* don't loop forever */ @@ -163,8 +171,8 @@ main(int argc, char *argv[]) gettimeofday(&last_ts, NULL); - buf = malloc(len); - if (buf == NULL) + recvbuf = malloc(len); + if (recvbuf == NULL) err(2, "malloc receive buffer"); #ifdef IP_MTU_DISCOVER @@ -201,17 +209,17 @@ main(int argc, char *argv[]) if (disconnected == 1) { tm = localtime((time_t *)&last_ts.tv_sec); - strftime(buf, sizeof(buf), "%F %T", tm); + strftime(date, sizeof(date), "%F %T", tm); printf("%s.%06ld: lost connection\n", - buf, last_ts.tv_usec); + date, last_ts.tv_usec); } continue; } addrlen = sizeof(client); - if ((received = recvfrom(sock, &buffer, sizeof(buffer), + if ((received = recvfrom(sock, recvbuf, len, MSG_DONTWAIT, (struct sockaddr *) &client, - &addrlen)) != sizeof(buffer)) { + &addrlen)) != len) { warn("recvfrom"); } @@ -228,16 +236,18 @@ main(int argc, char *argv[]) } if (disconnected) { tm = localtime((time_t *)&now.tv_sec); - strftime(buf, sizeof(buf), "%F %T", tm); + strftime(date, sizeof(date), "%F %T", tm); printf("%s.%06ld: connection is back " "dropped %d packets\n", - buf, now.tv_usec, seq - last); + date, now.tv_usec, seq - last); disconnected = 0; } - last = buffer; + last = strtonum(recvbuf, 0, INT_MAX, &errstr); + if (errstr) + errx(1, "invalid reply %s", errstr); memcpy(&last_ts, &now, sizeof(struct timeval)); if (verbose) - printf("received %d %ld.%06ld\n", buffer, + printf("received %d %ld.%06ld\n", last, (long)diff.tv_sec, diff.tv_usec); if (we_count) { counter--; From 703bab20ca8332819cbff7c69f56a351bf4eea96 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Wed, 30 Sep 2015 11:29:41 +0200 Subject: [PATCH 11/29] Quiet gcc warnings --- echoc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/echoc.c b/echoc.c index f923e81..591d698 100644 --- a/echoc.c +++ b/echoc.c @@ -88,7 +88,7 @@ main(int argc, char *argv[]) int error, last = -1; int disconnected; int nofragment = 0; - int we_count = 0, counter; /* don't loop forever */ + int we_count = 0, counter = 0; /* don't loop forever */ extern int optind; setbuf(stdout, NULL); @@ -205,7 +205,7 @@ main(int argc, char *argv[]) if ((nfds == 0)) { if (verbose) printf("%d packet(s) dropped in %ld.%06ld s\n", - seq - last, diff.tv_sec, diff.tv_usec); + seq - last, (long)diff.tv_sec, diff.tv_usec); if (disconnected == 1) { tm = localtime((time_t *)&last_ts.tv_sec); From 558bea99936357efba6b18c47931824d84a2b84f Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Wed, 30 Sep 2015 11:31:37 +0200 Subject: [PATCH 12/29] automake build system --- .gitignore | 25 ++++++++++++++++++++++++- Makefile | 19 ------------------- Makefile.am | 5 +++++ configure.ac | 10 ++++++++++ echoc.c | 2 ++ 5 files changed, 41 insertions(+), 20 deletions(-) delete mode 100644 Makefile create mode 100644 Makefile.am create mode 100644 configure.ac diff --git a/.gitignore b/.gitignore index 6fb5d60..46c3668 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,26 @@ -echoc +*.la +*.lo *.o *~ +.deps +.libs +m4/*.m4 +Makefile +Makefile.in +aclocal.m4 +autom4te.cache +compile +config.guess +config.h +config.h.in +config.log +config.status +config.sub +configure +depcomp +install-sh +libtool +ltmain.sh +missing +stamp-* +obj* diff --git a/Makefile b/Makefile deleted file mode 100644 index 16f7a91..0000000 --- a/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -# - -PROG= echoc -SRCS= echoc.c - -OBJS= $(SRCS:%.c=%.o) - -LIBS= -lbsd - -all: $(PROG) - -$(PROG): $(OBJS) - $(CC) -o $@ $(OBJS) $(LIBS) - -clean: - rm -f $(OBJS) $(PROG) - -.c.o: - $(CC) -c $(CFLAGS) -o $@ $< diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..c30d877 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,5 @@ +bin_PROGRAMS = echoc + +AM_CFLAGS = -g -Wall + +dist_man_MANS = echoc.1 diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..ecee3c3 --- /dev/null +++ b/configure.ac @@ -0,0 +1,10 @@ +AC_PREREQ([2.65]) +AC_INIT([echoc], 0.3.99, [https://chiliproject.tetaneutral.net/projects/git-tetaneutral-net/repository/echoc], echoc) +AM_INIT_AUTOMAKE([foreign dist-bzip2]) +AC_CONFIG_MACRO_DIR([m4]) +AC_PROG_CC + +AC_CHECK_HEADERS([bsd/stdlib.h]) +AC_SEARCH_LIBS(strtonum, [bsd]) + +AC_OUTPUT([Makefile]) diff --git a/echoc.c b/echoc.c index 591d698..993a8a2 100644 --- a/echoc.c +++ b/echoc.c @@ -19,7 +19,9 @@ #include #include +#ifdef HAVE_BSD_STDLIB_H #include +#endif #include #include From 52a3aee91d67186857b26196881967201e97587c Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Wed, 30 Sep 2015 11:48:59 +0200 Subject: [PATCH 13/29] update copyright notices --- echoc.1 | 15 +++++++++++++++ echoc.c | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/echoc.1 b/echoc.1 index 2f659b7..9cada97 100644 --- a/echoc.1 +++ b/echoc.1 @@ -1,3 +1,18 @@ +.\" +.\" Copyright (c) 2012-2015 Matthieu Herrb +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" .Dd $Mdocdate: September 29 2015 $ .Dt ECHOC 1 .Os diff --git a/echoc.c b/echoc.c index 993a8a2..a337cfe 100644 --- a/echoc.c +++ b/echoc.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 Matthieu Herrb + * Copyright (c) 2012-2015 Matthieu Herrb * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above From 9de72b0a31962929670ea7e3516cb4f48f9743be Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Wed, 30 Sep 2015 11:51:57 +0200 Subject: [PATCH 14/29] Convert README to markdown --- README | 21 --------------------- README.md | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 21 deletions(-) delete mode 100644 README create mode 100644 README.md diff --git a/README b/README deleted file mode 100644 index bf6504b..0000000 --- a/README +++ /dev/null @@ -1,21 +0,0 @@ -echoc is a small network test program that sends UDP packets to the -echo service (it should be activated in [x]inetd on the target host). -echoc displays the start/end date of loss of connectivity. - -It is distributed under the ISC license: - -/* - * Copyright (c) 2012 Matthieu Herrb - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ diff --git a/README.md b/README.md new file mode 100644 index 0000000..cb3dacf --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +echoc +===== + +echoc is a small network test program that sends UDP packets to the +echo service (it should be activated in [x]inetd on the target host). +echoc displays the start/end date of loss of connectivity. + +It is distributed under the ISC license: + + Copyright (c) 2012 Matthieu Herrb + + Permission to use, copy, modify, and distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + From a0bf5ae594c3d05abd5debebd7bd5cba06aa8ba4 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Wed, 30 Sep 2015 11:53:41 +0200 Subject: [PATCH 15/29] Release 0.4 --- README.md | 2 +- configure.ac | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cb3dacf..da2894e 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ echoc displays the start/end date of loss of connectivity. It is distributed under the ISC license: - Copyright (c) 2012 Matthieu Herrb + Copyright (c) 2012-2015 Matthieu Herrb Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/configure.ac b/configure.ac index ecee3c3..bcd0906 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.65]) -AC_INIT([echoc], 0.3.99, [https://chiliproject.tetaneutral.net/projects/git-tetaneutral-net/repository/echoc], echoc) +AC_INIT([echoc], 0.4, [https://chiliproject.tetaneutral.net/projects/git-tetaneutral-net/repository/echoc], echoc) AM_INIT_AUTOMAKE([foreign dist-bzip2]) AC_CONFIG_MACRO_DIR([m4]) AC_PROG_CC From 97315cd612790f282e01696bd39577fc50e84c82 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Tue, 17 Jul 2018 18:33:28 +0200 Subject: [PATCH 16/29] Add a standard autogen.sh script --- autogen.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 autogen.sh diff --git a/autogen.sh b/autogen.sh new file mode 100644 index 0000000..bb05f17 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,13 @@ +#! /bin/sh +srcdir=`dirname "$0"` +test -z "$srcdir" && srcdir=. + +ORIGDIR=`pwd` +cd "$srcdir" + +autoreconf -v --install || exit 1 +cd "$ORIGDIR" || exit $? + +if test -z "$NOCONFIGURE"; then + exec "$srcdir"/configure "$@" +fi From 22d0ef76971b410a7e5d93272edf611a10aa7870 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Tue, 17 Jul 2018 18:36:57 +0200 Subject: [PATCH 17/29] Add build instructions --- README.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index da2894e..9c3fb52 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,29 @@ echoc is a small network test program that sends UDP packets to the echo service (it should be activated in [x]inetd on the target host). echoc displays the start/end date of loss of connectivity. -It is distributed under the ISC license: +Building +-------- + +From git, run: + +``` +./autogen.sh +make +make install +``` + +From a source tarball, run: + +``` +./configure +make +make install +``` + +Licence +------- + +Echoc is distributed under the ISC license: Copyright (c) 2012-2015 Matthieu Herrb From c66fae7c45e35ca4e69f9cfaf1f52c4e70035c51 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Wed, 18 Jul 2018 10:54:23 +0200 Subject: [PATCH 18/29] Make autogen.sh executable --- autogen.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 autogen.sh diff --git a/autogen.sh b/autogen.sh old mode 100644 new mode 100755 From 2d3d859d9b0de7a394bc465ff66d0a6f57357d86 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Wed, 18 Jul 2018 10:55:27 +0200 Subject: [PATCH 19/29] Release 0.5 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index bcd0906..8f24152 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.65]) -AC_INIT([echoc], 0.4, [https://chiliproject.tetaneutral.net/projects/git-tetaneutral-net/repository/echoc], echoc) +AC_INIT([echoc], 0.5, [https://chiliproject.tetaneutral.net/projects/git-tetaneutral-net/repository/echoc], echoc) AM_INIT_AUTOMAKE([foreign dist-bzip2]) AC_CONFIG_MACRO_DIR([m4]) AC_PROG_CC From d791054cfe14c311fffd65c96da3d36a433028fa Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Wed, 18 Jul 2018 10:50:33 +0200 Subject: [PATCH 20/29] Set sockets parameters before activating up send_packet timer --- echoc.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/echoc.c b/echoc.c index a337cfe..2e99be1 100644 --- a/echoc.c +++ b/echoc.c @@ -161,18 +161,6 @@ main(int argc, char *argv[]) disconnected = 0; memset(&client, 0, sizeof(client)); - /* timer values */ - itv.it_interval.tv_usec = interval*1000; - itv.it_interval.tv_sec = 0; - itv.it_value.tv_usec = interval*1000; - itv.it_value.tv_sec = 0; - if (setitimer(ITIMER_REAL, &itv, NULL) == -1) - err(2, "setitimer"); - - signal(SIGALRM, send_packet); - - gettimeofday(&last_ts, NULL); - recvbuf = malloc(len); if (recvbuf == NULL) err(2, "malloc receive buffer"); @@ -186,6 +174,18 @@ main(int argc, char *argv[]) if (setsockopt(sock, IPPROTO_IP, IP_MTU_DISCOVER, &ch, sizeof(ch)) < 0) err(2, "setsockopt IP_MTU_DISCOVER"); #endif + /* timer values */ + itv.it_interval.tv_usec = interval*1000; + itv.it_interval.tv_sec = 0; + itv.it_value.tv_usec = interval*1000; + itv.it_value.tv_sec = 0; + if (setitimer(ITIMER_REAL, &itv, NULL) == -1) + err(2, "setitimer"); + + signal(SIGALRM, send_packet); + + gettimeofday(&last_ts, NULL); + while (1) { /* poll() loop to handle interruptions by SIGALRM */ while (1) { From 0f96d32d4c9136ba330d85f444236ea3fb4414a2 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Wed, 18 Jul 2018 10:56:06 +0200 Subject: [PATCH 21/29] Set SIGALRM handler before setting timer --- echoc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/echoc.c b/echoc.c index 2e99be1..eaed4e5 100644 --- a/echoc.c +++ b/echoc.c @@ -174,6 +174,8 @@ main(int argc, char *argv[]) if (setsockopt(sock, IPPROTO_IP, IP_MTU_DISCOVER, &ch, sizeof(ch)) < 0) err(2, "setsockopt IP_MTU_DISCOVER"); #endif + signal(SIGALRM, send_packet); + /* timer values */ itv.it_interval.tv_usec = interval*1000; itv.it_interval.tv_sec = 0; @@ -182,8 +184,6 @@ main(int argc, char *argv[]) if (setitimer(ITIMER_REAL, &itv, NULL) == -1) err(2, "setitimer"); - signal(SIGALRM, send_packet); - gettimeofday(&last_ts, NULL); while (1) { From 16d5383fb8153a4bd48c7cdee1163349ad7e6e98 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Wed, 18 Jul 2018 11:05:54 +0200 Subject: [PATCH 22/29] Add timestamped "starting" message --- echoc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/echoc.c b/echoc.c index eaed4e5..5eeaaa6 100644 --- a/echoc.c +++ b/echoc.c @@ -185,6 +185,9 @@ main(int argc, char *argv[]) err(2, "setitimer"); gettimeofday(&last_ts, NULL); + tm = localtime((time_t *)&last_ts.tv_sec); + strftime(date, sizeof(date), "%F %T", tm); + printf("%s.%06ld: starting\n", date, last_ts.tv_usec); while (1) { /* poll() loop to handle interruptions by SIGALRM */ From 4a15bdac0a016b065f89405a3b36a1655f21dfc7 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Wed, 18 Jul 2018 12:39:23 +0200 Subject: [PATCH 23/29] Add timestamped "aborting" message --- echoc.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/echoc.c b/echoc.c index 5eeaaa6..0d592bd 100644 --- a/echoc.c +++ b/echoc.c @@ -37,6 +37,7 @@ int sock = -1; int verbose = 0; +int aborting = 0; struct sockaddr *server; socklen_t serverlen; unsigned int seq = 0; @@ -48,11 +49,16 @@ usage(void) errx(2, "usage: echoc [-c nbr][-d][-i ms][-l len][-p port][-t ms][-v] server"); } +static void +sigint_handler(int unused) +{ + aborting = 1; +} + static void send_packet(int unused) { - char *buf; - + char *buf; buf = malloc(len); if (buf == NULL) return; @@ -172,9 +178,10 @@ main(int argc, char *argv[]) else ch = IP_PMTUDISC_DONT; if (setsockopt(sock, IPPROTO_IP, IP_MTU_DISCOVER, &ch, sizeof(ch)) < 0) - err(2, "setsockopt IP_MTU_DISCOVER"); + err(2, "setsockopt IP_MTU_DISCOVER"); #endif signal(SIGALRM, send_packet); + signal(SIGINT, sigint_handler); /* timer values */ itv.it_interval.tv_usec = interval*1000; @@ -189,9 +196,9 @@ main(int argc, char *argv[]) strftime(date, sizeof(date), "%F %T", tm); printf("%s.%06ld: starting\n", date, last_ts.tv_usec); - while (1) { + while (!aborting) { /* poll() loop to handle interruptions by SIGALRM */ - while (1) { + while (!aborting) { pfd[0].fd = sock; pfd[0].events = POLLIN; nfds = poll(pfd, 1, timeout); @@ -207,11 +214,13 @@ main(int argc, char *argv[]) break; } } + if (aborting) + break; if ((nfds == 0)) { if (verbose) printf("%d packet(s) dropped in %ld.%06ld s\n", seq - last, (long)diff.tv_sec, diff.tv_usec); - + if (disconnected == 1) { tm = localtime((time_t *)&last_ts.tv_sec); strftime(date, sizeof(date), "%F %T", tm); @@ -227,11 +236,11 @@ main(int argc, char *argv[]) &addrlen)) != len) { warn("recvfrom"); } - + if (verbose && (serverlen != addrlen || memcmp(&client, server, addrlen) != 0)) { if ((error = getnameinfo((struct sockaddr *)&client, - addrlen, name, sizeof(name), + addrlen, name, sizeof(name), NULL, 0, NI_DGRAM)) != 0) { warnx("%s", gai_strerror(error)); } else { @@ -262,6 +271,12 @@ main(int argc, char *argv[]) } } } + if (aborting) { + gettimeofday(&now, NULL); + tm = localtime((time_t *)&now.tv_sec); + strftime(date, sizeof(date), "%F %T", tm); + printf("%s.%06ld: aborting\n", date, now.tv_usec); + } close(sock); exit(0); } From 0153b223c0a9a8f4ff78607c33e2ad6e49e2fbb5 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Wed, 18 Jul 2018 19:04:42 +0200 Subject: [PATCH 24/29] white space police --- echoc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/echoc.c b/echoc.c index 0d592bd..269f4f6 100644 --- a/echoc.c +++ b/echoc.c @@ -89,7 +89,7 @@ main(int argc, char *argv[]) struct tm *tm; struct pollfd pfd[1]; socklen_t addrlen; - long interval = 100; /* default interval (ms) */ + long interval = 100; /* default interval (ms) */ long timeout = 500; /* default timeout (ms) */ int ch; int nfds, received = 0; @@ -175,10 +175,10 @@ main(int argc, char *argv[]) /* set the DF flag ? */ if (nofragment) ch = IP_PMTUDISC_DO; - else + else ch = IP_PMTUDISC_DONT; if (setsockopt(sock, IPPROTO_IP, IP_MTU_DISCOVER, &ch, sizeof(ch)) < 0) - err(2, "setsockopt IP_MTU_DISCOVER"); + err(2, "setsockopt IP_MTU_DISCOVER"); #endif signal(SIGALRM, send_packet); signal(SIGINT, sigint_handler); @@ -220,7 +220,7 @@ main(int argc, char *argv[]) if (verbose) printf("%d packet(s) dropped in %ld.%06ld s\n", seq - last, (long)diff.tv_sec, diff.tv_usec); - + if (disconnected == 1) { tm = localtime((time_t *)&last_ts.tv_sec); strftime(date, sizeof(date), "%F %T", tm); @@ -236,7 +236,7 @@ main(int argc, char *argv[]) &addrlen)) != len) { warn("recvfrom"); } - + if (verbose && (serverlen != addrlen || memcmp(&client, server, addrlen) != 0)) { if ((error = getnameinfo((struct sockaddr *)&client, From e757fa859503b9de32cf261f5ea70127383b4499 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Wed, 4 Aug 2021 07:57:39 +0000 Subject: [PATCH 25/29] Add LICENSE --- LICENSE | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..914ee49 --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ + Copyright (c) 2012-2015 Matthieu Herrb + + Permission to use, copy, modify, and distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. From b29605e530c7ac4c6504a6999cefabf1f44dd6be Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Wed, 4 Aug 2021 10:03:20 +0200 Subject: [PATCH 26/29] release echoc 0.6 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 8f24152..c0a27d3 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.65]) -AC_INIT([echoc], 0.5, [https://chiliproject.tetaneutral.net/projects/git-tetaneutral-net/repository/echoc], echoc) +AC_INIT([echoc], 0.6, [https://chiliproject.tetaneutral.net/projects/git-tetaneutral-net/repository/echoc], echoc) AM_INIT_AUTOMAKE([foreign dist-bzip2]) AC_CONFIG_MACRO_DIR([m4]) AC_PROG_CC From 7b587fd59fdb177a4e2f1ee24a5629e1dcaaf5fe Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Thu, 27 Apr 2023 13:55:23 +0200 Subject: [PATCH 27/29] Prepare for future development --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index c0a27d3..79db8aa 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.65]) -AC_INIT([echoc], 0.6, [https://chiliproject.tetaneutral.net/projects/git-tetaneutral-net/repository/echoc], echoc) +AC_INIT([echoc], 0.6.99, [https://chiliproject.tetaneutral.net/projects/git-tetaneutral-net/repository/echoc], echoc) AM_INIT_AUTOMAKE([foreign dist-bzip2]) AC_CONFIG_MACRO_DIR([m4]) AC_PROG_CC From 72eba42917b00ccd39b99a2ca69efb3b7370e505 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Thu, 27 Apr 2023 14:00:21 +0200 Subject: [PATCH 28/29] Update project URL --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 79db8aa..150ba8a 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.65]) -AC_INIT([echoc], 0.6.99, [https://chiliproject.tetaneutral.net/projects/git-tetaneutral-net/repository/echoc], echoc) +AC_INIT([echoc], 0.6.99, [https://gitlab.laas.fr/matthieu/echoc], echoc) AM_INIT_AUTOMAKE([foreign dist-bzip2]) AC_CONFIG_MACRO_DIR([m4]) AC_PROG_CC From 98a53d9bd231849beb6ec335cb2b828345e70c8d Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Tue, 16 Apr 2024 12:17:38 +0200 Subject: [PATCH 29/29] configure.ac: modernize for autoconf 2.71 --- configure.ac | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 150ba8a..f4e1c5d 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ -AC_PREREQ([2.65]) -AC_INIT([echoc], 0.6.99, [https://gitlab.laas.fr/matthieu/echoc], echoc) +AC_PREREQ([2.71]) +AC_INIT([echoc],[0.6.99],[https://gitlab.laas.fr/matthieu/echoc],[echoc]) AM_INIT_AUTOMAKE([foreign dist-bzip2]) AC_CONFIG_MACRO_DIR([m4]) AC_PROG_CC @@ -7,4 +7,5 @@ AC_PROG_CC AC_CHECK_HEADERS([bsd/stdlib.h]) AC_SEARCH_LIBS(strtonum, [bsd]) -AC_OUTPUT([Makefile]) +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT