From d625d804c6a2b985ab941233140f05f964ebcbbc Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Tue, 29 Sep 2015 18:53:51 +0200 Subject: [PATCH] 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) {