Compare commits
14 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
98a53d9bd2 | ||
![]() |
72eba42917 | ||
![]() |
7b587fd59f | ||
![]() |
b29605e530 | ||
![]() |
e757fa8595 | ||
![]() |
0153b223c0 | ||
![]() |
4a15bdac0a | ||
![]() |
16d5383fb8 | ||
![]() |
0f96d32d4c | ||
![]() |
d791054cfe | ||
![]() |
2d3d859d9b | ||
![]() |
c66fae7c45 | ||
![]() |
22d0ef7697 | ||
![]() |
97315cd612 |
5 changed files with 91 additions and 24 deletions
13
LICENSE
Normal file
13
LICENSE
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
Copyright (c) 2012-2015 Matthieu Herrb <matthieu@herrb.eu>
|
||||||
|
|
||||||
|
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.
|
24
README.md
24
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).
|
echo service (it should be activated in [x]inetd on the target host).
|
||||||
echoc displays the start/end date of loss of connectivity.
|
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 <matthieu@herrb.eu>
|
Copyright (c) 2012-2015 Matthieu Herrb <matthieu@herrb.eu>
|
||||||
|
|
||||||
|
|
13
autogen.sh
Executable file
13
autogen.sh
Executable file
|
@ -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
|
|
@ -1,5 +1,5 @@
|
||||||
AC_PREREQ([2.65])
|
AC_PREREQ([2.71])
|
||||||
AC_INIT([echoc], 0.4, [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])
|
AM_INIT_AUTOMAKE([foreign dist-bzip2])
|
||||||
AC_CONFIG_MACRO_DIR([m4])
|
AC_CONFIG_MACRO_DIR([m4])
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
|
@ -7,4 +7,5 @@ AC_PROG_CC
|
||||||
AC_CHECK_HEADERS([bsd/stdlib.h])
|
AC_CHECK_HEADERS([bsd/stdlib.h])
|
||||||
AC_SEARCH_LIBS(strtonum, [bsd])
|
AC_SEARCH_LIBS(strtonum, [bsd])
|
||||||
|
|
||||||
AC_OUTPUT([Makefile])
|
AC_CONFIG_FILES([Makefile])
|
||||||
|
AC_OUTPUT
|
||||||
|
|
56
echoc.c
56
echoc.c
|
@ -37,6 +37,7 @@
|
||||||
|
|
||||||
int sock = -1;
|
int sock = -1;
|
||||||
int verbose = 0;
|
int verbose = 0;
|
||||||
|
int aborting = 0;
|
||||||
struct sockaddr *server;
|
struct sockaddr *server;
|
||||||
socklen_t serverlen;
|
socklen_t serverlen;
|
||||||
unsigned int seq = 0;
|
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");
|
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
|
static void
|
||||||
send_packet(int unused)
|
send_packet(int unused)
|
||||||
{
|
{
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
buf = malloc(len);
|
buf = malloc(len);
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
return;
|
return;
|
||||||
|
@ -83,7 +89,7 @@ main(int argc, char *argv[])
|
||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
struct pollfd pfd[1];
|
struct pollfd pfd[1];
|
||||||
socklen_t addrlen;
|
socklen_t addrlen;
|
||||||
long interval = 100; /* default interval (ms) */
|
long interval = 100; /* default interval (ms) */
|
||||||
long timeout = 500; /* default timeout (ms) */
|
long timeout = 500; /* default timeout (ms) */
|
||||||
int ch;
|
int ch;
|
||||||
int nfds, received = 0;
|
int nfds, received = 0;
|
||||||
|
@ -161,18 +167,6 @@ main(int argc, char *argv[])
|
||||||
disconnected = 0;
|
disconnected = 0;
|
||||||
memset(&client, 0, sizeof(client));
|
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);
|
recvbuf = malloc(len);
|
||||||
if (recvbuf == NULL)
|
if (recvbuf == NULL)
|
||||||
err(2, "malloc receive buffer");
|
err(2, "malloc receive buffer");
|
||||||
|
@ -184,11 +178,27 @@ main(int argc, char *argv[])
|
||||||
else
|
else
|
||||||
ch = IP_PMTUDISC_DONT;
|
ch = IP_PMTUDISC_DONT;
|
||||||
if (setsockopt(sock, IPPROTO_IP, IP_MTU_DISCOVER, &ch, sizeof(ch)) < 0)
|
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
|
#endif
|
||||||
while (1) {
|
signal(SIGALRM, send_packet);
|
||||||
|
signal(SIGINT, sigint_handler);
|
||||||
|
|
||||||
|
/* 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");
|
||||||
|
|
||||||
|
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 (!aborting) {
|
||||||
/* poll() loop to handle interruptions by SIGALRM */
|
/* poll() loop to handle interruptions by SIGALRM */
|
||||||
while (1) {
|
while (!aborting) {
|
||||||
pfd[0].fd = sock;
|
pfd[0].fd = sock;
|
||||||
pfd[0].events = POLLIN;
|
pfd[0].events = POLLIN;
|
||||||
nfds = poll(pfd, 1, timeout);
|
nfds = poll(pfd, 1, timeout);
|
||||||
|
@ -204,6 +214,8 @@ main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (aborting)
|
||||||
|
break;
|
||||||
if ((nfds == 0)) {
|
if ((nfds == 0)) {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf("%d packet(s) dropped in %ld.%06ld s\n",
|
printf("%d packet(s) dropped in %ld.%06ld s\n",
|
||||||
|
@ -228,7 +240,7 @@ main(int argc, char *argv[])
|
||||||
if (verbose && (serverlen != addrlen ||
|
if (verbose && (serverlen != addrlen ||
|
||||||
memcmp(&client, server, addrlen) != 0)) {
|
memcmp(&client, server, addrlen) != 0)) {
|
||||||
if ((error = getnameinfo((struct sockaddr *)&client,
|
if ((error = getnameinfo((struct sockaddr *)&client,
|
||||||
addrlen, name, sizeof(name),
|
addrlen, name, sizeof(name),
|
||||||
NULL, 0, NI_DGRAM)) != 0) {
|
NULL, 0, NI_DGRAM)) != 0) {
|
||||||
warnx("%s", gai_strerror(error));
|
warnx("%s", gai_strerror(error));
|
||||||
} else {
|
} else {
|
||||||
|
@ -259,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);
|
close(sock);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue